Submission #620557

#TimeUsernameProblemLanguageResultExecution timeMemory
6205578e7Stations (IOI20_stations)C++17
0 / 100
869 ms548 KiB
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r){
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 1000
#define pii pair<int, int>
#define ff first
#define ss second
#include "stations.h"

vector<int> adj[maxn];
int in[maxn], out[maxn];
int tin, tout;
void dfs(int n, int par) {
	in[n] = tin++;
	for (int v:adj[n]) {
		if (v != par) {
			dfs(v, n);
		}
	}
	out[n] = tout++;
}
std::vector<int> label(int n, int LIM, std::vector<int> U, std::vector<int> V) {
	vector<int> ret(n);
	for (int i = 0;i < n;i++) {
		adj[i].clear();
		in[i] = 0, out[i] = 0;
	}
	tin = tout = 0;

	for (int i = 0;i < n - 1;i++) {
		adj[U[i]].push_back(V[i]);
		adj[V[i]].push_back(U[i]);
	}
	int root = 0;
	for (int i = 0;i < n;i++) {
		if (adj[i].size() > 2) {
			root = i;
			break;
		}
	}
	dfs(root, -1);
	for (int i = 0; i < n; i++) {
		ret[i] = in[i] * maxn + out[i];
	}
	return ret;
}

int find_next_station(int s, int t, std::vector<int> c) {
	int is = s / maxn, os = s % maxn, it = t / maxn, ot = t%maxn;
	if (is <= it && ot <= os) { //subtree
		for (int v:c) {
			int iv = v/maxn, ov = v%maxn;
			if (iv <= it && ot <= ov) return v;
		}
	} else {
		for (int v:c) {
			if (v/maxn < is) return v;
		}
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...