0% found this document useful (0 votes)
27 views4 pages

Role: Student: Name: Abhinav

Uploaded by

Abhinav Vats
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)
27 views4 pages

Role: Student: Name: Abhinav

Uploaded by

Abhinav Vats
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/ 4

eLab Role: Student Name: Abhinav Id: 307589233604 Dept: Computer Science And Engineering LOGOUT

November 11th 2024, 11:39:45 Pm

CHALLENGE INFORMATION

You have already solved this challenge ! Though you can run the code with different logic !

Course DS Session Graph Question Information Level 1 Challenge 84

Problem Question description

Byteland has n cities and m roads between them. The goal is to construct new roads so that there is a route between any two cities.
Your task is to find out the minimum number of roads required, and also determine which roads should be built.

Constraints

1≤n≤10^5
1≤m≤2⋅10^5
1≤a,b≤n

Input

The first input line has two integers n and m: the number of cities and roads. The cities are numbered 1,2,…,n.

After that, there are m lines describing the roads. Each line has two integers a and b: there is a road between those cities.

A road always connects two different cities, and there is at most one road between any two cities.

Output

First print an integer k: the number of required roads.


Then, print k lines that describe the new roads. You can print any valid solution.

Test Cases
Logical Test Cases

Test Case 1 Test Case 2

INPUT (STDIN) INPUT (STDIN)

4 2 4 2
1 2 2 3
3 4 2 4

EXPECTED OUTPUT EXPECTED OUTPUT

1 1
2 4 1 4

Mandatory Test Cases

Test Case 1

KEYWORD

while(m--)

Complexity Test Cases


Test Case 1 Test Case 2 Test Case 3

CYCLOMATIC COMPLEXITY TOKEN COUNT NLOC

5 475 50

Code
You have already solved this challenge ! Though you can run the code with different logic !
Editor

Code Editor c Custom Input (stdin) T1 T2

1 #include <bits/stdc++.h>
Type Here
2
3 using namespace std;
4 //abhinav Vats RA2311003030310
5
6 #define rep(i, a, b) for(int i = a; i < (b); ++i Output MATCH T1 MATCH T2
7 #define trav(a, x) for(auto& a : x)
8 #define all(x) begin(x), end(x)
9 #define sz(x) (int)(x).size()
10 typedef long long ll;
Empty
11 typedef pair<int, int> pii;
12 typedef vector<int> vi;
13 vi val, comp, z, cont; Complexity Analysis
14 int Time, ncomps;
15 template<class G, class F> int dfs(int j, G& g, F
16 int low = val[j] = ++Time, x; z.push_back(j);
17 trav(e,g[j]) if (comp[e] < 0) Test Case Status
18 low = min(low, val[e] ?: dfs(e,g,f));
19 if (low == val[j]) {
20 do {
21 x = z.back(); z.pop_back();
22 comp[x] = ncomps;
23 cont.push_back(x);
24 } while (x != j);
25 f(cont); cont.clear();
26 ncomps++;
26 ncomps++;
27 }
28
SAVE RESET RUN EVALUATE

Waiting for your Submission !


Your code will be Evaluated

For any inquiries, please contact your Faculty or Course Coordinator Student Manual DOWNLOAD

You might also like