#P5875. [IOI 2014] friend 朋友
[IOI 2014] friend 朋友
Description
We build a social network consisting of people numbered . Some pairs of people in the network will become friends. If person becomes a friend of person , then person will also become a friend of person .
These people will join the network in stages, also numbered from to . Person joins in stage . In stage , person joins the network and is the only person. After that, in each of the remaining stages, one person will be added to the network by a host, and this host can be any person already in the network. In stage (), the host can add person to the network using one of the following three methods:
- IAmYourFriend: Make person become friends only with the host.
- MyFriendsAreYourFriends: Make person become friends with each of the host's current friends. Note that this method does not make person become friends with the host.
- WeAreYourFriends: Make person become friends with the host, and also become friends with each of the host's current friends.
After building the network, we want to choose a survey sample, that is, select a group of people from the network. Since friends usually have similar interests, the sample should not contain any pair of people who are friends with each other. Each person has a survey credibility value, given as a positive integer, and we want to find a sample with the maximum total credibility.
Task
Given the description of each stage and the credibility value of each person, find a sample with the maximum total credibility. You only need to implement the function findSample.
findSample(n, confidence, host, protocol)- : the number of people.
confidence: an array of size ;confidence[i]is the credibility of person .host: an array of size ;host[i]is the host of stage .protocol: an array of size ;protocol[i]is the code of the method used in stage ():0means IAmYourFriend,1means MyFriendsAreYourFriends, and2means WeAreYourFriends.- Since there is no host in stage
0,host[0]andprotocol[0]are undefined, and your program must not access them.
This function should return the maximum possible total credibility of the sample.
Input Format
Below is the input format for the interactive library.
Line : a positive integer , the number of people.
Line : integers $\mathrm{confidence}[0],\ldots,\mathrm{confidence}[n-1]$.
Line : integers $\mathrm{host}[1],\mathrm{protocol}[1], \mathrm{host}[2], \mathrm{protocol}[2],\cdots, \mathrm{host}[n-1], \mathrm{protocol}[n-1]$.
Output Format
This problem only supports the C++ language series.
You can only submit one source file implementing the function above. The name and interface must follow the requirements below. Do not add extra header files.
int findSample(int n, int confidence[], int host[], int protocol[]);
6
13 3 6 20 10 15
0 0 0 1 1 2 2 1 0 0
35
Hint
For of the testdata, , .
| Subtask | Score | Credibility | Method used | |
|---|---|---|---|---|
| 1 | all three methods | |||
| 2 | only MyFriendsAreYourFriends |
|||
| 3 | only WeAreYourFriends |
|||
| 4 | only IAmYourFriend |
|||
| 5 | all credibility values are | only MyFriendsAreYourFriends and IAmYourFriend |
||
| 6 | all three methods |
Translated by ChatGPT 5
京公网安备 11011102002149号