#include "simurgh.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vii;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pb push_back
const ll M=250000;
vector<pii> adj[M];
bool vis[M];
vii sp;
void dfs(ll x) {
vis[x]=1;
for(auto it:adj[x]) {
if(vis[it.F])
continue;
sp.pb(it.S);
dfs(it.F);
}
}
struct dsu {
ll sz[250],pa[250];
void init(ll x) {
for(int i=0;i<x;i++)
sz[i]=1,pa[i]=i;
}
ll get(ll x) {
if(x==pa[x])
return x;
return pa[x]=get(pa[x]);
}
void unite(ll x,ll y) {
x=get(x),y=get(y);
if(x==y)
return;
if(sz[x]>sz[y])
swap(x,y);
pa[x]=y;
sz[y]+=sz[x];
}
bool same(ll x,ll y) {
return get(x)==get(y);
}
}d;
ll cnt[M],cc[M];
bool a[M];
set<ll>s;
vector<int> find_roads(int n, std::vector<int> u, std::vector<int> vv) {
for(int i=0;i<u.size();i++)
adj[u[i]].pb({vv[i],i}),adj[vv[i]].pb({u[i],i});
dfs(0);
vector<int>ans,res;
for(int i=0;i<u.size();i++)
vis[i]=0;
ll cntq=0;
for(auto it:sp) {
s.clear();
ans.clear();
d.init(n);
vii v;
for(auto itt:sp) {
if(itt!=it)
ans.pb(itt),d.unite(u[itt],vv[itt]);
}
for(int i=0;i<u.size();i++)
cnt[i]=0;
for(int i=0;i<u.size();i++) {
if(!d.same(u[i],vv[i])&&!vis[i]) {
ans.pb(i);
assert(cntq<30000);
ll x=count_common_roads(ans);
cntq++;
cnt[ans.back()]=x;
s.insert(x);
v.pb(i);
ans.pop_back();
}
}
if(s.size()==1) {
bool cc[2];
cc[0]=cc[1]=0;
for(int i=0;i<u.size();i++) {
if(!d.same(u[i],vv[i])&&vis[i]&&!cc[a[i]]) {
cc[a[i]]=1;
ans.pb(i);
assert(cntq<30000);
s.insert(count_common_roads(ans));
cntq++;
ans.pop_back();
}
}
}
for(auto it:v) {
vis[it]=1;
if(cnt[it]==*s.rbegin()) {
a[it]=1;
}
}
}
for(int i=0;i<u.size();i++)
if(a[i])res.pb(i);
assert(res.size()==n-1);
assert(cntq<=30000);
return res;
}
/*
5 10
0 1
0 2
0 3
0 4
1 2
1 3
1 4
2 3
2 4
3 4
3 6 8 9
*/
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:52:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int i=0;i<u.size();i++)
| ~^~~~~~~~~
simurgh.cpp:56:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int i=0;i<u.size();i++)
| ~^~~~~~~~~
simurgh.cpp:68:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(int i=0;i<u.size();i++)
| ~^~~~~~~~~
simurgh.cpp:70:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int i=0;i<u.size();i++) {
| ~^~~~~~~~~
simurgh.cpp:85:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for(int i=0;i<u.size();i++) {
| ~^~~~~~~~~
simurgh.cpp:103:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
103 | for(int i=0;i<u.size();i++)
| ~^~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
from simurgh.cpp:2:
simurgh.cpp:105:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
105 | assert(res.size()==n-1);
| ~~~~~~~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10332 KB |
correct |
2 |
Correct |
3 ms |
10332 KB |
correct |
3 |
Correct |
2 ms |
10332 KB |
correct |
4 |
Correct |
2 ms |
10332 KB |
correct |
5 |
Correct |
2 ms |
10332 KB |
correct |
6 |
Correct |
2 ms |
10332 KB |
correct |
7 |
Correct |
2 ms |
10332 KB |
correct |
8 |
Correct |
2 ms |
10312 KB |
correct |
9 |
Correct |
2 ms |
10332 KB |
correct |
10 |
Correct |
2 ms |
10332 KB |
correct |
11 |
Correct |
2 ms |
10332 KB |
correct |
12 |
Correct |
3 ms |
10328 KB |
correct |
13 |
Correct |
2 ms |
10332 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10332 KB |
correct |
2 |
Correct |
3 ms |
10332 KB |
correct |
3 |
Correct |
2 ms |
10332 KB |
correct |
4 |
Correct |
2 ms |
10332 KB |
correct |
5 |
Correct |
2 ms |
10332 KB |
correct |
6 |
Correct |
2 ms |
10332 KB |
correct |
7 |
Correct |
2 ms |
10332 KB |
correct |
8 |
Correct |
2 ms |
10312 KB |
correct |
9 |
Correct |
2 ms |
10332 KB |
correct |
10 |
Correct |
2 ms |
10332 KB |
correct |
11 |
Correct |
2 ms |
10332 KB |
correct |
12 |
Correct |
3 ms |
10328 KB |
correct |
13 |
Correct |
2 ms |
10332 KB |
correct |
14 |
Correct |
4 ms |
10584 KB |
correct |
15 |
Correct |
3 ms |
10588 KB |
correct |
16 |
Correct |
3 ms |
10588 KB |
correct |
17 |
Correct |
3 ms |
10588 KB |
correct |
18 |
Correct |
2 ms |
10332 KB |
correct |
19 |
Correct |
3 ms |
10588 KB |
correct |
20 |
Correct |
4 ms |
10588 KB |
correct |
21 |
Correct |
3 ms |
10588 KB |
correct |
22 |
Correct |
3 ms |
10588 KB |
correct |
23 |
Correct |
3 ms |
10588 KB |
correct |
24 |
Correct |
3 ms |
10588 KB |
correct |
25 |
Correct |
3 ms |
10332 KB |
correct |
26 |
Correct |
3 ms |
10588 KB |
correct |
27 |
Correct |
3 ms |
10588 KB |
correct |
28 |
Correct |
3 ms |
10328 KB |
correct |
29 |
Correct |
2 ms |
10332 KB |
correct |
30 |
Correct |
3 ms |
10588 KB |
correct |
31 |
Correct |
3 ms |
10588 KB |
correct |
32 |
Correct |
3 ms |
10588 KB |
correct |
33 |
Correct |
3 ms |
10588 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10332 KB |
correct |
2 |
Correct |
3 ms |
10332 KB |
correct |
3 |
Correct |
2 ms |
10332 KB |
correct |
4 |
Correct |
2 ms |
10332 KB |
correct |
5 |
Correct |
2 ms |
10332 KB |
correct |
6 |
Correct |
2 ms |
10332 KB |
correct |
7 |
Correct |
2 ms |
10332 KB |
correct |
8 |
Correct |
2 ms |
10312 KB |
correct |
9 |
Correct |
2 ms |
10332 KB |
correct |
10 |
Correct |
2 ms |
10332 KB |
correct |
11 |
Correct |
2 ms |
10332 KB |
correct |
12 |
Correct |
3 ms |
10328 KB |
correct |
13 |
Correct |
2 ms |
10332 KB |
correct |
14 |
Correct |
4 ms |
10584 KB |
correct |
15 |
Correct |
3 ms |
10588 KB |
correct |
16 |
Correct |
3 ms |
10588 KB |
correct |
17 |
Correct |
3 ms |
10588 KB |
correct |
18 |
Correct |
2 ms |
10332 KB |
correct |
19 |
Correct |
3 ms |
10588 KB |
correct |
20 |
Correct |
4 ms |
10588 KB |
correct |
21 |
Correct |
3 ms |
10588 KB |
correct |
22 |
Correct |
3 ms |
10588 KB |
correct |
23 |
Correct |
3 ms |
10588 KB |
correct |
24 |
Correct |
3 ms |
10588 KB |
correct |
25 |
Correct |
3 ms |
10332 KB |
correct |
26 |
Correct |
3 ms |
10588 KB |
correct |
27 |
Correct |
3 ms |
10588 KB |
correct |
28 |
Correct |
3 ms |
10328 KB |
correct |
29 |
Correct |
2 ms |
10332 KB |
correct |
30 |
Correct |
3 ms |
10588 KB |
correct |
31 |
Correct |
3 ms |
10588 KB |
correct |
32 |
Correct |
3 ms |
10588 KB |
correct |
33 |
Correct |
3 ms |
10588 KB |
correct |
34 |
Correct |
139 ms |
12128 KB |
correct |
35 |
Correct |
140 ms |
12120 KB |
correct |
36 |
Correct |
90 ms |
11868 KB |
correct |
37 |
Correct |
8 ms |
10584 KB |
correct |
38 |
Correct |
138 ms |
12356 KB |
correct |
39 |
Correct |
132 ms |
12240 KB |
correct |
40 |
Correct |
95 ms |
12360 KB |
correct |
41 |
Correct |
128 ms |
12352 KB |
correct |
42 |
Correct |
147 ms |
12124 KB |
correct |
43 |
Correct |
67 ms |
11612 KB |
correct |
44 |
Correct |
57 ms |
11356 KB |
correct |
45 |
Correct |
62 ms |
11428 KB |
correct |
46 |
Correct |
47 ms |
11100 KB |
correct |
47 |
Correct |
20 ms |
10844 KB |
correct |
48 |
Correct |
5 ms |
10588 KB |
correct |
49 |
Correct |
10 ms |
10684 KB |
correct |
50 |
Correct |
21 ms |
10816 KB |
correct |
51 |
Correct |
63 ms |
11464 KB |
correct |
52 |
Correct |
54 ms |
11600 KB |
correct |
53 |
Correct |
45 ms |
11100 KB |
correct |
54 |
Correct |
71 ms |
11820 KB |
correct |
55 |
Correct |
68 ms |
11356 KB |
correct |
56 |
Correct |
69 ms |
11452 KB |
correct |
57 |
Correct |
68 ms |
11352 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10328 KB |
correct |
2 |
Correct |
2 ms |
10332 KB |
correct |
3 |
Runtime error |
26 ms |
26716 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
10332 KB |
correct |
2 |
Correct |
3 ms |
10332 KB |
correct |
3 |
Correct |
2 ms |
10332 KB |
correct |
4 |
Correct |
2 ms |
10332 KB |
correct |
5 |
Correct |
2 ms |
10332 KB |
correct |
6 |
Correct |
2 ms |
10332 KB |
correct |
7 |
Correct |
2 ms |
10332 KB |
correct |
8 |
Correct |
2 ms |
10312 KB |
correct |
9 |
Correct |
2 ms |
10332 KB |
correct |
10 |
Correct |
2 ms |
10332 KB |
correct |
11 |
Correct |
2 ms |
10332 KB |
correct |
12 |
Correct |
3 ms |
10328 KB |
correct |
13 |
Correct |
2 ms |
10332 KB |
correct |
14 |
Correct |
4 ms |
10584 KB |
correct |
15 |
Correct |
3 ms |
10588 KB |
correct |
16 |
Correct |
3 ms |
10588 KB |
correct |
17 |
Correct |
3 ms |
10588 KB |
correct |
18 |
Correct |
2 ms |
10332 KB |
correct |
19 |
Correct |
3 ms |
10588 KB |
correct |
20 |
Correct |
4 ms |
10588 KB |
correct |
21 |
Correct |
3 ms |
10588 KB |
correct |
22 |
Correct |
3 ms |
10588 KB |
correct |
23 |
Correct |
3 ms |
10588 KB |
correct |
24 |
Correct |
3 ms |
10588 KB |
correct |
25 |
Correct |
3 ms |
10332 KB |
correct |
26 |
Correct |
3 ms |
10588 KB |
correct |
27 |
Correct |
3 ms |
10588 KB |
correct |
28 |
Correct |
3 ms |
10328 KB |
correct |
29 |
Correct |
2 ms |
10332 KB |
correct |
30 |
Correct |
3 ms |
10588 KB |
correct |
31 |
Correct |
3 ms |
10588 KB |
correct |
32 |
Correct |
3 ms |
10588 KB |
correct |
33 |
Correct |
3 ms |
10588 KB |
correct |
34 |
Correct |
139 ms |
12128 KB |
correct |
35 |
Correct |
140 ms |
12120 KB |
correct |
36 |
Correct |
90 ms |
11868 KB |
correct |
37 |
Correct |
8 ms |
10584 KB |
correct |
38 |
Correct |
138 ms |
12356 KB |
correct |
39 |
Correct |
132 ms |
12240 KB |
correct |
40 |
Correct |
95 ms |
12360 KB |
correct |
41 |
Correct |
128 ms |
12352 KB |
correct |
42 |
Correct |
147 ms |
12124 KB |
correct |
43 |
Correct |
67 ms |
11612 KB |
correct |
44 |
Correct |
57 ms |
11356 KB |
correct |
45 |
Correct |
62 ms |
11428 KB |
correct |
46 |
Correct |
47 ms |
11100 KB |
correct |
47 |
Correct |
20 ms |
10844 KB |
correct |
48 |
Correct |
5 ms |
10588 KB |
correct |
49 |
Correct |
10 ms |
10684 KB |
correct |
50 |
Correct |
21 ms |
10816 KB |
correct |
51 |
Correct |
63 ms |
11464 KB |
correct |
52 |
Correct |
54 ms |
11600 KB |
correct |
53 |
Correct |
45 ms |
11100 KB |
correct |
54 |
Correct |
71 ms |
11820 KB |
correct |
55 |
Correct |
68 ms |
11356 KB |
correct |
56 |
Correct |
69 ms |
11452 KB |
correct |
57 |
Correct |
68 ms |
11352 KB |
correct |
58 |
Correct |
2 ms |
10328 KB |
correct |
59 |
Correct |
2 ms |
10332 KB |
correct |
60 |
Runtime error |
26 ms |
26716 KB |
Execution killed with signal 11 |
61 |
Halted |
0 ms |
0 KB |
- |