Submission #167774

# Submission time Handle Problem Language Result Execution time Memory
167774 2019-12-10T06:07:11 Z oolimry Split the Attractions (IOI19_split) C++14
0 / 100
125 ms 18356 KB
#include "split.h"
#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;

static vi answer;
static vi adj[100005];
static vi child[100005];
static vi tree[100005];
static int sz[100005];
static int p[100005];
static bool vis[100005];

void dfs(int u){
	vis[u] = true;
	sz[u] = 1;
	for(int v : adj[u]){
		if(!vis[v]){
			child[u].push_back(v);
			tree[u].push_back(v);
			tree[v].push_back(u);
			p[v] = u;
			dfs(v);
			sz[u] += sz[v];
		}	
	}
}

void bfs(int root, int number){
	if(number == 0) return;
	queue<int> bf;
	bf.push(root);
	while(!bf.empty()){
		int u = bf.front(); bf.pop();
		for(int v : tree[u]){
			if(answer[v] == 0){
				answer[v] = answer[u];
				number--;
				if(number == 0) return;
				bf.push(v);
			}
		}
	}
}
vi find_split(int n, int aaa, int bbb, int ccc, vi p, vi q) {
	vector<ii> v = {ii(aaa,1),ii(bbb,2),ii(ccc,3)};
	sort(v.begin(),v.end());
	int A = v[0].first;
	int B = v[1].first;
	int AColour = v[0].second;
	int BColour = v[1].second;
	int CColour = v[2].second;
	
	answer.assign(n,0);
	
	for(int i = 0;i < (int) p.size();i++){
		int x = p[i], y = q[i];
		adj[y].push_back(x);
		adj[x].push_back(y);
	}
	
	dfs(0);
	
	for(int u = 0;u < n;u++){
		vector<ii> subtrees;
		if(u != 0) subtrees.push_back({n-1,u});
		for(int v : child[u]){
			subtrees.push_back({sz[v],v});
			if(u != 0) subtrees[0].first -= sz[v];
		}
		
		for(ii x : subtrees){
			if(x.first >= A && n - x.first >= B){
				answer[x.second] = AColour;
				answer[u] = BColour;
				bfs(x.second, A-1);
				bfs(u,B-1);
				for(int i = 0;i < n;i++){
					if(answer[i] == 0) answer[i] = CColour;
				}
				return answer;
			}
		}
	}
	
	return 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 Incorrect 8 ms 7416 KB invalid split: #1=20, #2=0, #3=80
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7292 KB ok, correct split
2 Correct 8 ms 7416 KB ok, correct split
3 Incorrect 8 ms 7416 KB invalid split: #1=0, #2=2, #3=3
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB ok, correct split
2 Incorrect 125 ms 18356 KB invalid split: #1=0, #2=20000, #3=80000
3 Halted 0 ms 0 KB -
# 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 7404 KB ok, correct split
4 Correct 9 ms 7416 KB ok, correct split
5 Incorrect 8 ms 7416 KB invalid split: #1=12, #2=0, #3=4
6 Halted 0 ms 0 KB -
# 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 Incorrect 8 ms 7416 KB invalid split: #1=20, #2=0, #3=80
7 Halted 0 ms 0 KB -