답안 #705370

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
705370 2023-03-04T07:10:47 Z Abrar_Al_Samit Simurgh (IOI17_simurgh) C++17
51 / 100
135 ms 4112 KB
#include<bits/stdc++.h>
#include "simurgh.h"

using namespace std;

const int nax = 500;
vector<pair<int,int>>g[nax];
int m;
vector<int>stk;
bool vis[nax];
int sz[nax], par[nax];
vector<int>grp[nax];
int where[nax*nax];
int known[nax*nax];
int res[nax*nax];

int find(int v) {
	return par[v] = (v==par[v]) ? v : find(par[v]);
}
void unite(int u, int v) {
	u = find(u), v = find(v);
	if(sz[u]<sz[v]) swap(u, v);
	sz[u] += sz[v];
	par[v] = u;
}
void dfs(int v, int ban) {
	vis[v] = 1;
	for(auto &[c, e] : g[v]) if(c!=ban && !vis[c]) {
		stk.push_back(e);
		unite(v, c);
		dfs(c, ban);
	}
}
vector<int>find_roads(int n, vector<int>u, vector<int>v) {
	m = u.size();

	for(int i=0; i<m; ++i) {
		g[u[i]].emplace_back(v[i], i);
		g[v[i]].emplace_back(u[i], i);
	}

	vector<int>royal;
	for(int ban=0; ban<n; ++ban) {
		stk.clear();
		for(int i=0; i<n; ++i) {
			vis[i] = 0;
			sz[i] = 1, par[i] = i;
			grp[i].clear();
		}
		for(int i=0; i<n; ++i) {
			if(i!=ban && !vis[i]) {
				dfs(i, ban);
			}
		}


		for(auto &[c, e] : g[ban]) {
			grp[find(c)].push_back(e);
		}

		for(int i=0; i<n; ++i) if(!grp[i].empty()) {
			where[grp[i][0]] = stk.size();
			stk.push_back(grp[i][0]);
		}

		for(int i=0; i<n; ++i) if(!grp[i].empty()) {
			int mx = -1, mn = n;

			int pos = where[grp[i][0]];
			for(int x : grp[i]) {
				if(known[x]) continue;
				stk[pos] = x;

				res[x] = count_common_roads(stk);
				//cerr<<x<<'\n';
				//cerr<<x<<'\n';
				mx = max(mx, res[x]);
				mn = min(mn, res[x]);
			}
			//cerr<<mx<<' '<<mn<<'\n';
			if(mx!=mn) {
				for(int x : grp[i]) if(!known[x]) {
					if(res[x]==mx) known[x] = 2;
					else known[x] = 1;
				}
			} else {
				bool something = false;
				bool big = false, small = false;
				for(int x : grp[i]) if(known[x]) {
					something = true;
					stk[pos] = x;
					if(known[x]==1) {
						mn = min(mn, count_common_roads(stk));
						small = true;
					} else {
						mx = max(mx, count_common_roads(stk));
						big = true;
					}
					break;
				}

				if(big && mx!=mn) small = true;
				if(small && mx!=mn) big = true;
				if(something) {
					for(int x : grp[i]) if(!known[x]) {
						if(res[x]==mn && small) known[x] = 1;
						else if(res[x]==mx && big) known[x] = 2;
						else {
							cerr<<mx<<' '<<mn<<' '<<res[x]<<'\n';
						}
					}
				} else {
					for(int x : grp[i]) {
						known[x] = 2;
					}
				}
			}			
		}
		// for(int i=0; i<m; ++i) {
		// 	cerr<<known[i]<<' ';
		// }
		// cerr<<'\n';
	}

	for(int i=0; i<m; ++i) if(known[i]==2) {
		royal.push_back(i);
		//cerr<<i<<' ';
	}
	//cerr<<'\n';

	// for(int x : royal) cerr<<x<<' ';
	// 	cerr<<'\n';
	return royal;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB correct
2 Correct 0 ms 340 KB correct
3 Correct 1 ms 340 KB correct
4 Correct 1 ms 340 KB correct
5 Correct 1 ms 340 KB correct
6 Correct 1 ms 340 KB correct
7 Correct 1 ms 340 KB correct
8 Correct 1 ms 340 KB correct
9 Correct 1 ms 340 KB correct
10 Correct 1 ms 340 KB correct
11 Correct 1 ms 340 KB correct
12 Correct 1 ms 340 KB correct
13 Correct 1 ms 340 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB correct
2 Correct 0 ms 340 KB correct
3 Correct 1 ms 340 KB correct
4 Correct 1 ms 340 KB correct
5 Correct 1 ms 340 KB correct
6 Correct 1 ms 340 KB correct
7 Correct 1 ms 340 KB correct
8 Correct 1 ms 340 KB correct
9 Correct 1 ms 340 KB correct
10 Correct 1 ms 340 KB correct
11 Correct 1 ms 340 KB correct
12 Correct 1 ms 340 KB correct
13 Correct 1 ms 340 KB correct
14 Correct 2 ms 344 KB correct
15 Correct 2 ms 340 KB correct
16 Correct 2 ms 344 KB correct
17 Correct 2 ms 340 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 2 ms 340 KB correct
20 Correct 2 ms 340 KB correct
21 Correct 2 ms 340 KB correct
22 Correct 1 ms 340 KB correct
23 Correct 1 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 1 ms 340 KB correct
26 Correct 1 ms 340 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 340 KB correct
31 Correct 2 ms 368 KB correct
32 Correct 1 ms 340 KB correct
33 Correct 1 ms 332 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB correct
2 Correct 0 ms 340 KB correct
3 Correct 1 ms 340 KB correct
4 Correct 1 ms 340 KB correct
5 Correct 1 ms 340 KB correct
6 Correct 1 ms 340 KB correct
7 Correct 1 ms 340 KB correct
8 Correct 1 ms 340 KB correct
9 Correct 1 ms 340 KB correct
10 Correct 1 ms 340 KB correct
11 Correct 1 ms 340 KB correct
12 Correct 1 ms 340 KB correct
13 Correct 1 ms 340 KB correct
14 Correct 2 ms 344 KB correct
15 Correct 2 ms 340 KB correct
16 Correct 2 ms 344 KB correct
17 Correct 2 ms 340 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 2 ms 340 KB correct
20 Correct 2 ms 340 KB correct
21 Correct 2 ms 340 KB correct
22 Correct 1 ms 340 KB correct
23 Correct 1 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 1 ms 340 KB correct
26 Correct 1 ms 340 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 340 KB correct
31 Correct 2 ms 368 KB correct
32 Correct 1 ms 340 KB correct
33 Correct 1 ms 332 KB correct
34 Correct 127 ms 1776 KB correct
35 Correct 127 ms 1868 KB correct
36 Correct 87 ms 1500 KB correct
37 Correct 9 ms 348 KB correct
38 Correct 135 ms 1788 KB correct
39 Correct 109 ms 1676 KB correct
40 Correct 88 ms 1492 KB correct
41 Correct 132 ms 1816 KB correct
42 Correct 125 ms 1868 KB correct
43 Correct 70 ms 1236 KB correct
44 Correct 58 ms 1000 KB correct
45 Correct 69 ms 988 KB correct
46 Correct 51 ms 956 KB correct
47 Correct 24 ms 652 KB correct
48 Correct 5 ms 336 KB correct
49 Correct 9 ms 340 KB correct
50 Correct 24 ms 604 KB correct
51 Correct 67 ms 980 KB correct
52 Correct 59 ms 1000 KB correct
53 Correct 52 ms 924 KB correct
54 Correct 70 ms 1304 KB correct
55 Correct 65 ms 980 KB correct
56 Correct 68 ms 1072 KB correct
57 Correct 67 ms 1108 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB correct
2 Correct 1 ms 340 KB correct
3 Incorrect 99 ms 4112 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB correct
2 Correct 0 ms 340 KB correct
3 Correct 1 ms 340 KB correct
4 Correct 1 ms 340 KB correct
5 Correct 1 ms 340 KB correct
6 Correct 1 ms 340 KB correct
7 Correct 1 ms 340 KB correct
8 Correct 1 ms 340 KB correct
9 Correct 1 ms 340 KB correct
10 Correct 1 ms 340 KB correct
11 Correct 1 ms 340 KB correct
12 Correct 1 ms 340 KB correct
13 Correct 1 ms 340 KB correct
14 Correct 2 ms 344 KB correct
15 Correct 2 ms 340 KB correct
16 Correct 2 ms 344 KB correct
17 Correct 2 ms 340 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 2 ms 340 KB correct
20 Correct 2 ms 340 KB correct
21 Correct 2 ms 340 KB correct
22 Correct 1 ms 340 KB correct
23 Correct 1 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 1 ms 340 KB correct
26 Correct 1 ms 340 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 340 KB correct
31 Correct 2 ms 368 KB correct
32 Correct 1 ms 340 KB correct
33 Correct 1 ms 332 KB correct
34 Correct 127 ms 1776 KB correct
35 Correct 127 ms 1868 KB correct
36 Correct 87 ms 1500 KB correct
37 Correct 9 ms 348 KB correct
38 Correct 135 ms 1788 KB correct
39 Correct 109 ms 1676 KB correct
40 Correct 88 ms 1492 KB correct
41 Correct 132 ms 1816 KB correct
42 Correct 125 ms 1868 KB correct
43 Correct 70 ms 1236 KB correct
44 Correct 58 ms 1000 KB correct
45 Correct 69 ms 988 KB correct
46 Correct 51 ms 956 KB correct
47 Correct 24 ms 652 KB correct
48 Correct 5 ms 336 KB correct
49 Correct 9 ms 340 KB correct
50 Correct 24 ms 604 KB correct
51 Correct 67 ms 980 KB correct
52 Correct 59 ms 1000 KB correct
53 Correct 52 ms 924 KB correct
54 Correct 70 ms 1304 KB correct
55 Correct 65 ms 980 KB correct
56 Correct 68 ms 1072 KB correct
57 Correct 67 ms 1108 KB correct
58 Correct 1 ms 340 KB correct
59 Correct 1 ms 340 KB correct
60 Incorrect 99 ms 4112 KB WA in grader: NO
61 Halted 0 ms 0 KB -