#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int nextnum;
int arr[1005];
vector<int> pairs[1005];
void dfs(int par, int a, int dep){
if(dep%2){
arr[a] = nextnum;
nextnum++;
}
for(int i:pairs[a]){
if(i!=par){
dfs(a,i,dep+1);
}
}
if(dep%2==0){
arr[a] = nextnum;
nextnum++;
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v){
nextnum = 0;
for(int i=0;i<n-1;i++){
pairs[u[i]].push_back(v[i]);
pairs[v[i]].push_back(u[i]);
}
dfs(-1,0,1);
vector<int> ans;
for(int i=0;i<n;i++){
ans.push_back(arr[i]);
}
return ans;
}
int find_next_station(int s, int t, vector<int> c){
sort(c.begin(),c.end());
if(s==0){
for(int i:c){
if(t<=i){
return i;
}
}
}
else if(c.size()==1){
return c[0];
}
else{
if(c[0]<s){
if(s<t){
return c[0];
}
reverse(c.begin(),c.end());
for(int i=0;i<c.size()-1;i++){
if(c[i]<=t){
return c[i];
}
}
return c[c.size()-1];
}
else{
if(s>t){
return c[c.size()-1];
}
for(int i=0;i<c.size()-1;i++){
if(c[i]>=t){
return c[i];
}
}
return c[c.size()-1];
}
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:58:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for(int i=0;i<c.size()-1;i++){
| ~^~~~~~~~~~~
stations.cpp:69:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for(int i=0;i<c.size()-1;i++){
| ~^~~~~~~~~~~
stations.cpp:77:1: warning: control reaches end of non-void function [-Wreturn-type]
77 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1899 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3021 ms |
416 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1359 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1051 ms |
400 KB |
Output is correct |
2 |
Runtime error |
1067 ms |
2097156 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2302 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |