Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
24 views2 pages

Problem - 1726D - Codeforces

The document describes a programming problem from Codeforces Round 819, where participants must color the edges of a connected, undirected graph to minimize the sum of connected components formed by red and blue edges. It provides input specifications, constraints, and examples of test cases. The output should be a binary string indicating the color of each edge, with multiple valid solutions possible for the minimum configuration.

Uploaded by

Yhlas Yklymow
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

Problem - 1726D - Codeforces

The document describes a programming problem from Codeforces Round 819, where participants must color the edges of a connected, undirected graph to minimize the sum of connected components formed by red and blue edges. It provides input specifications, constraints, and examples of test cases. The output should be a binary string indicating the color of each edge, with multiple valid solutions possible for the minimum configuration.

Uploaded by

Yhlas Yklymow
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

5/22/24, 12:11 PM Problem - 1726D - Codeforces

|
stdfloat | Logout

HOME TOP CATALOG CONTESTS GYM PROBLEMSET GROUPS RATING EDU API CALENDAR HELP

PROBLEMS SUBMIT STATUS STANDINGS CUSTOM TEST

Codeforces Round 819 (Div. 1 + Div. 2)


D. Edge Split and Grimoire of Code Annual Contest
2022
time limit per test: 2 seconds
Finished
memory limit per test: 256 megabytes
input: standard input Practice
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 edges: m ≤ n + 2 . → Virtual participation 
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 → Clone Contest to Mashup 
c1 . Similarly, consider only the blue edges and count the number of connected components in
the graph. Let this value be c2 .
→ Submit?
Find an assignment of colors to the edges such that the quantity c1 + c2 is minimised.
Language: GNU G++20 13.2 (64 bit, winlibs)
Input
5
Each test contains multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 10 ) Choose
Choose File No file chosen
file:
— the number of test cases. Description of the test cases follows.
Submit
The first line of each test case contains two integers n and m (2 ≤ n ≤ 2 ⋅ 105 ;
n − 1 ≤ m ≤ min (n + 2, ) ) — the number of vertices and the number of edges
n⋅(n−1)
2
respectively. → Contest materials

m lines follow. The i -th line contains two integers ui and vi (1 ≤ ui , vi ≤ n, ui ≠ vi ) Announcement (en)
denoting that the i -th edge goes between vertices ui and vi . The input is guaranteed to have
Tutorial (en)
no multiple edges or self loops. The graph is also guaranteed to be connected.

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

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.

Example
input Copy

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

https://mirror.codeforces.com/problemset/problem/1726/D 1/2
5/22/24, 12:11 PM Problem - 1726D - Codeforces
4 5
1 4
5 6
6 2
2 1
1 2

output Copy

0111010
1001
0001111
0

Note

The corresponding graph of the first test case is:

c1 + c2 = 1 + 2 = 3

The corresponding graph of the second test case is:

c1 + c2 = 2 + 2 = 4

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: May/22/2024 12:06:48UTC+5 (l1).
Desktop version, switch to mobile version.
Privacy Policy

Supported by

https://mirror.codeforces.com/problemset/problem/1726/D 2/2

You might also like