#P5811. [IOI 2019] 景点划分
[IOI 2019] 景点划分
Description
Baku has sightseeing spots, numbered from to . There are also bidirectional roads, numbered from to . Each road connects two different spots. Using these roads, it is possible to travel between any two spots.
Fatima plans to visit all the spots within three days. She has decided to visit spots on the first day, spots on the second day, and spots on the third day. Therefore, she wants to split the spots into three sets , , and , with sizes , , and respectively. Each spot belongs to exactly one set, so .
Fatima wants to find a split into , , and such that at least two of these three sets are connected. A set of spots is called connected if it is possible to travel between any two spots in using the roads, without having to pass through any spot not in . If the above requirement is satisfied, then the split into , , and is called valid.
Please help Fatima find a valid split (given , , and ), or determine that no valid split exists. If multiple valid splits exist, you may output any one of them.
Implementation details
You need to implement the following function:
int [] find_split(int n,int a,int b,int c,int [] p,int [] q)
- : the number of sightseeing spots.
- , , and : the desired sizes of sets , , and .
- and : arrays of length containing the endpoints of the roads. For each (), and are the two spots connected by road .
- The function should return an array of length . Call this array . If no valid split exists, should contain zeros. Otherwise, for , should be one of , , or , indicating that spot is assigned to set , , or , respectively.
Input Format
The first line contains two positive integers and .
The second line contains three positive integers , , and .
Line (for ) contains two positive integers and .
Their meanings are the same as in the statement.
Output Format
One line, containing the array returned by find_split.
9 10
4 2 3
0 1
0 2
0 3
0 4
0 6
0 8
1 7
3 7
4 5
5 6
1 1 3 1 2 2 3 1 3
Hint
Sample explanation

One possible solution is . This solution describes the following split: , , . Sets and are connected.
Constraints
For of the testdata:
- .
- .
- .
- .
- There is at most one road between each pair of spots.
- Using these roads, it is possible to travel between any two spots.
- For , and .
Subtasks
- ( points) Each spot can be an endpoint of at most two roads.
- ( points) .
- ( points) .
- ( points) , .
- ( points) No additional constraints.
Translated by ChatGPT 5
京公网安备 11011102002149号