#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;
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){
shuffle(all(ad[i]),rng);
}
dfs(0);
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]) cerr<<"W\n";
if(no[rep]){
yes[i]=0;
no[i]=1;
}
//return 0;
return no[rep];
//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];
}
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:82: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 |
5 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 |
5 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 |
5 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 |
5 ms |
384 KB |
correct |
12 |
Correct |
5 ms |
384 KB |
correct |
13 |
Correct |
5 ms |
384 KB |
correct |
14 |
Incorrect |
7 ms |
512 KB |
WA in grader: NO |
15 |
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 |
5 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 |
5 ms |
384 KB |
correct |
12 |
Correct |
5 ms |
384 KB |
correct |
13 |
Correct |
5 ms |
384 KB |
correct |
14 |
Incorrect |
7 ms |
512 KB |
WA in grader: NO |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
384 KB |
correct |
2 |
Correct |
5 ms |
384 KB |
correct |
3 |
Incorrect |
211 ms |
4856 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 |
5 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 |
5 ms |
384 KB |
correct |
12 |
Correct |
5 ms |
384 KB |
correct |
13 |
Correct |
5 ms |
384 KB |
correct |
14 |
Incorrect |
7 ms |
512 KB |
WA in grader: NO |
15 |
Halted |
0 ms |
0 KB |
- |