#include "stations.h"
#include<bits/stdc++.h>
using namespace std;
const int MAX=1000+4,M2=5e5+3;
#define pb push_back
vector < int > pr[MAX];
int in[MAX];
int tim=0;
void dfs(int v,int vpa,bool h){
if(!h) in[v]=tim++;
for(int u:pr[v])if(u!=vpa)
dfs(u,v,!h);
if(h) in[v]=tim++;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
std::vector<int> labels(n);
for(int i=0;i<n;i++) pr[i].clear();
tim=0;
for (int i = 0; i < n-1; i++){
pr[u[i]].pb(v[i]);
pr[v[i]].pb(u[i]);
}
dfs(0,0,0);
for (int i = 0; i < n; i++) {
labels[i] = in[i];
}
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(s<c[0]){
if(t<s) return c.back();
int b=0,e=int(c.size())-2,an=c.back();
if(s==0)
e++;
while(b<=e){
int m=b+e>>1;
if(t<=c[m]){
an=c[m];
b=m+1;
}
else e=m-1;
}
return an;
}
else{
if(t>s) return c[0];
int b=1,e=int(c.size())-1,an=c[0];
while(b<=e){
int m=b+e>>1;
if(t>=c[m]){
an=c[m];b=m+1;
}
else e=m-1;
}
return an;
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:40:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
40 | int m=b+e>>1;
| ~^~
stations.cpp:53:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
53 | int m=b+e>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
730 ms |
644 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
452 ms |
584 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
660 ms |
528 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1082 ms |
644 KB |
Output is correct |
2 |
Incorrect |
789 ms |
528 KB |
Wrong query response. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
627 ms |
528 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |