# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
309828 | emaborevkovic | Stations (IOI20_stations) | C++14 | 3048 ms | 2097156 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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define pb push_back
const int N = 1005;
vector <int> ls[N];
vector <int> res;
int depth[N], podstablo[N];
int dfs (int x, int d, int p) {
int suma = 0;
depth[x] = d;
for (int i=0;i<ls[x].size();i++) {
if (ls[x][i] == p) continue;
suma += dfs(ls[x][i], d+1, x);
}
return podstablo[x] = suma+1;
}
void oznaci (int x, int l, int r, int p) {
if (depth[x] % 2 == 0) {
res[x] = l;
l++;
}
else {
res[x] = r;
r--;
}
for (int i=0;i<ls[x].size();i++) {
if (ls[x][i] == p) continue;
oznaci(ls[x][i], l, l+podstablo[ls[x][i]]-1, x);
l += podstablo[ls[x][i]];
}
}
vector <int> label (int n, int k, vector <int> u, vector <int> v) {
res.resize(n);
for (int i=0;i<n-1;i++) {
ls[u[i]].pb(v[i]);
ls[v[i]].pb(u[i]);
}
dfs (0, 0, 0);
oznaci(0, 0, n-1, 0);
return res;
}
int find_next_station(int s, int t, vector <int> c) {
int n = c.size();
if (s == 0) {
for (int i=0;i<n;i++) {
if (c[i] >= t) return c[i];
}
}
if (n == 1) return c[0];
if (s < c[0]) {
if (t < s || t > c[n-2]) return c[n-1];
for (int i=0;i<n-1;i++) {
if (c[i] >= t) return c[i];
}
}
if (t < c[1] || t > s) return c[0];
for (int i=n-1;i>0;i--) {
if (t >= c[i]) return c[i];
}
}
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... |