# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
777058 | Trisanu_Das | Stations (IOI20_stations) | C++17 | 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 <bits/stdc++.h>
using namespace std;
vector<int> adj[1000], U, V, labelling;
int N, K, curr_tag;
void dfs(int u, int p){
if(p == -1 || !labelling[p]) labelling[u] = ++curr_tag;
for(int v : adj[u]) if(v != p) dfs(v, u);
if(!labelling[u]) labelling[u] = ++curr_tag;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v){
N = n; K = k;
U = u, V = v;
for(int i = 0; i < n; i++) adj[i].clear();
memset(labelling, 0, sizeof(labelling));
labelling.clear();
labelling.resize(n, 0);
curr_tag = 0;
for(int i = 0; i < n - 1; i++){
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
dfs(0, -1);
return labelling;
}
int find_next_station(int s, int t, vector<int> c){
if(c.back() < s) reverse(c.begin(), c.end());
for(int x : c) if(min(s, x) <= t && t <= max(s, x)) return x;
return c.back();
}