#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=a; i<b; i++)
typedef vector<int>vi;
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
typedef pair<ll,ll>pi;
typedef vector<pi>vpi;
#define fi first
#define se second
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
const ll INF=1e18;
//---------------------------------------------------------
const int MX=500+10;
vi p(MX);
int findSet(int u){return p[u]==u? u: p[u]=findSet(p[u]);}
vi rnk(MX);
void unionSet(int u, int v){
u=findSet(u); v=findSet(v);
if(rnk[u]<rnk[v]) swap(u,v);
if(rnk[u]==rnk[v]) rnk[u]++;
p[v]=u;
}
//----------------
int N,M;
vi U,V;
map<int,int>ed[MX];
vi a,b;
vi adj[MX];
void build(){
FOR(i,0,N) adj[i].clear();
for(int i: a){
int u=U[i], v=V[i];
adj[u].pb(v); adj[v].pb(u);
}
}
vi par(MX);
void dfs(int u, int p){
par[u]=p;
for(int v: adj[u]) if(v!=p) dfs(v,u);
}
vi find_roads(int n, vi U, vi V) {
N=n; M=sz(U);
::U=U; ::V=V;
FOR(i,0,N) p[i]=i,rnk[i]=0;
FOR(i,0,M){
int u=U[i], v=V[i];
ed[u][v]=ed[v][u]=i;
if(findSet(u)!=findSet(v)) unionSet(u,v), a.pb(i);
else b.pb(i);
}
vi val(M,-1);
int X=count_common_roads(a);
for(int i: b) if(val[i]==-1){
int u=U[i], v=V[i];
build(); //build tree
dfs(u,u);
vi vec;
while(v!=u){
int vp=par[v];
//considering edge vp-v
int j=ed[v][vp];
if(val[j]==1){ v=vp; continue; }
vi ap=a;
for(int &it: ap) if(it==j) it=i;
int Y=count_common_roads(ap);
/*if(Y>X){
X=Y;
a=ap;
break;
}*/
if(X>Y){
val[i]=0;
val[j]=1;
break;
}
else if(X<Y){
X=Y;
val[j]=0;
val[i]=1;
a=ap;
break;
}
else{
vec.pb(j);
}
v=vp;
}
if(val[i]==-1) val[i]=0;
for(int j: vec) val[j]=val[i];
}
return a;
}
/*
4 6
0 1
0 2
0 3
1 2
1 3
2 3
0 1 5
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
correct |
2 |
Correct |
0 ms |
340 KB |
correct |
3 |
Correct |
1 ms |
340 KB |
correct |
4 |
Correct |
0 ms |
340 KB |
correct |
5 |
Correct |
0 ms |
340 KB |
correct |
6 |
Correct |
0 ms |
340 KB |
correct |
7 |
Correct |
0 ms |
340 KB |
correct |
8 |
Correct |
0 ms |
340 KB |
correct |
9 |
Correct |
1 ms |
340 KB |
correct |
10 |
Correct |
0 ms |
340 KB |
correct |
11 |
Correct |
0 ms |
340 KB |
correct |
12 |
Correct |
0 ms |
340 KB |
correct |
13 |
Correct |
0 ms |
340 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
correct |
2 |
Correct |
0 ms |
340 KB |
correct |
3 |
Correct |
1 ms |
340 KB |
correct |
4 |
Correct |
0 ms |
340 KB |
correct |
5 |
Correct |
0 ms |
340 KB |
correct |
6 |
Correct |
0 ms |
340 KB |
correct |
7 |
Correct |
0 ms |
340 KB |
correct |
8 |
Correct |
0 ms |
340 KB |
correct |
9 |
Correct |
1 ms |
340 KB |
correct |
10 |
Correct |
0 ms |
340 KB |
correct |
11 |
Correct |
0 ms |
340 KB |
correct |
12 |
Correct |
0 ms |
340 KB |
correct |
13 |
Correct |
0 ms |
340 KB |
correct |
14 |
Correct |
7 ms |
468 KB |
correct |
15 |
Correct |
5 ms |
504 KB |
correct |
16 |
Correct |
5 ms |
468 KB |
correct |
17 |
Correct |
6 ms |
468 KB |
correct |
18 |
Correct |
2 ms |
340 KB |
correct |
19 |
Correct |
7 ms |
468 KB |
correct |
20 |
Correct |
5 ms |
468 KB |
correct |
21 |
Correct |
4 ms |
340 KB |
correct |
22 |
Correct |
2 ms |
340 KB |
correct |
23 |
Correct |
1 ms |
340 KB |
correct |
24 |
Correct |
2 ms |
340 KB |
correct |
25 |
Correct |
1 ms |
340 KB |
correct |
26 |
Correct |
1 ms |
340 KB |
correct |
27 |
Correct |
2 ms |
340 KB |
correct |
28 |
Correct |
1 ms |
340 KB |
correct |
29 |
Correct |
1 ms |
340 KB |
correct |
30 |
Correct |
1 ms |
428 KB |
correct |
31 |
Correct |
2 ms |
340 KB |
correct |
32 |
Correct |
2 ms |
340 KB |
correct |
33 |
Correct |
2 ms |
340 KB |
correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
correct |
2 |
Correct |
0 ms |
340 KB |
correct |
3 |
Correct |
1 ms |
340 KB |
correct |
4 |
Correct |
0 ms |
340 KB |
correct |
5 |
Correct |
0 ms |
340 KB |
correct |
6 |
Correct |
0 ms |
340 KB |
correct |
7 |
Correct |
0 ms |
340 KB |
correct |
8 |
Correct |
0 ms |
340 KB |
correct |
9 |
Correct |
1 ms |
340 KB |
correct |
10 |
Correct |
0 ms |
340 KB |
correct |
11 |
Correct |
0 ms |
340 KB |
correct |
12 |
Correct |
0 ms |
340 KB |
correct |
13 |
Correct |
0 ms |
340 KB |
correct |
14 |
Correct |
7 ms |
468 KB |
correct |
15 |
Correct |
5 ms |
504 KB |
correct |
16 |
Correct |
5 ms |
468 KB |
correct |
17 |
Correct |
6 ms |
468 KB |
correct |
18 |
Correct |
2 ms |
340 KB |
correct |
19 |
Correct |
7 ms |
468 KB |
correct |
20 |
Correct |
5 ms |
468 KB |
correct |
21 |
Correct |
4 ms |
340 KB |
correct |
22 |
Correct |
2 ms |
340 KB |
correct |
23 |
Correct |
1 ms |
340 KB |
correct |
24 |
Correct |
2 ms |
340 KB |
correct |
25 |
Correct |
1 ms |
340 KB |
correct |
26 |
Correct |
1 ms |
340 KB |
correct |
27 |
Correct |
2 ms |
340 KB |
correct |
28 |
Correct |
1 ms |
340 KB |
correct |
29 |
Correct |
1 ms |
340 KB |
correct |
30 |
Correct |
1 ms |
428 KB |
correct |
31 |
Correct |
2 ms |
340 KB |
correct |
32 |
Correct |
2 ms |
340 KB |
correct |
33 |
Correct |
2 ms |
340 KB |
correct |
34 |
Incorrect |
177 ms |
3940 KB |
WA in grader: NO |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
correct |
2 |
Correct |
0 ms |
340 KB |
correct |
3 |
Incorrect |
171 ms |
10360 KB |
WA in grader: NO |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
correct |
2 |
Correct |
0 ms |
340 KB |
correct |
3 |
Correct |
1 ms |
340 KB |
correct |
4 |
Correct |
0 ms |
340 KB |
correct |
5 |
Correct |
0 ms |
340 KB |
correct |
6 |
Correct |
0 ms |
340 KB |
correct |
7 |
Correct |
0 ms |
340 KB |
correct |
8 |
Correct |
0 ms |
340 KB |
correct |
9 |
Correct |
1 ms |
340 KB |
correct |
10 |
Correct |
0 ms |
340 KB |
correct |
11 |
Correct |
0 ms |
340 KB |
correct |
12 |
Correct |
0 ms |
340 KB |
correct |
13 |
Correct |
0 ms |
340 KB |
correct |
14 |
Correct |
7 ms |
468 KB |
correct |
15 |
Correct |
5 ms |
504 KB |
correct |
16 |
Correct |
5 ms |
468 KB |
correct |
17 |
Correct |
6 ms |
468 KB |
correct |
18 |
Correct |
2 ms |
340 KB |
correct |
19 |
Correct |
7 ms |
468 KB |
correct |
20 |
Correct |
5 ms |
468 KB |
correct |
21 |
Correct |
4 ms |
340 KB |
correct |
22 |
Correct |
2 ms |
340 KB |
correct |
23 |
Correct |
1 ms |
340 KB |
correct |
24 |
Correct |
2 ms |
340 KB |
correct |
25 |
Correct |
1 ms |
340 KB |
correct |
26 |
Correct |
1 ms |
340 KB |
correct |
27 |
Correct |
2 ms |
340 KB |
correct |
28 |
Correct |
1 ms |
340 KB |
correct |
29 |
Correct |
1 ms |
340 KB |
correct |
30 |
Correct |
1 ms |
428 KB |
correct |
31 |
Correct |
2 ms |
340 KB |
correct |
32 |
Correct |
2 ms |
340 KB |
correct |
33 |
Correct |
2 ms |
340 KB |
correct |
34 |
Incorrect |
177 ms |
3940 KB |
WA in grader: NO |
35 |
Halted |
0 ms |
0 KB |
- |