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 pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define pii pair<int,int>
#define ff first
#define ss second
void dfs(int v, int p, vector<vector<int>> &g, vi &tin, vi &tout, int &timer, vi &dep, vi &labels){
tin[v] = timer++;
dep[v] = dep[p] + 1;
for(int u: g[v]){
if(u != p) dfs(u, v, g, tout, tin, timer, dep, labels);
}
tout[v] = timer++;
if(dep[v] % 2) labels[v] = tin[v];
else labels[v] = tout[v];
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
std::vector<int> labels(n);
stack<int> s;
vector<vector<int>> g(n);
for(int i = 0; i < n-1; ++i){
g[u[i]].pb(v[i]);
g[v[i]].pb(u[i]);
}
vector<int> tin(n), tout(n);
int timer = 0;
vi dep(n);
dfs(0, 0, g, tin, tout, timer, dep, labels);
for(int i = 0; i < n; ++i) cout << tin[i] << ' '; cout << '\n';
for(int i = 0; i < n; ++i) cout << tout[i] << ' '; cout << '\n';
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(s % 2 == 0){
if(t < s || t > c.back()){
return c.back();
}
int val = *lower_bound(all(c), t);
return val;
}
if(t > s || t < c[0]){
return c[0];
}
int val = upper_bound(all(c), t) - c.begin() - 1;
return c[val];
}
Compilation message (stderr)
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:37:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
37 | for(int i = 0; i < n; ++i) cout << tin[i] << ' '; cout << '\n';
| ^~~
stations.cpp:37:52: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
37 | for(int i = 0; i < n; ++i) cout << tin[i] << ' '; cout << '\n';
| ^~~~
stations.cpp:38:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
38 | for(int i = 0; i < n; ++i) cout << tout[i] << ' '; cout << '\n';
| ^~~
stations.cpp:38:53: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
38 | for(int i = 0; i < n; ++i) cout << tout[i] << ' '; cout << '\n';
| ^~~~
# | 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... |