#P7816. 「Stoi2029」以父之名

    ID: 6557 远端评测题 2500ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>搜索图论树形结构Special JudgeO2优化深度优先搜索,DFS图遍历圈和块构造

「Stoi2029」以父之名

Description

In hell, there are nn sinners waiting for judgment, numbered from 11 to nn. There are mm connections of sin among the sinners, numbered from 11 to mm. Each connection has a value of 11 or 22 and connects exactly two sinners.

Define a sinner's arrogance as the sum of the values of the connections between them and all other sinners. There may be more than one connection between two sinners; in that case, the values of all those connections should be counted. Because these sinners have borne too much evil, they have become disharmonious. Specifically, each sinner's arrogance is an odd number.

Now, God is going to judge them. The judgment works as follows: orient every connection, so that among the two sinners connected by this connection, one receives punishment and the other receives redemption, and their values are both equal to the value of this connection.

Because God upholds the Father's mercy and hopes the sinners receive punishment and redemption more evenly, He requires that after the judgment, for each sinner, the absolute value of the difference between the total punishment value and the total redemption value they receive must be exactly 11.

Since God is busy, He asks you, in the name of the Father, to find a way to perform the judgment. Because the Father's instruction cannot be wrong, such a method must exist.


Problem summary

Given an undirected graph with nn vertices and mm edges, where each edge weight is either 11 or 22. It is guaranteed that for every vertex, the sum of weights of incident edges is odd. You need to orient all edges so that for every vertex, the absolute value of the difference between the sum of incoming edge weights and the sum of outgoing edge weights is exactly 11. A solution is guaranteed to exist. Output any valid solution.

Input Format

The first line contains two positive integers n,mn,m, meaning there are nn sinners and mm connections of sin.

The next mm lines describe the edges. The (i+1)(i+1)-th line contains three positive integers ui,vi,wiu_i,v_i,w_i, meaning the ii-th connection connects uiu_i and viv_i and has value wiw_i.

Output Format

Output one line with mm digits. The ii-th digit is 00 if uiu_i receives punishment and viv_i receives redemption; it is 11 if viv_i receives punishment and uiu_i receives redemption.

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

00100

Hint

Sample explanation

The oriented graph is as follows:

More samples can be found in the attachment trial_sample.zip.


Constraints

This problem uses bundled testdata.

  • Special property A: all edge weights are 11, and between any two vertices there is only one simple path, and there are no multiple edges.
  • Special property B: for the same vertex, it is connected to at most one edge with weight 11 and at most one edge with weight 22.
Subtask Score 1n1\le n \le 1m1\le m \le Special property
11 77 1010 1515 None
22 2020 10310^3 3×1033\times10^3
33 3×1053 \times 10^5 A
44 B
55 3333 10610^6 3×1063 \times 10^6 None

For 100%100\% of the testdata: 1ui,vin1061 \le u_i,v_i \le n \le 10^6, 1m3×1061 \le m \le 3 \times 10^6, and wi{1,2}w_i \in \{1,2\}.

In the attachment trial_sample.zip:

  • trial_sample1.in is sample #1.
  • trial_sample2.in satisfies special property A.
  • trial_sample3.in satisfies special property B.
  • trial_sample4.in does not satisfy any special property.

There is also checker.exe in the same directory.


Notes

The input and output are large, so please use fast I/O methods.

This problem provides the Special Judge source code and checker.exe for debugging. On Windows, usage is as follows:
In the command line, run the command in the target folder:

checker.exe data.in data.out data.out

Here, data.in is the input data file, and data.out is the output file produced by your program. Check the judging result.

  • Perfect answer. means the answer is correct.
  • Wrong answer on node x, and the difference is d. means the answer is wrong: for node xx, the absolute value of the difference between the sum of incoming edge weights and the sum of outgoing edge weights is dd instead of 11.
  • Invalid answer. means the output string length is incorrect or it contains invalid characters.

Be sure to keep the output format correct, otherwise the Special Judge may return unpredictable results such as Unknown Error.

Translated by ChatGPT 5