Submission #218422

# Submission time Handle Problem Language Result Execution time Memory
218422 2020-04-02T07:03:49 Z super_j6 Split the Attractions (IOI19_split) C++14
100 / 100
159 ms 24184 KB
#include "split.h"
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define endl '\n'
#define pi pair<int, int>
#define f first
#define s second
#define vi vector<int>

const int maxn = 100000;
int n, m;
pi a[3];
int l[maxn], h[maxn], sz[maxn], p[maxn];
vi graph[maxn], g[maxn];
vi ans;
int r, s, t;

void dfs(int c){
	sz[c] = 1;
	l[c] = h[c] = ++t;
	int amt = 0;
	for(int i : graph[c]){
		if(i == p[c]) continue;
		if(!l[i]){
			p[i] = c;
			dfs(i);
			sz[c] += sz[i];
			h[c] = min(h[c], h[i]);
			g[c].push_back(i);
			amt++;
		}else{
			h[c] = min(h[c], l[i]);
		}
	}
}

void dfs1(int c){
	s--;
	ans[c] = r;
	for(int i : g[c]) if(s) dfs1(i);
}

void dfs2(int c){
	s--;
	ans[c] = r;
	for(int i : graph[c]) if(s && ans[i] == a[2].s) dfs2(i);
}

vi find_split(int N, int A, int B, int C, vi P, vi Q){
	n = N, m = P.size();
	a[0] = {A, 1}, a[1] = {B, 2}, a[2] = {C, 3};
	sort(a, a + 3);
	
	for(int i = 0; i < m; i++){
		graph[P[i]].push_back(Q[i]);
		graph[Q[i]].push_back(P[i]);
	}
	
	p[0] = -1;
	dfs(0);
	
	int x = 0;
	for(bool f = 1; f;){
		f = 0;
		for(int i : g[x]){
			if(sz[i] >= a[0].f){
				f = 1;
				x = i;
				break;
			}
		}
	}
	
	ans = vector<int>(n, a[2].s);
	if(sz[x] + a[1].f <= n){
		s = a[0].f, r = a[0].s;
		dfs1(x);
		s = a[1].f, r = a[1].s;
		dfs2(p[x]);
	}else{
		s = a[1].f - 1, r = a[1].s;
		ans[x] = r;
		for(int i : g[x]){
			if(!s || h[i] < l[x]) continue;
			dfs1(i);
		}
		for(int i : g[x]){
			if(!s || h[i] >= l[x]) continue;
			dfs1(i);
		}
		s = a[0].f, r = a[0].s;
		if(p[x] != -1) dfs2(p[x]);
		if(s) ans = vector<int>(n, 0);
	}
	
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB ok, correct split
2 Correct 7 ms 4992 KB ok, correct split
3 Correct 7 ms 4992 KB ok, correct split
4 Correct 7 ms 4992 KB ok, correct split
5 Correct 7 ms 4992 KB ok, correct split
6 Correct 7 ms 4992 KB ok, correct split
7 Correct 114 ms 23800 KB ok, correct split
8 Correct 107 ms 21496 KB ok, correct split
9 Correct 130 ms 20856 KB ok, correct split
10 Correct 106 ms 24184 KB ok, correct split
11 Correct 110 ms 24184 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB ok, correct split
2 Correct 7 ms 4992 KB ok, correct split
3 Correct 7 ms 4992 KB ok, correct split
4 Correct 133 ms 20600 KB ok, correct split
5 Correct 90 ms 14968 KB ok, correct split
6 Correct 104 ms 24184 KB ok, correct split
7 Correct 118 ms 21368 KB ok, correct split
8 Correct 144 ms 18680 KB ok, correct split
9 Correct 103 ms 16376 KB ok, correct split
10 Correct 64 ms 13808 KB ok, correct split
11 Correct 62 ms 13852 KB ok, correct split
12 Correct 61 ms 14196 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB ok, correct split
2 Correct 96 ms 14968 KB ok, correct split
3 Correct 34 ms 8960 KB ok, correct split
4 Correct 7 ms 4992 KB ok, correct split
5 Correct 106 ms 19064 KB ok, correct split
6 Correct 107 ms 18680 KB ok, correct split
7 Correct 109 ms 18680 KB ok, correct split
8 Correct 106 ms 19832 KB ok, correct split
9 Correct 108 ms 18296 KB ok, correct split
10 Correct 31 ms 8320 KB ok, no valid answer
11 Correct 44 ms 10036 KB ok, no valid answer
12 Correct 80 ms 14584 KB ok, no valid answer
13 Correct 89 ms 14840 KB ok, no valid answer
14 Correct 62 ms 14192 KB ok, no valid answer
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB ok, correct split
2 Correct 7 ms 4992 KB ok, no valid answer
3 Correct 7 ms 4992 KB ok, correct split
4 Correct 7 ms 4992 KB ok, correct split
5 Correct 7 ms 5072 KB ok, correct split
6 Correct 7 ms 4992 KB ok, correct split
7 Correct 7 ms 4992 KB ok, correct split
8 Correct 7 ms 4992 KB ok, correct split
9 Correct 10 ms 5376 KB ok, correct split
10 Correct 10 ms 5376 KB ok, correct split
11 Correct 7 ms 4992 KB ok, correct split
12 Correct 9 ms 5376 KB ok, correct split
13 Correct 7 ms 4992 KB ok, correct split
14 Correct 7 ms 4992 KB ok, correct split
15 Correct 7 ms 4992 KB ok, correct split
16 Correct 7 ms 5120 KB ok, correct split
17 Correct 7 ms 4992 KB ok, correct split
18 Correct 7 ms 4992 KB ok, correct split
19 Correct 7 ms 5120 KB ok, correct split
20 Correct 8 ms 5120 KB ok, correct split
21 Correct 9 ms 5376 KB ok, correct split
22 Correct 8 ms 5376 KB ok, correct split
23 Correct 9 ms 5376 KB ok, correct split
24 Correct 9 ms 5376 KB ok, correct split
25 Correct 8 ms 5376 KB ok, correct split
26 Correct 9 ms 5376 KB ok, correct split
27 Correct 9 ms 5336 KB ok, correct split
28 Correct 9 ms 5376 KB ok, correct split
29 Correct 8 ms 4992 KB ok, correct split
30 Correct 9 ms 5376 KB ok, correct split
31 Correct 8 ms 5120 KB ok, correct split
32 Correct 8 ms 4992 KB ok, correct split
33 Correct 7 ms 5120 KB ok, correct split
34 Correct 9 ms 5248 KB ok, correct split
35 Correct 9 ms 5248 KB ok, correct split
36 Correct 9 ms 5248 KB ok, correct split
37 Correct 9 ms 5376 KB ok, correct split
38 Correct 11 ms 5376 KB ok, correct split
39 Correct 9 ms 5376 KB ok, correct split
40 Correct 9 ms 5376 KB ok, correct split
41 Correct 8 ms 5120 KB ok, correct split
42 Correct 8 ms 5120 KB ok, correct split
43 Correct 39 ms 5376 KB ok, correct split
44 Correct 10 ms 5376 KB ok, correct split
45 Correct 9 ms 5376 KB ok, correct split
46 Correct 9 ms 5376 KB ok, correct split
47 Correct 9 ms 5376 KB ok, no valid answer
48 Correct 9 ms 5376 KB ok, correct split
49 Correct 9 ms 5504 KB ok, correct split
50 Correct 7 ms 5120 KB ok, no valid answer
51 Correct 7 ms 4992 KB ok, no valid answer
52 Correct 9 ms 5248 KB ok, no valid answer
53 Correct 9 ms 5376 KB ok, no valid answer
54 Correct 8 ms 5248 KB ok, no valid answer
55 Correct 9 ms 5376 KB ok, no valid answer
56 Correct 9 ms 5376 KB ok, no valid answer
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB ok, correct split
2 Correct 7 ms 4992 KB ok, correct split
3 Correct 7 ms 4992 KB ok, correct split
4 Correct 7 ms 4992 KB ok, correct split
5 Correct 7 ms 4992 KB ok, correct split
6 Correct 7 ms 4992 KB ok, correct split
7 Correct 114 ms 23800 KB ok, correct split
8 Correct 107 ms 21496 KB ok, correct split
9 Correct 130 ms 20856 KB ok, correct split
10 Correct 106 ms 24184 KB ok, correct split
11 Correct 110 ms 24184 KB ok, correct split
12 Correct 7 ms 4992 KB ok, correct split
13 Correct 7 ms 4992 KB ok, correct split
14 Correct 7 ms 4992 KB ok, correct split
15 Correct 133 ms 20600 KB ok, correct split
16 Correct 90 ms 14968 KB ok, correct split
17 Correct 104 ms 24184 KB ok, correct split
18 Correct 118 ms 21368 KB ok, correct split
19 Correct 144 ms 18680 KB ok, correct split
20 Correct 103 ms 16376 KB ok, correct split
21 Correct 64 ms 13808 KB ok, correct split
22 Correct 62 ms 13852 KB ok, correct split
23 Correct 61 ms 14196 KB ok, correct split
24 Correct 7 ms 4992 KB ok, correct split
25 Correct 96 ms 14968 KB ok, correct split
26 Correct 34 ms 8960 KB ok, correct split
27 Correct 7 ms 4992 KB ok, correct split
28 Correct 106 ms 19064 KB ok, correct split
29 Correct 107 ms 18680 KB ok, correct split
30 Correct 109 ms 18680 KB ok, correct split
31 Correct 106 ms 19832 KB ok, correct split
32 Correct 108 ms 18296 KB ok, correct split
33 Correct 31 ms 8320 KB ok, no valid answer
34 Correct 44 ms 10036 KB ok, no valid answer
35 Correct 80 ms 14584 KB ok, no valid answer
36 Correct 89 ms 14840 KB ok, no valid answer
37 Correct 62 ms 14192 KB ok, no valid answer
38 Correct 7 ms 4992 KB ok, correct split
39 Correct 7 ms 4992 KB ok, no valid answer
40 Correct 7 ms 4992 KB ok, correct split
41 Correct 7 ms 4992 KB ok, correct split
42 Correct 7 ms 5072 KB ok, correct split
43 Correct 7 ms 4992 KB ok, correct split
44 Correct 7 ms 4992 KB ok, correct split
45 Correct 7 ms 4992 KB ok, correct split
46 Correct 10 ms 5376 KB ok, correct split
47 Correct 10 ms 5376 KB ok, correct split
48 Correct 7 ms 4992 KB ok, correct split
49 Correct 9 ms 5376 KB ok, correct split
50 Correct 7 ms 4992 KB ok, correct split
51 Correct 7 ms 4992 KB ok, correct split
52 Correct 7 ms 4992 KB ok, correct split
53 Correct 7 ms 5120 KB ok, correct split
54 Correct 7 ms 4992 KB ok, correct split
55 Correct 7 ms 4992 KB ok, correct split
56 Correct 7 ms 5120 KB ok, correct split
57 Correct 8 ms 5120 KB ok, correct split
58 Correct 9 ms 5376 KB ok, correct split
59 Correct 8 ms 5376 KB ok, correct split
60 Correct 9 ms 5376 KB ok, correct split
61 Correct 9 ms 5376 KB ok, correct split
62 Correct 8 ms 5376 KB ok, correct split
63 Correct 9 ms 5376 KB ok, correct split
64 Correct 9 ms 5336 KB ok, correct split
65 Correct 9 ms 5376 KB ok, correct split
66 Correct 8 ms 4992 KB ok, correct split
67 Correct 9 ms 5376 KB ok, correct split
68 Correct 8 ms 5120 KB ok, correct split
69 Correct 8 ms 4992 KB ok, correct split
70 Correct 7 ms 5120 KB ok, correct split
71 Correct 9 ms 5248 KB ok, correct split
72 Correct 9 ms 5248 KB ok, correct split
73 Correct 9 ms 5248 KB ok, correct split
74 Correct 9 ms 5376 KB ok, correct split
75 Correct 11 ms 5376 KB ok, correct split
76 Correct 9 ms 5376 KB ok, correct split
77 Correct 9 ms 5376 KB ok, correct split
78 Correct 8 ms 5120 KB ok, correct split
79 Correct 8 ms 5120 KB ok, correct split
80 Correct 39 ms 5376 KB ok, correct split
81 Correct 10 ms 5376 KB ok, correct split
82 Correct 9 ms 5376 KB ok, correct split
83 Correct 9 ms 5376 KB ok, correct split
84 Correct 9 ms 5376 KB ok, no valid answer
85 Correct 9 ms 5376 KB ok, correct split
86 Correct 9 ms 5504 KB ok, correct split
87 Correct 7 ms 5120 KB ok, no valid answer
88 Correct 7 ms 4992 KB ok, no valid answer
89 Correct 9 ms 5248 KB ok, no valid answer
90 Correct 9 ms 5376 KB ok, no valid answer
91 Correct 8 ms 5248 KB ok, no valid answer
92 Correct 9 ms 5376 KB ok, no valid answer
93 Correct 9 ms 5376 KB ok, no valid answer
94 Correct 116 ms 18248 KB ok, correct split
95 Correct 159 ms 23648 KB ok, correct split
96 Correct 144 ms 22008 KB ok, correct split
97 Correct 35 ms 8960 KB ok, correct split
98 Correct 38 ms 9216 KB ok, correct split
99 Correct 58 ms 11768 KB ok, correct split
100 Correct 146 ms 19192 KB ok, correct split
101 Correct 135 ms 18040 KB ok, correct split
102 Correct 119 ms 17392 KB ok, correct split
103 Correct 112 ms 17136 KB ok, correct split
104 Correct 114 ms 17508 KB ok, correct split
105 Correct 55 ms 11256 KB ok, correct split
106 Correct 108 ms 17128 KB ok, correct split
107 Correct 97 ms 14960 KB ok, correct split
108 Correct 94 ms 14968 KB ok, correct split
109 Correct 148 ms 18680 KB ok, correct split
110 Correct 148 ms 19440 KB ok, correct split
111 Correct 142 ms 19568 KB ok, correct split
112 Correct 135 ms 18160 KB ok, correct split
113 Correct 132 ms 18160 KB ok, correct split
114 Correct 18 ms 6784 KB ok, correct split
115 Correct 18 ms 6528 KB ok, correct split
116 Correct 142 ms 19568 KB ok, correct split
117 Correct 136 ms 19440 KB ok, correct split
118 Correct 103 ms 16504 KB ok, correct split
119 Correct 109 ms 16376 KB ok, correct split
120 Correct 123 ms 20540 KB ok, correct split
121 Correct 95 ms 14968 KB ok, no valid answer
122 Correct 84 ms 14840 KB ok, no valid answer
123 Correct 159 ms 19704 KB ok, no valid answer
124 Correct 144 ms 19320 KB ok, no valid answer
125 Correct 85 ms 15728 KB ok, no valid answer
126 Correct 56 ms 13296 KB ok, no valid answer
127 Correct 118 ms 16752 KB ok, no valid answer