답안 #430452

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
430452 2021-06-16T13:58:15 Z AmineWeslati Simurgh (IOI17_simurgh) C++14
30 / 100
20 ms 4104 KB
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std; 

typedef long long ll;
typedef vector<int>vi; 
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)

#define FOR(i,a,b) for(int i=a; i<b; i++)

//--------------------------------

const int MX=100;

int N; 
vi adj[MX]; //cur golden set

vi vec;
int score;


vi vis(MX),par(MX);
void dfs(int u){
	vis[u]=1;
	for(int v: adj[u]) if(!vis[v]){
		par[v]=u;
		dfs(v);
	}
}

bool can(int u, int v){
	FOR(i,0,N) vis[i]=0;
	dfs(u);
	return !vis[v];
}


bool check(int i, int j){
	//cout << i << ' ' << j << endl;
	vi v;
	for(int x: vec) if(x!=i) v.pb(x);
	v.pb(j);

	/*for(int x: v) cout << x << ' ';
		cout << endl;*/
	
	int x=count_common_roads(v);

	if(x==score+1) return 1;
	return 0;
}

vi find_roads(int N, vi U, vi V) {
	int M=sz(U);
	::N=N; 
	 
	map<int,int>mp[N];
	vi chosen(M,0);
	FOR(i,0,M){
		int u=U[i],v=V[i];
		mp[u][v]=i;
		mp[v][u]=i;

		if(can(u,v)){
			adj[u].pb(v),adj[v].pb(u);
			//cout << u << ' ' << v << endl;
			vec.pb(i);
			chosen[i]=1;
		}
	}

	score=count_common_roads(vec);
	//cout << score << endl;

	FOR(i,0,M) if(!chosen[i]){
		int u=U[i],v=V[i];
		
		FOR(i,0,N) vis[i]=0;
		dfs(u);

		int cur=v;
		//cout << u << ' ' << v << endl;
		while(cur!=u){
			int j=mp[cur][par[cur]];

			//cout << cur << ' ' << par[cur] << endl;

			if(check(j,i)){
				vi nw; 
				for(auto x: vec) if(x!=j) nw.pb(x);
				nw.pb(i);
				vec.assign(all(nw));


				FOR(u,0,N) adj[u].clear();
				for(int idx: vec){
					u=U[idx],v=V[idx];
					adj[u].pb(v),adj[v].pb(u);
				}
				score++;

				break;
			}


			cur=par[cur];
		}

		//cout << endl;
	}

	assert(score==N-1);
	return vec; 
}

