Role: Student: Name: Abhinav
Role: Student: Name: Abhinav
CHALLENGE INFORMATION
You have already solved this challenge ! Though you can run the code with different logic !
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
Test Cases
Logical Test Cases
4 2 4 2
1 2 2 3
3 4 2 4
1 1
2 4 1 4
Test Case 1
KEYWORD
while(m--)
5 475 50
Code
You have already solved this challenge ! Though you can run the code with different logic !
Editor
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
For any inquiries, please contact your Faculty or Course Coordinator Student Manual DOWNLOAD