#include "stations.h"
#define X first
#define Y second
#define pb push_back
#include<bits/stdc++.h>
using namespace std;
const int MAX=1000+4,M2=5e5+3;
void maxx(int &a,int b){if(b>a) a=b;}
void minn(int &a,int b){if(b<a) a=b;}
template <class X, class Y>
bool cmin(X &a, const Y &b) {
return a > b ? a = b, 1 : 0;
}
bool cmax(int &a,int b){
if(b>a){a=b;return 1;} else return 0;
}
typedef pair < int, int > ii;
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) {
//cout<<s<<' '<<t<<'\n';
//for(int u:c) cout<<u<<'\n';
if(s<c[0]){
if(t<s) return c.back();
int b=0,e=int(c.size())-2,an=c.back();
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;
}
//cout<<"sp "<<an<<'\n';
return an;
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:52:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
52 | int m=b+e>>1;
| ~^~
stations.cpp:65:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
65 | int m=b+e>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
683 ms |
656 KB |
Output is correct |
2 |
Correct |
706 ms |
640 KB |
Output is correct |
3 |
Correct |
903 ms |
400 KB |
Output is correct |
4 |
Correct |
782 ms |
400 KB |
Output is correct |
5 |
Correct |
765 ms |
400 KB |
Output is correct |
6 |
Correct |
475 ms |
528 KB |
Output is correct |
7 |
Correct |
473 ms |
516 KB |
Output is correct |
8 |
Correct |
4 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
400 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
514 ms |
528 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
628 ms |
528 KB |
Output is correct |
2 |
Correct |
501 ms |
628 KB |
Output is correct |
3 |
Correct |
849 ms |
400 KB |
Output is correct |
4 |
Correct |
805 ms |
520 KB |
Output is correct |
5 |
Correct |
778 ms |
516 KB |
Output is correct |
6 |
Correct |
574 ms |
508 KB |
Output is correct |
7 |
Correct |
572 ms |
528 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Incorrect |
801 ms |
528 KB |
Wrong query response. |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1067 ms |
400 KB |
Output is correct |
2 |
Correct |
826 ms |
520 KB |
Output is correct |
3 |
Correct |
709 ms |
492 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
5 ms |
472 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
730 ms |
516 KB |
Output is correct |
8 |
Correct |
1077 ms |
400 KB |
Output is correct |
9 |
Correct |
906 ms |
532 KB |
Output is correct |
10 |
Correct |
641 ms |
640 KB |
Output is correct |
11 |
Incorrect |
7 ms |
468 KB |
Wrong query response. |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
728 ms |
528 KB |
Output is correct |
2 |
Correct |
517 ms |
700 KB |
Output is correct |
3 |
Correct |
994 ms |
496 KB |
Output is correct |
4 |
Correct |
727 ms |
516 KB |
Output is correct |
5 |
Correct |
649 ms |
428 KB |
Output is correct |
6 |
Correct |
509 ms |
528 KB |
Output is correct |
7 |
Correct |
565 ms |
572 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
6 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
476 KB |
Output is correct |
11 |
Incorrect |
531 ms |
516 KB |
Wrong query response. |
12 |
Halted |
0 ms |
0 KB |
- |