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;
vector<int> g[1005];int l[1005];int z[1005];
int w(int n,int a){
int c=1;
for(auto i:g[n])if(i!=a)c+=w(i,n);
z[n]=c;return c;
}
void d(int n,int a,int e,bool p){
if(p)l[n]=a+z[n];
else l[n]=a-z[n];
int f=l[n];//cerr<<n<<' '<<f<<endl;
for(auto i:g[n])if(i!=e){d(i,f,n,!p);f=l[i];}
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
for(int i=0;i<n-1;i++){g[u[i]].push_back(v[i]);g[v[i]].push_back(u[i]);}
w(0,n);d(0,n,n,0);vector<int> r;
for(int i=0;i<n;i++){r.push_back(l[i]);g[i].clear();}
return r;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(s<c[0]){
if(t<s||t>=c.back())return c.back();
for(auto i:c)if(t<=i)return i;
}
else{
reverse(c.begin(),c.end());
if(t>s||t<=c.back())return c.back();
for(auto i:c)if(t>=i)return i;
}
exit(1);
}
# | 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... |