#P6346. [CCO 2017] 专业网络
[CCO 2017] 专业网络
Description
Kevin is building his professional network in a community. Unfortunately, he is an outsider and does not know anyone in the community yet. However, he can form friendships with people.
However, not many people in the community want to be friends with an outsider. Each of the people Kevin wants to befriend has a similar but different rule for becoming friends with an outsider. After Kevin already directly knows people in the community, person is willing to become friends with Kevin; otherwise, Kevin must pay a cost of to become friends with them.
Your task is to make Kevin become friends with all people while minimizing the total cost he pays.
Input Format
The first line contains an integer .
The next lines each contain two integers .
Output Format
Output one integer on a single line, representing the minimum total cost Kevin needs to pay.
4
3 3
1 2
0 5
3 4
3
5
0 9
1 8
2 7
3 6
4 5
0
3
0 6
2 7
3 8
8
Hint
Sample Explanation
For Sample : Kevin can immediately become friends with person . After establishing this friendship, he can also become friends with person . He needs to pay a cost of to become friends with person . Then he has friends in total, which allows him to become friends with person .
For Sample : Kevin does not need to pay anything to become friends with everyone.
For Sample : Kevin should immediately become friends with person , then pay a cost of to become friends with person , and finally establish a friendship with person .
Constraints and Notes
This problem uses bundled multi-test evaluation, with subtasks in total.
- Subtask 1 (15 points): all are equal to ;
- Subtask 2 (30 points): ;
- Subtask 3 (30 points): .
- Subtask 4 (25 points): .
For all testdata, it is guaranteed that , , , and .
Source: CCO 2017 Day2 “Professional Network”.
Note: This translation is from LOJ.
Translated by ChatGPT 5
京公网安备 11011102002149号