#include<bits/stdc++.h>
#include "stations.h"
using namespace std;
const int N = 1005;
vector<int> adj[N];
int dtime;
/// in-stvis unda vicode out-ebi , out-stvis in-ebi
void dfs(int u , int h , vector<int> &R ,int p = -1){
if(!h) R[u]= dtime++;
for(int v : adj[u])if(v ^ p)dfs(v ,h^1 , R , u);
if(h) R[u] = dtime++;
}
vector<int> label(int n , int k ,vector<int> u , vector<int> v){
for(int i = 0; i < n; ++i) adj[i].clear();
for(int i = 0; i < n-1; ++i) adj[u[i]].emplace_back(v[i]) , adj[v[i]].emplace_back(u[i]);
vector<int> R(n);
dtime =0;
dfs(0 , 0 , R);
return R;
}
/// (in1 , out1) in = out0 + 1
/// (in0 , out0) out0 = in1 - 1;
int find_next_station(int s , int t , vector<int> c){
/// s-in
if(s < c[0]){
int cur = s;
for(int x: c){
if(cur < t && t <= x) return x;
cur = x;
}
return c.back(); /// parent
} else {
/// s out
for(int i = 0; i < c.size(); ++i){
if(i == c.size()) if(c[i] <= t && t < s) return i;
else if(c[i] <= t && t < c[i + 1]) return c[i];
}
}/// parent
return c[0];
}
/*
int main (){
cin >> n;
for(int i =1; i < n; ++i){
int u , v; cin >> u>> v;
adj[u].emplace_back(v); adj[v].emplace_back(u);
}
vector<int> k = label(n , 1 , {3} , {3});
cout << find_next_station(1 , 3 , {3 , 2 ,0}) << endl;
}
*/
//int main (){}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:34:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int i = 0; i < c.size(); ++i){
| ~~^~~~~~~~~~
stations.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | if(i == c.size()) if(c[i] <= t && t < s) return i;
| ~~^~~~~~~~~~~
stations.cpp:35:15: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
35 | if(i == c.size()) if(c[i] <= t && t < s) return i;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
539 ms |
1028 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
437 ms |
892 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
515 ms |
864 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
837 ms |
952 KB |
Output is correct |
2 |
Incorrect |
675 ms |
864 KB |
Wrong query response. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
521 ms |
992 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |