Codeforces Round 819 (Div. 1 + Div. 2) and Grimoire of Code Annual Contest 2022
D
Edge Split
Codeforces
2000
原题
← CE →
翻译中…

You are given a connected, undirected and unweighted graph with $n$ vertices and $m$ edges. Notice the limit on the number of edges: $m \le n + 2$.

翻译中…

Let's say we color some of the edges red and the remaining edges blue. Now consider only the red edges and count the number of connected components in the graph. Let this value be $c_1$. Similarly, consider only the blue edges and count the number of connected components in the graph. Let this value be $c_2$.

翻译中…

Find an assignment of colors to the edges such that the quantity $c_1+c_2$ is minimised.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 10^5$) — the number of test cases. Description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $m$ ($2 \le n \le 2 \cdot 10^5$; $n-1 \leq m \leq \min{\left(n+2,\frac{n \cdot (n-1)}{2}\right)}$) — the number of vertices and the number of edges respectively.

翻译中…

$m$ lines follow. The $i$-th line contains two integers $u_i$ and $v_i$ ($1 \le u_i,v_i \le n$, $u_i \ne v_i$) denoting that the $i$-th edge goes between vertices $u_i$ and $v_i$. The input is guaranteed to have no multiple edges or self loops. The graph is also guaranteed to be connected.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$. It is guaranteed that the sum of $m$ over all test cases does not exceed $2 \cdot 10^6$.

翻译中…

Output

翻译中…

For each test case, output a binary string of length $m$. The $i$-th character of the string should be 1 if the $i$-th edge should be colored red, and 0 if it should be colored blue. If there are multiple ways to assign colors to edges that give the minimum answer, you may output any.

翻译中…

Note

翻译中…
  • The corresponding graph of the first test case is: image $c_1 + c_2 = 1 + 2 = 3$
  • The corresponding graph of the second test case is: image $c_1 + c_2 = 2 + 2 = 4$
翻译中…

样例

Input #1
4
5 7
1 2
2 3
3 4
4 5
5 1
1 3
3 5
4 4
1 2
2 3
1 4
3 4
6 7
1 2
1 3
3 4
4 5
1 4
5 6
6 2
2 1
1 2
Output #1
0111010
1001
0001111
0
InputCopy OutputCopy
题目信息
题号
1726D
时间限制
2 s
内存限制
256 MB
标签
暴力
构造
DFS 及类似
并查集
图论
概率论
树

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