답안 #39817

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
39817 2018-01-19T13:25:43 Z UncleGrandpa925 Amusement Park (JOI17_amusement_park) C++14
100 / 100
35 ms 7208 KB
#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define bit(x,y) ((x>>(y))&1LL)
#define NMAX 10000
#define MMAX 20000
#define MOVEMAX 20000

// start of the common part
	int par[NMAX + 5], child[NMAX + 5], numcc = 0;
	vector<vector<int> > a(NMAX + 5); bool mark[60]; int lab[NMAX + 5]; int whcc[NMAX + 5]; int szcc[NMAX + 5];
	struct dsu {
		int par[NMAX + 5];
		dsu() {
			for (int i = 0; i < NMAX; i++) par[i] = i;
		}
		int find(int x) {
			if (par[x] == x) return x;
			return par[x] = find(par[x]);
		}
		void uni(int x, int y) {
			x = find(x); y = find(y);
			if (x != y) par[x] = y;
		}
	} d;
	void dfs(int u, int p) {
		child[u] = 1;
		for (auto v : a[u]) {
			if (v == p) continue;
			par[v] = u;
			dfs(v, u);
			child[u] += child[v];
		}
	}
	void makeTree(int N, int M, int A[], int B[]) {
		for (int i = 0; i < M; i++) {
			if (d.find(A[i]) != d.find(B[i])) {
				d.uni(A[i], B[i]);
				a[A[i]].push_back(B[i]);
				a[B[i]].push_back(A[i]);
			}
		}
		dfs(0, 0);
	}
	void preMark(int u, int p, int &rem, const int key) {
		if (rem == 0) return;
		mark[lab[u]] = true; rem--;
		for (auto v : a[u]) {
			if (whcc[v] != key || v == p) continue;
			preMark(v, u, rem, key);
			if (rem == 0) return;
		}
	}
	void fullMark(int u, int p, int &it, const long long X, int key) {
		whcc[u] = key; szcc[key]++;
		while (mark[it] && it < 59)
			it++;
		lab[u] = it; MessageBoard(u, bit(X, it)); mark[it] = true; it++;
		if (it == 60) return;
		for (auto v : a[u]) {
			if (v == p) continue;
			fullMark(v, u, it, X, key);
			if (it == 60) return;
		}
	}
	void dfs2(int u, int p, const long long X) {
		if (lab[u] == -1) {
			memset(mark, 0, sizeof(mark));
			int rem = 60 - min(60, child[u]);
			preMark(par[u], u, rem, whcc[par[u]]);
			int it = 0;
			fullMark(u, par[u], it, X, ++numcc);
		}
		for (auto v : a[u]) {
			if (v == p) continue;
			dfs2(v, u, X);
		}
	}
// end of the common part
	void Joi(int N, int M, int A[], int B[], long long X, int T) {
		memset(lab, -1, sizeof(lab));
		makeTree(N, M, A, B);
		dfs2(0, 0, X);
	}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define bit(x,y) ((x>>(y))&1LL)
#define NMAX 10000
#define MMAX 20000
#define MOVEMAX 20000

