Submission #295815

# Submission time Handle Problem Language Result Execution time Memory
295815 2020-09-10T02:14:52 Z ChrisT Split the Attractions (IOI19_split) C++17
100 / 100
215 ms 21144 KB
#include <bits/stdc++.h>
#include "split.h"
using namespace std;
const int MN = 1e5+5;
vector<int> adj[MN];
int sz[MN], ohp[MN], p[MN], togo[MN]; bool vis[MN];
int dfs (int cur) {
	vis[cur] = 1;
	for (int i : adj[cur]) if (!vis[i]) {
		ohp[i] = cur; 
		sz[cur] += dfs(i);
	}
	return ++sz[cur];
}
int getcent (int cur, int tot) {
	for (int i : adj[cur]) if (ohp[i] == cur && sz[i] > (tot >> 1))
		return getcent(i,tot);
	return cur;
}
int calc (int cur) {
	vis[cur] = sz[cur] = 1;
	for (int i : adj[cur]) if ((ohp[i] == cur || ohp[cur] == i) && !vis[i]) {
		p[i] = cur;
		sz[cur] += calc(i);
	}
	return sz[cur];
}
vector<int> find_split (int n, int a, int b, int c, vector<int> P, vector<int> Q) {
	vector<pair<int,int>> vv = {{a,1},{b,2},{c,3}};
	sort(vv.begin(),vv.end());
	vector<int> ret(n,vv[2].second);
	a = vv[0].first; b = vv[1].first; c = vv[2].first;
	for (int i = 0; i < (int)P.size(); i++) {
		adj[++P[i]].push_back(++Q[i]);
		adj[Q[i]].push_back(P[i]);
	}
	auto fillB = [&] (int st, int go, int put) {
		queue<int> q; q.push(st); ret[st-1] = put; --go;
		while (!q.empty()) {
			int cur = q.front(); q.pop();
			for (int i : adj[cur]) if (ret[i-1] == vv[2].second) {
				q.push(i);
				if (go) --go, ret[i-1] = put;
				else return;
			}
		}
	};
	int cent = getcent(1,dfs(1)); memset(vis,0,sizeof vis);
	calc(cent);
	for (int i : adj[cent]) if (p[i] == cent && sz[i] >= a) {
		queue<int> q; q.push(i);
		while (a--) {
			int cur = q.front(); q.pop(); ret[cur-1] = vv[0].second;
			for (int j : adj[cur]) if (p[j] == cur) q.push(j);
		}
		fillB(cent,b,vv[1].second);
		return ret;
	}
	vector<vector<int>> ree; vector<int> cnt,in(n+1);
	for (int i : adj[cent]) if (p[i] == cent) {
		in[i] = (int)ree.size(); ree.push_back({i}); cnt.push_back(sz[i]);
		queue<int> q; q.push(i);
		while (!q.empty()) {
			int cur = q.front(); q.pop(); togo[cur] = i;
			for (int j : adj[cur]) if (p[j] == cur) q.push(j);
		}
	}
	for (int i = 0; i < (int)P.size(); i++) if (p[P[i]] != Q[i] && p[Q[i]] != P[i] && in[P[i]] != in[Q[i]]) {
		int u = in[togo[P[i]]], v = in[togo[Q[i]]];
		if (u == v) continue;
		if (cnt[u] > cnt[v]) swap(u,v);
		cnt[v] += cnt[u];
		for (int j : ree[u]) {in[j] = v; ree[v].push_back(j);}
	}
	for (int i = 0; i < (int)ree.size(); i++) if (cnt[i] >= a) {
		while (cnt[i] - sz[ree[i].back()] >= a) {
			ree[i].pop_back(); cnt[i] -= sz[ree[i].back()];
		} 
		for (int j : ree[i]) {
			queue<int> q; q.push(j);
			while (a && !q.empty()) {
				int cur = q.front(); q.pop(); --a; ret[cur-1] = vv[0].second;
				for (int k : adj[cur]) if (p[k] == cur) q.push(k);
			}
		}
		fillB(cent,b,vv[1].second);
		return ret;
	}
	fill(ret.begin(),ret.end(),0);
	return ret;
}

Compilation message

split.cpp: In function 'int calc(int)':
split.cpp:21:21: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   21 |  vis[cur] = sz[cur] = 1;
      |             ~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2816 KB ok, correct split
