# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
565224 |
2022-05-20T13:33:39 Z |
jamezzz |
Simurgh (IOI17_simurgh) |
C++17 |
|
533 ms |
7488 KB |
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef pair<int,int> ii;
#define maxn 505
struct UFDS{
int par[maxn],rnk[maxn];
void init(int n){
for(int i=0;i<n;++i)par[i]=i,rnk[i]=1;
}
int fp(int i){
return (par[i]==i)?i:par[i]=fp(par[i]);
}
void join(int x,int y){
x=fp(x),y=fp(y);
if(x==y)return;
if(rnk[x]<rnk[y])par[x]=y;
else par[y]=x;
if(rnk[x]==rnk[y])++rnk[x];
}
}ufds;
int n,m,good[maxn*maxn],edge[maxn][maxn];
int par[maxn],depth[maxn],deg[maxn],done[maxn];
vector<int> AL[maxn];
vector<ii> EL,back_edge,tree_edge;
void dfs(int u){
int far=u;
for(int v:AL[u]){
if(depth[v]==0){
par[v]=u;
depth[v]=depth[u]+1;
dfs(v);
tree_edge.pb({u,v});
}
else if(v!=par[u]&&depth[far]>depth[v])far=v;
}
back_edge.pb({u,far});
}
int count(vector<int> e){
int num=0;
ufds.init(n);
vector<int> ask;
for(int i:e){
int u,v;
tie(u,v)=EL[i];
ufds.join(u,v);
ask.pb(edge[u][v]);
}
for(auto[u,v]:tree_edge){
if(ufds.fp(u)!=ufds.fp(v)){
ufds.join(u,v);
ask.pb(edge[u][v]);
num+=good[edge[u][v]];
}
}
return count_common_roads(ask)-num;
}
vector<int> find_roads(int _n,vector<int> u,vector<int> v){
n=_n;m=u.size();
memset(edge,-1,sizeof edge);
memset(good,-1,sizeof good);
for(int i=0;i<m;++i){
AL[u[i]].pb(v[i]);
AL[v[i]].pb(u[i]);
edge[u[i]][v[i]]=edge[v[i]][u[i]]=i;
EL.pb({u[i],v[i]});
}
depth[0]=1;
dfs(0);
for(auto[u,v]:back_edge){
if(u==v)continue;
vector<ii> edges;
edges.pb({u,v});
ufds.init(n);
while(u!=v){
edges.pb({u,par[u]});
ufds.join(u,par[u]);
u=par[u];
}
vector<ii> others;
for(auto[u,v]:EL){
if(ufds.fp(u)!=ufds.fp(v)){
others.pb({u,v});
ufds.join(u,v);
}
}
vector<ii> res;
bool have_ref=false;
int ref_type=-1,ref_val=-1;
for(auto[u,v]:edges){
int id=edge[u][v];
if(good[id]!=-1&&have_ref)continue;
if(good[id]!=-1)have_ref=true;
vector<int> ask;
for(auto[u,v]:others)ask.pb(edge[u][v]);
for(auto[x,y]:edges){
if(x!=u||y!=v)ask.pb(edge[x][y]);
}
res.pb({count_common_roads(ask),id});
if(good[id]!=-1)ref_type=good[id],ref_val=res.back().fi;
}
if(res.size()==0)continue;
sort(res.begin(),res.end());
int small=res[0].fi,big=res.back().fi;
for(auto[x,i]:res){
if(x==ref_val)good[i]=ref_type;
else if(x==big)good[i]=0;
else if(x==small)good[i]=1;
}
}
for(auto[u,v]:tree_edge){
int id=edge[u][v];
if(good[id]==-1)good[id]=1;
}
for(int u=0;u<n;++u){
vector<int> tmp;
for(int v:AL[u])tmp.pb(edge[u][v]);
deg[u]=count(tmp);
}
while(true){
int u=-1;
for(int i=0;i<n;++i){
if(done[i]==0&°[i]==1)u=i;
}
if(u==-1)break;
vector<int> e;
for(int v:AL[u]){
if(!done[v])e.pb(edge[u][v]);
}
int lo=0,hi=e.size()-1,mid,res;
while(lo<=hi){
mid=(lo+hi)>>1;
vector<int> tmp;
for(int i=0;i<=mid;++i)tmp.pb(e[i]);
if(count(tmp)==1)res=mid,hi=mid-1;
else lo=mid+1;
}
good[e[res]]=1;
int v=EL[e[res]].fi;
if(u==v)v=EL[e[res]].se;
--deg[v];
done[u]=1;
}
vector<int> ans;
for(int i=0;i<m;++i){
if(good[i]==1)ans.pb(i);
}
assert(count_common_roads(ans)==n-1);
return ans;
}
Compilation message
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:156:13: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
156 | good[e[res]]=1;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2260 KB |
correct |
2 |
Correct |
1 ms |
2260 KB |
correct |
3 |
Correct |
1 ms |
2260 KB |
correct |
4 |
Correct |
1 ms |
2260 KB |
correct |
5 |
Correct |
1 ms |
2260 KB |
correct |
6 |
Correct |
1 ms |
2260 KB |
correct |
7 |
Correct |
2 ms |
2260 KB |
correct |
8 |
Correct |
2 ms |
2260 KB |
correct |
9 |
Correct |
1 ms |
2260 KB |
correct |
10 |
Correct |
1 ms |
2260 KB |
correct |
11 |
Correct |
2 ms |
2260 KB |
correct |
12 |
Correct |
1 ms |
2260 KB |
correct |
13 |
Correct |
1 ms |
2260 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2260 KB |
correct |
2 |
Correct |
1 ms |
2260 KB |
correct |
3 |
Correct |
1 ms |
2260 KB |
correct |
4 |
Correct |
1 ms |
2260 KB |
correct |
5 |
Correct |
1 ms |
2260 KB |
correct |
6 |
Correct |
1 ms |
2260 KB |
correct |
7 |
Correct |
2 ms |
2260 KB |
correct |
8 |
Correct |
2 ms |
2260 KB |
correct |
9 |
Correct |
1 ms |
2260 KB |
correct |
10 |
Correct |
1 ms |
2260 KB |
correct |
11 |
Correct |
2 ms |
2260 KB |
correct |
12 |
Correct |
1 ms |
2260 KB |
correct |
13 |
Correct |
1 ms |
2260 KB |
correct |
14 |
Correct |
4 ms |
2296 KB |
correct |
15 |
Correct |
3 ms |
2388 KB |
correct |
16 |
Correct |
3 ms |
2388 KB |
correct |
17 |
Correct |
3 ms |
2260 KB |
correct |
18 |
Correct |
2 ms |
2260 KB |
correct |
19 |
Correct |
3 ms |
2260 KB |
correct |
20 |
Correct |
3 ms |
2260 KB |
correct |
21 |
Correct |
2 ms |
2260 KB |
correct |
22 |
Correct |
2 ms |
2260 KB |
correct |
23 |
Correct |
3 ms |
2260 KB |
correct |
24 |
Correct |
2 ms |
2260 KB |
correct |
25 |
Correct |
2 ms |
2244 KB |
correct |
26 |
Correct |
3 ms |
2260 KB |
correct |
27 |
Correct |
2 ms |
2260 KB |
correct |
28 |
Correct |
2 ms |
2244 KB |
correct |
29 |
Correct |
3 ms |
2260 KB |
correct |
30 |
Correct |
2 ms |
2260 KB |
correct |
31 |
Correct |
2 ms |
2260 KB |
correct |
32 |
Correct |
2 ms |
2260 KB |
correct |
33 |
Correct |
3 ms |
2260 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2260 KB |
correct |
2 |
Correct |
1 ms |
2260 KB |
correct |
3 |
Correct |
1 ms |
2260 KB |
correct |
4 |
Correct |
1 ms |
2260 KB |
correct |
5 |
Correct |
1 ms |
2260 KB |
correct |
6 |
Correct |
1 ms |
2260 KB |
correct |
7 |
Correct |
2 ms |
2260 KB |
correct |
8 |
Correct |
2 ms |
2260 KB |
correct |
9 |
Correct |
1 ms |
2260 KB |
correct |
10 |
Correct |
1 ms |
2260 KB |
correct |
11 |
Correct |
2 ms |
2260 KB |
correct |
12 |
Correct |
1 ms |
2260 KB |
correct |
13 |
Correct |
1 ms |
2260 KB |
correct |
14 |
Correct |
4 ms |
2296 KB |
correct |
15 |
Correct |
3 ms |
2388 KB |
correct |
16 |
Correct |
3 ms |
2388 KB |
correct |
17 |
Correct |
3 ms |
2260 KB |
correct |
18 |
Correct |
2 ms |
2260 KB |
correct |
19 |
Correct |
3 ms |
2260 KB |
correct |
20 |
Correct |
3 ms |
2260 KB |
correct |
21 |
Correct |
2 ms |
2260 KB |
correct |
22 |
Correct |
2 ms |
2260 KB |
correct |
23 |
Correct |
3 ms |
2260 KB |
correct |
24 |
Correct |
2 ms |
2260 KB |
correct |
25 |
Correct |
2 ms |
2244 KB |
correct |
26 |
Correct |
3 ms |
2260 KB |
correct |
27 |
Correct |
2 ms |
2260 KB |
correct |
28 |
Correct |
2 ms |
2244 KB |
correct |
29 |
Correct |
3 ms |
2260 KB |
correct |
30 |
Correct |
2 ms |
2260 KB |
correct |
31 |
Correct |
2 ms |
2260 KB |
correct |
32 |
Correct |
2 ms |
2260 KB |
correct |
33 |
Correct |
3 ms |
2260 KB |
correct |
34 |
Correct |
73 ms |
3536 KB |
correct |
35 |
Correct |
69 ms |
3532 KB |
correct |
36 |
Correct |
59 ms |
3284 KB |
correct |
37 |
Correct |
15 ms |
2420 KB |
correct |
38 |
Correct |
72 ms |
3536 KB |
correct |
39 |
Correct |
62 ms |
3412 KB |
correct |
40 |
Correct |
59 ms |
3260 KB |
correct |
41 |
Correct |
80 ms |
3536 KB |
correct |
42 |
Correct |
71 ms |
3536 KB |
correct |
43 |
Correct |
42 ms |
3028 KB |
correct |
44 |
Correct |
37 ms |
2896 KB |
correct |
45 |
Correct |
40 ms |
2900 KB |
correct |
46 |
Correct |
38 ms |
2760 KB |
correct |
47 |
Correct |
26 ms |
2516 KB |
correct |
48 |
Correct |
8 ms |
2260 KB |
correct |
49 |
Correct |
13 ms |
2428 KB |
correct |
50 |
Correct |
22 ms |
2596 KB |
correct |
51 |
Correct |
41 ms |
2900 KB |
correct |
52 |
Correct |
37 ms |
2900 KB |
correct |
53 |
Correct |
36 ms |
2772 KB |
correct |
54 |
Correct |
47 ms |
3020 KB |
correct |
55 |
Correct |
45 ms |
2972 KB |
correct |
56 |
Correct |
42 ms |
2900 KB |
correct |
57 |
Correct |
41 ms |
2900 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2260 KB |
correct |
2 |
Correct |
1 ms |
2260 KB |
correct |
3 |
Correct |
277 ms |
5548 KB |
correct |
4 |
Correct |
507 ms |
6484 KB |
correct |
5 |
Correct |
501 ms |
6488 KB |
correct |
6 |
Correct |
507 ms |
6500 KB |
correct |
7 |
Correct |
533 ms |
7424 KB |
correct |
8 |
Correct |
518 ms |
7488 KB |
correct |
9 |
Correct |
502 ms |
7368 KB |
correct |
10 |
Correct |
518 ms |
7424 KB |
correct |
11 |
Correct |
522 ms |
7428 KB |
correct |
12 |
Correct |
509 ms |
7440 KB |
correct |
13 |
Correct |
1 ms |
2260 KB |
correct |
14 |
Correct |
514 ms |
7420 KB |
correct |
15 |
Correct |
509 ms |
7424 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2260 KB |
correct |
2 |
Correct |
1 ms |
2260 KB |
correct |
3 |
Correct |
1 ms |
2260 KB |
correct |
4 |
Correct |
1 ms |
2260 KB |
correct |
5 |
Correct |
1 ms |
2260 KB |
correct |
6 |
Correct |
1 ms |
2260 KB |
correct |
7 |
Correct |
2 ms |
2260 KB |
correct |
8 |
Correct |
2 ms |
2260 KB |
correct |
9 |
Correct |
1 ms |
2260 KB |
correct |
10 |
Correct |
1 ms |
2260 KB |
correct |
11 |
Correct |
2 ms |
2260 KB |
correct |
12 |
Correct |
1 ms |
2260 KB |
correct |
13 |
Correct |
1 ms |
2260 KB |
correct |
14 |
Correct |
4 ms |
2296 KB |
correct |
15 |
Correct |
3 ms |
2388 KB |
correct |
16 |
Correct |
3 ms |
2388 KB |
correct |
17 |
Correct |
3 ms |
2260 KB |
correct |
18 |
Correct |
2 ms |
2260 KB |
correct |
19 |
Correct |
3 ms |
2260 KB |
correct |
20 |
Correct |
3 ms |
2260 KB |
correct |
21 |
Correct |
2 ms |
2260 KB |
correct |
22 |
Correct |
2 ms |
2260 KB |
correct |
23 |
Correct |
3 ms |
2260 KB |
correct |
24 |
Correct |
2 ms |
2260 KB |
correct |
25 |
Correct |
2 ms |
2244 KB |
correct |
26 |
Correct |
3 ms |
2260 KB |
correct |
27 |
Correct |
2 ms |
2260 KB |
correct |
28 |
Correct |
2 ms |
2244 KB |
correct |
29 |
Correct |
3 ms |
2260 KB |
correct |
30 |
Correct |
2 ms |
2260 KB |
correct |
31 |
Correct |
2 ms |
2260 KB |
correct |
32 |
Correct |
2 ms |
2260 KB |
correct |
33 |
Correct |
3 ms |
2260 KB |
correct |
34 |
Correct |
73 ms |
3536 KB |
correct |
35 |
Correct |
69 ms |
3532 KB |
correct |
36 |
Correct |
59 ms |
3284 KB |
correct |
37 |
Correct |
15 ms |
2420 KB |
correct |
38 |
Correct |
72 ms |
3536 KB |
correct |
39 |
Correct |
62 ms |
3412 KB |
correct |
40 |
Correct |
59 ms |
3260 KB |
correct |
41 |
Correct |
80 ms |
3536 KB |
correct |
42 |
Correct |
71 ms |
3536 KB |
correct |
43 |
Correct |
42 ms |
3028 KB |
correct |
44 |
Correct |
37 ms |
2896 KB |
correct |
45 |
Correct |
40 ms |
2900 KB |
correct |
46 |
Correct |
38 ms |
2760 KB |
correct |
47 |
Correct |
26 ms |
2516 KB |
correct |
48 |
Correct |
8 ms |
2260 KB |
correct |
49 |
Correct |
13 ms |
2428 KB |
correct |
50 |
Correct |
22 ms |
2596 KB |
correct |
51 |
Correct |
41 ms |
2900 KB |
correct |
52 |
Correct |
37 ms |
2900 KB |
correct |
53 |
Correct |
36 ms |
2772 KB |
correct |
54 |
Correct |
47 ms |
3020 KB |
correct |
55 |
Correct |
45 ms |
2972 KB |
correct |
56 |
Correct |
42 ms |
2900 KB |
correct |
57 |
Correct |
41 ms |
2900 KB |
correct |
58 |
Correct |
1 ms |
2260 KB |
correct |
59 |
Correct |
1 ms |
2260 KB |
correct |
60 |
Correct |
277 ms |
5548 KB |
correct |
61 |
Correct |
507 ms |
6484 KB |
correct |
62 |
Correct |
501 ms |
6488 KB |
correct |
63 |
Correct |
507 ms |
6500 KB |
correct |
64 |
Correct |
533 ms |
7424 KB |
correct |
65 |
Correct |
518 ms |
7488 KB |
correct |
66 |
Correct |
502 ms |
7368 KB |
correct |
67 |
Correct |
518 ms |
7424 KB |
correct |
68 |
Correct |
522 ms |
7428 KB |
correct |
69 |
Correct |
509 ms |
7440 KB |
correct |
70 |
Correct |
1 ms |
2260 KB |
correct |
71 |
Correct |
514 ms |
7420 KB |
correct |
72 |
Correct |
509 ms |
7424 KB |
correct |
73 |
Correct |
1 ms |
2260 KB |
correct |
74 |
Correct |
520 ms |
7420 KB |
correct |
75 |
Correct |
474 ms |
7240 KB |
correct |
76 |
Correct |
190 ms |
4244 KB |
correct |
77 |
Correct |
499 ms |
7424 KB |
correct |
78 |
Correct |
529 ms |
7400 KB |
correct |
79 |
Correct |
531 ms |
7424 KB |
correct |
80 |
Correct |
494 ms |
7288 KB |
correct |
81 |
Correct |
429 ms |
6724 KB |
correct |
82 |
Correct |
503 ms |
7308 KB |
correct |
83 |
Correct |
295 ms |
5048 KB |
correct |
84 |
Correct |
324 ms |
5872 KB |
correct |
85 |
Correct |
286 ms |
5352 KB |
correct |
86 |
Correct |
232 ms |
4372 KB |
correct |
87 |
Correct |
173 ms |
3836 KB |
correct |
88 |
Correct |
160 ms |
3392 KB |
correct |
89 |
Correct |
138 ms |
3284 KB |
correct |
90 |
Correct |
123 ms |
3296 KB |
correct |
91 |
Correct |
54 ms |
2388 KB |
correct |
92 |
Correct |
35 ms |
2388 KB |
correct |
93 |
Correct |
282 ms |
5320 KB |
correct |
94 |
Correct |
224 ms |
4432 KB |
correct |
95 |
Correct |
208 ms |
4304 KB |
correct |
96 |
Correct |
131 ms |
3284 KB |
correct |
97 |
Correct |
146 ms |
3444 KB |
correct |
98 |
Correct |
177 ms |
3792 KB |
correct |
99 |
Correct |
146 ms |
3412 KB |
correct |
100 |
Correct |
72 ms |
2644 KB |
correct |
101 |
Correct |
31 ms |
2388 KB |
correct |
102 |
Correct |
302 ms |
4936 KB |
correct |
103 |
Correct |
267 ms |
4940 KB |
correct |
104 |
Correct |
274 ms |
4812 KB |
correct |
105 |
Correct |
274 ms |
4912 KB |
correct |