int par[NMAX + 5], child[NMAX + 5], numcc = 0;
vector<vector<int> > a(NMAX + 5); bool mark[60]; int lab[NMAX + 5]; int whcc[NMAX + 5]; int szcc[NMAX + 5];
struct dsu {
	int par[NMAX + 5];
	dsu() {
		for (int i = 0; i < NMAX; i++) par[i] = i;
	}
	int find(int x) {
		if (par[x] == x) return x;
		return par[x] = find(par[x]);
	}
	void uni(int x, int y) {
		x = find(x); y = find(y);
		if (x != y) par[x] = y;
	}
} d;
void dfs(int u, int p) {
	child[u] = 1;
	for (auto v : a[u]) {
		if (v == p) continue;
		par[v] = u;
		dfs(v, u);
		child[u] += child[v];
	}
}
void makeTree(int N, int M, int A[], int B[]) {
	for (int i = 0; i < M; i++) {
		if (d.find(A[i]) != d.find(B[i])) {
			d.uni(A[i], B[i]);
			a[A[i]].push_back(B[i]);
			a[B[i]].push_back(A[i]);
		}
	}
	dfs(0, 0);
}
void preMark(int u, int p, int &rem, const int key, int root) {
	if (rem == 0) return;
	mark[lab[u]] = true; rem--;
	for (auto v : a[u]) {
		if (whcc[v] != key || v == p) continue;
		preMark(v, u, rem, key, root);
		if (rem == 0) return;
	}
}
void fullMark(int u, int p, int &it, int key, int root) {
	whcc[u] = key; szcc[key]++;
	while (mark[it] && it < 59)
		it++;
	lab[u] = it; mark[it] = true; it++;
	if (it == 60) return;
	for (auto v : a[u]) {
		if (v == p) continue;
		fullMark(v, u, it, key, root);
		if (it == 60) return;
	}
}
void dfs2(int u, int p) {
	if (lab[u] == -1) {
		memset(mark, 0, sizeof(mark));
		int rem = 60 - min(60, child[u]);
		preMark(par[u], u, rem, whcc[par[u]], u);
		int it = 0;
		fullMark(u, par[u], it, ++numcc, u);
	}
	for (auto v : a[u]) {
		if (v == p) continue;
		dfs2(v, u);
	}
}
// start of Ioi part
long long ret = 0;
void dfs3(int u, int p, const int key, int Z) {
	if (Z) ret ^= (1LL << lab[u]);
	for (auto v : a[u]) {
		if (v == p || whcc[v] != key) continue;
		dfs3(v, u, key, Move(v));
	}
	if (u != p) Move(p);
}
const int INF = 1e9;
void dfs4(int u, int p, int &rem, const int key) {
	whcc[u] = INF; rem--;
	if (rem == 0) return;
	for (auto v : a[u]) {
		if (whcc[v] != key || v == p) continue;
		dfs4(v, u, rem, key);
		if (rem == 0) return;
	}
}
void dfs2x(int u, int Z) {
	if (szcc[whcc[u]] >= 60) {
		dfs3(u, u, whcc[u], Z);
		return;
	}
	int ori = u;
	while (u != 0 && szcc[whcc[par[u]]] < 60) {
		u = par[u];
	}
	int rem = 60 - min(60, child[u]);
	dfs4(par[u], u, rem, whcc[par[u]]);
	dfs4(u, par[u], child[u], whcc[u]);
	dfs3(ori, ori, INF, Z);
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
	memset(lab, -1, sizeof(lab));
	makeTree(N, M, A, B);
	dfs2(0, 0);
	dfs2x(P, V);
	return ret;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5696 KB Output is correct
2 Correct 0 ms 5696 KB Output is correct
3 Correct 2 ms 5696 KB Output is correct
4 Correct 0 ms 5696 KB Output is correct
5 Correct 0 ms 5696 KB Output is correct
6 Correct 2 ms 5696 KB Output is correct
7 Correct 1 ms 5696 KB Output is correct
8 Correct 2 ms 5696 KB Output is correct
9 Correct 2 ms 5696 KB Output is correct
10 Correct 1 ms 5696 KB Output is correct
11 Correct 5 ms 5696 KB Output is correct
12 Correct 1 ms 5696 KB Output is correct
13 Correct 2 ms 5696 KB Output is correct
14 Correct 2 ms 5696 KB Output is correct
15 Correct 2 ms 5696 KB Output is correct
16 Correct 2 ms 5696 KB Output is correct
17 Correct 2 ms 5696 KB Output is correct
18 Correct 2 ms 5696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 6488 KB Output is correct
2 Correct 30 ms 6488 KB Output is correct
3 Correct 35 ms 6488 KB Output is correct
4 Correct 22 ms 6488 KB Output is correct
5 Correct 16 ms 6552 KB Output is correct
6 Correct 17 ms 6628 KB Output is correct
7 Correct 22 ms 6648 KB Output is correct
8 Correct 23 ms 6724 KB Output is correct
9 Correct 27 ms 6744 KB Output is correct
10 Correct 16 ms 6616 KB Output is correct
11 Correct 18 ms 6616 KB Output is correct
12 Correct 17 ms 6224 KB Output is correct
13 Correct 18 ms 6224 KB Output is correct
14 Correct 13 ms 6224 KB Output is correct
15 Correct 22 ms 6488 KB Output is correct
16 Correct 20 ms 6488 KB Output is correct
17 Correct 19 ms 6488 KB Output is correct
18 Correct 16 ms 6488 KB Output is correct
19 Correct 17 ms 6488 KB Output is correct
20 Correct 9 ms 6596 KB Output is correct
21 Correct 15 ms 6588 KB Output is correct
22 Correct 22 ms 6292 KB Output is correct
23 Correct 26 ms 6468 KB Output is correct
24 Correct 24 ms 6352 KB Output is correct
25 Correct 24 ms 6420 KB Output is correct
26 Correct 25 ms 6468 KB Output is correct
27 Correct 26 ms 6472 KB Output is correct
28 Correct 34 ms 6504 KB Output is correct
29 Correct 17 ms 6400 KB Output is correct
30 Correct 25 ms 6400 KB Output is correct
31 Correct 1 ms 5696 KB Output is correct
32 Correct 0 ms 5696 KB Output is correct
33 Correct 1 ms 5696 KB Output is correct
34 Correct 2 ms 5696 KB Output is correct
35 Correct 2 ms 5696 KB Output is correct
36 Correct 1 ms 5696 KB Output is correct
37 Correct 0 ms 5696 KB Output is correct
38 Correct 2 ms 5696 KB Output is correct
39 Correct 1 ms 5696 KB Output is correct
40 Correct 1 ms 5696 KB Output is correct
41 Correct 2 ms 5696 KB Output is correct
42 Correct 0 ms 5696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5696 KB Output is correct
2 Correct 1 ms 5696 KB Output is correct
3 Correct 1 ms 5696 KB Output is correct
4 Correct 2 ms 5960 KB Output is correct
5 Correct 2 ms 5960 KB Output is correct
6 Correct 4 ms 5960 KB Output is correct
7 Correct 4 ms 5960 KB Output is correct
8 Correct 2 ms 5960 KB Output is correct
9 Correct 16 ms 7208 KB Output is correct
10 Correct 13 ms 7208 KB Output is correct
11 Correct 8 ms 7208 KB Output is correct
12 Correct 2 ms 5696 KB Output is correct
13 Correct 0 ms 5696 KB Output is correct
14 Correct 1 ms 5696 KB Output is correct
15 Correct 0 ms 5696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 6488 KB Output is correct
2 Correct 24 ms 6488 KB Output is correct
3 Correct 22 ms 6488 KB Output is correct
4 Correct 16 ms 6488 KB Output is correct
5 Correct 13 ms 6868 KB Output is correct
6 Correct 18 ms 6740 KB Output is correct
7 Correct 18 ms 6720 KB Output is correct
8 Correct 24 ms 6496 KB Output is correct
9 Correct 20 ms 6600 KB Output is correct
10 Correct 24 ms 6616 KB Output is correct
11 Correct 26 ms 6616 KB Output is correct
12 Correct 16 ms 6224 KB Output is correct
13 Correct 16 ms 6224 KB Output is correct
14 Correct 20 ms 6224 KB Output is correct
15 Correct 13 ms 6488 KB Output is correct
16 Correct 20 ms 6488 KB Output is correct
17 Correct 20 ms 6488 KB Output is correct
18 Correct 20 ms 6488 KB Output is correct
19 Correct 19 ms 6488 KB Output is correct
20 Correct 12 ms 6600 KB Output is correct
21 Correct 11 ms 6600 KB Output is correct
22 Correct 25 ms 6444 KB Output is correct
23 Correct 23 ms 6384 KB Output is correct
24 Correct 19 ms 6380 KB Output is correct
25 Correct 25 ms 6476 KB Output is correct
26 Correct 24 ms 6452 KB Output is correct
27 Correct 25 ms 6556 KB Output is correct
28 Correct 22 ms 6320 KB Output is correct
29 Correct 24 ms 6380 KB Output is correct
30 Correct 18 ms 6428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 6488 KB Output is correct
2 Correct 24 ms 6488 KB Output is correct
3 Correct 30 ms 6488 KB Output is correct
4 Correct 27 ms 6488 KB Output is correct
5 Correct 19 ms 7012 KB Output is correct
6 Correct 15 ms 6608 KB Output is correct
7 Correct 18 ms 6564 KB Output is correct
8 Correct 22 ms 6744 KB Output is correct
9 Correct 16 ms 6660 KB Output is correct
10 Correct 23 ms 6616 KB Output is correct
11 Correct 22 ms 6616 KB Output is correct
12 Correct 16 ms 6224 KB Output is correct
13 Correct 11 ms 6224 KB Output is correct
14 Correct 13 ms 6224 KB Output is correct
15 Correct 19 ms 6488 KB Output is correct
16 Correct 12 ms 6488 KB Output is correct
17 Correct 19 ms 6488 KB Output is correct
18 Correct 17 ms 6488 KB Output is correct
19 Correct 19 ms 6488 KB Output is correct
20 Correct 9 ms 6596 KB Output is correct
21 Correct 10 ms 6588 KB Output is correct
22 Correct 17 ms 6416 KB Output is correct
23 Correct 19 ms 6360 KB Output is correct
24 Correct 32 ms 6372 KB Output is correct
25 Correct 25 ms 6400 KB Output is correct
26 Correct 18 ms 6300 KB Output is correct
27 Correct 26 ms 6564 KB Output is correct
28 Correct 20 ms 6576 KB Output is correct
29 Correct 22 ms 6516 KB Output is correct
30 Correct 23 ms 6472 KB Output is correct
31 Correct 0 ms 5696 KB Output is correct
32 Correct 0 ms 5696 KB Output is correct
33 Correct 1 ms 5696 KB Output is correct
34 Correct 0 ms 5696 KB Output is correct
35 Correct 0 ms 5696 KB Output is correct
36 Correct 0 ms 5696 KB Output is correct
37 Correct 2 ms 5696 KB Output is correct
38 Correct 0 ms 5696 KB Output is correct
39 Correct 0 ms 5696 KB Output is correct
40 Correct 2 ms 5696 KB Output is correct
41 Correct 0 ms 5696 KB Output is correct
42 Correct 1 ms 5696 KB Output is correct