2 Correct 2 ms 2816 KB ok, correct split
3 Correct 2 ms 2816 KB ok, correct split
4 Correct 2 ms 2816 KB ok, correct split
5 Correct 2 ms 2816 KB ok, correct split
6 Correct 2 ms 2816 KB ok, correct split
7 Correct 123 ms 13432 KB ok, correct split
8 Correct 112 ms 12152 KB ok, correct split
9 Correct 113 ms 11768 KB ok, correct split
10 Correct 118 ms 13688 KB ok, correct split
11 Correct 126 ms 13692 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2816 KB ok, correct split
2 Correct 2 ms 2944 KB ok, correct split
3 Correct 2 ms 2816 KB ok, correct split
4 Correct 132 ms 12280 KB ok, correct split
5 Correct 99 ms 9368 KB ok, correct split
6 Correct 114 ms 13688 KB ok, correct split
7 Correct 115 ms 12024 KB ok, correct split
8 Correct 163 ms 11428 KB ok, correct split
9 Correct 105 ms 9080 KB ok, correct split
10 Correct 59 ms 9584 KB ok, correct split
11 Correct 61 ms 9604 KB ok, correct split
12 Correct 63 ms 9584 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2944 KB ok, correct split
2 Correct 94 ms 9208 KB ok, correct split
3 Correct 29 ms 5376 KB ok, correct split
4 Correct 2 ms 2816 KB ok, correct split
5 Correct 116 ms 10616 KB ok, correct split
6 Correct 114 ms 10488 KB ok, correct split
7 Correct 110 ms 10488 KB ok, correct split
8 Correct 115 ms 11128 KB ok, correct split
9 Correct 112 ms 10488 KB ok, correct split
10 Correct 27 ms 5248 KB ok, no valid answer
11 Correct 40 ms 6520 KB ok, no valid answer
12 Correct 111 ms 13608 KB ok, no valid answer
13 Correct 103 ms 10620 KB ok, no valid answer
14 Correct 106 ms 16228 KB ok, no valid answer
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2816 KB ok, correct split
2 Correct 2 ms 2816 KB ok, no valid answer
3 Correct 2 ms 2816 KB ok, correct split
4 Correct 2 ms 2816 KB ok, correct split
5 Correct 2 ms 2816 KB ok, correct split
6 Correct 2 ms 2816 KB ok, correct split
7 Correct 2 ms 2816 KB ok, correct split
8 Correct 2 ms 2816 KB ok, correct split
9 Correct 4 ms 3072 KB ok, correct split
10 Correct 4 ms 3008 KB ok, correct split
11 Correct 2 ms 2816 KB ok, correct split
12 Correct 4 ms 2944 KB ok, correct split
13 Correct 2 ms 2816 KB ok, correct split
14 Correct 2 ms 2816 KB ok, correct split
15 Correct 2 ms 2816 KB ok, correct split
16 Correct 2 ms 2816 KB ok, correct split
17 Correct 2 ms 2816 KB ok, correct split
18 Correct 2 ms 2816 KB ok, correct split
19 Correct 2 ms 2816 KB ok, correct split
20 Correct 3 ms 2816 KB ok, correct split
21 Correct 4 ms 2944 KB ok, correct split
22 Correct 4 ms 2996 KB ok, correct split
23 Correct 4 ms 2944 KB ok, correct split
24 Correct 4 ms 2944 KB ok, correct split
25 Correct 4 ms 2944 KB ok, correct split
26 Correct 5 ms 3200 KB ok, correct split
27 Correct 5 ms 3200 KB ok, correct split
28 Correct 5 ms 3072 KB ok, correct split
29 Correct 2 ms 2816 KB ok, correct split
30 Correct 4 ms 3072 KB ok, correct split
31 Correct 3 ms 2816 KB ok, correct split
32 Correct 2 ms 2816 KB ok, correct split
33 Correct 2 ms 2816 KB ok, correct split
34 Correct 4 ms 3072 KB ok, correct split
35 Correct 4 ms 3072 KB ok, correct split
36 Correct 3 ms 2944 KB ok, correct split
37 Correct 5 ms 3072 KB ok, correct split
38 Correct 5 ms 3072 KB ok, correct split
39 Correct 5 ms 3072 KB ok, correct split
40 Correct 4 ms 3072 KB ok, correct split
41 Correct 4 ms 2944 KB ok, correct split
42 Correct 3 ms 2976 KB ok, correct split
43 Correct 5 ms 3072 KB ok, correct split
44 Correct 5 ms 3072 KB ok, correct split
45 Correct 4 ms 3072 KB ok, correct split
46 Correct 4 ms 2944 KB ok, correct split
47 Correct 3 ms 3072 KB ok, no valid answer
48 Correct 3 ms 2944 KB ok, correct split
49 Correct 4 ms 3072 KB ok, correct split
50 Correct 2 ms 2816 KB ok, no valid answer
51 Correct 2 ms 2816 KB ok, no valid answer
52 Correct 4 ms 3072 KB ok, no valid answer
53 Correct 5 ms 3072 KB ok, no valid answer
54 Correct 4 ms 3200 KB ok, no valid answer
55 Correct 5 ms 3064 KB ok, no valid answer
56 Correct 4 ms 3072 KB ok, no valid answer
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2816 KB ok, correct split
2 Correct 2 ms 2816 KB ok, correct split
3 Correct 2 ms 2816 KB ok, correct split
4 Correct 2 ms 2816 KB ok, correct split
5 Correct 2 ms 2816 KB ok, correct split
6 Correct 2 ms 2816 KB ok, correct split
7 Correct 123 ms 13432 KB ok, correct split
8 Correct 112 ms 12152 KB ok, correct split
9 Correct 113 ms 11768 KB ok, correct split
10 Correct 118 ms 13688 KB ok, correct split
11 Correct 126 ms 13692 KB ok, correct split
12 Correct 2 ms 2816 KB ok, correct split
13 Correct 2 ms 2944 KB ok, correct split
14 Correct 2 ms 2816 KB ok, correct split
15 Correct 132 ms 12280 KB ok, correct split
16 Correct 99 ms 9368 KB ok, correct split
17 Correct 114 ms 13688 KB ok, correct split
18 Correct 115 ms 12024 KB ok, correct split
19 Correct 163 ms 11428 KB ok, correct split
20 Correct 105 ms 9080 KB ok, correct split
21 Correct 59 ms 9584 KB ok, correct split
22 Correct 61 ms 9604 KB ok, correct split
23 Correct 63 ms 9584 KB ok, correct split
24 Correct 2 ms 2944 KB ok, correct split
25 Correct 94 ms 9208 KB ok, correct split
26 Correct 29 ms 5376 KB ok, correct split
27 Correct 2 ms 2816 KB ok, correct split
28 Correct 116 ms 10616 KB ok, correct split
29 Correct 114 ms 10488 KB ok, correct split
30 Correct 110 ms 10488 KB ok, correct split
31 Correct 115 ms 11128 KB ok, correct split
32 Correct 112 ms 10488 KB ok, correct split
33 Correct 27 ms 5248 KB ok, no valid answer
34 Correct 40 ms 6520 KB ok, no valid answer
35 Correct 111 ms 13608 KB ok, no valid answer
36 Correct 103 ms 10620 KB ok, no valid answer
37 Correct 106 ms 16228 KB ok, no valid answer
38 Correct 2 ms 2816 KB ok, correct split
39 Correct 2 ms 2816 KB ok, no valid answer
40 Correct 2 ms 2816 KB ok, correct split
41 Correct 2 ms 2816 KB ok, correct split
42 Correct 2 ms 2816 KB ok, correct split
43 Correct 2 ms 2816 KB ok, correct split
44 Correct 2 ms 2816 KB ok, correct split
45 Correct 2 ms 2816 KB ok, correct split
46 Correct 4 ms 3072 KB ok, correct split
47 Correct 4 ms 3008 KB ok, correct split
48 Correct 2 ms 2816 KB ok, correct split
49 Correct 4 ms 2944 KB ok, correct split
50 Correct 2 ms 2816 KB ok, correct split
51 Correct 2 ms 2816 KB ok, correct split
52 Correct 2 ms 2816 KB ok, correct split
53 Correct 2 ms 2816 KB ok, correct split
54 Correct 2 ms 2816 KB ok, correct split
55 Correct 2 ms 2816 KB ok, correct split
56 Correct 2 ms 2816 KB ok, correct split
57 Correct 3 ms 2816 KB ok, correct split
58 Correct 4 ms 2944 KB ok, correct split
59 Correct 4 ms 2996 KB ok, correct split
60 Correct 4 ms 2944 KB ok, correct split
61 Correct 4 ms 2944 KB ok, correct split
62 Correct 4 ms 2944 KB ok, correct split
63 Correct 5 ms 3200 KB ok, correct split
64 Correct 5 ms 3200 KB ok, correct split
65 Correct 5 ms 3072 KB ok, correct split
66 Correct 2 ms 2816 KB ok, correct split
67 Correct 4 ms 3072 KB ok, correct split
68 Correct 3 ms 2816 KB ok, correct split
69 Correct 2 ms 2816 KB ok, correct split
70 Correct 2 ms 2816 KB ok, correct split
71 Correct 4 ms 3072 KB ok, correct split
72 Correct 4 ms 3072 KB ok, correct split
73 Correct 3 ms 2944 KB ok, correct split
74 Correct 5 ms 3072 KB ok, correct split
75 Correct 5 ms 3072 KB ok, correct split
76 Correct 5 ms 3072 KB ok, correct split
77 Correct 4 ms 3072 KB ok, correct split
78 Correct 4 ms 2944 KB ok, correct split
79 Correct 3 ms 2976 KB ok, correct split
80 Correct 5 ms 3072 KB ok, correct split
81 Correct 5 ms 3072 KB ok, correct split
82 Correct 4 ms 3072 KB ok, correct split
83 Correct 4 ms 2944 KB ok, correct split
84 Correct 3 ms 3072 KB ok, no valid answer
85 Correct 3 ms 2944 KB ok, correct split
86 Correct 4 ms 3072 KB ok, correct split
87 Correct 2 ms 2816 KB ok, no valid answer
88 Correct 2 ms 2816 KB ok, no valid answer
89 Correct 4 ms 3072 KB ok, no valid answer
90 Correct 5 ms 3072 KB ok, no valid answer
91 Correct 4 ms 3200 KB ok, no valid answer
92 Correct 5 ms 3064 KB ok, no valid answer
93 Correct 4 ms 3072 KB ok, no valid answer
94 Correct 123 ms 12280 KB ok, correct split
95 Correct 181 ms 16760 KB ok, correct split
96 Correct 153 ms 15224 KB ok, correct split
97 Correct 30 ms 5752 KB ok, correct split
98 Correct 34 ms 5888 KB ok, correct split
99 Correct 55 ms 8312 KB ok, correct split
100 Correct 162 ms 14072 KB ok, correct split
101 Correct 139 ms 12920 KB ok, correct split
102 Correct 124 ms 12656 KB ok, correct split
103 Correct 116 ms 12272 KB ok, correct split
104 Correct 121 ms 13796 KB ok, correct split
105 Correct 59 ms 8440 KB ok, correct split
106 Correct 215 ms 21144 KB ok, correct split
107 Correct 124 ms 11256 KB ok, correct split
108 Correct 102 ms 11128 KB ok, correct split
109 Correct 175 ms 14456 KB ok, correct split
110 Correct 172 ms 14192 KB ok, correct split
111 Correct 179 ms 14192 KB ok, correct split
112 Correct 158 ms 14448 KB ok, correct split
113 Correct 142 ms 14448 KB ok, correct split
114 Correct 14 ms 4224 KB ok, correct split
115 Correct 13 ms 4096 KB ok, correct split
116 Correct 171 ms 14196 KB ok, correct split
117 Correct 166 ms 14064 KB ok, correct split
118 Correct 112 ms 10360 KB ok, correct split
119 Correct 119 ms 10232 KB ok, correct split
120 Correct 124 ms 12740 KB ok, correct split
121 Correct 101 ms 11128 KB ok, no valid answer
122 Correct 105 ms 12468 KB ok, no valid answer
123 Correct 175 ms 14968 KB ok, no valid answer
124 Correct 175 ms 15096 KB ok, no valid answer
125 Correct 129 ms 17640 KB ok, no valid answer
126 Correct 87 ms 15848 KB ok, no valid answer
127 Correct 141 ms 15688 KB ok, no valid answer