#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0);
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define gg exit(0);
#include "simurgh.h"
const int N=510;
int mode,it,asked=1;
int dd[N],fa[N],st[N],ed[N];
int id[N][N];
int asking[1000000];
int yes[1000000];
int no[1000000];
int tested[1000000];
vector<int> ask;
vector<int> ad[N];
void dfs(int u){
st[u]=++it;
dd[u]=1;
//cerr<<u<<" "<<fa[u]<<"\n";
forv(v,ad[u]){
if(!dd[v]){
if(mode && !asking[id[u][v]]) continue;
if(!mode){
ask.push_back(id[u][v]);
asking[id[u][v]]=1;
}
fa[v]=u;
dfs(v);
}
}
ed[u]=it;
}
int anc(int u,int v){
return st[u]<=st[v] && ed[u]>=ed[v];
}
vector<int> find_roads(int n,vector<int> u,vector<int> v){
int m=u.size();
forinc(i,0,m-1){
ad[u[i]].pb(v[i]);
ad[v[i]].pb(u[i]);
id[u[i]][v[i]]=id[v[i]][u[i]]=i;
}
forinc(i,0,n-1){
reverse(all(ad[i]));
//shuffle(all(ad[i]),rng);
}
dfs(0);
//cerr<<"\n";
int tmp=count_common_roads(ask);
if(tmp==n-1) return ask;
vector<int> pos;
forinc(i,0,m-1) if(!asking[i])
pos.push_back(i);
mode=1;
int tot=0;
vector<int> eq;
auto tim=[&](int i,int rep){
if(no[i]) return 1;
if(yes[rep]){
//if(tested[i])
//return 0;
//tested[i]=1;
}
int suc=0;
if(yes[rep] || no[i]) suc=1;
int j=0; while(ask[j]!=rep) j++;
ask[j]=i;
asked++;
//if(asked>30000) gg
int to=count_common_roads(ask);
if(to>tmp){
tmp=to;
asking[rep]=0;
no[rep]=yes[i]=asking[i]=1;
tot++;
reset(dd,0);
dfs(it=0);
return 1;
}
ask[j]=rep;
if(to<tmp){
no[i]=yes[rep]=1;
return 1;
}
eq.push_back(rep);
if(no[rep]){
yes[i]=0;
no[i]=1;
}
return no[rep];
};
forv(i,pos){
int x=u[i], y=v[i], found=0;
while(!anc(x,y)){
int rep=id[x][fa[x]];
if(tim(i,rep)){
found=1;
break;
}
x=fa[x];
}
while(y!=x && !found){
int rep=id[y][fa[y]];
if(tim(i,rep)) break;
y=fa[y];
}
if(no[i])
forv(j,eq){
no[j]=1;
yes[j]=0;
}
eq.clear();
}
cerr<<asked<<"\n";
return ask;
}
Compilation message
simurgh.cpp: In lambda function:
simurgh.cpp:86:13: warning: variable 'suc' set but not used [-Wunused-but-set-variable]
int suc=0;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
correct |
2 |
Correct |
5 ms |
384 KB |
correct |
3 |
Correct |
5 ms |
384 KB |
correct |
4 |
Correct |
5 ms |
384 KB |
correct |
5 |
Correct |
5 ms |
384 KB |
correct |
6 |
Correct |
5 ms |
384 KB |
correct |
7 |
Correct |
4 ms |
384 KB |
correct |
8 |
Correct |
5 ms |
384 KB |
correct |
9 |
Correct |
5 ms |
384 KB |
correct |
10 |
Correct |
5 ms |
384 KB |
correct |
11 |
Correct |
4 ms |
384 KB |
correct |
12 |
Correct |
5 ms |
384 KB |
correct |
13 |
Correct |
5 ms |
384 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
correct |
2 |
Correct |
5 ms |
384 KB |
correct |
3 |
Correct |
5 ms |
384 KB |
correct |
4 |
Correct |
5 ms |
384 KB |
correct |
5 |
Correct |
5 ms |
384 KB |
correct |
6 |
Correct |
5 ms |
384 KB |
correct |
7 |
Correct |
4 ms |
384 KB |
correct |
8 |
Correct |
5 ms |
384 KB |
correct |
9 |
Correct |
5 ms |
384 KB |
correct |
10 |
Correct |
5 ms |
384 KB |
correct |
11 |
Correct |
4 ms |
384 KB |
correct |
12 |
Correct |
5 ms |
384 KB |
correct |
13 |
Correct |
5 ms |
384 KB |
correct |
14 |
Correct |
7 ms |
512 KB |
correct |
15 |
Correct |
8 ms |
512 KB |
correct |
16 |
Correct |
7 ms |
512 KB |
correct |
17 |
Correct |
8 ms |
512 KB |
correct |
18 |
Correct |
5 ms |
512 KB |
correct |
19 |
Correct |
6 ms |
512 KB |
correct |
20 |
Correct |
6 ms |
512 KB |
correct |
21 |
Correct |
7 ms |
512 KB |
correct |
22 |
Correct |
6 ms |
512 KB |
correct |
23 |
Correct |
6 ms |
512 KB |
correct |
24 |
Correct |
6 ms |
512 KB |
correct |
25 |
Correct |
5 ms |
512 KB |
correct |
26 |
Correct |
6 ms |
512 KB |
correct |
27 |
Correct |
6 ms |
512 KB |
correct |
28 |
Correct |
5 ms |
512 KB |
correct |
29 |
Correct |
5 ms |
512 KB |
correct |
30 |
Correct |
6 ms |
512 KB |
correct |
31 |
Correct |
6 ms |
512 KB |
correct |
32 |
Correct |
6 ms |
512 KB |
correct |
33 |
Correct |
6 ms |
512 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
correct |
2 |
Correct |
5 ms |
384 KB |
correct |
3 |
Correct |
5 ms |
384 KB |
correct |
4 |
Correct |
5 ms |
384 KB |
correct |
5 |
Correct |
5 ms |
384 KB |
correct |
6 |
Correct |
5 ms |
384 KB |
correct |
7 |
Correct |
4 ms |
384 KB |
correct |
8 |
Correct |
5 ms |
384 KB |
correct |
9 |
Correct |
5 ms |
384 KB |
correct |
10 |
Correct |
5 ms |
384 KB |
correct |
11 |
Correct |
4 ms |
384 KB |
correct |
12 |
Correct |
5 ms |
384 KB |
correct |
13 |
Correct |
5 ms |
384 KB |
correct |
14 |
Correct |
7 ms |
512 KB |
correct |
15 |
Correct |
8 ms |
512 KB |
correct |
16 |
Correct |
7 ms |
512 KB |
correct |
17 |
Correct |
8 ms |
512 KB |
correct |
18 |
Correct |
5 ms |
512 KB |
correct |
19 |
Correct |
6 ms |
512 KB |
correct |
20 |
Correct |
6 ms |
512 KB |
correct |
21 |
Correct |
7 ms |
512 KB |
correct |
22 |
Correct |
6 ms |
512 KB |
correct |
23 |
Correct |
6 ms |
512 KB |
correct |
24 |
Correct |
6 ms |
512 KB |
correct |
25 |
Correct |
5 ms |
512 KB |
correct |
26 |
Correct |
6 ms |
512 KB |
correct |
27 |
Correct |
6 ms |
512 KB |
correct |
28 |
Correct |
5 ms |
512 KB |
correct |
29 |
Correct |
5 ms |
512 KB |
correct |
30 |
Correct |
6 ms |
512 KB |
correct |
31 |
Correct |
6 ms |
512 KB |
correct |
32 |
Correct |
6 ms |
512 KB |
correct |
33 |
Correct |
6 ms |
512 KB |
correct |
34 |
Correct |
250 ms |
2388 KB |
correct |
35 |
Correct |
238 ms |
2168 KB |
correct |
36 |
Correct |
177 ms |
1912 KB |
correct |
37 |
Correct |
17 ms |
896 KB |
correct |
38 |
Correct |
248 ms |
2168 KB |
correct |
39 |
Correct |
215 ms |
2040 KB |
correct |
40 |
Correct |
182 ms |
2040 KB |
correct |
41 |
Correct |
250 ms |
2168 KB |
correct |
42 |
Correct |
246 ms |
2168 KB |
correct |
43 |
Correct |
126 ms |
1664 KB |
correct |
44 |
Correct |
106 ms |
1536 KB |
correct |
45 |
Correct |
124 ms |
1536 KB |
correct |
46 |
Correct |
90 ms |
1408 KB |
correct |
47 |
Correct |
41 ms |
1152 KB |
correct |
48 |
Correct |
7 ms |
896 KB |
correct |
49 |
Correct |
15 ms |
896 KB |
correct |
50 |
Correct |
42 ms |
1152 KB |
correct |
51 |
Correct |
122 ms |
1536 KB |
correct |
52 |
Correct |
111 ms |
1528 KB |
correct |
53 |
Correct |
99 ms |
1408 KB |
correct |
54 |
Correct |
129 ms |
1796 KB |
correct |
55 |
Correct |
124 ms |
1536 KB |
correct |
56 |
Correct |
122 ms |
1536 KB |
correct |
57 |
Correct |
120 ms |
1536 KB |
correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
correct |
2 |
Correct |
5 ms |
384 KB |
correct |
3 |
Incorrect |
177 ms |
4028 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
correct |
2 |
Correct |
5 ms |
384 KB |
correct |
3 |
Correct |
5 ms |
384 KB |
correct |
4 |
Correct |
5 ms |
384 KB |
correct |
5 |
Correct |
5 ms |
384 KB |
correct |
6 |
Correct |
5 ms |
384 KB |
correct |
7 |
Correct |
4 ms |
384 KB |
correct |
8 |
Correct |
5 ms |
384 KB |
correct |
9 |
Correct |
5 ms |
384 KB |
correct |
10 |
Correct |
5 ms |
384 KB |
correct |
11 |
Correct |
4 ms |
384 KB |
correct |
12 |
Correct |
5 ms |
384 KB |
correct |
13 |
Correct |
5 ms |
384 KB |
correct |
14 |
Correct |
7 ms |
512 KB |
correct |
15 |
Correct |
8 ms |
512 KB |
correct |
16 |
Correct |
7 ms |
512 KB |
correct |
17 |
Correct |
8 ms |
512 KB |
correct |
18 |
Correct |
5 ms |
512 KB |
correct |
19 |
Correct |
6 ms |
512 KB |
correct |
20 |
Correct |
6 ms |
512 KB |
correct |
21 |
Correct |
7 ms |
512 KB |
correct |
22 |
Correct |
6 ms |
512 KB |
correct |
23 |
Correct |
6 ms |
512 KB |
correct |
24 |
Correct |
6 ms |
512 KB |
correct |
25 |
Correct |
5 ms |
512 KB |
correct |
26 |
Correct |
6 ms |
512 KB |
correct |
27 |
Correct |
6 ms |
512 KB |
correct |
28 |
Correct |
5 ms |
512 KB |
correct |
29 |
Correct |
5 ms |
512 KB |
correct |
30 |
Correct |
6 ms |
512 KB |
correct |
31 |
Correct |
6 ms |
512 KB |
correct |
32 |
Correct |
6 ms |
512 KB |
correct |
33 |
Correct |
6 ms |
512 KB |
correct |
34 |
Correct |
250 ms |
2388 KB |
correct |
35 |
Correct |
238 ms |
2168 KB |
correct |
36 |
Correct |
177 ms |
1912 KB |
correct |
37 |
Correct |
17 ms |
896 KB |
correct |
38 |
Correct |
248 ms |
2168 KB |
correct |
39 |
Correct |
215 ms |
2040 KB |
correct |
40 |
Correct |
182 ms |
2040 KB |
correct |
41 |
Correct |
250 ms |
2168 KB |
correct |
42 |
Correct |
246 ms |
2168 KB |
correct |
43 |
Correct |
126 ms |
1664 KB |
correct |
44 |
Correct |
106 ms |
1536 KB |
correct |
45 |
Correct |
124 ms |
1536 KB |
correct |
46 |
Correct |
90 ms |
1408 KB |
correct |
47 |
Correct |
41 ms |
1152 KB |
correct |
48 |
Correct |
7 ms |
896 KB |
correct |
49 |
Correct |
15 ms |
896 KB |
correct |
50 |
Correct |
42 ms |
1152 KB |
correct |
51 |
Correct |
122 ms |
1536 KB |
correct |
52 |
Correct |
111 ms |
1528 KB |
correct |
53 |
Correct |
99 ms |
1408 KB |
correct |
54 |
Correct |
129 ms |
1796 KB |
correct |
55 |
Correct |
124 ms |
1536 KB |
correct |
56 |
Correct |
122 ms |
1536 KB |
correct |
57 |
Correct |
120 ms |
1536 KB |
correct |
58 |
Correct |
5 ms |
384 KB |
correct |
59 |
Correct |
5 ms |
384 KB |
correct |
60 |
Incorrect |
177 ms |
4028 KB |
WA in grader: NO |
61 |
Halted |
0 ms |
0 KB |
- |