#include <bits/stdc++.h>
using namespace std;
vector<int> label(int n ,int l , vector<int> u , vector<int> v){
vector<int> ans(n) ;
vector<int> adj[n] ;
for(int i=0;i<n-2;++i){
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
function<vector<int>(int,int,int)> dfs = [&](int a ,int p , int lvl){
vector<int> ans ;
if(lvl)
ans.push_back(a) ;
for(int x : adj[a]){
if(x!=p){
vector<int> res = dfs(x,a,lvl^1) ;
for(int x :res) ans.push_back(x) ;
}
}
if(lvl==0) ans.push_back(a) ;
return ans ;
};
vector<int> res = dfs(1,-1,1) ;
for(int i=0;i<n;i++) ans[res[i]]=i ;
return ans ;
}
int find_next_station(int u , int v , vector<int> ne){
if(u==0){
if(u<=v&&v<=ne[0]) return ne[0] ;
for(int i=1;i<ne.size();i++) if(ne[i]>=v&&v>ne[i-1]) return ne[i] ;
}
if(u<=ne[0]){
int dad = ne.back() ;
if(u<=v&&v<=ne[0]) return ne[0] ;
for(int i=1;i+1<ne.size();i++)
if(ne[i]>=v&&v>ne[i-1]) return ne[i] ;
return dad ;
}
else{
int dad = ne[0] ;
if(u>=v&&u>=ne.back()) return ne.back() ;
for(int i=(int)ne.size()-2;i>0;i--)
if(ne[i+1]>v&&v>=ne[i]) return ne[i] ;
return dad ;
}
return 5/0 ;
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:30:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int i=1;i<ne.size();i++) if(ne[i]>=v&&v>ne[i-1]) return ne[i] ;
| ~^~~~~~~~~~
stations.cpp:35:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int i=1;i+1<ne.size();i++)
| ~~~^~~~~~~~~~
stations.cpp:46:13: warning: division by zero [-Wdiv-by-zero]
46 | return 5/0 ;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
420 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
296 KB |
Invalid labels (duplicates values). scenario=0, label=0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
584 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1065 ms |
460 KB |
Output is correct |
2 |
Runtime error |
1 ms |
280 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
668 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |