Submission #600478

# Submission time Handle Problem Language Result Execution time Memory
600478 2022-07-20T22:28:06 Z StrawHatWess Simurgh (IOI17_simurgh) C++17
51 / 100
353 ms 10364 KB
#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{
				if(val[j]!=-1){val[i]=val[j]; break;}
				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 0 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 0 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 1 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 0 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 0 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 1 ms 340 KB correct
14 Correct 4 ms 468 KB correct
15 Correct 3 ms 468 KB correct
16 Correct 4 ms 468 KB correct
17 Correct 3 ms 468 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 3 ms 468 KB correct
20 Correct 3 ms 468 KB correct
21 Correct 3 ms 340 KB correct
22 Correct 2 ms 340 KB correct
23 Correct 2 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 1 ms 340 KB correct
26 Correct 2 ms 428 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 340 KB correct
29 Correct 1 ms 340 KB correct
30 Correct 1 ms 400 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 0 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 0 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 1 ms 340 KB correct
14 Correct 4 ms 468 KB correct
15 Correct 3 ms 468 KB correct
16 Correct 4 ms 468 KB correct
17 Correct 3 ms 468 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 3 ms 468 KB correct
20 Correct 3 ms 468 KB correct
21 Correct 3 ms 340 KB correct
22 Correct 2 ms 340 KB correct
23 Correct 2 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 1 ms 340 KB correct
26 Correct 2 ms 428 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 340 KB correct
29 Correct 1 ms 340 KB correct
30 Correct 1 ms 400 KB correct
31 Correct 2 ms 340 KB correct
32 Correct 2 ms 340 KB correct
33 Correct 2 ms 340 KB correct
34 Correct 342 ms 3924 KB correct
35 Correct 337 ms 3924 KB correct
36 Correct 227 ms 2900 KB correct
37 Correct 14 ms 468 KB correct
38 Correct 353 ms 4068 KB correct
39 Correct 298 ms 3600 KB correct
40 Correct 220 ms 2772 KB correct
41 Correct 296 ms 4068 KB correct
42 Correct 300 ms 4104 KB correct
43 Correct 107 ms 2260 KB correct
44 Correct 88 ms 2004 KB correct
45 Correct 103 ms 2228 KB correct
46 Correct 76 ms 1752 KB correct
47 Correct 32 ms 868 KB correct
48 Correct 2 ms 340 KB correct
49 Correct 9 ms 468 KB correct
50 Correct 32 ms 924 KB correct
51 Correct 102 ms 2212 KB correct
52 Correct 89 ms 1952 KB correct
53 Correct 77 ms 1748 KB correct
54 Correct 108 ms 2352 KB correct
55 Correct 102 ms 2248 KB correct
56 Correct 108 ms 2252 KB correct
57 Correct 104 ms 2248 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB correct
2 Correct 1 ms 340 KB correct
3 Incorrect 312 ms 10364 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 0 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 0 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 1 ms 340 KB correct
14 Correct 4 ms 468 KB correct
15 Correct 3 ms 468 KB correct
16 Correct 4 ms 468 KB correct
17 Correct 3 ms 468 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 3 ms 468 KB correct
20 Correct 3 ms 468 KB correct
21 Correct 3 ms 340 KB correct
22 Correct 2 ms 340 KB correct
23 Correct 2 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 1 ms 340 KB correct
26 Correct 2 ms 428 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 340 KB correct
29 Correct 1 ms 340 KB correct
30 Correct 1 ms 400 KB correct
31 Correct 2 ms 340 KB correct
32 Correct 2 ms 340 KB correct
33 Correct 2 ms 340 KB correct
34 Correct 342 ms 3924 KB correct
35 Correct 337 ms 3924 KB correct
36 Correct 227 ms 2900 KB correct
37 Correct 14 ms 468 KB correct
38 Correct 353 ms 4068 KB correct
39 Correct 298 ms 3600 KB correct
40 Correct 220 ms 2772 KB correct
41 Correct 296 ms 4068 KB correct
42 Correct 300 ms 4104 KB correct
43 Correct 107 ms 2260 KB correct
44 Correct 88 ms 2004 KB correct
45 Correct 103 ms 2228 KB correct
46 Correct 76 ms 1752 KB correct
47 Correct 32 ms 868 KB correct
48 Correct 2 ms 340 KB correct
49 Correct 9 ms 468 KB correct
50 Correct 32 ms 924 KB correct
51 Correct 102 ms 2212 KB correct
52 Correct 89 ms 1952 KB correct
53 Correct 77 ms 1748 KB correct
54 Correct 108 ms 2352 KB correct
55 Correct 102 ms 2248 KB correct
56 Correct 108 ms 2252 KB correct
57 Correct 104 ms 2248 KB correct
58 Correct 1 ms 340 KB correct
59 Correct 1 ms 340 KB correct
60 Incorrect 312 ms 10364 KB WA in grader: NO
61 Halted 0 ms 0 KB -