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 <bits/stdc++.h>
using namespace std;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define RE(a,b) REP(a,0,b)
#define FOR(a,b) for(auto& a:b)
#define pb push_back
#define fi first
#define se second
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int INF=1e9;
const int MX=5e5;
int M;
vi adj[MX];
vi lab;
void dfs(int u, int p=-1, bool pre=1) {
if( pre) lab[u] = M++;
FOR(v,adj[u]) if(v!=p) dfs(v,u,!pre);
if(!pre) lab[u] = M++;
}
vi label(int n, int k, vi U, vi V) {
lab.assign(n,0);
RE(i,n) adj[i].clear();
RE(i,n-1) {
adj[U[i]].pb(V[i]);
adj[V[i]].pb(U[i]);
}
M=0;
dfs(0);
return lab;
}
int find_next_station(int s, int t, vi c) {
if(c.size() == 1) return c[0];
if(s < c[0]) {
// s is pre
if(s == 0) {
// s is root
FOR(i,c) if(i >= t) return i;
} else {
int par = c.back();
if(t < s) return par;
FOR(i,c) if(i != par && i >= t) return i;
return par;
}
} else {
// s is post
int par = c[0];
if(t > s) return par;
REV(i,0,c.size()) if(c[i] != par && c[i] <= t) return c[i];
return par;
}
return 0;
}
# | 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... |