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;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
#define pb push_back
#define popb pop_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
const int nax = 1001;
vi rep;
int cureul = -1;
vi adj[nax];
int in[nax], out[nax];
void dfs(int x, int d = 0, int p = -1)
{
in[x] = ++cureul;
for(auto e: adj[x])
if(e != p)
dfs(e, d + 1, x);
out[x] = cureul;
if(d & 1)
rep[x] = out[x];
else
rep[x] = in[x];
}
vi label(int n, int k, vi u, vi v)
{
for(int i = 0 ; i < n; i++)
adj[i].clear();
cureul = -1;
rep.assign(n , 0);
for(int i= 0; i < n - 1; i ++)
{
adj[u[i]].pb(v[i]);
adj[v[i]].pb(u[i]);
}
dfs(0);
vpi vec;
for(int i= 0; i < n; i++)
vec.pb({rep[i], i});
sort(all(vec));
for(int i= 0 ; i < n; i ++)
rep[vec[i].ss] = i;
return rep;
}
int find_next_station(int s, int t, vi c)
{
sort(all(c));
int ini, outi;
int sz = c.size();
bool flag= true;
if(s < c[0])
{
ini = s;
if(ini == 0)
{
outi = 1000;
}
else if(sz == 1)
outi = ini;
else
outi = c[sz - 2];
}
else
{
flag = false;
outi = s;
if(sz == 1)
ini = outi;
else
ini = c[1] - 1;
}
if(t >= ini && t <= outi)
{
for(auto e: c)
{
if(flag)
{
for(auto e: c)
if(e >= t)
return e;
}
else
{
reverse(all(c));
for(auto e: c)
if(t >= e)
return e;
}
}
}
else
{
if(flag)
{
return c[sz - 1];
}
else
return c[0];
}
return c[0];
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, vi)':
stations.cpp:88:22: warning: unused variable 'e' [-Wunused-variable]
88 | for(auto e: c)
| ^
# | 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... |