This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//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 > is && iv <= it && ot <= ov) return v;
}
} else {
for (int v:c) {
if (v/maxn < is) return v;
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |