[Solution] Edge Split Codeforces Solution
You are given a connected, undirected and unweighted graph with vertices and edges. Notice the limit on the number of edges: .
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 . Similarly, consider only the blue edges and count the number of connected components in the graph. Let this value be .
Find an assignment of colors to the edges such that the quantity is minimised.
Each test contains multiple test cases. The first line contains a single integer () — the number of test cases. Description of the test cases follows.
The first line of each test case contains two integers and (; ) — the number of vertices and the number of edges respectively.
lines follow. The -th line contains two integers and (, ) denoting that the -th edge goes between vertices and . 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 over all test cases does not exceed . It is guaranteed that the sum of over all test cases does not exceed .
For each test case, output a binary string of length . The -th character of the string should be 1 if the -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.
No comments:
Post a Comment