# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1018090 | Boas | Stations (IOI20_stations) | C++17 | 627 ms | 1280 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;
#include "stations.h"
#define loop(x, i) for (int i = 0; i < x; i++)
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef set<int> si;
typedef vector<vi> vvi;
vvi adj;
vi nrs;
vi nrMx;
int curNr = 0;
void DFS(int i, int prev = -1)
{
nrs[i] = curNr;
curNr++;
for (int j : adj[i])
{
if (prev == j)
continue;
DFS(j, i);
}
nrMx[i] = curNr - 1;
}
vi label(int n, int k, vi u, vi v)
{
curNr = 0;
nrs = vi(n);
nrMx = vi(n);
adj = vvi(n);
loop(u.size(), i)
{
adj[u[i]].pb(v[i]);
adj[v[i]].pb(u[i]);
}
int start = 0;
loop(n, i)
{
if (adj[i].size() == 1)
{
start = i;
break;
}
}
DFS(start);
vi labels(n);
for (int i = 0; i < n; i++)
{
labels[i] = 1000 * nrs[i] + nrMx[i];
}
return labels;
}
int find_next_station(int s, int t, vi c)
{
int nrMax = s % 1000;
int nr = s / 1000;
int nrGoal = t / 1000;
if (nrGoal > nrMax || nrGoal < nr)
{
// smallest number, so to the root
return c[0];
}
for (int l : c)
{
int nrC = l / 1000;
if (nrC < nr)
continue;
int nrCMax = l % 1000;
if (nrGoal <= nrCMax && nrGoal >= nrC)
return l;
}
// throw;
return 0;
}
Compilation message (stderr)
# | 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... |