CF1610F.Mashtali: a Space Oddysey
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
输入格式
The first line contains two integers n and m (1≤n≤105;1≤m≤105) — the numbers of vertices and edges in the graph.
The i -th line of the following m lines contains three integers ui , vi and wi (1≤ui,vi≤n;ui=vi;wi∈{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.
输出格式
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 ui to vertex vi , i -th character of the string should be 1 . Otherwise, it should be 2 .
输入输出样例
输入#1
6 7 1 2 1 1 3 2 2 3 2 1 4 1 4 5 1 2 5 2 2 6 2
输出#1
2 1212212
输入#2
6 7 1 2 2 1 3 2 2 3 2 1 4 2 4 5 2 2 5 2 2 6 2
输出#2
0 1212212
输入#3
6 7 1 2 1 1 3 1 2 3 1 1 4 1 4 5 1 2 5 1 2 6 1
输出#3
2 1212212
说明/提示
Explanation for the first sample:
vertices 2 and 5 are Oddyseys.Explanation for the third sample:
vertices 1 and 6 are Oddyseys.