# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
434453 | arayi | Stations (IOI20_stations) | C++17 | 1051 ms | 784 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 "stations.h"
#include <iostream>
#include <algorithm>
#include <vector>
#define ad push_back
using namespace std;
const int N = 1010;
int n;
vector<int> g[N], l;
vector<pair<int, int> > a;
int xr[N], ti;
void dfs(int v, int par)
{
ti++;
if(xr[v]%2==0) a.ad({ti,v});
for(auto p : g[v])
{
if(p==par) continue;
xr[p]=1+xr[v];
dfs(p,v);
}
ti++;
if(xr[v]%2==1) a.ad({ti, v});
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
::n=n;
l.clear(), a.clear();
for (int i = 0; i < n; i++) g[i].clear(),xr[i]=0;
ti=0;
l.resize(n);
for (int i = 0; i < n - 1; i++) {
g[u[i]].ad(v[i]);
g[v[i]].ad(u[i]);
}
dfs(0, 0);
sort(a.begin(), a.end());
for (int i = 0; i < a.size(); i++) l[a[i].second] = i;
return l;
}
int find_next_station(int s, int t, std::vector<int> c)
{
if(c.size() == 1) return c[0];
sort(c.begin(), c.end());
if(s < c[0])
{
int nx = s;
for(auto p : c)
{
if(t > nx && t <= p) return p;
nx = p;
}
return c.back();
}
else
{
int nx = c[1];
for (int i = 2; i < c.size(); i++)
{
if(t >= nx && t < c[i]) return nx;
nx = c[i];
}
if(t >= nx && t < s) return nx;
return c[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... |