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;
#include "stations.h"
#define pb push_back
const int nax=1e3+5;
vector<int> adj[nax];
int tin[nax];
int tout[nax];
set<int> st;
std::vector<int> ans(nax);
int timer=-1;
int in=-1;
int out;
void compute(int x,int p){
tin[x]=++timer;
//cout <<x<<" "<<timer<<endl;
for(auto u:adj[x]){
if(u==p) continue;
compute(u,x);
}
tout[x]=timer;
}
void dfs1(int x,int p,int dep,int cnt){
if(dep==0){
ans[x]=tin[x]-cnt;
}else cnt++;
for(auto u:adj[x]){
if(u==p) continue;
dfs1(u,x,dep^1,cnt);
}
}
void dfs2(int x,int p,int dep,int cnt){
if(dep==1){
ans[x]=tout[x]-cnt;
cnt++;
}
vector<int> cur;
for(auto u:adj[x]){
if(u==p) continue;
cur.pb(u);
dfs2(u,x,dep^1,cnt);
}
reverse(cur.begin(),cur.end());
for(auto u:cur){
if(u==p) continue;
dfs2(u,x,dep^1,cnt);
}
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
out=n-1;
ans.resize(n);
ans[0]=0;
for (int i = 0; i < n-1; i++) {
st.insert(i+1);
int x=u[i],y=v[i];
adj[x].pb(y);
adj[y].pb(x);
}
compute(0,-1);
dfs1(0,-1,0,0);
dfs2(0,-1,0,0);
return ans;
}
int find_next_station(int s, int t, std::vector<int> c) {
sort(c.begin(),c.end());
int lst;
if(s>c.back()){
if(t>s) return c[0];
for (int i = c.size()-1; i >= 0; --i)
{
if(c[i]<t) break;
lst=c[i];
}
}else{
if(t<s) return c.back();
for (int i = 0; i < c.size(); ++i)
{
if(c[i]>t) break;
lst=c[i];
}
}
return lst;
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:77:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for (int i = 0; i < c.size(); ++i)
| ~~^~~~~~~~~~
stations.cpp:67:9: warning: 'lst' may be used uninitialized in this function [-Wmaybe-uninitialized]
67 | int lst;
| ^~~
# | 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... |