Task: | Light rail connections |
Sender: | ¯\_(._.)_/¯ |
Submission time: | 2024-11-16 13:59:28 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.01 s | details |
#3 | ACCEPTED | 0.01 s | details |
#4 | ACCEPTED | 0.00 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | ACCEPTED | 0.00 s | details |
#7 | ACCEPTED | 0.01 s | details |
#8 | ACCEPTED | 0.00 s | details |
#9 | ACCEPTED | 0.00 s | details |
#10 | ACCEPTED | 0.00 s | details |
#11 | ACCEPTED | 0.01 s | details |
#12 | ACCEPTED | 0.01 s | details |
#13 | ACCEPTED | 0.01 s | details |
#14 | ACCEPTED | 0.01 s | details |
#15 | ACCEPTED | 0.00 s | details |
#16 | ACCEPTED | 0.00 s | details |
#17 | ACCEPTED | 0.00 s | details |
#18 | ACCEPTED | 0.00 s | details |
#19 | ACCEPTED | 0.00 s | details |
#20 | ACCEPTED | 0.01 s | details |
#21 | ACCEPTED | 0.00 s | details |
#22 | ACCEPTED | 0.00 s | details |
#23 | ACCEPTED | 0.01 s | details |
#24 | ACCEPTED | 0.00 s | details |
#25 | ACCEPTED | 0.00 s | details |
#26 | ACCEPTED | 0.00 s | details |
#27 | ACCEPTED | 0.00 s | details |
#28 | ACCEPTED | 0.01 s | details |
#29 | ACCEPTED | 0.00 s | details |
#30 | ACCEPTED | 0.00 s | details |
#31 | ACCEPTED | 0.00 s | details |
#32 | ACCEPTED | 0.00 s | details |
#33 | ACCEPTED | 0.00 s | details |
#34 | ACCEPTED | 0.00 s | details |
#35 | ACCEPTED | 0.00 s | details |
#36 | ACCEPTED | 0.00 s | details |
#37 | ACCEPTED | 0.00 s | details |
#38 | ACCEPTED | 0.01 s | details |
Compiler report
input/code.cpp: In function 'void dfs(long long int, long long int, std::vector<std::vector<long long int> >&, std::vector<long long int>&, std::vector<std::pair<long long int, long long int> >&, long long int)': input/code.cpp:21:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 21 | for (int i = 0; i < adj[start].size(); i++) { | ~~^~~~~~~~~~~~~~~~~~~ input/code.cpp: In function 'void solve()': input/code.cpp:54:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 54 | for (int v = 1; v < visited.size(); v++) | ~~^~~~~~~~~~~~~~~~ input/code.cpp:61:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type'...
Code
#include <bits/stdc++.h> #include <iostream> #define int long long using namespace std; void dfs(int start, int prev, vector<vector<int>> &adj, vector<int> &visited, vector<pair<int, int>> &edges, int prev_ind) { if(visited[start] == 1) { return; } visited[start] = 1; // remove edge from structure if (prev_ind != -1) { adj[prev][prev_ind] = -1; edges.push_back({prev, start}); } // add edge to saved edges for (int i = 0; i < adj[start].size(); i++) { if (adj[start][i] == prev) { // remove duplicate edges adj[start][i] = -1; continue; } if (adj[start][i] != -1) dfs(adj[start][i], start, adj, visited, edges, i); } } void solve() { int n, m; cin >> n >> m; vector<int> visited(n + 1, 0); vector<vector<int>> adj(n + 1, vector<int>()); int a, b; for (int i = 0; i < m; i++) { cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } /*for (auto u : adj) { for (auto el : u) { cout << el << " "; } cout << "\n"; }*/ vector<pair<int, int>> edges; // dfs(1, 1, adj, visited, edges, 0); for (int v = 1; v < visited.size(); v++) { if (visited[v] == 0) { dfs(v, v, adj, visited, edges, -1); } } visited = vector<int>(n + 1, 0); for (int v = 1; v < visited.size(); v++) { if (visited[v] == 0) { dfs(v, v, adj, visited, edges, -1); } } visited = vector<int>(n + 1, 0); for (int v = 1; v < visited.size(); v++) { if (visited[v] == 0) { dfs(v, v, adj, visited, edges, -1); } } cout << edges.size() << "\n"; for (auto u : edges) { cout << u.first << " " << u.second << "\n"; } } signed main() { int t = 1; // cin >> t; for (int i = 0; i < t; i++) solve(); }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
5 8 1 2 1 3 1 4 2 3 ... |
correct output |
---|
8 1 2 1 3 1 4 2 3 ... |
user output |
---|
8 1 2 2 3 3 4 3 5 ... |
Test 2
Verdict: ACCEPTED
input |
---|
100 2451 1 2 1 3 1 4 1 5 ... |
correct output |
---|
289 1 2 1 3 1 4 1 5 ... |
user output |
---|
295 1 2 2 3 3 4 4 5 ... |
Test 3
Verdict: ACCEPTED
input |
---|
100 1206 1 2 26 27 51 52 76 77 ... |
correct output |
---|
282 1 2 1 3 1 4 1 5 ... |
user output |
---|
294 1 2 2 3 3 4 4 5 ... |
Test 4
Verdict: ACCEPTED
input |
---|
5 8 2 3 1 3 1 5 5 4 ... |
correct output |
---|
8 1 3 1 5 2 1 2 3 ... |
user output |
---|
8 1 3 3 2 3 5 5 4 ... |
Test 5
Verdict: ACCEPTED
input |
---|
10 10 1 2 2 5 7 10 5 4 ... |
correct output |
---|
10 1 2 1 6 2 5 2 10 ... |
user output |
---|
10 1 2 2 5 5 4 4 7 ... |
Test 6
Verdict: ACCEPTED
input |
---|
10 45 1 6 1 7 10 6 4 6 ... |
correct output |
---|
27 1 3 1 6 1 7 1 9 ... |
user output |
---|
27 1 6 6 10 10 2 2 5 ... |
Test 7
Verdict: ACCEPTED
input |
---|
100 45 42 4 39 75 99 87 9 65 ... |
correct output |
---|
45 1 13 4 96 7 26 9 65 ... |
user output |
---|
45 1 13 3 39 39 75 4 42 ... |
Test 8
Verdict: ACCEPTED
input |
---|
100 400 19 66 48 11 34 85 22 9 ... |
correct output |
---|
296 1 27 1 38 1 63 2 44 ... |
user output |
---|
293 1 38 38 15 15 4 4 58 ... |
Test 9
Verdict: ACCEPTED
input |
---|
100 500 17 75 80 65 89 16 65 73 ... |
correct output |
---|
297 1 55 1 62 1 75 1 78 ... |
user output |
---|
296 1 75 75 17 17 37 37 85 ... |
Test 10
Verdict: ACCEPTED
input |
---|
1000 500 989 549 7 137 716 180 20 265 ... |
correct output |
---|
500 1 931 7 137 11 781 14 305 ... |
user output |
---|
500 1 931 931 96 96 973 931 434 ... |
Test 11
Verdict: ACCEPTED
input |
---|
1000 5000 911 615 730 255 283 617 821 101 ... |
correct output |
---|
2992 1 359 1 579 1 688 1 826 ... |
user output |
---|
2987 1 579 579 878 878 766 766 658 ... |
Test 12
Verdict: ACCEPTED
input |
---|
1000 10000 116 615 301 287 869 274 717 549 ... |
correct output |
---|
2997 1 165 1 496 1 661 2 22 ... |
user output |
---|
2997 1 661 661 380 380 895 895 309 ... |
Test 13
Verdict: ACCEPTED
input |
---|
1000 1000 395 816 73 640 124 192 920 419 ... |
correct output |
---|
1000 2 903 3 634 4 959 5 274 ... |
user output |
---|
1000 1 875 875 12 12 420 12 349 ... |
Test 14
Verdict: ACCEPTED
input |
---|
100 4000 18 66 63 12 50 12 48 78 ... |
correct output |
---|
297 1 8 1 34 1 40 1 43 ... |
user output |
---|
297 1 34 34 35 35 71 71 46 ... |
Test 15
Verdict: ACCEPTED
input |
---|
1 0 |
correct output |
---|
0 |
user output |
---|
0 |
Test 16
Verdict: ACCEPTED
input |
---|
10 0 |
correct output |
---|
0 |
user output |
---|
0 |
Test 17
Verdict: ACCEPTED
input |
---|
100 0 |
correct output |
---|
0 |
user output |
---|
0 |
Test 18
Verdict: ACCEPTED
input |
---|
1000 0 |
correct output |
---|
0 |
user output |
---|
0 |
Test 19
Verdict: ACCEPTED
input |
---|
5 6 5 1 4 1 5 2 4 2 ... |
correct output |
---|
6 4 1 4 2 4 3 5 1 ... |
user output |
---|
6 1 5 5 2 2 4 4 3 ... |
Test 20
Verdict: ACCEPTED
input |
---|
9 12 6 8 7 8 6 5 7 5 ... |
correct output |
---|
12 6 2 6 5 6 8 7 1 ... |
user output |
---|
12 1 7 7 8 8 6 6 5 ... |
Test 21
Verdict: ACCEPTED
input |
---|
37 54 37 31 14 31 37 15 14 15 ... |
correct output |
---|
54 6 2 6 7 6 19 6 30 ... |
user output |
---|
54 1 20 20 35 35 6 6 2 ... |
Test 22
Verdict: ACCEPTED
input |
---|
397 594 370 81 16 81 370 215 16 215 ... |
correct output |
---|
594 4 19 4 31 4 60 4 110 ... |
user output |
---|
594 1 208 208 44 44 127 127 382 ... |
Test 23
Verdict: ACCEPTED
input |
---|
997 1494 555 594 295 594 555 422 295 422 ... |
correct output |
---|
1494 6 214 6 280 6 455 6 472 ... |
user output |
---|
1494 1 945 945 254 254 183 183 274 ... |
Test 24
Verdict: ACCEPTED
input |
---|
6 8 5 3 6 3 5 4 6 4 ... |
correct output |
---|
8 5 1 5 2 5 3 5 4 ... |
user output |
---|
8 1 5 5 3 3 6 6 4 ... |
Test 25
Verdict: ACCEPTED
input |
---|
11 16 6 5 11 5 6 3 11 3 ... |
correct output |
---|
16 2 1 2 7 2 8 2 9 ... |
user output |
---|
16 1 11 11 5 5 6 6 3 ... |
Test 26
Verdict: ACCEPTED
input |
---|
46 72 20 46 33 46 20 15 33 15 ... |
correct output |
---|
72 2 4 2 5 2 10 2 11 ... |
user output |
---|
72 1 16 16 22 22 31 31 4 ... |
Test 27
Verdict: ACCEPTED
input |
---|
496 792 129 244 128 244 129 230 128 230 ... |
correct output |
---|
792 3 15 3 29 3 428 3 447 ... |
user output |
---|
792 1 437 437 305 305 69 69 168 ... |
Test 28
Verdict: ACCEPTED
input |
---|
996 1592 940 446 864 446 940 50 864 50 ... |
correct output |
---|
1592 2 362 2 482 2 545 2 572 ... |
user output |
---|
1592 1 531 531 438 438 870 870 683 ... |
Test 29
Verdict: ACCEPTED
input |
---|
3 2 3 1 2 1 |
correct output |
---|
2 2 1 3 1 |
user output |
---|
2 1 3 1 2 |
Test 30
Verdict: ACCEPTED
input |
---|
5 4 5 3 1 3 1 2 4 2 |
correct output |
---|
4 1 2 1 3 4 2 5 3 |
user output |
---|
4 1 3 3 5 1 2 2 4 |
Test 31
Verdict: ACCEPTED
input |
---|
19 18 5 2 1 2 1 4 15 4 ... |
correct output |
---|
18 1 2 1 4 5 2 7 10 ... |
user output |
---|
18 1 2 2 5 1 4 4 15 ... |
Test 32
Verdict: ACCEPTED
input |
---|
199 198 20 93 53 93 53 7 152 7 ... |
correct output |
---|
198 3 44 3 128 5 18 5 184 ... |
user output |
---|
198 1 87 87 95 95 156 156 142 ... |
Test 33
Verdict: ACCEPTED
input |
---|
999 998 481 471 242 471 242 95 525 95 ... |
correct output |
---|
998 2 267 2 303 3 378 3 644 ... |
user output |
---|
998 1 180 180 316 316 422 422 127 ... |
Test 34
Verdict: ACCEPTED
input |
---|
4 4 2 4 1 4 2 3 1 3 |
correct output |
---|
4 1 3 1 4 2 3 2 4 |
user output |
---|
4 1 4 4 2 2 3 1 3 |
Test 35
Verdict: ACCEPTED
input |
---|
7 8 2 7 4 7 2 5 4 5 ... |
correct output |
---|
8 2 5 2 7 4 1 4 3 ... |
user output |
---|
8 1 4 4 7 7 2 2 5 ... |
Test 36
Verdict: ACCEPTED
input |
---|
28 36 22 9 24 9 22 5 24 5 ... |
correct output |
---|
36 3 8 3 18 3 21 3 27 ... |
user output |
---|
36 1 11 11 4 4 25 25 2 ... |
Test 37
Verdict: ACCEPTED
input |
---|
298 396 293 290 133 290 293 228 133 228 ... |
correct output |
---|
396 1 62 1 112 1 174 1 250 ... |
user output |
---|
396 1 112 112 178 178 12 12 109 ... |
Test 38
Verdict: ACCEPTED
input |
---|
1000 1332 949 882 156 882 949 515 156 515 ... |
correct output |
---|
1332 2 508 2 774 2 885 2 921 ... |
user output |
---|
1332 1 880 880 118 118 631 631 123 ... |