#include<bits/stdc++.h>
#include "simurgh.h"
using namespace std;
int a,b,c,d,e,i,j,ii,jj,zx,xc,msh[200009],E,BO[200009],ans[200009],Q[200009],QI,W[200009],WI,p[200009],pi,dep[200009],O[503][503],st,bo[200009],lef,rig,mid,cnt;
pair <int, int> P[200009];
vector <int> v[200009],xe,vv[200009],VV,V;
int fnd(int q){
if(msh[q]==0) return q; else return msh[q]=fnd(msh[q]);
}
bool mrg(int q, int w){
q=fnd(q);w=fnd(w);
if(q==w) return 0;
msh[q]=w;
return 1;
}
void dfs(int q, int w){
msh[q]=w;dep[q]=dep[w]+1;
for(vector <int>::iterator it=vv[q].begin(); it!=vv[q].end(); it++){
if((*it)==w) continue;
dfs((*it),q);
}
}
vector <int> tofull(vector <int> q){
vector <int> Q=q;
cnt++;
for(int h=0; h<q.size(); h++){
int we=0;
if(P[q[h]].first==ii) we=P[q[h]].second; else we=P[q[h]].first;
int qw=O[we][msh[we]];bo[qw]=cnt;
}
for(int h=0; h<xe.size(); h++){
if(bo[xe[h]]!=cnt){
Q.push_back(xe[h]);
}
}
return Q;
}
vector<int> find_roads(int Nn, std::vector<int> Uu, std::vector<int> Vv) {
a=Nn;b=Uu.size();
for(i=0; i<Uu.size(); i++){
P[i]={Uu[i]+1,Vv[i]+1};
v[P[i].first].push_back(P[i].second);v[P[i].second].push_back(P[i].first);
O[P[i].first][P[i].second]=O[P[i].second][P[i].first]=i;
}
for(i=0; i<b; i++){
E=mrg(P[i].first,P[i].second);
if(E==1){
xe.push_back(i);BO[i]=1;
vv[P[i].first].push_back(P[i].second);vv[P[i].second].push_back(P[i].first);
}
}
st=count_common_roads(xe);
for(i=0; i<b; i++) ans[i]=2;
dfs(1,0);
for(ii=0; ii<b; ii++){
if(BO[ii]==0){
QI=0;WI=0;pi=0;
c=P[ii].first;d=P[ii].second;
while(c!=d){
if(dep[c]>=dep[d]){
QI++;Q[QI]=c;c=msh[c];
}else{
WI++;W[WI]=d;d=msh[d];
}
}
QI++;Q[QI]=c;
for(i=1; i<=QI; i++){
pi++;p[pi]=Q[i];
}
for(i=WI; i>=1; i--){
pi++;p[pi]=W[i];
}
QI=0;
for(i=1; i<pi; i++){
c=O[p[i]][p[i+1]];
if(ans[c]==2){
QI++;Q[QI]=c;
}
}
if(QI==0) continue;
E=0;
for(i=1; i<pi; i++){
c=O[p[i]][p[i+1]];
if(ans[c]!=2){
QI++;Q[QI]=c;E=ans[c];break;
}
}
if(QI==0){
QI++;Q[QI]=O[p[1]][p[2]];
}
WI=0;
for(i=1; i<=QI; i++){
VV.clear();
for(j=0; j<xe.size(); j++){
if(xe[j]!=Q[i]){
VV.push_back(xe[j]);
}
}
VV.push_back(ii);
WI++;W[WI]=count_common_roads(VV);
}
WI++;W[WI]=st;zx=0;xc=a+4;Q[WI]=ii;
for(i=1; i<=WI; i++){
zx=max(zx,W[i]);xc=min(xc,W[i]);
}
for(i=1; i<=WI; i++){
if(zx==xc){
ans[Q[i]]=E;
continue;
}
if(W[i]==zx){
ans[Q[i]]=0;
}else{
ans[Q[i]]=1;
}
}
}
}
for(ii=0; ii<b; ii++){
if(BO[ii]==1){
if(ans[ii]==2) ans[ii]=1;
}
}
for(ii=1; ii<=a; ii++){
dfs(ii,0);VV.clear();V.clear();
for(vector <int>::iterator it=v[ii].begin(); it!=v[ii].end(); it++){
c=O[ii][(*it)];
if(ans[c]!=2) continue;
VV.push_back(c);
}
if(VV.size()==0) continue;
V=tofull(VV);
zx=count_common_roads(V);
for(int h=0; h<V.size(); h++){
if(ans[V[h]]==1) zx--;
}
E=-1;
while(zx>0){
lef=E;rig=VV.size();
while(1){
if(lef+1>=rig) break;
mid=(lef+rig)/2;
V.clear();
for(int h=E+1; h<=mid; h++){
V.push_back(VV[h]);
}
V=tofull(V);
c=count_common_roads(V);
for(int h=0; h<V.size(); h++){
if(ans[V[h]]==1) c--;
}
if(c>0){
rig=mid;
}else{
lef=mid;
}
}
for(int h=E+1; h<rig; h++) ans[VV[h]]=0;
ans[VV[rig]]=1;
zx--;E=rig;
}
}
VV.clear();
for(ii=0; ii<b; ii++){
if(ans[ii]==1) VV.push_back(ii);
}
return VV;
}
Compilation message
simurgh.cpp: In function 'std::vector<int> tofull(std::vector<int>)':
simurgh.cpp:26:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int h=0; h<q.size(); h++){
| ~^~~~~~~~~
simurgh.cpp:31:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int h=0; h<xe.size(); h++){
| ~^~~~~~~~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:40:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(i=0; i<Uu.size(); i++){
| ~^~~~~~~~~~
simurgh.cpp:94:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for(j=0; j<xe.size(); j++){
| ~^~~~~~~~~~
simurgh.cpp:134:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
134 | for(int h=0; h<V.size(); h++){
| ~^~~~~~~~~
simurgh.cpp:149:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
149 | for(int h=0; h<V.size(); h++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
correct |
2 |
Correct |
6 ms |
9812 KB |
correct |
3 |
Correct |
7 ms |
9648 KB |
correct |
4 |
Correct |
5 ms |
9684 KB |
correct |
5 |
Correct |
7 ms |
9684 KB |
correct |
6 |
Correct |
6 ms |
9660 KB |
correct |
7 |
Correct |
5 ms |
9684 KB |
correct |
8 |
Correct |
5 ms |
9684 KB |
correct |
9 |
Correct |
6 ms |
9684 KB |
correct |
10 |
Correct |
5 ms |
9684 KB |
correct |
11 |
Correct |
4 ms |
9740 KB |
correct |
12 |
Correct |
5 ms |
9684 KB |
correct |
13 |
Correct |
5 ms |
9684 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
correct |
2 |
Correct |
6 ms |
9812 KB |
correct |
3 |
Correct |
7 ms |
9648 KB |
correct |
4 |
Correct |
5 ms |
9684 KB |
correct |
5 |
Correct |
7 ms |
9684 KB |
correct |
6 |
Correct |
6 ms |
9660 KB |
correct |
7 |
Correct |
5 ms |
9684 KB |
correct |
8 |
Correct |
5 ms |
9684 KB |
correct |
9 |
Correct |
6 ms |
9684 KB |
correct |
10 |
Correct |
5 ms |
9684 KB |
correct |
11 |
Correct |
4 ms |
9740 KB |
correct |
12 |
Correct |
5 ms |
9684 KB |
correct |
13 |
Correct |
5 ms |
9684 KB |
correct |
14 |
Correct |
6 ms |
9812 KB |
correct |
15 |
Correct |
6 ms |
9812 KB |
correct |
16 |
Correct |
6 ms |
9812 KB |
correct |
17 |
Correct |
6 ms |
9812 KB |
correct |
18 |
Correct |
8 ms |
9812 KB |
correct |
19 |
Correct |
6 ms |
9812 KB |
correct |
20 |
Correct |
6 ms |
9788 KB |
correct |
21 |
Correct |
6 ms |
9812 KB |
correct |
22 |
Correct |
7 ms |
9876 KB |
correct |
23 |
Correct |
8 ms |
9856 KB |
correct |
24 |
Correct |
8 ms |
9880 KB |
correct |
25 |
Correct |
5 ms |
9812 KB |
correct |
26 |
Correct |
6 ms |
9812 KB |
correct |
27 |
Correct |
6 ms |
9812 KB |
correct |
28 |
Correct |
5 ms |
9812 KB |
correct |
29 |
Correct |
5 ms |
9812 KB |
correct |
30 |
Correct |
5 ms |
9812 KB |
correct |
31 |
Correct |
6 ms |
9780 KB |
correct |
32 |
Correct |
5 ms |
9888 KB |
correct |
33 |
Correct |
6 ms |
9852 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
correct |
2 |
Correct |
6 ms |
9812 KB |
correct |
3 |
Correct |
7 ms |
9648 KB |
correct |
4 |
Correct |
5 ms |
9684 KB |
correct |
5 |
Correct |
7 ms |
9684 KB |
correct |
6 |
Correct |
6 ms |
9660 KB |
correct |
7 |
Correct |
5 ms |
9684 KB |
correct |
8 |
Correct |
5 ms |
9684 KB |
correct |
9 |
Correct |
6 ms |
9684 KB |
correct |
10 |
Correct |
5 ms |
9684 KB |
correct |
11 |
Correct |
4 ms |
9740 KB |
correct |
12 |
Correct |
5 ms |
9684 KB |
correct |
13 |
Correct |
5 ms |
9684 KB |
correct |
14 |
Correct |
6 ms |
9812 KB |
correct |
15 |
Correct |
6 ms |
9812 KB |
correct |
16 |
Correct |
6 ms |
9812 KB |
correct |
17 |
Correct |
6 ms |
9812 KB |
correct |
18 |
Correct |
8 ms |
9812 KB |
correct |
19 |
Correct |
6 ms |
9812 KB |
correct |
20 |
Correct |
6 ms |
9788 KB |
correct |
21 |
Correct |
6 ms |
9812 KB |
correct |
22 |
Correct |
7 ms |
9876 KB |
correct |
23 |
Correct |
8 ms |
9856 KB |
correct |
24 |
Correct |
8 ms |
9880 KB |
correct |
25 |
Correct |
5 ms |
9812 KB |
correct |
26 |
Correct |
6 ms |
9812 KB |
correct |
27 |
Correct |
6 ms |
9812 KB |
correct |
28 |
Correct |
5 ms |
9812 KB |
correct |
29 |
Correct |
5 ms |
9812 KB |
correct |
30 |
Correct |
5 ms |
9812 KB |
correct |
31 |
Correct |
6 ms |
9780 KB |
correct |
32 |
Correct |
5 ms |
9888 KB |
correct |
33 |
Correct |
6 ms |
9852 KB |
correct |
34 |
Correct |
42 ms |
11344 KB |
correct |
35 |
Correct |
42 ms |
11220 KB |
correct |
36 |
Correct |
36 ms |
11056 KB |
correct |
37 |
Correct |
13 ms |
10196 KB |
correct |
38 |
Correct |
41 ms |
11348 KB |
correct |
39 |
Correct |
37 ms |
11216 KB |
correct |
40 |
Correct |
33 ms |
10964 KB |
correct |
41 |
Correct |
41 ms |
11336 KB |
correct |
42 |
Correct |
43 ms |
11340 KB |
correct |
43 |
Correct |
16 ms |
10836 KB |
correct |
44 |
Correct |
15 ms |
10688 KB |
correct |
45 |
Correct |
15 ms |
10708 KB |
correct |
46 |
Correct |
13 ms |
10680 KB |
correct |
47 |
Correct |
13 ms |
10464 KB |
correct |
48 |
Correct |
8 ms |
10196 KB |
correct |
49 |
Correct |
10 ms |
10196 KB |
correct |
50 |
Correct |
11 ms |
10452 KB |
correct |
51 |
Correct |
15 ms |
10704 KB |
correct |
52 |
Correct |
14 ms |
10692 KB |
correct |
53 |
Correct |
13 ms |
10580 KB |
correct |
54 |
Correct |
15 ms |
10836 KB |
correct |
55 |
Correct |
16 ms |
10708 KB |
correct |
56 |
Correct |
15 ms |
10708 KB |
correct |
57 |
Correct |
16 ms |
10776 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
correct |
2 |
Correct |
5 ms |
9684 KB |
correct |
3 |
Correct |
127 ms |
13652 KB |
correct |
4 |
Correct |
198 ms |
15292 KB |
correct |
5 |
Correct |
167 ms |
15308 KB |
correct |
6 |
Correct |
173 ms |
15404 KB |
correct |
7 |
Correct |
202 ms |
15404 KB |
correct |
8 |
Correct |
152 ms |
15308 KB |
correct |
9 |
Correct |
193 ms |
15436 KB |
correct |
10 |
Correct |
193 ms |
15292 KB |
correct |
11 |
Correct |
177 ms |
15352 KB |
correct |
12 |
Correct |
200 ms |
15312 KB |
correct |
13 |
Correct |
5 ms |
9628 KB |
correct |
14 |
Correct |
171 ms |
15340 KB |
correct |
15 |
Correct |
212 ms |
15308 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
correct |
2 |
Correct |
6 ms |
9812 KB |
correct |
3 |
Correct |
7 ms |
9648 KB |
correct |
4 |
Correct |
5 ms |
9684 KB |
correct |
5 |
Correct |
7 ms |
9684 KB |
correct |
6 |
Correct |
6 ms |
9660 KB |
correct |
7 |
Correct |
5 ms |
9684 KB |
correct |
8 |
Correct |
5 ms |
9684 KB |
correct |
9 |
Correct |
6 ms |
9684 KB |
correct |
10 |
Correct |
5 ms |
9684 KB |
correct |
11 |
Correct |
4 ms |
9740 KB |
correct |
12 |
Correct |
5 ms |
9684 KB |
correct |
13 |
Correct |
5 ms |
9684 KB |
correct |
14 |
Correct |
6 ms |
9812 KB |
correct |
15 |
Correct |
6 ms |
9812 KB |
correct |
16 |
Correct |
6 ms |
9812 KB |
correct |
17 |
Correct |
6 ms |
9812 KB |
correct |
18 |
Correct |
8 ms |
9812 KB |
correct |
19 |
Correct |
6 ms |
9812 KB |
correct |
20 |
Correct |
6 ms |
9788 KB |
correct |
21 |
Correct |
6 ms |
9812 KB |
correct |
22 |
Correct |
7 ms |
9876 KB |
correct |
23 |
Correct |
8 ms |
9856 KB |
correct |
24 |
Correct |
8 ms |
9880 KB |
correct |
25 |
Correct |
5 ms |
9812 KB |
correct |
26 |
Correct |
6 ms |
9812 KB |
correct |
27 |
Correct |
6 ms |
9812 KB |
correct |
28 |
Correct |
5 ms |
9812 KB |
correct |
29 |
Correct |
5 ms |
9812 KB |
correct |
30 |
Correct |
5 ms |
9812 KB |
correct |
31 |
Correct |
6 ms |
9780 KB |
correct |
32 |
Correct |
5 ms |
9888 KB |
correct |
33 |
Correct |
6 ms |
9852 KB |
correct |
34 |
Correct |
42 ms |
11344 KB |
correct |
35 |
Correct |
42 ms |
11220 KB |
correct |
36 |
Correct |
36 ms |
11056 KB |
correct |
37 |
Correct |
13 ms |
10196 KB |
correct |
38 |
Correct |
41 ms |
11348 KB |
correct |
39 |
Correct |
37 ms |
11216 KB |
correct |
40 |
Correct |
33 ms |
10964 KB |
correct |
41 |
Correct |
41 ms |
11336 KB |
correct |
42 |
Correct |
43 ms |
11340 KB |
correct |
43 |
Correct |
16 ms |
10836 KB |
correct |
44 |
Correct |
15 ms |
10688 KB |
correct |
45 |
Correct |
15 ms |
10708 KB |
correct |
46 |
Correct |
13 ms |
10680 KB |
correct |
47 |
Correct |
13 ms |
10464 KB |
correct |
48 |
Correct |
8 ms |
10196 KB |
correct |
49 |
Correct |
10 ms |
10196 KB |
correct |
50 |
Correct |
11 ms |
10452 KB |
correct |
51 |
Correct |
15 ms |
10704 KB |
correct |
52 |
Correct |
14 ms |
10692 KB |
correct |
53 |
Correct |
13 ms |
10580 KB |
correct |
54 |
Correct |
15 ms |
10836 KB |
correct |
55 |
Correct |
16 ms |
10708 KB |
correct |
56 |
Correct |
15 ms |
10708 KB |
correct |
57 |
Correct |
16 ms |
10776 KB |
correct |
58 |
Correct |
5 ms |
9684 KB |
correct |
59 |
Correct |
5 ms |
9684 KB |
correct |
60 |
Correct |
127 ms |
13652 KB |
correct |
61 |
Correct |
198 ms |
15292 KB |
correct |
62 |
Correct |
167 ms |
15308 KB |
correct |
63 |
Correct |
173 ms |
15404 KB |
correct |
64 |
Correct |
202 ms |
15404 KB |
correct |
65 |
Correct |
152 ms |
15308 KB |
correct |
66 |
Correct |
193 ms |
15436 KB |
correct |
67 |
Correct |
193 ms |
15292 KB |
correct |
68 |
Correct |
177 ms |
15352 KB |
correct |
69 |
Correct |
200 ms |
15312 KB |
correct |
70 |
Correct |
5 ms |
9628 KB |
correct |
71 |
Correct |
171 ms |
15340 KB |
correct |
72 |
Correct |
212 ms |
15308 KB |
correct |
73 |
Correct |
5 ms |
9684 KB |
correct |
74 |
Correct |
168 ms |
15296 KB |
correct |
75 |
Correct |
186 ms |
15252 KB |
correct |
76 |
Correct |
95 ms |
12248 KB |
correct |
77 |
Correct |
173 ms |
15460 KB |
correct |
78 |
Correct |
171 ms |
15344 KB |
correct |
79 |
Correct |
205 ms |
15356 KB |
correct |
80 |
Correct |
167 ms |
15240 KB |
correct |
81 |
Correct |
145 ms |
14740 KB |
correct |
82 |
Correct |
186 ms |
15220 KB |
correct |
83 |
Correct |
144 ms |
13196 KB |
correct |
84 |
Correct |
53 ms |
13652 KB |
correct |
85 |
Correct |
53 ms |
13420 KB |
correct |
86 |
Correct |
42 ms |
12564 KB |
correct |
87 |
Correct |
37 ms |
12160 KB |
correct |
88 |
Correct |
37 ms |
11732 KB |
correct |
89 |
Correct |
36 ms |
11680 KB |
correct |
90 |
Correct |
31 ms |
11604 KB |
correct |
91 |
Correct |
21 ms |
10876 KB |
correct |
92 |
Correct |
16 ms |
10708 KB |
correct |
93 |
Correct |
50 ms |
13396 KB |
correct |
94 |
Correct |
44 ms |
12560 KB |
correct |
95 |
Correct |
43 ms |
12492 KB |
correct |
96 |
Correct |
37 ms |
11640 KB |
correct |
97 |
Correct |
35 ms |
11736 KB |
correct |
98 |
Correct |
35 ms |
12140 KB |
correct |
99 |
Correct |
33 ms |
11744 KB |
correct |
100 |
Correct |
25 ms |
11032 KB |
correct |
101 |
Correct |
17 ms |
10796 KB |
correct |
102 |
Correct |
52 ms |
13088 KB |
correct |
103 |
Correct |
52 ms |
13048 KB |
correct |
104 |
Correct |
55 ms |
13052 KB |
correct |
105 |
Correct |
62 ms |
13012 KB |
correct |