#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
const int len = 1000000;
ii edge[len];
int explore[len], vis[len], par[len];
int fin(int i){
if (par[i] == i) return i;
return par[i] = fin(par[i]);
}
void join(int i, int j){
i = fin(i), j = fin(j);
if (i == j) return;
par[i] = j;
}
vector<int> find_roads(int N, vector<int> U, vector<int> V) {
int n = N, m = U.size();
for (int i = 0; i < m; i++)
edge[i] = mp(U[i], V[i]);
while (true){
vector<int> temp;
for (int i = 0; i < n; i++)
par[i] = i;
for (int i = 0; i < m; i++)
if (vis[i] == 1)
join(edge[i].fi, edge[i].se), temp.pb(i);
int fir = n-1, sec = 0;
for (int i = 0; i < n; i++)
fir = min(fir, fin(i)), sec = max(sec, fin(i));
if (fir == sec) break;
//printf("iteration starts now\n");
//printf("fir = %d, sec = %d\n", fir, sec);
for (int i = 0; i < m; i++){
if (vis[i]) continue;
int a = fin(edge[i].fi), b = fin(edge[i].se);
if ((a == b) || (a == fir && b == sec) || (a == sec && b == fir))
continue;
//printf("joining %d - %d\n", a, b);
join(a, b), temp.pb(i);
fir = fin(fir);
sec = fin(sec);
}
int mx = 0;
for (int i = 0; i < m; i++){
if (vis[i] || fin(edge[i].fi) == fin(edge[i].se)){
explore[i] = -1;
}
else{
temp.pb(i);
explore[i] = count_common_roads(temp);
/*printf("temp asked:");
for (auto val: temp)
printf(" %d", val);
printf("\n");*/
temp.pop_back();
mx = max(mx, explore[i]);
}
}
for (int i = 0; i < m; i++){
if (explore[i] == -1) continue;
if (explore[i] == mx)
vis[i] = 1;
else
vis[i] = -1;
}
}
vector<int> res;
for (int i = 0; i < m; i++)
if (vis[i] == 1)
res.pb(i);
return res;
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:92:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
92 | for (int i = 0; i < m; i++)
| ^~~
simurgh.cpp:95:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
95 | return res;
| ^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
correct |
2 |
Correct |
1 ms |
384 KB |
correct |
3 |
Correct |
0 ms |
384 KB |
correct |
4 |
Correct |
1 ms |
384 KB |
correct |
5 |
Correct |
0 ms |
384 KB |
correct |
6 |
Correct |
1 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
0 ms |
384 KB |
correct |
9 |
Correct |
0 ms |
384 KB |
correct |
10 |
Correct |
1 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
0 ms |
384 KB |
correct |
13 |
Correct |
1 ms |
384 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
correct |
2 |
Correct |
1 ms |
384 KB |
correct |
3 |
Correct |
0 ms |
384 KB |
correct |
4 |
Correct |
1 ms |
384 KB |
correct |
5 |
Correct |
0 ms |
384 KB |
correct |
6 |
Correct |
1 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
0 ms |
384 KB |
correct |
9 |
Correct |
0 ms |
384 KB |
correct |
10 |
Correct |
1 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
0 ms |
384 KB |
correct |
13 |
Correct |
1 ms |
384 KB |
correct |
14 |
Correct |
2 ms |
384 KB |
correct |
15 |
Correct |
2 ms |
384 KB |
correct |
16 |
Correct |
2 ms |
384 KB |
correct |
17 |
Correct |
2 ms |
384 KB |
correct |
18 |
Correct |
1 ms |
384 KB |
correct |
19 |
Correct |
2 ms |
384 KB |
correct |
20 |
Correct |
2 ms |
384 KB |
correct |
21 |
Correct |
2 ms |
384 KB |
correct |
22 |
Correct |
2 ms |
384 KB |
correct |
23 |
Correct |
3 ms |
384 KB |
correct |
24 |
Correct |
2 ms |
384 KB |
correct |
25 |
Correct |
1 ms |
384 KB |
correct |
26 |
Correct |
2 ms |
384 KB |
correct |
27 |
Correct |
2 ms |
384 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
384 KB |
correct |
30 |
Correct |
2 ms |
384 KB |
correct |
31 |
Correct |
2 ms |
384 KB |
correct |
32 |
Correct |
2 ms |
384 KB |
correct |
33 |
Correct |
2 ms |
384 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
correct |
2 |
Correct |
1 ms |
384 KB |
correct |
3 |
Correct |
0 ms |
384 KB |
correct |
4 |
Correct |
1 ms |
384 KB |
correct |
5 |
Correct |
0 ms |
384 KB |
correct |
6 |
Correct |
1 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
0 ms |
384 KB |
correct |
9 |
Correct |
0 ms |
384 KB |
correct |
10 |
Correct |
1 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
0 ms |
384 KB |
correct |
13 |
Correct |
1 ms |
384 KB |
correct |
14 |
Correct |
2 ms |
384 KB |
correct |
15 |
Correct |
2 ms |
384 KB |
correct |
16 |
Correct |
2 ms |
384 KB |
correct |
17 |
Correct |
2 ms |
384 KB |
correct |
18 |
Correct |
1 ms |
384 KB |
correct |
19 |
Correct |
2 ms |
384 KB |
correct |
20 |
Correct |
2 ms |
384 KB |
correct |
21 |
Correct |
2 ms |
384 KB |
correct |
22 |
Correct |
2 ms |
384 KB |
correct |
23 |
Correct |
3 ms |
384 KB |
correct |
24 |
Correct |
2 ms |
384 KB |
correct |
25 |
Correct |
1 ms |
384 KB |
correct |
26 |
Correct |
2 ms |
384 KB |
correct |
27 |
Correct |
2 ms |
384 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
384 KB |
correct |
30 |
Correct |
2 ms |
384 KB |
correct |
31 |
Correct |
2 ms |
384 KB |
correct |
32 |
Correct |
2 ms |
384 KB |
correct |
33 |
Correct |
2 ms |
384 KB |
correct |
34 |
Correct |
183 ms |
1228 KB |
correct |
35 |
Correct |
185 ms |
1264 KB |
correct |
36 |
Correct |
140 ms |
896 KB |
correct |
37 |
Correct |
10 ms |
384 KB |
correct |
38 |
Correct |
200 ms |
1400 KB |
correct |
39 |
Correct |
151 ms |
1152 KB |
correct |
40 |
Correct |
121 ms |
888 KB |
correct |
41 |
Correct |
21 ms |
1280 KB |
correct |
42 |
Correct |
119 ms |
1400 KB |
correct |
43 |
Correct |
143 ms |
768 KB |
correct |
44 |
Correct |
114 ms |
768 KB |
correct |
45 |
Correct |
138 ms |
888 KB |
correct |
46 |
Correct |
104 ms |
760 KB |
correct |
47 |
Correct |
51 ms |
540 KB |
correct |
48 |
Correct |
9 ms |
384 KB |
correct |
49 |
Correct |
18 ms |
384 KB |
correct |
50 |
Correct |
50 ms |
632 KB |
correct |
51 |
Correct |
136 ms |
768 KB |
correct |
52 |
Correct |
120 ms |
768 KB |
correct |
53 |
Correct |
107 ms |
640 KB |
correct |
54 |
Correct |
146 ms |
888 KB |
correct |
55 |
Correct |
120 ms |
760 KB |
correct |
56 |
Correct |
116 ms |
760 KB |
correct |
57 |
Correct |
119 ms |
768 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
correct |
2 |
Correct |
0 ms |
384 KB |
correct |
3 |
Incorrect |
142 ms |
2408 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
correct |
2 |
Correct |
1 ms |
384 KB |
correct |
3 |
Correct |
0 ms |
384 KB |
correct |
4 |
Correct |
1 ms |
384 KB |
correct |
5 |
Correct |
0 ms |
384 KB |
correct |
6 |
Correct |
1 ms |
384 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
0 ms |
384 KB |
correct |
9 |
Correct |
0 ms |
384 KB |
correct |
10 |
Correct |
1 ms |
384 KB |
correct |
11 |
Correct |
0 ms |
384 KB |
correct |
12 |
Correct |
0 ms |
384 KB |
correct |
13 |
Correct |
1 ms |
384 KB |
correct |
14 |
Correct |
2 ms |
384 KB |
correct |
15 |
Correct |
2 ms |
384 KB |
correct |
16 |
Correct |
2 ms |
384 KB |
correct |
17 |
Correct |
2 ms |
384 KB |
correct |
18 |
Correct |
1 ms |
384 KB |
correct |
19 |
Correct |
2 ms |
384 KB |
correct |
20 |
Correct |
2 ms |
384 KB |
correct |
21 |
Correct |
2 ms |
384 KB |
correct |
22 |
Correct |
2 ms |
384 KB |
correct |
23 |
Correct |
3 ms |
384 KB |
correct |
24 |
Correct |
2 ms |
384 KB |
correct |
25 |
Correct |
1 ms |
384 KB |
correct |
26 |
Correct |
2 ms |
384 KB |
correct |
27 |
Correct |
2 ms |
384 KB |
correct |
28 |
Correct |
1 ms |
384 KB |
correct |
29 |
Correct |
1 ms |
384 KB |
correct |
30 |
Correct |
2 ms |
384 KB |
correct |
31 |
Correct |
2 ms |
384 KB |
correct |
32 |
Correct |
2 ms |
384 KB |
correct |
33 |
Correct |
2 ms |
384 KB |
correct |
34 |
Correct |
183 ms |
1228 KB |
correct |
35 |
Correct |
185 ms |
1264 KB |
correct |
36 |
Correct |
140 ms |
896 KB |
correct |
37 |
Correct |
10 ms |
384 KB |
correct |
38 |
Correct |
200 ms |
1400 KB |
correct |
39 |
Correct |
151 ms |
1152 KB |
correct |
40 |
Correct |
121 ms |
888 KB |
correct |
41 |
Correct |
21 ms |
1280 KB |
correct |
42 |
Correct |
119 ms |
1400 KB |
correct |
43 |
Correct |
143 ms |
768 KB |
correct |
44 |
Correct |
114 ms |
768 KB |
correct |
45 |
Correct |
138 ms |
888 KB |
correct |
46 |
Correct |
104 ms |
760 KB |
correct |
47 |
Correct |
51 ms |
540 KB |
correct |
48 |
Correct |
9 ms |
384 KB |
correct |
49 |
Correct |
18 ms |
384 KB |
correct |
50 |
Correct |
50 ms |
632 KB |
correct |
51 |
Correct |
136 ms |
768 KB |
correct |
52 |
Correct |
120 ms |
768 KB |
correct |
53 |
Correct |
107 ms |
640 KB |
correct |
54 |
Correct |
146 ms |
888 KB |
correct |
55 |
Correct |
120 ms |
760 KB |
correct |
56 |
Correct |
116 ms |
760 KB |
correct |
57 |
Correct |
119 ms |
768 KB |
correct |
58 |
Correct |
1 ms |
384 KB |
correct |
59 |
Correct |
0 ms |
384 KB |
correct |
60 |
Incorrect |
142 ms |
2408 KB |
WA in grader: NO |
61 |
Halted |
0 ms |
0 KB |
- |