GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Tuesday, 6 September 2022

[Solution] Edge Split Codeforces Solution



D. Edge Split
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a connected, undirected and unweighted graph with n vertices and m edges. Notice the limit on the number of edgesmn+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 c1. Similarly, consider only the blue edges and count the number of connected components in the graph. Let this value be c2.

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

Input

Each test contains multiple test cases. The first line contains a single integer t (1t105) — the number of test cases. Description of the test cases follows.

The first line of each test case contains two integers n and m (2n2105n1mmin(n+2,n(n1)2)) — the number of vertices and the number of edges respectively.

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

m lines follow. The i-th line contains two integers ui and vi (1ui,vinuivi) denoting that the i-th edge goes between vertices ui and vi. 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 106. It is guaranteed that the sum of m over all test cases does not exceed 2106.

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.

No comments:

Post a Comment