Codeforces Global Round 17
F
Mashtali: a Space Oddysey
Codeforces
3000
原题
← EG →
翻译中…

Lee was planning to get closer to Mashtali's heart to proceed with his evil plan(which we're not aware of, yet), so he decided to beautify Mashtali's graph. But he made several rules for himself. And also he was too busy with his plans that he didn't have time for such minor tasks, so he asked you for help.

翻译中…

Mashtali's graph is an undirected weighted graph with $n$ vertices and $m$ edges with weights equal to either $1$ or $2$. Lee wants to direct the edges of Mashtali's graph so that it will be as beautiful as possible.

翻译中…

Lee thinks that the beauty of a directed weighted graph is equal to the number of its Oddysey vertices. A vertex $v$ is an Oddysey vertex if $|d^+(v) - d^-(v)| = 1$, where $d^+(v)$ is the sum of weights of the outgoing from $v$ edges, and $d^-(v)$ is the sum of the weights of the incoming to $v$ edges.

翻译中…

Find the largest possible beauty of a graph that Lee can achieve by directing the edges of Mashtali's graph. In addition, find any way to achieve it.

翻译中…

Note that you have to orient each edge.

翻译中…

Input

翻译中…

The first line contains two integers $n$ and $m$ $(1 \le n \le 10^5;\; 1 \le m \le 10^5)$ — the numbers of vertices and edges in the graph.

翻译中…

The $i$-th line of the following $m$ lines contains three integers $u_i$, $v_i$ and $w_i$ $( 1 \le u_i , v_i \le n;\; u_i \neq v_i;\; \bf{w_i \in \{1, 2\}} )$ — the endpoints of the $i$-th edge and its weight.

翻译中…

Note that the graph doesn't have to be connected, and it might contain multiple edges.

翻译中…

Output

翻译中…

In the first line print a single integer — the maximum beauty of the graph Lee can achieve.

翻译中…

In the second line print a string of length $m$ consisting of $1$s and $2$s — directions of the edges.

翻译中…

If you decide to direct the $i$-th edge from vertex $u_i$ to vertex $v_i$, $i$-th character of the string should be $1$. Otherwise, it should be $2$.

翻译中…

Note

翻译中…

Explanation for the first sample:

翻译中…

image vertices $2$ and $5$ are Oddyseys.

翻译中…

Explanation for the third sample:

翻译中…

image vertices $1$ and $6$ are Oddyseys.

翻译中…

样例

Input #1
6 7
1 2 1
1 3 2
2 3 2
1 4 1
4 5 1
2 5 2
2 6 2
Output #1
2
1212212
InputCopy OutputCopy
Input #2
6 7
1 2 2
1 3 2
2 3 2
1 4 2
4 5 2
2 5 2
2 6 2
Output #2
0
1212212
InputCopy OutputCopy
Input #3
6 7
1 2 1
1 3 1
2 3 1
1 4 1
4 5 1
2 5 1
2 6 1
Output #3
2
1212212
InputCopy OutputCopy
题目信息
题号
1610F
时间限制
1 s
内存限制
256 MB
标签
构造
DFS 及类似
图论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。