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;
void dfs1(int u, int p, vector<int> &weight, vector<vector<int> > &g){
weight[u] = 1;
for(int i=0;i<g[u].size();i++){
int v = g[u][i];
if(v != p){
dfs1(v, u, weight, g);
weight[u] += weight[v];
}
}
}
void dfs2(int u, int p, int d, int l, int r, vector<int> &ans, vector<int> &weight, vector<vector<int> > &g){
if(d%2 == 0){
ans[u] = l;
l++;
}
else{
ans[u] = r;
r--;
}
for(int i=0;i<g[u].size();i++){
int v = g[u][i];
if(v != p){
dfs2(v, u, d+1, l, l+weight[v]-1, ans, weight, g);
l += weight[v];
}
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v){
vector<vector<int> > g(n);
vector<int> weight(n);
vector<int> ans(n);
for(int i=0;i<n-1;i++){
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
dfs1(0, 0, weight, g);
dfs2(0, 0, 0, 0, n-1, ans, weight, g);
return ans;
}
int find_next_station(int s, int t, vector<int> c){
if(c.size() == 1) return c[0];
int d = 1;
if(s < c[0]) d = 0;
if(d){
int p = c[0];
if(t < c[0] || t > s) return p;
for(int i=0;i<(int)c.size()-1;i++){
if(c[i] <= t && t <= c[i+1]-1) return c[i];
}
return c[(int)c.size()-1];
}
else{
int p = c[(int)c.size()-1];
if(t < s || t > c[(int)c.size()-1]) return p;
for(int i=1;i<(int)c.size();i++){
if(c[i-1]+1 <= t && t <= c[i]) return c[i];
}
return c[0];
}
}
Compilation message (stderr)
stations.cpp: In function 'void dfs1(int, int, std::vector<int>&, std::vector<std::vector<int> >&)':
stations.cpp:6:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
6 | for(int i=0;i<g[u].size();i++){
| ~^~~~~~~~~~~~
stations.cpp: In function 'void dfs2(int, int, int, int, int, std::vector<int>&, std::vector<int>&, std::vector<std::vector<int> >&)':
stations.cpp:23:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int i=0;i<g[u].size();i++){
| ~^~~~~~~~~~~~
# | 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... |