Repovive
  • Dashboard
  • Ranking
  • Submissions
  • Discussion
  1. Contests
  2. Starter Round 8Rated: < 1700
  3. 23G
Sponsor
Abhishek Choudhary

My submissions

/
/
/
/

Announcements

My submissions

/
/
/
/

Announcements

Solve
Author

23G. Keyring Order

3500 pts·2s·256 MB

Constraints

Input

Output

Samples

Input
t
2
Case 1
2 1
1 2 1
Case 2
7 3
1 2 1
2 3 2
3 4 3
4 5 2
5 6 1
3 7 3
Explanation
Case 1

Starting at either endpoint, you can open the only door.

Case 2

Starting at vertex 3, 4, or 7, you can open both doors of keyring 3, then both doors of keyring 2, and finally both doors of keyring 1. From vertex 2 or 5, neither adjacent keyring can be completed before switching keyrings. From vertex 1 or 6, the first door forces you to start keyring 1, but its other door cannot yet be reached.

Output
Case 1
11
Case 2
0011001
Input
t
3
Case 1
5 2
1 2 1
2 3 2
3 4 1
4 5 2
Case 2
4 2
1 2 1
2 3 2
3 4 1
Case 3
6 3
1 2 1
1 3 2
1 4 1
1 5 3
1 6 2
Explanation
Case 1

The two doors of either keyring are separated by a door of the other keyring. Whichever keyring you start with, you cannot finish it without first using the other one. No starting vertex works.

Case 2

Starting at vertex 2 or 3, open the door of keyring 2 first, then the two doors of keyring 1. Starting at vertex 1 or 4 forces keyring 1 first, but its other door is unreachable without using keyring 2.

Case 3

Every starting vertex works. From a leaf, first finish the keyring of its incident door; all its doors can be reached through vertex 1. You can then finish each remaining keyring. Starting at vertex 1 also allows any order of keyrings.

Output
Case 1
00000
Case 2
0110
Case 3
111111

You are given a tree with nnn vertices, numbered from 111 to nnn. There is a closed door on every edge.

Each door has exactly one key. These keys are divided among mmm nonempty keyrings, numbered from 111 to mmm. You carry all the keyrings from the beginning.

You choose a starting vertex. You may move through open doors in either direction any number of times. If you are at either endpoint of an edge with a closed door, you may use its key to open it. Once opened, a door remains open forever.

You may use the keyrings in any order. However, once you open a door using a keyring, you must open every door whose key belongs to that keyring before you can open a door using another keyring. You may choose the order of the keys within each keyring.

For every vertex, determine whether it is possible to open all the doors when starting there.

Output a binary string sss of length nnn, where sis_isi​ is 111 if starting at vertex iii is possible, and 000 otherwise.

  • 1≤t≤1041 \le t \le 10^41≤t≤104
  • 2≤n≤2×1052 \le n \le 2 \times 10^52≤n≤2×105
  • 1≤m<n1 \le m < n1≤m<n
  • 1≤ui,vi≤n1 \le u_i,v_i \le n1≤ui​,vi​≤n, ui≠viu_i \ne v_iui​=vi​
  • 1≤ci≤m1 \le c_i \le m1≤ci​≤m
  • The given edges form a tree.
  • Every keyring contains at least one key: each number from 111 to mmm appears among c1,c2,…,cn−1c_1,c_2,\ldots,c_{n-1}c1​,c2​,…,cn−1​.
  • The sum of nnn over all test cases is at most 2×1052 \times 10^52×105.
ttt nmu1v1c1u2v2c2⋮un−1vn−1cn−1}×t\left. \begin{array}{l} n \quad m \\ u_1 \quad v_1 \quad c_1 \\ u_2 \quad v_2 \quad c_2 \\ \vdots \\ u_{n-1} \quad v_{n-1} \quad c_{n-1} \end{array} \right\} \times tnmu1​v1​c1​u2​v2​c2​⋮un−1​vn−1​cn−1​​⎭⎬⎫​×t

Each triple ui,vi,ciu_i,v_i,c_iui​,vi​,ci​ describes an edge between vertices uiu_iui​ and viv_ivi​ whose door has its key on keyring cic_ici​.

s}×t\left. \begin{array}{l} s \end{array} \right\} \times ts​}×t

For each test case, output one binary string sss of length nnn, without spaces between its characters.