답안 #152591

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
152591 2019-09-08T13:59:05 Z Myldero Split the Attractions (IOI19_split) C++14
0 / 100
4 ms 2680 KB
#include "split.h"
#include <algorithm>
#include <queue>

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;

int n, m;
ii att[3];
vi nb[100005];
int size[100005];
int parent[100005];
bool visited[100005];
bool visited2[100005];
int bestA = 111111, bestAV = -1;
int bestB = 111111, bestBV = -1;
vi res;

void bfs_fill1 (int s) {

	queue<int> q;
	q.push(s);

	for (int count = 0; count < att[0].first; count++) {
		int v = q.front();
		q.pop();
		res[v] = att[0].second;

		for (int w : nb[v]) {
			if (w != parent[v]) {
				q.push(w);
			}
		}
	}
}

void bfs_fill2 (int s) {

	queue<int> q;
	q.push(s);

	for (int count = 0; count <= att[1].first; count++) {
		int v = q.front();
		q.pop();
		res[v] = att[1].second;

		for (int w : nb[v]) {
			if (!visited2[w]) {
				q.push(w);
				visited2[w] = true;
			}
		}
	}
}

void dfs (int v, int p) {
	visited[v] = true;
	parent[v] = p;
	size[v] = 1;

	for (int w : nb[v]) {
		if (!visited[w]) {
			dfs(w, v);
			size[v] += size[w];
		}
	}

	if (size[v] >= att[0].first && size[v] < bestA) {
		bestA = size[v];
		bestAV = v;
	}
	if (size[v] >= att[1].first && size[v] < bestB) {
		bestB = size[v];
		bestBV = v;
	}
}

void solve () {
	dfs(0, -1);

	if (n - bestA >= att[1].first) {
		visited2[bestAV] = true;
		bfs_fill1(bestAV);
		bfs_fill2(parent[bestAV]);
	} else if (n - bestB >= att[0].first) {
		swap(att[0], att[1]);
		visited2[bestBV] = true;
		bfs_fill1(bestBV);
		bfs_fill2(parent[bestBV]);
	} else {
		return;
	}


	for (int i = 0; i < n; i++) {
		if (res[i] == 0) {
			res[i] = att[2].second;
		}
	}
}

vi find_split(int N, int a, int b, int c, vi p, vi q) {
	n = N;
	m = p.size();

	att[0] = make_pair(a, 1);
	att[1] = make_pair(b, 2);
	att[2] = make_pair(c, 3);
	sort(att, att+3);

	for (int i = 0; i < m; i++) {
		nb[p[i]].push_back(q[i]);
		nb[q[i]].push_back(p[i]);
	}

	res = vi(n);

	solve();

	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2680 KB invalid split: #1=1, #2=2, #3=0
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2676 KB invalid split: #1=1, #2=2, #3=0
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2680 KB invalid split: #1=3, #2=1, #3=1
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB ok, correct split
2 Correct 4 ms 2680 KB ok, no valid answer
3 Incorrect 4 ms 2680 KB invalid split: #1=1, #2=2, #3=0
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 2680 KB invalid split: #1=1, #2=2, #3=0
2 Halted 0 ms 0 KB -