| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1310938 | moha1111 | Stations (IOI20_stations) | C++20 | 0 ms | 0 KiB |
#include "bits/stdc++.h"
#include "stations.h"
using namespace std;
int[] label(int n, int k, int[] u, int[] v)
{
vector<int> graph[n + 5];
for(int i = 0 ; i < n - 1 ; i++)
{
graph[u[i]].push_back(v[i]);
graph[v[i]].push_back(u[i]);
}
int la[n] = {};
int cur;
for(int i = 0 ; i < n ; i++)
{
if(graph[i].size() == 1)
{
la[i] = 1 , cur = i;
break;
}
}
for(int i = 2 ; i < n ; i++)
{
int n1 = graph[cur][0];
if(la[n1] == 0)
la[n1] = i , cur = n1;
else
la[graph[cur][1]] = i , cur = la[graph[cur][1]];
}
if(la[graph[cur][0]] == 0)
la[graph[cur][0]] = n;
else
la[graph[cur][1]] = n;
return la;
}
int find_next_station(int s, int t, int[] c)
{
if(s < t)
return c[0];
else
return c[1];
}
