#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
const int Nmax=1010;
int N, K, Size[Nmax], Dep[Nmax];
vector<int> adj[Nmax], L;
void DFS_Size(int curr, int prev) {
Size[curr]=1;
for(int next:adj[curr]) if(next!=prev) {
Dep[next]=Dep[curr]+1;
DFS_Size(next, curr);
Size[curr]+=Size[next];
}
}
void DFS_Label(int curr, int prev, int s, int e) {
if(Dep[curr]%2) L[curr]=s++;
else L[curr]=e--;
for(int next:adj[curr]) if(next!=prev) {
DFS_Label(next, curr, s, s+Size[next]-1);
s+=Size[next];
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
for(int i=0; i<N; i++) adj[i].clear(), Size[i]=Dep[i]=0;
N=n, K=k;
for(int i=0; i<N-1; i++) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
DFS_Size(0, -1);
L.resize(N);
DFS_Label(0, -1, 0, N-1);
return L;
}
int find_next_station(int s, int t, vector<int> c) {
for(int i:c) if(i==t) return i;
if(c[0]<s) {
if(s<t && (c.size()==1 || t<c[c.size()-2])) return (*lower_bound(c.begin(), c.end(), t));
else return c.back();
}
else {
if(t<c[0] || t>s) return c[0];
else return (*(lower_bound(c.begin(), c.end(), t)-1));
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
432 ms |
640 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
412 ms |
624 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
464 ms |
660 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
770 ms |
488 KB |
Output is correct |
2 |
Correct |
648 ms |
504 KB |
Output is correct |
3 |
Incorrect |
609 ms |
404 KB |
Wrong query response. |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
488 ms |
644 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |