#include "stations.h"
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
vector<vector<int>> adj;
vector<int> L, R, lvl;
int ind;
void dfs(int x) {
L[x]=ind++;
for(auto i:adj[x]) {
if(!L[i]) {
dfs(i);
lvl[i]=lvl[x]+1;
}
}
R[x]=ind++;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
adj.resize(n);
for(auto& 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]);
}
L.assign(n, 0);
R.assign(n, 0);
lvl.assign(n, 0);
ind=1;
dfs(0);
std::vector<int> labels(n);
for (int i = 0; i < n; i++) {
labels[i] = lvl[i]&1?L[i]:R[i];
}
vector<int> s(labels.begin(), labels.end());
sort(s.begin(), s.end());
for(int i=0;i<n;++i) labels[i]=lower_bound(s.begin(), s.end(), labels[i])-s.begin();
return labels;
}
bool contains(int a, int b, int x) {
return min(a, b)<=x && x<=max(a, b);
}
int find_next_station(int s, int t, std::vector<int> c) {
int best=-1;
for(int i:c) {
if(contains(s, i, t)) {
if(best==-1 || abs(best-s)>abs(s-i)) best=i;
}
}
if(best==-1) {
for(int i:c) {
if(best==-1 || abs(best-s)<abs(s-i)) best=i;
}
}
return best;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
462 ms |
612 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
381 ms |
488 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
562 ms |
648 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
919 ms |
492 KB |
Output is correct |
2 |
Correct |
487 ms |
404 KB |
Output is correct |
3 |
Incorrect |
522 ms |
472 KB |
Wrong query response. |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
507 ms |
608 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |