# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
979306 | Zicrus | 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>
#include "stations.h"
using namespace std;
vector<int> lbl;
vector<vector<int>> adj;
void DFS(int index, int last, int id)
{
lbl[index] = id;
for (auto node : adj[index])
{
if (node == last) continue;
DFS(node, index, id + 1);
}
}
vector<int> label(int N, int K, vector<int> U, vector<int> V)
{
adj = vector<vector<int>>(n);
lbl = vector<int>(n);
for (int i = 0; i < N - 1; i++)
{
adj[U[i]].push_back(V[i]);
adj[V[i]].push_back(U[i]);
}
for (int i = 0; i < N; i++)
{
if (adj[i].size() == 1)
{
DFS(i, -1, 0);
break;
}
}
return lbl;
}
int find_next_station(int S, int T, vector<int> C)
{
if (T > S)
{
return S + 1;
}
return S - 1;
}