/*

4 6
0 1
0 2
0 3
1 2
1 3
2 3
0 1 5

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB correct
2 Correct 1 ms 204 KB correct
3 Correct 1 ms 204 KB correct
4 Correct 1 ms 296 KB correct
5 Correct 1 ms 204 KB correct
6 Correct 1 ms 204 KB correct
7 Correct 1 ms 292 KB correct
8 Correct 1 ms 204 KB correct
9 Correct 1 ms 204 KB correct
10 Correct 1 ms 204 KB correct
11 Correct 1 ms 204 KB correct
12 Correct 1 ms 204 KB correct
13 Correct 1 ms 204 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB correct
2 Correct 1 ms 204 KB correct
3 Correct 1 ms 204 KB correct
4 Correct 1 ms 296 KB correct
5 Correct 1 ms 204 KB correct
6 Correct 1 ms 204 KB correct
7 Correct 1 ms 292 KB correct
8 Correct 1 ms 204 KB correct
9 Correct 1 ms 204 KB correct
10 Correct 1 ms 204 KB correct
11 Correct 1 ms 204 KB correct
12 Correct 1 ms 204 KB correct
13 Correct 1 ms 204 KB correct
14 Correct 15 ms 444 KB correct
15 Correct 8 ms 436 KB correct
16 Correct 9 ms 452 KB correct
17 Correct 12 ms 332 KB correct
18 Correct 4 ms 332 KB correct
19 Correct 13 ms 332 KB correct
20 Correct 11 ms 300 KB correct
21 Correct 9 ms 404 KB correct
22 Correct 6 ms 332 KB correct
23 Correct 6 ms 332 KB correct
24 Correct 5 ms 332 KB correct
25 Correct 1 ms 204 KB correct
26 Correct 7 ms 332 KB correct
27 Correct 6 ms 332 KB correct
28 Correct 2 ms 332 KB correct
29 Correct 1 ms 204 KB correct
30 Correct 8 ms 364 KB correct
31 Correct 9 ms 332 KB correct
32 Correct 9 ms 368 KB correct
33 Correct 7 ms 332 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB correct
2 Correct 1 ms 204 KB correct
3 Correct 1 ms 204 KB correct
4 Correct 1 ms 296 KB correct
5 Correct 1 ms 204 KB correct
6 Correct 1 ms 204 KB correct
7 Correct 1 ms 292 KB correct
8 Correct 1 ms 204 KB correct
9 Correct 1 ms 204 KB correct
10 Correct 1 ms 204 KB correct
11 Correct 1 ms 204 KB correct
12 Correct 1 ms 204 KB correct
13 Correct 1 ms 204 KB correct
14 Correct 15 ms 444 KB correct
15 Correct 8 ms 436 KB correct
16 Correct 9 ms 452 KB correct
17 Correct 12 ms 332 KB correct
18 Correct 4 ms 332 KB correct
19 Correct 13 ms 332 KB correct
20 Correct 11 ms 300 KB correct
21 Correct 9 ms 404 KB correct
22 Correct 6 ms 332 KB correct
23 Correct 6 ms 332 KB correct
24 Correct 5 ms 332 KB correct
25 Correct 1 ms 204 KB correct
26 Correct 7 ms 332 KB correct
27 Correct 6 ms 332 KB correct
28 Correct 2 ms 332 KB correct
29 Correct 1 ms 204 KB correct
30 Correct 8 ms 364 KB correct
31 Correct 9 ms 332 KB correct
32 Correct 9 ms 368 KB correct
33 Correct 7 ms 332 KB correct
34 Runtime error 8 ms 1740 KB Execution killed with signal 11
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB correct
2 Correct 1 ms 204 KB correct
3 Runtime error 20 ms 4104 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB correct
2 Correct 1 ms 204 KB correct
3 Correct 1 ms 204 KB correct
4 Correct 1 ms 296 KB correct
5 Correct 1 ms 204 KB correct
6 Correct 1 ms 204 KB correct
7 Correct 1 ms 292 KB correct
8 Correct 1 ms 204 KB correct
9 Correct 1 ms 204 KB correct
10 Correct 1 ms 204 KB correct
11 Correct 1 ms 204 KB correct
12 Correct 1 ms 204 KB correct
13 Correct 1 ms 204 KB correct
14 Correct 15 ms 444 KB correct
15 Correct 8 ms 436 KB correct
16 Correct 9 ms 452 KB correct
17 Correct 12 ms 332 KB correct
18 Correct 4 ms 332 KB correct
19 Correct 13 ms 332 KB correct
20 Correct 11 ms 300 KB correct
21 Correct 9 ms 404 KB correct
22 Correct 6 ms 332 KB correct
23 Correct 6 ms 332 KB correct
24 Correct 5 ms 332 KB correct
25 Correct 1 ms 204 KB correct
26 Correct 7 ms 332 KB correct
27 Correct 6 ms 332 KB correct
28 Correct 2 ms 332 KB correct
29 Correct 1 ms 204 KB correct
30 Correct 8 ms 364 KB correct
31 Correct 9 ms 332 KB correct
32 Correct 9 ms 368 KB correct
33 Correct 7 ms 332 KB correct
34 Runtime error 8 ms 1740 KB Execution killed with signal 11
35 Halted 0 ms 0 KB -