# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
313984 | dlwocks31 | Connecting Supertrees (IOI20_supertrees) | 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 "stations.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[1000];
int lbl[1000], cnt;
void dfs(int i, int p, int d) {
if(d % 2 == 0)
lbl[i] = cnt++;
for(int a: adj[i]) {
if(a == p) continue;
dfs(a, i, d+1);
}
if(d % 2 == 1)
lbl[i] = cnt++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<int> labels(n);
for(int i=0; i<u.size(); i++) {
//printf("edge = %d, %d\n", u[i], v[i]);
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
dfs(0, -1, 0);
for(int i=0; i<n; i++) {
//printf("label %d = %d\n", i, lbl[i]);
labels[i] = lbl[i];
}
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
if(c[0] > s) { // s is out
reverse(c.begin(), c.end());
}
c.insert(c.begin(), s);
for(int i=1; i<c.size(); i++) {
if(c[i-1] <= t && t <= c[i]) {
return c[i];
}
}
return c.back();
}