Submission #207340

# Submission time Handle Problem Language Result Execution time Memory
207340 2020-03-07T08:51:47 Z nvmdava Amusement Park (JOI17_amusement_park) C++17
0 / 100
3000 ms 3880 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 p[10005];
void dfs(int v, int p){
	mxd[v] = v;
	::p[v] = p;
	for(auto& x : adj[v]){
		if(x == p) continue;
		d[x] = d[v] + 1;
		dfs(x, v);
		if(d[mxd[v]] < d[mxd[x]]){
			mxd[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){
			dfs(i, -1);
			break;
		}
	}

	while(d[P] < 59){
		P = mxd[P];
		V = move(P);
	}
	while(d[P] % 60 != 59){
		P = p[P];
		V = move(P);
	}
	long long X = 0;
	for(int i = 59; i >= 0; --i){
		X |= V * (1LL << i);
		if(i){
			P = p[P];
			V = move(P);
		}
	}
	return X;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 3045 ms 1532 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3047 ms 3880 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 1520 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3009 ms 3860 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 3868 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -