#P5811. [IOI 2019] 景点划分

[IOI 2019] 景点划分

Description

Baku has nn sightseeing spots, numbered from 00 to n1n-1. There are also mm bidirectional roads, numbered from 00 to m1m-1. 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 aa spots on the first day, bb spots on the second day, and cc spots on the third day. Therefore, she wants to split the nn spots into three sets AA, BB, and CC, with sizes aa, bb, and cc respectively. Each spot belongs to exactly one set, so a+b+c=na+b+c=n.

Fatima wants to find a split into AA, BB, and CC such that at least two of these three sets are connected. A set of spots SS is called connected if it is possible to travel between any two spots in SS using the roads, without having to pass through any spot not in SS. If the above requirement is satisfied, then the split into AA, BB, and CC is called valid.

Please help Fatima find a valid split (given aa, bb, and cc), 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)

  • nn: the number of sightseeing spots.
  • aa, bb, and cc: the desired sizes of sets AA, BB, and CC.
  • pp and qq: arrays of length mm containing the endpoints of the roads. For each ii (0im1 0 \le i \le m-1 ), p[i]p[i] and q[i]q[i] are the two spots connected by road ii.
  • The function should return an array of length nn. Call this array ss. If no valid split exists, ss should contain nn zeros. Otherwise, for 0in10 \le i \le n-1, s[i]s[i] should be one of 11, 22, or 33, indicating that spot ii is assigned to set AA, BB, or CC, respectively.

Input Format

The first line contains two positive integers nn and mm.

The second line contains three positive integers aa, bb, and cc.

Line 3+i3+i (for 0im1 0 \le i \le m-1 ) contains two positive integers p[i]p[i] and q[i]q[i].

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 [1,1,3,1,2,2,3,1,3][1,1,3,1,2,2,3,1,3]. This solution describes the following split: A={0,1,3,7}A=\{0,1,3,7\}, B={4,5}B=\{4,5\}, C={2,6,8}C=\{2,6,8\}. Sets AA and BB are connected.

Constraints

For 100%100\% of the testdata:

  • 3n1053 \le n \le 10^5.
  • 2m2×1052 \le m \le 2 \times 10^5.
  • 1a,b,cn1 \le a,b,c \le n.
  • a+b+c=na+b+c=n.
  • There is at most one road between each pair of spots.
  • Using these roads, it is possible to travel between any two spots.
  • For 0im10 \le i \le m-1, 0p[i],q[i]n10 \le p[i],q[i] \le n-1 and p[i]q[i]p[i] ≠ q[i].

Subtasks

  1. (77 points) Each spot can be an endpoint of at most two roads.
  2. (1111 points) a=1a=1.
  3. (2222 points) m=n1m=n-1.
  4. (2424 points) n2500n \le 2500, m5000m \le 5000.
  5. (3636 points) No additional constraints.

Translated by ChatGPT 5