Submission #207351

# Submission time Handle Problem Language Result Execution time Memory
207351 2020-03-07T09:09:39 Z nvmdava Amusement Park (JOI17_amusement_park) C++17
0 / 100
3000 ms 3676 KB
#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;

int dsu[10005];
vector<int> adj[10005];
int get(int v){
	return v == dsu[v] ? v : dsu[v] = get(dsu[v]);
}

void merge(int v, int u){
	int _v = get(v);
	int _u = get(u);
	if(_v == _u) return;
	adj[v].push_back(u);
	adj[u].push_back(v);
	dsu[_v] = _u;
}

int d[10005];
long long X;
void dfs(int v, int p){
	MessageBoard(v, (X & (1LL << d[v])) != 0);
	for(auto& x : adj[v]){
		if(x == p) continue;
		d[x] = (d[v] + 1) % 60;
		dfs(x, v);
	}
}

void Joi(int N, int M, int A[], int B[], long long X, int T) {
	::X = X;
	for(int i = 0; i < N; ++i)
		dsu[i] = i;
	for(int i = 0; i < M; ++i)
		merge(A[i], B[i]);

	for(int i = 0; i < N; ++i){
		if(adj[i].size() == 1){
			dfs(i, -1);
			return;
		}
	}
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;

int dsu[10005];
vector<int> adj[10005];
int get(int v){
	return v == dsu[v] ? v : dsu[v] = get(dsu[v]);
}

void merge(int v, int u){
	int _v = get(v);
	int _u = get(u);
	if(_v == _u) return;
	adj[v].push_back(u);
	adj[u].push_back(v);
	dsu[_v] = _u;
}

int d[10005];
int mxd[10005];
int go[10005];
int p[10005];

void dfs(int v, int p){
	mxd[v] = d[v];
	go[v] = -1;
	::p[v] = p;
	for(auto& x : adj[v]){
		if(x == p) continue;
		d[x] = d[v] + 1;
		dfs(x, v);
		if(mxd[v] < mxd[x]){
			mxd[v] = mxd[x];
			go[v] = x;
		}
	}
}


long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
	for(int i = 0; i < N; ++i)
		dsu[i] = i;
	for(int i = 0; i < M; ++i)
		merge(A[i], B[i]);

	for(int i = 0; i < N; ++i){
		if(adj[i].size() == 1){
			p[i] = -1;
			dfs(i, -1);
			break;
		}
	}

	while(d[P] < 59){
		P = go[P];
		if(P == -1) for(;;)
		V = move(P);
	}
	while(d[P] % 60 != 59){
		P = p[P];
		if(P == -1) for(;;)
		V = move(P);
	}
	long long X = 0;
	for(int i = 59; i >= 0; --i){
		X |= V * (1LL << i);
		if(i){
			P = p[P];
			if(P == -1) for(;;)
			V = move(P);
		}
	}
	return X;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 3029 ms 1520 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 3676 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 1396 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3097 ms 3540 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 3620 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -