# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
475202 | AdamGS | Stations (IOI20_stations) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "stations.h"
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=1e3+7;
int pre[LIM], post[LIM], lpre, lpost;
vector<int>label(int n, int k, vector<int>u, vector<int>v) {
vector<int>ans(n), V[n];
rep(i, n-1) {
V[u[i]].pb(v[i]);
V[v[i]].pb(u[i]);
}
queue<int>q;
q.push(0);
while(!q.empty()) {
int p=q.top();
if(pre[p]) {
++lpost;
post[p]=lpost;
q.pop();
continue;
}
++lpre;
pre[p]=lpre;
for(auto i : V[p]) if(!pre[i]) q.push(i);
}
rep(i, n) ans[i]=i;
return ans;
}
int find_next_station(int s, int t, vector<int>c) {
int ojciec=-1;
for(auto i : c) if(pre[i]<pre[s]) ojciec=i;
for(auto i : c) if(i!=ojciec && pre[i]<=pre[t] && post[i]>=post[t]) return i;
return ojciec;
}