Submission #86591

# Submission time Handle Problem Language Result Execution time Memory
86591 2018-11-26T20:22:56 Z KCSC Amusement Park (JOI17_amusement_park) C++14
0 / 100
33 ms 6600 KB
#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 10000;

int szt[MAXN], psb[MAXN], psl[MAXN], inc[MAXN], fth[MAXN];

bitset<MAXN> oki;
vector<int> ied[MAXN], edg[MAXN], lin[MAXN];
/*
#ifdef HOME
int mess[MAXN], _tot, _cr;
set<int> mst;

void MessageBoard(int x, int v) {
	assert(mst.find(x) == mst.end());
	mess[x] = v; mst.insert(x); }

int Move(int x) {
	assert(_cr == fth[x] or find(edg[x].begin(), edg[x].end(), _cr) != edg[x].end()); 
	_cr = x; ++_tot; assert(_tot <= 120);
	return mess[x]; }
#endif
*/
void MessageBoard(int x, int v);

void dfsJoi1(int x) {
	oki[x] = true; szt[x] = 1;
	sort(ied[x].begin(), ied[x].end());
	for (int y : ied[x]) { if (!oki[y]) { 
		fth[y] = x; dfsJoi1(y); 
		edg[x].push_back(y); szt[x] += szt[y]; } } }

void dfsJoi3(int x, int c) {
	psl[x] = lin[c].size(); lin[c].push_back(x);
	for (int y : edg[x]) {
		if (inc[y] == c) {
			dfsJoi3(y, c); lin[c].push_back(x); } } }

int tot;
void dfsJoi2(int x, long long v) {
	if (szt[x] >= 60 and inc[x] == -1) {	
		vector<int> que(1, x); ++tot;
		for (int i = 0; i < 60; ++i) {
			int cr = que[i]; inc[cr] = tot; 
			psb[cr] = i; 
			if (v > 0) {
				MessageBoard(cr, (v >> psb[cr]) & 1); }
			for (int nx : edg[cr]) { 
				if (que.size() < 60) { 
					que.push_back(nx); } } } 
		dfsJoi3(x, tot); }
	else if (szt[x] < 60 and inc[x] == -1) {
		int nr = 0, ax = x;	
		while (inc[ax] == -1) {
			++nr; ax = fth[ax]; }
		int ps = ((120 - nr) + psl[ax]) % lin[inc[ax]].size(); 
		psb[x] = psb[lin[inc[ax]][ps]];
		if (v > 0) {
			MessageBoard(x, (v >> psb[x]) & 1); } 
	} 
	for (int y : edg[x]) {
		dfsJoi2(y, v); } }

void Precalculate(int n, int m, int ls1[], int ls2[], long long x) {
	oki.reset(); tot = -1;
	for (int i = 0; i < n; ++i) {
		lin[i].clear(); edg[i].clear(); ied[i].clear();
		psb[i] = inc[i] = fth[i] = psl[i] = szt[i] = -1; }
	for (int i = 0; i < m; ++i) {
		int x = ls1[i], y = ls2[i];
		ied[x].push_back(y); ied[y].push_back(x); }
	dfsJoi1(0); dfsJoi2(0, x); }

void Joi(int n, int m, int ls1[], int ls2[], long long x, int t) {
	Precalculate(n, m, ls1, ls2, x); }
/*
int Move(int x);

long long Ioi(int n, int m, int ls1[], int ls2[], int p, int v, int t) {
	Precalculate(n, m, ls1, ls2, -1); long long x = ((1LL * v) << psb[p]); int nr = 0;
	while (inc[p] == -1) {
		p = fth[p]; 
		if (inc[p] == -1) {
			x |= (Move(p) << psb[p]); ++nr; } }
	for (int i = psl[p]; nr != 120; i = (i + 1) % lin[inc[p]].size(), ++nr) {
		int cr = lin[inc[p]][i]; x |= ((1LL * Move(cr)) << psb[cr]); }
	return x; }

#ifdef HOME
int main(void) {
	freopen("amusement.in", "r", stdin);
	freopen("amusement.out", "w", stdout); 
	int n, m, p, t; long long x; cin >> n >> m >> x >> p >> t;
	int *ls1 = new int[m], *ls2 = new int[m];
	for (int i = 0; i < m; ++i) {
		cin >> ls1[i] >> ls2[i]; }
	Joi(n, m, ls1, ls2, x, t); _cr = p;
	cout << (Ioi(n, m, ls1, ls2, p, mess[p], t) == x ? "Yes\n" : "No\n");
	assert(mst.size() == n);
	return 0; }
#endif
*/
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 10000;

