Submission #352602

# Submission time Handle Problem Language Result Execution time Memory
352602 2021-01-21T02:45:17 Z tengiz05 Split the Attractions (IOI19_split) C++17
40 / 100
191 ms 25964 KB
#include "split.h"
#ifndef EVAL
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int,int>
using namespace std;
const int N = 1e5+5;
int n, m;
vector<int> edges[N];
vector<int> g[N];
bool used[N];
int subtree_size[N];
vector<pii> extra;
void Dfs(int u, int p=-1){
	used[u] = true;
	subtree_size[u] = 1;
	for(auto v : edges[u]){
		if(used[v]){
			if(v != p)extra.pb({u,v});
			continue;
		}
		g[u].pb(v);
		g[v].pb(u);
		Dfs(v,u);
		subtree_size[u] += subtree_size[v];
	}
}
int find_centroid(int u, int p){
	for(auto v : g[u]){
		if(v!=p && subtree_size[v] >= n/2)return find_centroid(v,u);
	}return u;
}
void recalc_size(int u, int p){
	subtree_size[u] = 1;
	for(auto v : g[u]){
		if(v == p)continue;
		recalc_size(v,u);
		subtree_size[u] += subtree_size[v];
	}
}

// start of DSU
vector<int> p, sz;
void Init(int n){
	p.assign(n,0);
	sz.assign(n,1);
	for(int i=0;i<n;i++)p[i]=i;
}
int par(int u){
	if(p[u] == u)return u;
	return p[u] = par(p[u]);
}
bool IsSame(int u, int v){
	return par(u) == par(v);
}
void merge(int u,int v){
	u=par(u);v=par(v);
	if(u == v)return;
	p[v] = u;
	sz[u] += sz[v];
	return;
}
int size_of_node(int u){
	return sz[par(u)];
}// end of DSU

pii sizes[3];
vector<int> ans;
int center;
int remaining;
void color(int u){
	used[u] = true;
	ans[u] = sizes[0].second;
	remaining--;
	if(not remaining)return;
	for(auto v : g[u]){
		if(not remaining)return;
		if(used[v] || v == center)continue;
		color(v);
	}
}

void colorB(int u){
	used[u] = true;
	ans[u] = sizes[1].second;
	remaining--;
	if(not remaining)return;
	for(auto v : edges[u]){
		if(not remaining)return;
		if(used[v])continue;
		colorB(v);
	}
}


vector<int> find_split(int N, int a, int b, int c, vector<int> P, vector<int> Q) {
	Init(N);
	sizes[0] = {a,1};
	sizes[1] = {b,2};
	sizes[2] = {c,3};
	sort(sizes,sizes+3);
	a = sizes[0].first;
	b = sizes[1].first;
	c = sizes[2].first;
	n=N; m = P.size();
	for(int i=0;i<m;i++){
		edges[P[i]].pb(Q[i]);
		edges[Q[i]].pb(P[i]);
	}
	ans.assign(n,sizes[2].second);
	Dfs(0);
	center = find_centroid(0,0);
	recalc_size(center,center);
	for(int u=0;u<n;u++){
		if(u == center)continue;
		for(auto v : g[u]){
			if(v != center)merge(u,v);
		}
	}for(auto u : edges[center]){
		if(size_of_node(u) >= a){
			// yay we found solution! (I hope)
			remaining = a;
			memset(used,0,sizeof used);
			color(u);
			remaining = b;
			colorB(center);
			return ans;
		}
	}
	for(auto [u, v] : extra){
		if(IsSame(u,v))continue;
		g[u].pb(v);
		g[v].pb(u);
		merge(u,v);
		for(auto u : edges[center]){
			if(size_of_node(u) >= a){
				// yay we found solution! (I hope)
				memset(used,0,sizeof used);
				remaining = a;
				color(u);
				assert(not remaining);
				remaining = b;
				colorB(center);
				assert(not remaining);
				return ans;
			}
		}
	}
	return vector<int>(n,0);
}








# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB ok, correct split
2 Correct 4 ms 5100 KB ok, correct split
3 Correct 4 ms 5100 KB ok, correct split
4 Correct 4 ms 5100 KB ok, correct split
5 Correct 4 ms 5100 KB ok, correct split
6 Correct 5 ms 5100 KB ok, correct split
7 Correct 156 ms 25324 KB ok, correct split
8 Correct 140 ms 22124 KB ok, correct split
9 Correct 167 ms 21284 KB ok, correct split
10 Correct 143 ms 25964 KB ok, correct split
11 Correct 151 ms 25836 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5132 KB ok, correct split
2 Correct 5 ms 5100 KB ok, correct split
3 Correct 4 ms 5100 KB ok, correct split
4 Correct 166 ms 21824 KB ok, correct split
5 Correct 151 ms 15084 KB ok, correct split
6 Correct 161 ms 25836 KB ok, correct split
7 Correct 143 ms 21868 KB ok, correct split
8 Correct 191 ms 18344 KB ok, correct split
9 Correct 145 ms 14956 KB ok, correct split
10 Correct 77 ms 15716 KB ok, correct split
11 Correct 75 ms 15716 KB ok, correct split
12 Correct 85 ms 15716 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB ok, correct split
2 Correct 137 ms 15084 KB ok, correct split
3 Correct 42 ms 9196 KB ok, correct split
4 Correct 4 ms 5100 KB ok, correct split
5 Correct 151 ms 18540 KB ok, correct split
6 Correct 152 ms 18156 KB ok, correct split
7 Correct 142 ms 17900 KB ok, correct split
8 Correct 145 ms 19904 KB ok, correct split
9 Correct 152 ms 17784 KB ok, correct split
10 Correct 33 ms 8428 KB ok, no valid answer
11 Correct 53 ms 10092 KB ok, no valid answer
12 Correct 102 ms 15464 KB ok, no valid answer
13 Correct 134 ms 15212 KB ok, no valid answer
14 Correct 83 ms 15716 KB ok, no valid answer
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB ok, correct split
2 Correct 4 ms 4972 KB ok, no valid answer
3 Correct 4 ms 5100 KB ok, correct split
4 Correct 4 ms 5100 KB ok, correct split
5 Correct 4 ms 5100 KB ok, correct split
6 Correct 4 ms 5100 KB ok, correct split
7 Correct 5 ms 5100 KB ok, correct split
8 Correct 4 ms 5100 KB ok, correct split
9 Correct 7 ms 5612 KB ok, correct split
10 Correct 7 ms 5484 KB ok, correct split
11 Correct 4 ms 5100 KB ok, correct split
12 Correct 6 ms 5484 KB ok, correct split
13 Correct 5 ms 5100 KB ok, correct split
14 Correct 4 ms 5100 KB ok, correct split
15 Correct 4 ms 5100 KB ok, correct split
16 Correct 4 ms 5100 KB ok, correct split
17 Correct 4 ms 5100 KB ok, correct split
18 Correct 4 ms 5100 KB ok, correct split
19 Correct 4 ms 5100 KB ok, correct split
20 Correct 5 ms 5228 KB ok, correct split
21 Correct 6 ms 5484 KB ok, correct split
22 Correct 6 ms 5484 KB ok, correct split
23 Correct 6 ms 5484 KB ok, correct split
24 Correct 6 ms 5484 KB ok, correct split
25 Correct 6 ms 5484 KB ok, correct split
26 Correct 15 ms 5484 KB ok, correct split
27 Correct 13 ms 5484 KB ok, correct split
28 Correct 9 ms 5484 KB ok, correct split
29 Correct 4 ms 5100 KB ok, correct split
30 Correct 7 ms 5504 KB ok, correct split
31 Correct 4 ms 5228 KB ok, correct split
32 Correct 4 ms 5120 KB ok, correct split
33 Correct 4 ms 5100 KB ok, correct split
34 Correct 9 ms 5356 KB ok, correct split
35 Correct 7 ms 5356 KB ok, correct split
36 Correct 6 ms 5356 KB ok, correct split
37 Correct 8 ms 5484 KB ok, correct split
38 Correct 7 ms 5484 KB ok, correct split
39 Correct 7 ms 5484 KB ok, correct split
40 Correct 6 ms 5484 KB ok, correct split
41 Correct 5 ms 5356 KB ok, correct split
42 Correct 5 ms 5356 KB ok, correct split
43 Correct 7 ms 5484 KB ok, correct split
44 Correct 6 ms 5356 KB ok, correct split
45 Correct 6 ms 5484 KB ok, correct split
46 Correct 5 ms 5484 KB ok, correct split
47 Correct 5 ms 5356 KB ok, no valid answer
48 Correct 5 ms 5356 KB ok, correct split
49 Correct 6 ms 5484 KB ok, correct split
50 Correct 4 ms 4972 KB ok, no valid answer
51 Correct 4 ms 4972 KB ok, no valid answer
52 Correct 6 ms 5228 KB ok, no valid answer
53 Correct 6 ms 5356 KB ok, no valid answer
54 Correct 5 ms 5484 KB ok, no valid answer
55 Runtime error 24 ms 10876 KB Execution killed with signal 6
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB ok, correct split
2 Correct 4 ms 5100 KB ok, correct split
3 Correct 4 ms 5100 KB ok, correct split
4 Correct 4 ms 5100 KB ok, correct split
5 Correct 4 ms 5100 KB ok, correct split
6 Correct 5 ms 5100 KB ok, correct split
7 Correct 156 ms 25324 KB ok, correct split
8 Correct 140 ms 22124 KB ok, correct split
9 Correct 167 ms 21284 KB ok, correct split
10 Correct 143 ms 25964 KB ok, correct split
11 Correct 151 ms 25836 KB ok, correct split
12 Correct 5 ms 5132 KB ok, correct split
13 Correct 5 ms 5100 KB ok, correct split
14 Correct 4 ms 5100 KB ok, correct split
15 Correct 166 ms 21824 KB ok, correct split
16 Correct 151 ms 15084 KB ok, correct split
17 Correct 161 ms 25836 KB ok, correct split
18 Correct 143 ms 21868 KB ok, correct split
19 Correct 191 ms 18344 KB ok, correct split
20 Correct 145 ms 14956 KB ok, correct split
21 Correct 77 ms 15716 KB ok, correct split
22 Correct 75 ms 15716 KB ok, correct split
23 Correct 85 ms 15716 KB ok, correct split
24 Correct 4 ms 5100 KB ok, correct split
25 Correct 137 ms 15084 KB ok, correct split
26 Correct 42 ms 9196 KB ok, correct split
27 Correct 4 ms 5100 KB ok, correct split
28 Correct 151 ms 18540 KB ok, correct split
29 Correct 152 ms 18156 KB ok, correct split
30 Correct 142 ms 17900 KB ok, correct split
31 Correct 145 ms 19904 KB ok, correct split
32 Correct 152 ms 17784 KB ok, correct split
33 Correct 33 ms 8428 KB ok, no valid answer
34 Correct 53 ms 10092 KB ok, no valid answer
35 Correct 102 ms 15464 KB ok, no valid answer
36 Correct 134 ms 15212 KB ok, no valid answer
37 Correct 83 ms 15716 KB ok, no valid answer
38 Correct 4 ms 5100 KB ok, correct split
39 Correct 4 ms 4972 KB ok, no valid answer
40 Correct 4 ms 5100 KB ok, correct split
41 Correct 4 ms 5100 KB ok, correct split
42 Correct 4 ms 5100 KB ok, correct split
43 Correct 4 ms 5100 KB ok, correct split
44 Correct 5 ms 5100 KB ok, correct split
45 Correct 4 ms 5100 KB ok, correct split
46 Correct 7 ms 5612 KB ok, correct split
47 Correct 7 ms 5484 KB ok, correct split
48 Correct 4 ms 5100 KB ok, correct split
49 Correct 6 ms 5484 KB ok, correct split
50 Correct 5 ms 5100 KB ok, correct split
51 Correct 4 ms 5100 KB ok, correct split
52 Correct 4 ms 5100 KB ok, correct split
53 Correct 4 ms 5100 KB ok, correct split
54 Correct 4 ms 5100 KB ok, correct split
55 Correct 4 ms 5100 KB ok, correct split
56 Correct 4 ms 5100 KB ok, correct split
57 Correct 5 ms 5228 KB ok, correct split
58 Correct 6 ms 5484 KB ok, correct split
59 Correct 6 ms 5484 KB ok, correct split
60 Correct 6 ms 5484 KB ok, correct split
61 Correct 6 ms 5484 KB ok, correct split
62 Correct 6 ms 5484 KB ok, correct split
63 Correct 15 ms 5484 KB ok, correct split
64 Correct 13 ms 5484 KB ok, correct split
65 Correct 9 ms 5484 KB ok, correct split
66 Correct 4 ms 5100 KB ok, correct split
67 Correct 7 ms 5504 KB ok, correct split
68 Correct 4 ms 5228 KB ok, correct split
69 Correct 4 ms 5120 KB ok, correct split
70 Correct 4 ms 5100 KB ok, correct split
71 Correct 9 ms 5356 KB ok, correct split
72 Correct 7 ms 5356 KB ok, correct split
73 Correct 6 ms 5356 KB ok, correct split
74 Correct 8 ms 5484 KB ok, correct split
75 Correct 7 ms 5484 KB ok, correct split
76 Correct 7 ms 5484 KB ok, correct split
77 Correct 6 ms 5484 KB ok, correct split
78 Correct 5 ms 5356 KB ok, correct split
79 Correct 5 ms 5356 KB ok, correct split
80 Correct 7 ms 5484 KB ok, correct split
81 Correct 6 ms 5356 KB ok, correct split
82 Correct 6 ms 5484 KB ok, correct split
83 Correct 5 ms 5484 KB ok, correct split
84 Correct 5 ms 5356 KB ok, no valid answer
85 Correct 5 ms 5356 KB ok, correct split
86 Correct 6 ms 5484 KB ok, correct split
87 Correct 4 ms 4972 KB ok, no valid answer
88 Correct 4 ms 4972 KB ok, no valid answer
89 Correct 6 ms 5228 KB ok, no valid answer
90 Correct 6 ms 5356 KB ok, no valid answer
91 Correct 5 ms 5484 KB ok, no valid answer
92 Runtime error 24 ms 10876 KB Execution killed with signal 6
93 Halted 0 ms 0 KB -