#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 3;
vector<int> adj[N];
int dfs(int u, int p, int idx, bool big, vector<int> &labels){
if(!big) labels[u] = idx++;
for(int to: adj[u]){
if(to == p) continue;
idx = dfs(to, u, idx, !big, labels);
}
if(big) labels[u] = idx++;
return idx;
}
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]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
vector<int> labels(n);
dfs(0, -1, 0, true, labels);
return labels;
}
int find_next_station(int s, int t, vector<int> c){
if(c.size() == 1) return c[0];
if(s < c[0]){
if(t < s) return c.back();
for(int i = 0; i < (int)c.size() - 1; ++i)
if(t <= c[i])
return c[i];
return c.back();
}
if(t > s || t < c[0]) return c.back();
for(int i = 1; i < (int)c.size() - 1; ++i)
if(t < c[i])
return c[i - 1];
return c[(int)c.size() - 2];
}
/*
2
5 10
0 1
0 2
1 3
1 4
1
0 4 0
2 1
0 1
1
1 0 0
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
512 ms |
1024 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
513 ms |
820 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
536 ms |
1024 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1016 ms |
672 KB |
Output is correct |
2 |
Incorrect |
696 ms |
768 KB |
Wrong query response. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
554 ms |
1280 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |