#include "stations.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
int ret[1050],sz[1050];
vector<int> adj[1050];
void calcsze(int id,int par=-1){
sz[id]=1;
for (int i:adj[id]){
if (i==par) continue;
calcsze(i,id);
sz[id]+=sz[i];
}
}
void dfs(int id,int par,int l,int r,bool bck){
if (bck) ret[id]=r;
else ret[id]=l;
int curr=l+(!bck);
for (int i:adj[id]){
if (i==par) continue;
dfs(i,id,curr,curr+sz[i]-1,!bck);
curr+=sz[i];
}
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
std::vector<int> labels(n);
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]);
}
calcsze(0);
dfs(0,-1,0,n-1,0);
for (int i = 0; i < n; i++) {
labels[i] = ret[i];
}
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
sort(c.begin(),c.end());
if (c[0]<s){
//current one is back
for (int i=1;i<(int)c.size();i++){
if (t<c[i]) return c[i-1];
}
if (t<s) return c.back();
return c[0];
}else{
//current one is front
for (int i:c) if (t<=i) return i;
return c.back();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
458 ms |
632 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
476 ms |
492 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
513 ms |
656 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
902 ms |
400 KB |
Output is correct |
2 |
Correct |
700 ms |
520 KB |
Output is correct |
3 |
Incorrect |
551 ms |
492 KB |
Wrong query response. |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
535 ms |
620 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |