Submission #143423

# Submission time Handle Problem Language Result Execution time Memory
143423 2019-08-14T01:21:11 Z gs14004 Split the Attractions (IOI19_split) C++17
100 / 100
371 ms 24316 KB
#include "split.h"
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
using namespace std;
using pi = pair<int, int>;
const int MAXN = 100005;

int n;
vector<int> gph[MAXN];
vector<int> tr[MAXN];

namespace report{
	vector<int> gph[MAXN];
	int mark[MAXN], vis[MAXN];
	void dfs(int x, vector<int> &dfn){
		dfn.push_back(x);
		vis[x] = 1;
		for(auto &i : gph[x]){
			if(mark[x] == mark[i] && !vis[i]){
				dfs(i, dfn);
			}
		}
	}
	vector<pi> color;
	vector<int> Do(vector<int> S){
		for(auto &i : S) mark[i] = 1;
		vector<int> ans(n, color[2].second);
		for(int i=0; i<n; i++){
			vector<int> dfn;
			if(mark[i] == 1 && !vis[i]){
				dfs(i, dfn);
				for(int j=0; j<color[0].first; j++){
					ans[dfn[j]] = color[0].second;
				}
			}
			if(mark[i] == 0 && !vis[i]){
				dfs(i, dfn);
				for(int j=0; j<color[1].first; j++){
					ans[dfn[j]] = color[1].second;
				}
			}
		}
		return ans;
	}
}

struct disj{
	int pa[MAXN], sz[MAXN];
	void init(int n){
		iota(pa, pa + n + 1, 0);
		fill(sz, sz + n + 1, 1);
	}
	int find(int x){
		return pa[x] = (pa[x] == x ? x : find(pa[x]));
	}
	int getsz(int x){ return sz[find(x)]; }
	bool uni(int p, int q){
		p = find(p); q = find(q);
		if(p == q) return 0;
		sz[p] += sz[q];
		pa[q] = p; 
		return 1;
	}
}disj;

int sz[MAXN], msz[MAXN];

void dfsc(int x, int p){
	sz[x] = 1; msz[x] = 0;
	for(auto &i : tr[x]){
		if(i != p){
			dfsc(i, x);
			sz[x] += sz[i];
			msz[x] = max(msz[x], sz[i]);
		}
	}
}

int get_center(){
	dfsc(0, 0);
	pi ret(1e9, 1e9);
	for(int i=0; i<n; i++){
		ret = min(ret, pi(max(msz[i], n - sz[i]), i));
	}
	return ret.second;
}

void dfs(int x, int p, vector<int> &dfn){
	dfn.push_back(x);
	for(auto &i : tr[x]){
		if(i != p){
			disj.uni(x, i);
			dfs(i, x, dfn);
		}
	}
}

bool vis[MAXN];

void dfsa(int x, vector<int> &dfn){
	dfn.push_back(x);
	vis[x] = 1;
	for(auto &i : gph[x]){
		if(!vis[i]) dfsa(i, dfn);
	}
}

vector<int> find_split(int _n, int a, int b, int _c, vector<int> p, vector<int> q) {
	n = _n;
	vector<pi> cs = {pi(a, 1), pi(b, 2), pi(_c, 3)};
	sort(cs.begin(), cs.end());
	report::color = cs;
	a = cs[0].first;
	disj.init(n);
	for(int i=0; i<sz(p); i++){
		if(disj.uni(p[i], q[i])){
			tr[p[i]].push_back(q[i]);
			tr[q[i]].push_back(p[i]);
		}
		report::gph[p[i]].push_back(q[i]);
		report::gph[q[i]].push_back(p[i]);
	}
	disj.init(n);
	int c = get_center();
	for(auto &i : tr[c]){
		vector<int> dfn;
		dfs(i, c, dfn);
		if(disj.getsz(i) >= a){
			return report::Do(dfn);
		}
	}
	for(int i=0; i<sz(p); i++){
		if(p[i] == c || q[i] == c) continue;
		int l = disj.find(p[i]);
		int r = disj.find(q[i]);
		if(l != r){
			gph[l].push_back(r);
			gph[r].push_back(l);
		}
	}
	for(int i=0; i<n; i++){
		if(i != c && disj.find(i) == i && !vis[i]){
			vector<int> dfn;
			dfsa(i, dfn);
			int sum = 0;
			set<int> pot;
			for(auto &i : dfn){
				sum += disj.getsz(i);
				pot.insert(i);
				if(sum >= a) break;
			}
			if(sum >= a){
				vector<int> ans;
				for(int i=0; i<n; i++){
					if(pot.find(disj.find(i)) != pot.end()){
						ans.push_back(i);
					}
				}
				return report::Do(ans);
			}
		}
	}
	return vector<int>(n, 0);
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB ok, correct split
2 Correct 8 ms 7416 KB ok, correct split
3 Correct 8 ms 7416 KB ok, correct split
4 Correct 8 ms 7416 KB ok, correct split
5 Correct 8 ms 7416 KB ok, correct split
6 Correct 8 ms 7416 KB ok, correct split
7 Correct 181 ms 24240 KB ok, correct split
8 Correct 199 ms 24236 KB ok, correct split
9 Correct 171 ms 24276 KB ok, correct split
10 Correct 169 ms 24236 KB ok, correct split
11 Correct 177 ms 24240 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB ok, correct split
2 Correct 8 ms 7416 KB ok, correct split
3 Correct 8 ms 7416 KB ok, correct split
4 Correct 205 ms 21848 KB ok, correct split
5 Correct 162 ms 18932 KB ok, correct split
6 Correct 194 ms 24316 KB ok, correct split
7 Correct 175 ms 24240 KB ok, correct split
8 Correct 225 ms 20852 KB ok, correct split
9 Correct 180 ms 18804 KB ok, correct split
10 Correct 100 ms 19048 KB ok, correct split
11 Correct 99 ms 19072 KB ok, correct split
12 Correct 105 ms 19048 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB ok, correct split
2 Correct 165 ms 18920 KB ok, correct split
3 Correct 54 ms 12152 KB ok, correct split
4 Correct 8 ms 7416 KB ok, correct split
5 Correct 196 ms 22128 KB ok, correct split
6 Correct 269 ms 22200 KB ok, correct split
7 Correct 194 ms 22172 KB ok, correct split
8 Correct 192 ms 22112 KB ok, correct split
9 Correct 204 ms 22116 KB ok, correct split
10 Correct 46 ms 10744 KB ok, no valid answer
11 Correct 68 ms 12536 KB ok, no valid answer
12 Correct 170 ms 17908 KB ok, no valid answer
13 Correct 161 ms 17656 KB ok, no valid answer
14 Correct 116 ms 18024 KB ok, no valid answer
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB ok, correct split
2 Correct 8 ms 7416 KB ok, no valid answer
3 Correct 8 ms 7416 KB ok, correct split
4 Correct 8 ms 7416 KB ok, correct split
5 Correct 8 ms 7416 KB ok, correct split
6 Correct 8 ms 7416 KB ok, correct split
7 Correct 8 ms 7416 KB ok, correct split
8 Correct 8 ms 7416 KB ok, correct split
9 Correct 11 ms 7672 KB ok, correct split
10 Correct 11 ms 7800 KB ok, correct split
11 Correct 8 ms 7416 KB ok, correct split
12 Correct 11 ms 7800 KB ok, correct split
13 Correct 8 ms 7416 KB ok, correct split
14 Correct 8 ms 7416 KB ok, correct split
15 Correct 8 ms 7416 KB ok, correct split
16 Correct 8 ms 7416 KB ok, correct split
17 Correct 8 ms 7416 KB ok, correct split
18 Correct 8 ms 7416 KB ok, correct split
19 Correct 10 ms 7416 KB ok, correct split
20 Correct 9 ms 7544 KB ok, correct split
21 Correct 10 ms 7800 KB ok, correct split
22 Correct 12 ms 7800 KB ok, correct split
23 Correct 11 ms 7800 KB ok, correct split
24 Correct 12 ms 7800 KB ok, correct split
25 Correct 10 ms 7800 KB ok, correct split
26 Correct 11 ms 7800 KB ok, correct split
27 Correct 11 ms 7800 KB ok, correct split
28 Correct 10 ms 7672 KB ok, correct split
29 Correct 8 ms 7416 KB ok, correct split
30 Correct 10 ms 7672 KB ok, correct split
31 Correct 9 ms 7416 KB ok, correct split
32 Correct 8 ms 7416 KB ok, correct split
33 Correct 9 ms 7416 KB ok, correct split
34 Correct 10 ms 7672 KB ok, correct split
35 Correct 10 ms 7672 KB ok, correct split
36 Correct 10 ms 7672 KB ok, correct split
37 Correct 12 ms 7800 KB ok, correct split
38 Correct 12 ms 7800 KB ok, correct split
39 Correct 14 ms 7828 KB ok, correct split
40 Correct 13 ms 7800 KB ok, correct split
41 Correct 10 ms 7672 KB ok, correct split
42 Correct 9 ms 7544 KB ok, correct split
43 Correct 11 ms 7672 KB ok, correct split
44 Correct 11 ms 7800 KB ok, correct split
45 Correct 11 ms 7800 KB ok, correct split
46 Correct 10 ms 7800 KB ok, correct split
47 Correct 10 ms 7672 KB ok, no valid answer
48 Correct 10 ms 7672 KB ok, correct split
49 Correct 10 ms 7800 KB ok, correct split
50 Correct 8 ms 7416 KB ok, no valid answer
51 Correct 9 ms 7416 KB ok, no valid answer
52 Correct 10 ms 7672 KB ok, no valid answer
53 Correct 11 ms 7672 KB ok, no valid answer
54 Correct 10 ms 7672 KB ok, no valid answer
55 Correct 10 ms 7672 KB ok, no valid answer
56 Correct 10 ms 7652 KB ok, no valid answer
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB ok, correct split
2 Correct 8 ms 7416 KB ok, correct split
3 Correct 8 ms 7416 KB ok, correct split
4 Correct 8 ms 7416 KB ok, correct split
5 Correct 8 ms 7416 KB ok, correct split
6 Correct 8 ms 7416 KB ok, correct split
7 Correct 181 ms 24240 KB ok, correct split
8 Correct 199 ms 24236 KB ok, correct split
9 Correct 171 ms 24276 KB ok, correct split
10 Correct 169 ms 24236 KB ok, correct split
11 Correct 177 ms 24240 KB ok, correct split
12 Correct 8 ms 7416 KB ok, correct split
13 Correct 8 ms 7416 KB ok, correct split
14 Correct 8 ms 7416 KB ok, correct split
15 Correct 205 ms 21848 KB ok, correct split
16 Correct 162 ms 18932 KB ok, correct split
17 Correct 194 ms 24316 KB ok, correct split
18 Correct 175 ms 24240 KB ok, correct split
19 Correct 225 ms 20852 KB ok, correct split
20 Correct 180 ms 18804 KB ok, correct split
21 Correct 100 ms 19048 KB ok, correct split
22 Correct 99 ms 19072 KB ok, correct split
23 Correct 105 ms 19048 KB ok, correct split
24 Correct 8 ms 7416 KB ok, correct split
25 Correct 165 ms 18920 KB ok, correct split
26 Correct 54 ms 12152 KB ok, correct split
27 Correct 8 ms 7416 KB ok, correct split
28 Correct 196 ms 22128 KB ok, correct split
29 Correct 269 ms 22200 KB ok, correct split
30 Correct 194 ms 22172 KB ok, correct split
31 Correct 192 ms 22112 KB ok, correct split
32 Correct 204 ms 22116 KB ok, correct split
33 Correct 46 ms 10744 KB ok, no valid answer
34 Correct 68 ms 12536 KB ok, no valid answer
35 Correct 170 ms 17908 KB ok, no valid answer
36 Correct 161 ms 17656 KB ok, no valid answer
37 Correct 116 ms 18024 KB ok, no valid answer
38 Correct 8 ms 7416 KB ok, correct split
39 Correct 8 ms 7416 KB ok, no valid answer
40 Correct 8 ms 7416 KB ok, correct split
41 Correct 8 ms 7416 KB ok, correct split
42 Correct 8 ms 7416 KB ok, correct split
43 Correct 8 ms 7416 KB ok, correct split
44 Correct 8 ms 7416 KB ok, correct split
45 Correct 8 ms 7416 KB ok, correct split
46 Correct 11 ms 7672 KB ok, correct split
47 Correct 11 ms 7800 KB ok, correct split
48 Correct 8 ms 7416 KB ok, correct split
49 Correct 11 ms 7800 KB ok, correct split
50 Correct 8 ms 7416 KB ok, correct split
51 Correct 8 ms 7416 KB ok, correct split
52 Correct 8 ms 7416 KB ok, correct split
53 Correct 8 ms 7416 KB ok, correct split
54 Correct 8 ms 7416 KB ok, correct split
55 Correct 8 ms 7416 KB ok, correct split
56 Correct 10 ms 7416 KB ok, correct split
57 Correct 9 ms 7544 KB ok, correct split
58 Correct 10 ms 7800 KB ok, correct split
59 Correct 12 ms 7800 KB ok, correct split
60 Correct 11 ms 7800 KB ok, correct split
61 Correct 12 ms 7800 KB ok, correct split
62 Correct 10 ms 7800 KB ok, correct split
63 Correct 11 ms 7800 KB ok, correct split
64 Correct 11 ms 7800 KB ok, correct split
65 Correct 10 ms 7672 KB ok, correct split
66 Correct 8 ms 7416 KB ok, correct split
67 Correct 10 ms 7672 KB ok, correct split
68 Correct 9 ms 7416 KB ok, correct split
69 Correct 8 ms 7416 KB ok, correct split
70 Correct 9 ms 7416 KB ok, correct split
71 Correct 10 ms 7672 KB ok, correct split
72 Correct 10 ms 7672 KB ok, correct split
73 Correct 10 ms 7672 KB ok, correct split
74 Correct 12 ms 7800 KB ok, correct split
75 Correct 12 ms 7800 KB ok, correct split
76 Correct 14 ms 7828 KB ok, correct split
77 Correct 13 ms 7800 KB ok, correct split
78 Correct 10 ms 7672 KB ok, correct split
79 Correct 9 ms 7544 KB ok, correct split
80 Correct 11 ms 7672 KB ok, correct split
81 Correct 11 ms 7800 KB ok, correct split
82 Correct 11 ms 7800 KB ok, correct split
83 Correct 10 ms 7800 KB ok, correct split
84 Correct 10 ms 7672 KB ok, no valid answer
85 Correct 10 ms 7672 KB ok, correct split
86 Correct 10 ms 7800 KB ok, correct split
87 Correct 8 ms 7416 KB ok, no valid answer
88 Correct 9 ms 7416 KB ok, no valid answer
89 Correct 10 ms 7672 KB ok, no valid answer
90 Correct 11 ms 7672 KB ok, no valid answer
91 Correct 10 ms 7672 KB ok, no valid answer
92 Correct 10 ms 7672 KB ok, no valid answer
93 Correct 10 ms 7652 KB ok, no valid answer
94 Correct 177 ms 19856 KB ok, correct split
95 Correct 241 ms 23196 KB ok, correct split
96 Correct 244 ms 22276 KB ok, correct split
97 Correct 50 ms 12152 KB ok, correct split
98 Correct 57 ms 12104 KB ok, correct split
99 Correct 77 ms 13432 KB ok, correct split
100 Correct 231 ms 21336 KB ok, correct split
101 Correct 248 ms 20412 KB ok, correct split
102 Correct 207 ms 21612 KB ok, correct split
103 Correct 205 ms 21356 KB ok, correct split
104 Correct 177 ms 21860 KB ok, correct split
105 Correct 122 ms 14592 KB ok, correct split
106 Correct 218 ms 21664 KB ok, correct split
107 Correct 159 ms 19112 KB ok, correct split
108 Correct 156 ms 19008 KB ok, correct split
109 Correct 247 ms 21124 KB ok, correct split
110 Correct 364 ms 23836 KB ok, correct split
111 Correct 371 ms 23708 KB ok, correct split
112 Correct 276 ms 24180 KB ok, correct split
113 Correct 275 ms 24228 KB ok, correct split
114 Correct 27 ms 9180 KB ok, correct split
115 Correct 26 ms 9084 KB ok, correct split
116 Correct 227 ms 20844 KB ok, correct split
117 Correct 235 ms 20844 KB ok, correct split
118 Correct 212 ms 18856 KB ok, correct split
119 Correct 287 ms 18816 KB ok, correct split
120 Correct 263 ms 21876 KB ok, correct split
121 Correct 164 ms 17508 KB ok, no valid answer
122 Correct 149 ms 17696 KB ok, no valid answer
123 Correct 243 ms 19872 KB ok, no valid answer
124 Correct 232 ms 19960 KB ok, no valid answer
125 Correct 167 ms 19048 KB ok, no valid answer
126 Correct 152 ms 17128 KB ok, no valid answer
127 Correct 176 ms 19860 KB ok, no valid answer