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=10005;
vector<int> adj[nax];
int tin[nax];
int tout[nax];
vector<int> ans(nax);
int timer=-1;
void compute(int x,int p){
tin[x]=++timer;
for(auto u:adj[x]){
if(u==p) continue;
compute(u,x);
}
tout[x]=timer;
return;
}
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);
}
return;
}
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]){
cur.pb(u);
}
reverse(cur.begin(),cur.end());
for(auto u:cur){
if(u==p) continue;
dfs2(u,x,dep^1,cnt);
}
return;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
ans.resize(n);
/*for (int i = 0; i < n-1; i++) {
int x=u[i];
int 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()){
lst=c.back();
if(t>s) return c[0];
for (int i = c.size()-1; i >= 0; --i)
{
lst=c[i];
if(c[i]<=t) break;
}
}else{
lst=c[0];
if(t<s) return c.back();
for (int i = 0; i < c.size(); ++i)
{
lst=c[i];
if(c[i]>=t) break;
}
}
return lst;
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:74:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for (int i = 0; i < c.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... |