이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "stations.h"
using namespace std;
const int N = 1505;
int n;
vector<int> adj[N] , R;
int tin[N] , tout[N] , dtime;
void dfs(int u , int p = -1){
R[u] =tin[u] = dtime++;
for(int v : adj[u]){
if(v==p)continue;
dfs(v ,u);
}
tout[u]= dtime;
}
vector<int> label(int n , int k ,vector<int> u , vector<int> v){
for(int i = 0; i < n; ++i) adj[i].clear();
for(int i = 0; i < n; ++i) adj[u[i]].emplace_back(v[i]) , adj[v[i]].emplace_back(u[i]);
R.resize(n);
dfs(0);
return R;
}
bool cmp(int a, int b){
return tin[a] > tin[b];
}
int find_next_station(int s , int t , vector<int> c){
sort(c.begin() , c.end() , cmp);
for(int u : c){
if(tin[u] <= tin[t] && tout[t] <= tout[u]) return u;
}
if(tin[s] <= tin[t] && tout[t] <= tout[s]) return s;
return c[c.size()-1];
}
/*
int main (){
cin >> n;
for(int i =1; i < n; ++i){
int u , v; cin >> u>> v;
adj[u].emplace_back(v); adj[v].emplace_back(u);
}
vector<int> k = label(n , 1 , {3} , {3});
cout << find_next_station(1 , 3 , {3 , 2 ,0}) << endl;
}
*/
# | 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... |