# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1034087 | Boas | Stations (IOI20_stations) | C++17 | 572 ms | 940 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 d;
vi nrMx;
int curNr = 0;
void DFS(int i, int prev = -1, int de = 0)
{
nrs[i] = curNr;
curNr++;
d[i] = de;
for (int j : adj[i])
{
if (prev == j)
continue;
DFS(j, i, de + 1);
}
nrMx[i] = curNr;
curNr++;
}
vi label(int n, int k, vi u, vi v)
{
assert(k >= n);
curNr = 0;
nrs = vi(n);
nrMx = vi(n);
d = vi(n);
adj = vvi(n);
loop(u.size(), i)
{
adj[u[i]].pb(v[i]);
adj[v[i]].pb(u[i]);
}
DFS(0);
vi labels(n);
for (int i = 0; i < n; i++)
{
if (d[i] % 2 == 0)
labels[i] = nrs[i];
else
labels[i] = nrMx[i];
}
return labels;
}
int find_next_station(int s, int t, vi c)
{
if (c.size() == 1)
return c[0];
if (s > c[0])
{
int nrMax = s;
int nrGoal = t;
if (nrGoal > nrMax || nrGoal < c[1])
{
// smallest number, so to the root
return c[0];
}
c.pb(s);
for (int i = 1; i < c.size() - 1; i++)
{
int l = c[i];
if (nrGoal < c[i + 1] && nrGoal >= l)
return l;
}
}
else if (s == 0)
{
c.pb(0);
for (int i = 1; i < c.size(); i++)
{
int l = c[i];
if (t <= l && t > c[i - 1])
return l;
}
}
else // s < c[0]
{
int nr = s;
int nrGoal = t;
if (nrGoal > c[c.size() - 2] || nrGoal < nr)
{
// to the root
return c.back();
}
c.insert(c.begin(), s);
for (int i = 1; i < c.size(); i++)
{
int l = c[i];
if (t <= l && t > c[i - 1])
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... |