#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1010;
int timer , ans[MAXN];
vector<int> adj[MAXN];
void DFS(int v , int p = -1 , int h = 0){
if(h % 2 == 0) ans[v] = timer++;
for(int u : adj[v]){
if(u == p) continue;
DFS(u , v , h + 1);
}
if(h % 2 == 1) ans[v] = timer++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector<int> labels(n , 0); timer = 0;
for (int i = 0; i < n; i++) {
adj[i].clear(); ans[i] = 0;
}
for(int i = 0 ; i < n - 1 ; i++){
adj[v[i]].push_back(u[i]);
adj[u[i]].push_back(v[i]);
}
DFS(0);
for(int i = 0 ; i < n ; i++) labels[i] = ans[i];
return labels;
}
int SolveSt(int s , int t , vector<int> c){
int prv = s;
for(int u : c){
if(prv < t && t <= u) return u;
prv = u;
}
return c.back();
}
int SolveFn(int s , int t , vector<int> c){
int prv = s;
reverse(c.begin() , c.end());
for(int u : c){
if(u <= t && u < prv) return u;
prv = u;
}
return c.back();
}
int find_next_station(int s, int t, vector<int> c) {
if(s < c[0]) return SolveSt(s , t , c);
if(s > c[0]) return SolveFn(s , t , c);
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:54:1: warning: control reaches end of non-void function [-Wreturn-type]
54 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
693 ms |
508 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
542 ms |
548 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
673 ms |
520 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1000 ms |
420 KB |
Output is correct |
2 |
Correct |
657 ms |
604 KB |
Output is correct |
3 |
Incorrect |
850 ms |
508 KB |
Wrong query response. |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
655 ms |
644 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |