#include "simurgh.h"
#include<bits/stdc++.h>
#define pb emplace_back
#define vi vector<int>
#define pii pair<int,int>
#define fi first
#define se second
#define all(n) (n).begin(),(n).end()
using namespace std;
vi ans, pos, pos2, U, V;
int pa[505], N, M;
void init(){
for(int i=0;i<N;i++) pa[i] = i;
}
int fp(int x){
if(pa[x] == x) return x;
return pa[x] = fp(pa[x]);
}
void uni(int x,int y){
x = fp(x), y = fp(y);
assert(x != y);
pa[x] = y;
}
void search_next(){
init();
int cnt = N;
vi cur;
for(auto &i:ans){
uni(U[i], V[i]);
cur.pb(i);
cnt--;
}
vector<pii> tried;
for(auto &i:pos){
if(cnt == 2){
if(fp(U[i]) != fp(V[i])){
cur.pb(i);
assert(cur.size() == N-1);
int common = count_common_roads(cur);
/* cout<<common<<" "<<i<<'\n'; */
tried.pb(common,i);
cur.pop_back();
}
else pos2.pb(i);
}
else{
if(fp(U[i]) != fp(V[i])){
cur.pb(i);
uni(U[i], V[i]);
cnt--;
}
pos2.pb(i);
}
}
pair<int,int> mx = *max_element(all(tried));
for(auto &x : tried){
if(x.fi == mx.fi){
ans.pb(x.se);
}
}
swap(pos, pos2);
pos2.clear();
/* for(auto i:pos) cout<<i<<" "; cout<<'\n'; */
}
// count_common_roads(vi v);
std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) {
M = u.size(), N = n;
U = u, V = v;
for(int i=0;i<M;i++) pos.pb(i);
while(ans.size() < N - 1) search_next();
/* for(auto i:ans) cout<<i<<" "; cout<<'\n'; */
return ans;
}
Compilation message
In file included from /usr/include/c++/9/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
from simurgh.cpp:2:
simurgh.cpp: In function 'void search_next()':
simurgh.cpp:41:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
41 | assert(cur.size() == N-1);
| ~~~~~~~~~~~^~~~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:74:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
74 | while(ans.size() < N - 1) search_next();
| ~~~~~~~~~~~^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
correct |
2 |
Correct |
0 ms |
256 KB |
correct |
3 |
Correct |
1 ms |
384 KB |
correct |
4 |
Correct |
1 ms |
384 KB |
correct |
5 |
Correct |
0 ms |
256 KB |
correct |
6 |
Correct |
1 ms |
256 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
0 ms |
256 KB |
correct |
9 |
Correct |
1 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
256 KB |
correct |
11 |
Correct |
0 ms |
256 KB |
correct |
12 |
Correct |
0 ms |
256 KB |
correct |
13 |
Correct |
1 ms |
256 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
correct |
2 |
Correct |
0 ms |
256 KB |
correct |
3 |
Correct |
1 ms |
384 KB |
correct |
4 |
Correct |
1 ms |
384 KB |
correct |
5 |
Correct |
0 ms |
256 KB |
correct |
6 |
Correct |
1 ms |
256 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
0 ms |
256 KB |
correct |
9 |
Correct |
1 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
256 KB |
correct |
11 |
Correct |
0 ms |
256 KB |
correct |
12 |
Correct |
0 ms |
256 KB |
correct |
13 |
Correct |
1 ms |
256 KB |
correct |
14 |
Correct |
3 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 |
3 ms |
512 KB |
correct |
22 |
Correct |
2 ms |
384 KB |
correct |
23 |
Correct |
2 ms |
384 KB |
correct |
24 |
Correct |
2 ms |
384 KB |
correct |
25 |
Correct |
1 ms |
256 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 |
256 KB |
correct |
30 |
Correct |
1 ms |
384 KB |
correct |
31 |
Correct |
1 ms |
384 KB |
correct |
32 |
Correct |
1 ms |
384 KB |
correct |
33 |
Correct |
1 ms |
384 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
correct |
2 |
Correct |
0 ms |
256 KB |
correct |
3 |
Correct |
1 ms |
384 KB |
correct |
4 |
Correct |
1 ms |
384 KB |
correct |
5 |
Correct |
0 ms |
256 KB |
correct |
6 |
Correct |
1 ms |
256 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
0 ms |
256 KB |
correct |
9 |
Correct |
1 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
256 KB |
correct |
11 |
Correct |
0 ms |
256 KB |
correct |
12 |
Correct |
0 ms |
256 KB |
correct |
13 |
Correct |
1 ms |
256 KB |
correct |
14 |
Correct |
3 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 |
3 ms |
512 KB |
correct |
22 |
Correct |
2 ms |
384 KB |
correct |
23 |
Correct |
2 ms |
384 KB |
correct |
24 |
Correct |
2 ms |
384 KB |
correct |
25 |
Correct |
1 ms |
256 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 |
256 KB |
correct |
30 |
Correct |
1 ms |
384 KB |
correct |
31 |
Correct |
1 ms |
384 KB |
correct |
32 |
Correct |
1 ms |
384 KB |
correct |
33 |
Correct |
1 ms |
384 KB |
correct |
34 |
Correct |
203 ms |
1408 KB |
correct |
35 |
Correct |
186 ms |
1280 KB |
correct |
36 |
Correct |
135 ms |
1024 KB |
correct |
37 |
Correct |
11 ms |
384 KB |
correct |
38 |
Correct |
182 ms |
1400 KB |
correct |
39 |
Correct |
171 ms |
1264 KB |
correct |
40 |
Correct |
142 ms |
1024 KB |
correct |
41 |
Correct |
101 ms |
1408 KB |
correct |
42 |
Correct |
165 ms |
1536 KB |
correct |
43 |
Correct |
95 ms |
1016 KB |
correct |
44 |
Correct |
79 ms |
768 KB |
correct |
45 |
Correct |
93 ms |
1016 KB |
correct |
46 |
Correct |
71 ms |
768 KB |
correct |
47 |
Correct |
31 ms |
512 KB |
correct |
48 |
Correct |
6 ms |
384 KB |
correct |
49 |
Correct |
11 ms |
384 KB |
correct |
50 |
Correct |
31 ms |
512 KB |
correct |
51 |
Correct |
94 ms |
896 KB |
correct |
52 |
Correct |
81 ms |
768 KB |
correct |
53 |
Correct |
73 ms |
768 KB |
correct |
54 |
Correct |
97 ms |
896 KB |
correct |
55 |
Correct |
84 ms |
896 KB |
correct |
56 |
Correct |
80 ms |
896 KB |
correct |
57 |
Correct |
80 ms |
896 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
correct |
2 |
Correct |
0 ms |
256 KB |
correct |
3 |
Incorrect |
190 ms |
3316 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
correct |
2 |
Correct |
0 ms |
256 KB |
correct |
3 |
Correct |
1 ms |
384 KB |
correct |
4 |
Correct |
1 ms |
384 KB |
correct |
5 |
Correct |
0 ms |
256 KB |
correct |
6 |
Correct |
1 ms |
256 KB |
correct |
7 |
Correct |
0 ms |
384 KB |
correct |
8 |
Correct |
0 ms |
256 KB |
correct |
9 |
Correct |
1 ms |
384 KB |
correct |
10 |
Correct |
0 ms |
256 KB |
correct |
11 |
Correct |
0 ms |
256 KB |
correct |
12 |
Correct |
0 ms |
256 KB |
correct |
13 |
Correct |
1 ms |
256 KB |
correct |
14 |
Correct |
3 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 |
3 ms |
512 KB |
correct |
22 |
Correct |
2 ms |
384 KB |
correct |
23 |
Correct |
2 ms |
384 KB |
correct |
24 |
Correct |
2 ms |
384 KB |
correct |
25 |
Correct |
1 ms |
256 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 |
256 KB |
correct |
30 |
Correct |
1 ms |
384 KB |
correct |
31 |
Correct |
1 ms |
384 KB |
correct |
32 |
Correct |
1 ms |
384 KB |
correct |
33 |
Correct |
1 ms |
384 KB |
correct |
34 |
Correct |
203 ms |
1408 KB |
correct |
35 |
Correct |
186 ms |
1280 KB |
correct |
36 |
Correct |
135 ms |
1024 KB |
correct |
37 |
Correct |
11 ms |
384 KB |
correct |
38 |
Correct |
182 ms |
1400 KB |
correct |
39 |
Correct |
171 ms |
1264 KB |
correct |
40 |
Correct |
142 ms |
1024 KB |
correct |
41 |
Correct |
101 ms |
1408 KB |
correct |
42 |
Correct |
165 ms |
1536 KB |
correct |
43 |
Correct |
95 ms |
1016 KB |
correct |
44 |
Correct |
79 ms |
768 KB |
correct |
45 |
Correct |
93 ms |
1016 KB |
correct |
46 |
Correct |
71 ms |
768 KB |
correct |
47 |
Correct |
31 ms |
512 KB |
correct |
48 |
Correct |
6 ms |
384 KB |
correct |
49 |
Correct |
11 ms |
384 KB |
correct |
50 |
Correct |
31 ms |
512 KB |
correct |
51 |
Correct |
94 ms |
896 KB |
correct |
52 |
Correct |
81 ms |
768 KB |
correct |
53 |
Correct |
73 ms |
768 KB |
correct |
54 |
Correct |
97 ms |
896 KB |
correct |
55 |
Correct |
84 ms |
896 KB |
correct |
56 |
Correct |
80 ms |
896 KB |
correct |
57 |
Correct |
80 ms |
896 KB |
correct |
58 |
Correct |
1 ms |
256 KB |
correct |
59 |
Correct |
0 ms |
256 KB |
correct |
60 |
Incorrect |
190 ms |
3316 KB |
WA in grader: NO |
61 |
Halted |
0 ms |
0 KB |
- |