#include <bits/stdc++.h>
using namespace std;
int counter;
vector<int>tree[1005];
vector<int>labels;
void dfs(int cur,int par){
labels[cur] = ++counter;
for(int nxt : tree[cur]){
if(nxt == par) continue;
dfs(nxt,cur);
}
labels[cur] += 1000*counter;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
labels = vector<int>(n,-1);
counter = -1;
for(int i=0; i<n; i++) tree[i].clear();
for(int i=0; i<u.size(); i++){
int a = u[i],b = v[i];
tree[a].emplace_back(b);
tree[b].emplace_back(a);
}
dfs(0,-1);
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
int l = s%1000,r = s/1000;
int a = t%1000,b = t/1000;
t = -1;
if(l <= a && b <= r){
for(int nxt : c){
int x = nxt%1000,y = nxt/1000;
if(x <= a && b <= y){
t = nxt;
break;
}
}
}
else{
//go to parent
for(int nxt : c){
int x = nxt%1000,y = nxt/1000;
if(l <= x && y <= r) continue;
t = nxt;
break;
}
}
assert(t != -1);
return t;
}
# | 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... |