#P7228. [COCI 2015/2016 #3] MOLEKULE

    ID: 6233 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>2015Special Judge深度优先搜索,DFSCOCI

[COCI 2015/2016 #3] MOLEKULE

Description

There are NN vertices and N1N-1 undirected edges. Define the cost of a directed graph as the length of the longest path in this directed graph.

Now assign directions to these N1N-1 undirected edges so that the cost of the resulting directed graph is minimized.

Output one such direction assignment.

Input Format

The first line contains an integer NN, the number of vertices.
The next N1N-1 lines each contain two integers ai,bia_i, b_i, representing an edge.

Output Format

Output N1N-1 lines, each containing one integer rr:

  • If r=1r=1, it means the direction is from aia_i to bib_i.
  • If r=0r=0, it means the direction is from bib_i to aia_i.
3
1 2
2 3
1
0
4
2 1
1 3
4 1
0
1
0

Hint

Explanation of Sample 1

As shown in the figure:

The cost of this graph is 11. Note that 0 10\ 1 is also an optimal solution.

Explanation of Sample 2

As shown in the figure:

Constraints

For 30%30\% of the testdata, N20N \le 20.
For 100%100\% of the testdata, 2N1052 \le N \le 10^5, 1ai,biN1 \le a_i, b_i \le N.

This problem uses Special Judge.
You only need to output any valid solution.

Notes

Translated from COCI 2015-2016 #3 C MOLEKULE.

Translated by ChatGPT 5