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 forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(x) x.begin(), x.end()
using ll = long long;
const int N=1e3;
int l[N], r[N];
vector<int> adj[N];
int nxt=0;
int col[N];
void dfs(int u, int p, int c) {
col[u]=c;
l[u]=nxt++;
for(auto&v:adj[u]) {
if (v==p) continue;
dfs(v,u,!c);
}
r[u]=nxt++;
}
vector<int> label(int n, int k, vector<int>u, vector<int> v) {
forn(i,n) adj[i].clear(); nxt=0;
forn(i,n-1) {
adj[u[i]].pb(v[i]);
adj[v[i]].pb(u[i]);
}
dfs(0,-1,0);
vector<int> ans(n);
forn(i,n) {
if (col[i]) {
ans[i]=l[i];
} else {
ans[i]=r[i];
}
}
set<int> s; forn(i,n) s.insert(ans[i]);
int mex=0;
map<int,int> c;
for(auto&x:s) c[x]=mex++;
forn(i,n) ans[i]=c[ans[i]];
return ans;
}
int is_ancestor(int l, int r, int y) {
//x is anc of y
return l <= y && y <= r;
}
int find_next_station(int s, int t, vector<int> adj) {
//cout<<"? "<<s<<' '<<t<<": "; for(auto&x:adj) cout<<x<<' '; cout<<'\n';
if (adj.size()==1) return adj[0];
if (s > adj.back()) {
int l=adj[1]-1;
int r=s;
if (is_ancestor(l,r,t)) {
for (int i=1; i<adj.size()-1; ++i) {
int l=adj[i], r=adj[i+1]-1;
if (is_ancestor(l,r,t)) return adj[i];
}
return adj.back();
} else {
return adj[0];
}
} else {
int l=s;
int r=adj[adj.size()-2]+1;
if (is_ancestor(l,r,t)) {
for (int i=1; i<adj.size()-1; ++i) {
int l=adj[i-1]+1, r=adj[i];
if (is_ancestor(l,r,t)) return adj[i];
}
return adj[0];
} else {
return adj.back();
}
}
assert(0);
}
Compilation message (stderr)
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:4:19: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
4 | #define forn(i,n) for(int i=0;i<n;++i)
| ^~~
stations.cpp:25:2: note: in expansion of macro 'forn'
25 | forn(i,n) adj[i].clear(); nxt=0;
| ^~~~
stations.cpp:25:28: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
25 | forn(i,n) adj[i].clear(); nxt=0;
| ^~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:60:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for (int i=1; i<adj.size()-1; ++i) {
| ~^~~~~~~~~~~~~
stations.cpp:72:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for (int i=1; i<adj.size()-1; ++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... |