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 <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 12;
vector<int> g[N],ord;
bool vis[N];
vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v){
vector<int> lab(n);
for(int i = 0;i < n;i++){
lab[i] = i;
vis[i] = 0;
g[i].clear();
}
for(int i = 0;i < n - 1;i++){
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
queue<int> q;
for(int i = 0;i < n;i++){
if((int)g[i].size() == 1){
q.push(i);
vis[i] = 1;
break;
}
}
while(!q.empty()){
int v = q.front();
ord.push_back(v);
q.pop();
for(int to:g[v]){
if(!vis[to]){
vis[to] = 1;
q.push(to);
}
}
}
for(int i = 0;i < (int)ord.size();i++){
lab[ord[i]] = i;
}
return lab;
}
int find_next_station(int s, int t, std::vector<int> c){
if(s < t)return s + 1;
return s - 1;
}
# | 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... |