int szt[MAXN], psb[MAXN], psl[MAXN], inc[MAXN], fth[MAXN];

bitset<MAXN> oki;
vector<int> ied[MAXN], edg[MAXN], lin[MAXN];
/*
#ifdef HOME
int mess[MAXN], _tot, _cr;
set<int> mst;

void MessageBoard(int x, int v) {
	assert(mst.find(x) == mst.end());
	mess[x] = v; mst.insert(x); }

int Move(int x) {
	assert(_cr == fth[x] or find(edg[x].begin(), edg[x].end(), _cr) != edg[x].end()); 
	_cr = x; ++_tot; assert(_tot <= 120);
	return mess[x]; }
#endif

void MessageBoard(int x, int v);
*/
void dfsJoi1(int x) {
	oki[x] = true; szt[x] = 1;
	sort(ied[x].begin(), ied[x].end());
	for (int y : ied[x]) { if (!oki[y]) { 
		fth[y] = x; dfsJoi1(y); 
		edg[x].push_back(y); szt[x] += szt[y]; } } }

void dfsJoi3(int x, int c) {
	psl[x] = lin[c].size(); lin[c].push_back(x);
	for (int y : edg[x]) {
		if (inc[y] == c) {
			dfsJoi3(y, c); lin[c].push_back(x); } } }

int tot;
void dfsJoi2(int x, long long v) {
	if (szt[x] >= 60 and inc[x] == -1) {	
		vector<int> que(1, x); ++tot;
		for (int i = 0; i < 60; ++i) {
			int cr = que[i]; inc[cr] = tot; 
			psb[cr] = i; 
		//	if (v > 0) {
		//		MessageBoard(cr, (v >> psb[cr]) & 1); }
			for (int nx : edg[cr]) { 
				if (que.size() < 60) { 
					que.push_back(nx); } } } 
		dfsJoi3(x, tot); }
	else if (szt[x] < 60 and inc[x] == -1) {
		int nr = 0, ax = x;	
		while (inc[ax] == -1) {
			++nr; ax = fth[ax]; }
		int ps = ((120 - nr) + psl[ax]) % lin[inc[ax]].size(); 
		psb[x] = psb[lin[inc[ax]][ps]];
	//	if (v > 0) {
	//		MessageBoard(x, (v >> psb[x]) & 1); } 
	} 
	for (int y : edg[x]) {
		dfsJoi2(y, v); } }

void Precalculate(int n, int m, int ls1[], int ls2[], long long x) {
	oki.reset(); tot = -1;
	for (int i = 0; i < n; ++i) {
		lin[i].clear(); edg[i].clear(); ied[i].clear();
		psb[i] = inc[i] = fth[i] = psl[i] = szt[i] = -1; }
	for (int i = 0; i < m; ++i) {
		int x = ls1[i], y = ls2[i];
		ied[x].push_back(y); ied[y].push_back(x); }
	dfsJoi1(0); dfsJoi2(0, x); }
/*
void Joi(int n, int m, int ls1[], int ls2[], long long x, int t) {
	Precalculate(n, m, ls1, ls2, x); }
*/	
int Move(int x);

long long Ioi(int n, int m, int ls1[], int ls2[], int p, int v, int t) {
	Precalculate(n, m, ls1, ls2, -1); long long x = ((1LL * v) << psb[p]); int nr = 0;
	while (inc[p] == -1) {
		p = fth[p]; 
		if (inc[p] == -1) {
			x |= (Move(p) << psb[p]); ++nr; } }
	for (int i = psl[p]; nr != 120; i = (i + 1) % lin[inc[p]].size(), ++nr) {
		int cr = lin[inc[p]][i]; x |= ((1LL * Move(cr)) << psb[cr]); }
	return x; }
/*
#ifdef HOME
int main(void) {
	freopen("amusement.in", "r", stdin);
	freopen("amusement.out", "w", stdout); 
	int n, m, p, t; long long x; cin >> n >> m >> x >> p >> t;
	int *ls1 = new int[m], *ls2 = new int[m];
	for (int i = 0; i < m; ++i) {
		cin >> ls1[i] >> ls2[i]; }
	Joi(n, m, ls1, ls2, x, t); _cr = p;
	cout << (Ioi(n, m, ls1, ls2, p, mess[p], t) == x ? "Yes\n" : "No\n");
	assert(mst.size() == n);
	return 0; }
#endif
*/
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2160 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 6468 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2160 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 6600 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 6596 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -