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>graf[1010];
int pre[1010], it=-1, post[1010];
int dep[1010];
int czyost[1010];
void dfs(int x, int o){
dep[x] = dep[o]+1;
pre[x] = ++it;
if(graf[x].size())
czyost[graf[x].back()] = 1;
for(auto j: graf[x])
if(j!=o)
dfs(j, x);
//if(czyost[x])
it++;
post[x] = it;
}
vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
int i;
dep[0] = 0;
for(i=0;i<n;i++)graf[i].clear();
for(i=0;i<n;i++)czyost[i] = 0;
for(i=0;i<n-1;i++){
graf[u[i]].push_back(v[i]);
graf[v[i]].push_back(u[i]);
}
it= -1;
dfs(0, 0);
std::vector<int> labels(n);
for (int i = 0; i < n; i++) {
if(dep[i]%2==1)
labels[i] = pre[i]/2;
else labels[i] = post[i]/2;
}
// for(i=0;i<n;i++)printf("%d: %d %d %d %d\n", i, dep[i], pre[i], post[i], labels[i]);
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(c.size()==1)return c[0];
int maxi=0;
for(auto j: c)
maxi = max(maxi, j);
if(s>=maxi){
// printf(" %d\n", s);
sort(c.begin(), c.end());
if(t>s)return c[0];
if(t<c[1])return c[0];
for(int i=1;i<(int)c.size();i++)
if(i==(int)c.size()-1 || c[i+1]>t)return c[i];
}
sort(c.begin(), c.end());
if(t<s){
return c.back();
}
if(s==0){
int pom = *lower_bound(c.begin(), c.end(), t);
return pom;
}
if(t>c[(int)c.size()-1])return c.back();
int pom = *lower_bound(c.begin(), c.end(), t);
return pom;
}
# | 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... |