#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
const int N=505*505;
int n,m,askt,h[N],ok[N],vis[N],last[N],f[N],A[N],B[N],mark[N];
pair<int,int> par[N];
vector<int> tree;
vector<pair<int,int>> g[N];
int getpar(int u){
if(f[u]<0) return u;
return f[u]=getpar(f[u]);
}
void merge(int u,int v){
u=getpar(u),v=getpar(v);
if(f[u]>f[v]) swap(u,v);
f[u]+=f[v];
f[v]=u;
}
int ask(vector<int> vec){
return count_common_roads(vec);
}
int get(vector<int> vec){
fill(f,f+n,-1);
int sum=0;
for(auto id : vec){
merge(A[id],B[id]);
}
for(auto id : tree){
int u=getpar(A[id]),v=getpar(B[id]);
if(u==v) continue ;
merge(u,v);
vec.pb(id);
sum+=ok[id];
}
return ask(vec)-sum;
}
void dfs(int u){
vis[u]=1;
for(auto [v,id] : g[u]){
if(vis[v]) continue ;
tree.pb(id);
h[v]=h[u]+1;
par[v]={u,id};
dfs(v);
}
}
vector<int> G(vector<int> vec,int ad,int dl){
vec.pb(ad);
f(i,0,vec.size()){
if(vec[i]==dl){
vec.erase(vec.begin()+i);
}
}
return vec;
}
vector<int> P(int u,int x){
vector<int> res;
f(i,0,x+1){
res.pb(g[u][i].S);
}
return res;
}
vector<int> find_roads(int _n,vector<int> _B,vector<int> _A){
fill(ok,ok+N,-1);
// build graph
vector<int> ans;
n=_n,m=_A.size();
f(i,0,m) A[i]=_A[i],B[i]=_B[i],g[A[i]].pb({B[i],i}),g[B[i]].pb({A[i],i});
//find a tree
dfs(0);
askt=ask(tree);
f(i,0,m){
int u=A[i],v=B[i],mx=askt,cnt=0,edge=0;
if(abs(h[u]-h[v])==1) continue ;
if(h[u]>h[v]) swap(u,v);
for(int x=v;x!=u;x=par[x].F){
if(ok[par[x].S]!=-1){
cnt++;
edge=par[x].S;
}
}
if(cnt==h[v]-h[u]) continue ;
//cout<<u<<" -> "<<v<<endl;
if(cnt>0){
vector<int> prt=G(tree,i,edge);
maxm(mx,ask(prt)+ok[edge]);
}
for(int x=v;x!=u;x=par[x].F){
if(ok[par[x].S]!=-1) continue ;
vector<int> prt=G(tree,i,par[x].S);
last[par[x].S]=ask(prt);
maxm(mx,last[par[x].S]);
}
for(int x=v;x!=u;x=par[x].F){
if(ok[par[x].S]!=-1) continue ;
if(last[par[x].S]==mx) ok[par[x].S]=0;
else ok[par[x].S]=1;
}
}
for(auto id : tree) if(ok[id]==-1) ok[id]=1;
//dbga(ok,0,m);
//main
f(u,0,n){
f_(i,g[u].size()-1,0) if(mark[g[u][i].S]) g[u].erase(g[u].begin()+i);
vector<int> vec;
int deg=get(P(u,g[u].size()-1));
f(i,0,deg){
int l=-1,r=g[u].size();
while(l+1<r){
int mid=(l+r)>>1;
if(get(P(u,mid))<=i){
l=mid;
}
else{
r=mid;
}
}
mark[g[u][r].S]=1;
ans.pb(g[u][r].S);
}
}
sort(all(ans));
ans.resize(unique(all(ans))-ans.begin());
return ans;
}
Compilation message
simurgh.cpp: In function 'void dfs(int)':
simurgh.cpp:61:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
61 | for(auto [v,id] : g[u]){
| ^
simurgh.cpp: In function 'std::vector<int> G(std::vector<int>, int, int)':
simurgh.cpp:9:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | #define f(i,a,b) for(int i=a;i<b;i++)
......
71 | f(i,0,vec.size()){
| ~~~~~~~~~~~~~~
simurgh.cpp:71:2: note: in expansion of macro 'f'
71 | f(i,0,vec.size()){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
correct |
2 |
Correct |
4 ms |
7252 KB |
correct |
3 |
Correct |
4 ms |
7252 KB |
correct |
4 |
Correct |
4 ms |
7260 KB |
correct |
5 |
Correct |
4 ms |
7220 KB |
correct |
6 |
Correct |
4 ms |
7252 KB |
correct |
7 |
Correct |
4 ms |
7252 KB |
correct |
8 |
Correct |
4 ms |
7252 KB |
correct |
9 |
Correct |
4 ms |
7252 KB |
correct |
10 |
Correct |
4 ms |
7252 KB |
correct |
11 |
Correct |
4 ms |
7252 KB |
correct |
12 |
Correct |
4 ms |
7252 KB |
correct |
13 |
Correct |
4 ms |
7252 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
correct |
2 |
Correct |
4 ms |
7252 KB |
correct |
3 |
Correct |
4 ms |
7252 KB |
correct |
4 |
Correct |
4 ms |
7260 KB |
correct |
5 |
Correct |
4 ms |
7220 KB |
correct |
6 |
Correct |
4 ms |
7252 KB |
correct |
7 |
Correct |
4 ms |
7252 KB |
correct |
8 |
Correct |
4 ms |
7252 KB |
correct |
9 |
Correct |
4 ms |
7252 KB |
correct |
10 |
Correct |
4 ms |
7252 KB |
correct |
11 |
Correct |
4 ms |
7252 KB |
correct |
12 |
Correct |
4 ms |
7252 KB |
correct |
13 |
Correct |
4 ms |
7252 KB |
correct |
14 |
Correct |
5 ms |
7380 KB |
correct |
15 |
Correct |
5 ms |
7380 KB |
correct |
16 |
Correct |
5 ms |
7324 KB |
correct |
17 |
Correct |
5 ms |
7380 KB |
correct |
18 |
Correct |
4 ms |
7380 KB |
correct |
19 |
Correct |
5 ms |
7380 KB |
correct |
20 |
Correct |
5 ms |
7380 KB |
correct |
21 |
Correct |
5 ms |
7380 KB |
correct |
22 |
Correct |
5 ms |
7380 KB |
correct |
23 |
Correct |
5 ms |
7252 KB |
correct |
24 |
Correct |
5 ms |
7252 KB |
correct |
25 |
Correct |
4 ms |
7252 KB |
correct |
26 |
Correct |
5 ms |
7292 KB |
correct |
27 |
Correct |
5 ms |
7372 KB |
correct |
28 |
Correct |
4 ms |
7252 KB |
correct |
29 |
Correct |
4 ms |
7252 KB |
correct |
30 |
Correct |
5 ms |
7380 KB |
correct |
31 |
Correct |
5 ms |
7252 KB |
correct |
32 |
Correct |
5 ms |
7380 KB |
correct |
33 |
Correct |
5 ms |
7280 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
correct |
2 |
Correct |
4 ms |
7252 KB |
correct |
3 |
Correct |
4 ms |
7252 KB |
correct |
4 |
Correct |
4 ms |
7260 KB |
correct |
5 |
Correct |
4 ms |
7220 KB |
correct |
6 |
Correct |
4 ms |
7252 KB |
correct |
7 |
Correct |
4 ms |
7252 KB |
correct |
8 |
Correct |
4 ms |
7252 KB |
correct |
9 |
Correct |
4 ms |
7252 KB |
correct |
10 |
Correct |
4 ms |
7252 KB |
correct |
11 |
Correct |
4 ms |
7252 KB |
correct |
12 |
Correct |
4 ms |
7252 KB |
correct |
13 |
Correct |
4 ms |
7252 KB |
correct |
14 |
Correct |
5 ms |
7380 KB |
correct |
15 |
Correct |
5 ms |
7380 KB |
correct |
16 |
Correct |
5 ms |
7324 KB |
correct |
17 |
Correct |
5 ms |
7380 KB |
correct |
18 |
Correct |
4 ms |
7380 KB |
correct |
19 |
Correct |
5 ms |
7380 KB |
correct |
20 |
Correct |
5 ms |
7380 KB |
correct |
21 |
Correct |
5 ms |
7380 KB |
correct |
22 |
Correct |
5 ms |
7380 KB |
correct |
23 |
Correct |
5 ms |
7252 KB |
correct |
24 |
Correct |
5 ms |
7252 KB |
correct |
25 |
Correct |
4 ms |
7252 KB |
correct |
26 |
Correct |
5 ms |
7292 KB |
correct |
27 |
Correct |
5 ms |
7372 KB |
correct |
28 |
Correct |
4 ms |
7252 KB |
correct |
29 |
Correct |
4 ms |
7252 KB |
correct |
30 |
Correct |
5 ms |
7380 KB |
correct |
31 |
Correct |
5 ms |
7252 KB |
correct |
32 |
Correct |
5 ms |
7380 KB |
correct |
33 |
Correct |
5 ms |
7280 KB |
correct |
34 |
Correct |
44 ms |
8660 KB |
correct |
35 |
Correct |
44 ms |
8660 KB |
correct |
36 |
Correct |
37 ms |
8416 KB |
correct |
37 |
Correct |
15 ms |
7380 KB |
correct |
38 |
Correct |
46 ms |
8692 KB |
correct |
39 |
Correct |
43 ms |
8640 KB |
correct |
40 |
Correct |
38 ms |
8488 KB |
correct |
41 |
Correct |
41 ms |
8740 KB |
correct |
42 |
Correct |
43 ms |
8780 KB |
correct |
43 |
Correct |
29 ms |
8220 KB |
correct |
44 |
Correct |
25 ms |
7964 KB |
correct |
45 |
Correct |
30 ms |
8020 KB |
correct |
46 |
Correct |
26 ms |
7892 KB |
correct |
47 |
Correct |
20 ms |
7612 KB |
correct |
48 |
Correct |
11 ms |
7380 KB |
correct |
49 |
Correct |
14 ms |
7456 KB |
correct |
50 |
Correct |
22 ms |
7636 KB |
correct |
51 |
Correct |
27 ms |
8024 KB |
correct |
52 |
Correct |
28 ms |
7924 KB |
correct |
53 |
Correct |
29 ms |
7892 KB |
correct |
54 |
Correct |
28 ms |
8232 KB |
correct |
55 |
Correct |
29 ms |
8020 KB |
correct |
56 |
Correct |
28 ms |
8020 KB |
correct |
57 |
Correct |
28 ms |
7940 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
correct |
2 |
Correct |
4 ms |
7252 KB |
correct |
3 |
Correct |
137 ms |
11396 KB |
correct |
4 |
Correct |
223 ms |
13152 KB |
correct |
5 |
Correct |
231 ms |
13140 KB |
correct |
6 |
Correct |
214 ms |
13148 KB |
correct |
7 |
Correct |
213 ms |
13116 KB |
correct |
8 |
Correct |
209 ms |
13304 KB |
correct |
9 |
Correct |
221 ms |
13232 KB |
correct |
10 |
Correct |
223 ms |
13132 KB |
correct |
11 |
Correct |
232 ms |
13032 KB |
correct |
12 |
Correct |
243 ms |
13184 KB |
correct |
13 |
Correct |
4 ms |
7252 KB |
correct |
14 |
Correct |
228 ms |
13148 KB |
correct |
15 |
Correct |
227 ms |
13068 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
correct |
2 |
Correct |
4 ms |
7252 KB |
correct |
3 |
Correct |
4 ms |
7252 KB |
correct |
4 |
Correct |
4 ms |
7260 KB |
correct |
5 |
Correct |
4 ms |
7220 KB |
correct |
6 |
Correct |
4 ms |
7252 KB |
correct |
7 |
Correct |
4 ms |
7252 KB |
correct |
8 |
Correct |
4 ms |
7252 KB |
correct |
9 |
Correct |
4 ms |
7252 KB |
correct |
10 |
Correct |
4 ms |
7252 KB |
correct |
11 |
Correct |
4 ms |
7252 KB |
correct |
12 |
Correct |
4 ms |
7252 KB |
correct |
13 |
Correct |
4 ms |
7252 KB |
correct |
14 |
Correct |
5 ms |
7380 KB |
correct |
15 |
Correct |
5 ms |
7380 KB |
correct |
16 |
Correct |
5 ms |
7324 KB |
correct |
17 |
Correct |
5 ms |
7380 KB |
correct |
18 |
Correct |
4 ms |
7380 KB |
correct |
19 |
Correct |
5 ms |
7380 KB |
correct |
20 |
Correct |
5 ms |
7380 KB |
correct |
21 |
Correct |
5 ms |
7380 KB |
correct |
22 |
Correct |
5 ms |
7380 KB |
correct |
23 |
Correct |
5 ms |
7252 KB |
correct |
24 |
Correct |
5 ms |
7252 KB |
correct |
25 |
Correct |
4 ms |
7252 KB |
correct |
26 |
Correct |
5 ms |
7292 KB |
correct |
27 |
Correct |
5 ms |
7372 KB |
correct |
28 |
Correct |
4 ms |
7252 KB |
correct |
29 |
Correct |
4 ms |
7252 KB |
correct |
30 |
Correct |
5 ms |
7380 KB |
correct |
31 |
Correct |
5 ms |
7252 KB |
correct |
32 |
Correct |
5 ms |
7380 KB |
correct |
33 |
Correct |
5 ms |
7280 KB |
correct |
34 |
Correct |
44 ms |
8660 KB |
correct |
35 |
Correct |
44 ms |
8660 KB |
correct |
36 |
Correct |
37 ms |
8416 KB |
correct |
37 |
Correct |
15 ms |
7380 KB |
correct |
38 |
Correct |
46 ms |
8692 KB |
correct |
39 |
Correct |
43 ms |
8640 KB |
correct |
40 |
Correct |
38 ms |
8488 KB |
correct |
41 |
Correct |
41 ms |
8740 KB |
correct |
42 |
Correct |
43 ms |
8780 KB |
correct |
43 |
Correct |
29 ms |
8220 KB |
correct |
44 |
Correct |
25 ms |
7964 KB |
correct |
45 |
Correct |
30 ms |
8020 KB |
correct |
46 |
Correct |
26 ms |
7892 KB |
correct |
47 |
Correct |
20 ms |
7612 KB |
correct |
48 |
Correct |
11 ms |
7380 KB |
correct |
49 |
Correct |
14 ms |
7456 KB |
correct |
50 |
Correct |
22 ms |
7636 KB |
correct |
51 |
Correct |
27 ms |
8024 KB |
correct |
52 |
Correct |
28 ms |
7924 KB |
correct |
53 |
Correct |
29 ms |
7892 KB |
correct |
54 |
Correct |
28 ms |
8232 KB |
correct |
55 |
Correct |
29 ms |
8020 KB |
correct |
56 |
Correct |
28 ms |
8020 KB |
correct |
57 |
Correct |
28 ms |
7940 KB |
correct |
58 |
Correct |
4 ms |
7252 KB |
correct |
59 |
Correct |
4 ms |
7252 KB |
correct |
60 |
Correct |
137 ms |
11396 KB |
correct |
61 |
Correct |
223 ms |
13152 KB |
correct |
62 |
Correct |
231 ms |
13140 KB |
correct |
63 |
Correct |
214 ms |
13148 KB |
correct |
64 |
Correct |
213 ms |
13116 KB |
correct |
65 |
Correct |
209 ms |
13304 KB |
correct |
66 |
Correct |
221 ms |
13232 KB |
correct |
67 |
Correct |
223 ms |
13132 KB |
correct |
68 |
Correct |
232 ms |
13032 KB |
correct |
69 |
Correct |
243 ms |
13184 KB |
correct |
70 |
Correct |
4 ms |
7252 KB |
correct |
71 |
Correct |
228 ms |
13148 KB |
correct |
72 |
Correct |
227 ms |
13068 KB |
correct |
73 |
Correct |
5 ms |
7252 KB |
correct |
74 |
Correct |
229 ms |
13068 KB |
correct |
75 |
Correct |
226 ms |
13900 KB |
correct |
76 |
Correct |
107 ms |
9988 KB |
correct |
77 |
Correct |
235 ms |
13972 KB |
correct |
78 |
Correct |
224 ms |
14108 KB |
correct |
79 |
Correct |
223 ms |
14144 KB |
correct |
80 |
Correct |
217 ms |
13868 KB |
correct |
81 |
Correct |
195 ms |
13288 KB |
correct |
82 |
Correct |
218 ms |
13884 KB |
correct |
83 |
Correct |
158 ms |
11072 KB |
correct |
84 |
Correct |
136 ms |
11552 KB |
correct |
85 |
Correct |
133 ms |
11316 KB |
correct |
86 |
Correct |
105 ms |
9892 KB |
correct |
87 |
Correct |
95 ms |
9452 KB |
correct |
88 |
Correct |
83 ms |
8788 KB |
correct |
89 |
Correct |
84 ms |
8744 KB |
correct |
90 |
Correct |
80 ms |
8584 KB |
correct |
91 |
Correct |
44 ms |
7480 KB |
correct |
92 |
Correct |
33 ms |
7432 KB |
correct |
93 |
Correct |
129 ms |
11212 KB |
correct |
94 |
Correct |
113 ms |
9880 KB |
correct |
95 |
Correct |
103 ms |
9876 KB |
correct |
96 |
Correct |
82 ms |
8684 KB |
correct |
97 |
Correct |
85 ms |
8716 KB |
correct |
98 |
Correct |
95 ms |
9428 KB |
correct |
99 |
Correct |
85 ms |
8808 KB |
correct |
100 |
Correct |
58 ms |
7744 KB |
correct |
101 |
Correct |
34 ms |
7380 KB |
correct |
102 |
Correct |
134 ms |
10532 KB |
correct |
103 |
Correct |
138 ms |
10536 KB |
correct |
104 |
Correct |
140 ms |
10640 KB |
correct |
105 |
Correct |
135 ms |
10516 KB |
correct |