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 ll long long
#define pb push_back
#define pi pair<int,int>
vector<int> labels;
vector<vector<int>> graph;
vector<pi> ord;
int cnt = 0;
void dfs1(int n,int p){//calc sizes
ord[n].first = cnt++;
for(int adj : graph[n])
{
if(adj == p) continue;
dfs1(adj, n);
}
ord[n].second = cnt++;
}
void name_subtree(int n, int p, bool first){
if(first)
labels[n] = ord[n].first;
else
labels[n] = ord[n].second;
for(int adj : graph[n]){
if(adj == p)
continue;
name_subtree(adj, n, !first);
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
cnt = 0;
ord.clear();
labels.clear();
graph.clear();
ord.assign(n, {0,0});
labels.assign(n, 0);
graph.assign( n, vector<int>());
for (int i = 0; i < n - 1; i++) {
graph[u[i]].pb(v[i]);
graph[v[i]].pb(u[i]);
}
dfs1(0,-1);
int root = 0;
//for(int i =0; i<n; i++) cout <<i<<": "<< ord[i].first<<", "<<ord[i].second<<endl;
name_subtree(root, -1, 1);
//for(int i =0; i<n; i++) cout <<i<<": "<< labels[i]<<endl;
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
if(c.size() == 1) return c[0];
bool isfirst = c[0] > s;
if(isfirst){
if(t < s) return c[c.size() - 1];
for(int adj : c){
if(t <= adj) return adj;
}
return c[c.size()-1] ;
}
else{
//if( t > s) return c[0];
//reverse(c.begin(), c.end());
for(int adj : c)
if(t <= adj)
return adj;
return c[0];
}
return c[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... |