CF1726D.Edge Split

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a connected, undirected and unweighted graph with nn vertices and mm edges. Notice the limit on the number of edges: mn+2m \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 c1c_1 . Similarly, consider only the blue edges and count the number of connected components in the graph. Let this value be c2c_2 .

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

输入格式

Each test contains multiple test cases. The first line contains a single integer tt ( 1t1051 \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 nn and mm ( 2n21052 \le n \le 2 \cdot 10^5 ; n1mmin(n+2,n(n1)2)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.

mm lines follow. The ii -th line contains two integers uiu_i and viv_i ( 1ui,vin1 \le u_i,v_i \le n , uiviu_i \ne v_i ) denoting that the ii -th edge goes between vertices uiu_i and viv_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 nn over all test cases does not exceed 10610^6 . It is guaranteed that the sum of mm over all test cases does not exceed 21062 \cdot 10^6 .

输出格式

For each test case, output a binary string of length mm . The ii -th character of the string should be 1 if the ii -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.

输入输出样例

  • 输入#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

    输出#1

    0111010
    1001
    0001111
    0

说明/提示

  • The corresponding graph of the first test case is: c1+c2=1+2=3c_1 + c_2 = 1 + 2 = 3
  • The corresponding graph of the second test case is: c1+c2=2+2=4c_1 + c_2 = 2 + 2 = 4
首页