#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;
int dd[N],fa[N],st[N],ed[N];
int id[N][N];
int asking[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;
}
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;
auto tim=[&](int i,int rep){
int j=0; while(ask[j]!=rep) j++;
ask[j]=i;
int to=count_common_roads(ask);
if(to>tmp){
tmp=to;
asking[i]=1;
asking[rep]=0;
tot++;
reset(dd,0);
dfs(it=0);
return 1;
}
ask[j]=rep;
if(to<tmp){
return 1;
}
return 0;
};
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];
}
//cerr<<"B\n";
}
//cerr<<tot<<"\n";
return ask;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
12 ms |
512 KB |
correct |
15 |
Correct |
9 ms |
512 KB |
correct |
16 |
Correct |
10 ms |
512 KB |
correct |
17 |
Correct |
8 ms |
512 KB |
correct |
18 |
Correct |
6 ms |
512 KB |
correct |
19 |
Correct |
8 ms |
512 KB |
correct |
20 |
Correct |
8 ms |
512 KB |
correct |
21 |
Correct |
8 ms |
512 KB |
correct |
22 |
Correct |
6 ms |
512 KB |
correct |
23 |
Correct |
6 ms |
512 KB |
correct |
24 |
Correct |
5 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 |
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 |
Correct |
12 ms |
512 KB |
correct |
15 |
Correct |
9 ms |
512 KB |
correct |
16 |
Correct |
10 ms |
512 KB |
correct |
17 |
Correct |
8 ms |
512 KB |
correct |
18 |
Correct |
6 ms |
512 KB |
correct |
19 |
Correct |
8 ms |
512 KB |
correct |
20 |
Correct |
8 ms |
512 KB |
correct |
21 |
Correct |
8 ms |
512 KB |
correct |
22 |
Correct |
6 ms |
512 KB |
correct |
23 |
Correct |
6 ms |
512 KB |
correct |
24 |
Correct |
5 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 |
Incorrect |
177 ms |
2168 KB |
WA in grader: NO |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
correct |
2 |
Correct |
5 ms |
384 KB |
correct |
3 |
Incorrect |
133 ms |
4220 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 |
Correct |
12 ms |
512 KB |
correct |
15 |
Correct |
9 ms |
512 KB |
correct |
16 |
Correct |
10 ms |
512 KB |
correct |
17 |
Correct |
8 ms |
512 KB |
correct |
18 |
Correct |
6 ms |
512 KB |
correct |
19 |
Correct |
8 ms |
512 KB |
correct |
20 |
Correct |
8 ms |
512 KB |
correct |
21 |
Correct |
8 ms |
512 KB |
correct |
22 |
Correct |
6 ms |
512 KB |
correct |
23 |
Correct |
6 ms |
512 KB |
correct |
24 |
Correct |
5 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 |
Incorrect |
177 ms |
2168 KB |
WA in grader: NO |
35 |
Halted |
0 ms |
0 KB |
- |