Submission #27024

# Submission time Handle Problem Language Result Execution time Memory
27024 2017-07-08T22:17:20 Z ulna Amusement Park (JOI17_amusement_park) C++14
0 / 100
89 ms 262144 KB
#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;

static vector<int> g[10055];
static int res[10055];

static int dfn[10055];
static int t;

static int dp[10055];

void dfs(int v, int par = -1) {
	dfn[v] = t++;
	dp[v] = 1;

	for (auto u : g[v]) if (u != par) {
		dfs(u, v);
		dp[v] = max(dp[v], dp[u] + 1);
	}
}
void rdfs(int v, int par, long long X, int d = 0) {
	if (X & (1ll << (d % 60))) {
		res[v] = 1;
	}

	for (auto u : g[v]) if (u != par) {
		rdfs(u, v, X, d + 1);
	}
}
void init1() {
	for (int i = 0; i < 10000; i++) {
		g[i].clear();
		res[i] = 0;
		dfn[i] = 0;
		t = 0;
		dp[i] = 0;
	}
}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
	init1();
	for (int i = 0; i < M; i++) {
		g[A[i]].push_back(B[i]);
		g[B[i]].push_back(A[i]);
	}

	dfs(0);

	if (dp[0] >= 60) {
		rdfs(0, -1, X);
	} else {
		vector<int> vec(N);

		for (int i = 0; i < N; i++) {
			vec[i] = i;
		}

		sort(vec.begin(), vec.end(), [&] (int u, int v) {
			return dfn[u] < dfn[v];
		});
		
		for (int i = 0; i < N; i++) {
			if (X & (1ll << (i % 60))) {
				res[i] = 1;
			}
		}
	}

	for (int i = 0; i < N; i++) {
		MessageBoard(i, res[i]);
	}
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;

static int dp[10055];
static vector<int> g[10055];

static int dfn[10055];
static int t;

static int depth[10055];
static bool used[10055];

static int par[10055];

void dfs(int v, int par = -1, int d = 0) {
	depth[v] = d;
	dfn[v] = t++;

	::par[v] = par;

	dp[v] = 1;

	for (auto u : g[v]) if (u != par) {
		dfs(u, v, d + 1);
		dp[v] = max(dp[v], dp[u] + 1);
	}
}
void gao(int v, long long &res, int d = 1) {
	if (d == 60) return;

	if (Move(v)) {
		res |= (1ll << d);
	}

	for (auto u : g[v]) if (depth[u] == d + 1 && dp[u] + d + 1 >= 60) {
		gao(u, res, d + 1);
		break;
	}
}

static bool vis[10055];

void init() {
	for (int i = 0; i < 10000; i++) {
		used[i] = false;
		depth[i] = 0;
		t = 0;
		dfn[i] = 0;
		g[i].clear();
		dp[i] = 0;
	}
}
inline bool check() {
	for (int i = 0; i < 60; i++) if (!used[i]) return false;
	return true;
}
inline void rdfs(int v, long long &res) {
	if (check()) return;

	used[dfn[v] % 60] = true;

	if (Move(v)) {
		res |= (1ll << (dfn[v] % 60));
	}

	if (check()) return;

	for (auto u : g[v]) if (!vis[u]) {
		rdfs(u, res);
		Move(v);
	}
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
	init();
	swap(P, V);
	for (int i = 0; i < M; i++) {
		g[A[i]].push_back(B[i]);
		g[B[i]].push_back(A[i]);
	}

	long long res = 0ll;

	dfs(0);

	if (dp[0] >= 60) {
		int cur = V;
		int last = P;

		while (depth[cur] % 60 != 0) {
			cur = par[cur];
			last = Move(cur);
		}

		if (last) res |= 1;

		for (auto u : g[cur]) if (depth[u] > depth[cur] && dp[u] + 1 >= 60) {
			gao(u, res);
			break;
		}
	} else {
		int v = V;
		used[dfn[v] % 60] = true;

		if (P) res |= (1ll << (dfn[v] % 60));

		vector<int> vec(N);

		for (int i = 0; i < N; i++) vec[i] = i;

		sort(vec.begin(), vec.end(), [&] (int u, int v) {
			return dfn[u] < dfn[v];
		});

		for (int u = v; !check(); u = par[u]) {
			vis[u] = true;

			for (auto w : g[u]) if (!vis[w]) {
				rdfs(w, res);
				if (check()) {
					break;
				}

				Move(u);
			}

			if (check()) break;

			if (Move(par[u])) {
				res |= (1ll << (dfn[par[u]] % 60));
			}

			used[dfn[par[u]] % 60] = true;
		}
	}

  return res;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 6032 KB Wrong Answer [8]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Memory limit exceeded 33 ms 262144 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5528 KB Output is correct
2 Correct 0 ms 5528 KB Output is correct
3 Incorrect 0 ms 5528 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Memory limit exceeded 56 ms 262144 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Memory limit exceeded 89 ms 262144 KB Memory limit exceeded
2 Halted 0 ms 0 KB -