#P10298. [CCC 2024 S4] Painting Roads

    ID: 11623 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>图论2024Special JudgeCCC(加拿大)生成树构造

[CCC 2024 S4] Painting Roads

Problem Description

The mayor of Kitchener, Alanna, has successfully improved the city’s road plan. However, a salesperson from RedBlue City still complains that the roads are not colorful enough. Alanna’s next task is to paint some roads.

Kitchener’s road plan can be represented as NN intersections and MM roads. Road ii connects intersection uiu_i and intersection viv_i. At the beginning, all roads are gray. Alanna wants to paint some roads red or blue such that:

  • For every gray road, suppose it connects intersections uiu_i and viv_i. There must exist a path from intersection uiu_i to intersection viv_i such that the road colors along the path alternate between red and blue, and no road on the path is gray.

To reduce the city’s spending, Alanna wants to paint as few roads as possible. Please help Alanna design a painting plan that satisfies the requirement.

Input Format

The first line contains two integers NN and MM (1N,M2×1051 \leq N, M \leq 2 \times 10^5).

Each of the next MM lines contains two integers uiu_i and viv_i, indicating that there is a road connecting intersections uiu_i and viv_i (1ui,viN1 \leq u_i, v_i \leq N, uiviu_i \neq v_i).

Between any two intersections, there is at most one road.

Output Format

Output a string of length MM describing the painting plan. The ii-th character represents the color of road ii: R means red, B means blue, and G means gray (unpainted).

Note that you must minimize the number of painted roads while satisfying the condition. If there are multiple such painting plans, output any one of them.

5 7
1 2
2 4
5 2
4 5
4 3
1 3
1 4

BRGBBGG

4 2
1 2
3 4

BB

Hint

[Sample 1 Explanation]

A diagram of the intersections and the valid roads is shown below. This plan minimizes the number of painted roads. Note that each road is labeled with R (red), B (blue), or G (gray).

All unpainted roads satisfy the condition:

  • The second road, labeled G2G_2, connects intersections 22 and 44. On the path 2,1,42, 1, 4, the roads are painted red, blue.
  • The third road, labeled G3G_3, connects intersections 55 and 22. On the path 5,4,1,25, 4, 1, 2, the roads are painted red, blue, red.
  • The fifth road, labeled G5G_5, connects intersections 44 and 33. On the path 4,1,34, 1, 3, the roads are painted blue, red.

[Sample 2 Explanation]

Note that Kitchener’s road graph may be disconnected.

[Constraints]

This problem uses bundled testdata.

For all testdata, it is guaranteed that 1N,M2×1051 \leq N, M \leq 2 \times 10^5, 1ui,viN1 \leq u_i, v_i \leq N, and uiviu_i \neq v_i.

The table below shows the distribution of the 1515 points:

Points Additional Condition
22 For every 1i<N1 \leq i < N, there is a road connecting ii and i+1i + 1 (there may also be other roads).
33 The graph is connected and N=MN = M.
No road belongs to at least two simple cycles at the same time (see the definition below).
77 None.

Definition: Using uvu \leftrightarrow v to represent a road connecting uu and vv, for k3k \geq 3 and all wiw_i pairwise distinct, the sequence $w_1 \leftrightarrow w_2 \leftrightarrow \cdots \leftrightarrow w_k \leftrightarrow w_1$ is called a simple cycle.

Translated by ChatGPT 5