# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
475202 | AdamGS | 기지국 (IOI20_stations) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}