#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define sz(v) int(v.size())
int tt=0;
vector<int> ans;
vector<vector<int>> adj;
void dfs(int c=0, int p=-1, bool b=0){
if (!b) ans[c] = tt++;
for (auto nxt : adj[c]) if (nxt != p) dfs(nxt, c, b^1);
if (b) ans[c] = tt++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
ans.assign(n, -1), adj.assign(n, vector<int>());
for (int i = 0; i < n-1; i++)
adj[u[i]].push_back(v[i]), adj[v[i]].push_back(u[i]);
dfs();
return ans;
}
int find_next_station(int s, int t, vector<int> c) {
bool b=s>c[0];
if (b){ //i'm postorder
int p = c[0];
if (sz(c) == 1 || t < c[1] || t > s) //either going out of my subtree, there is no subtree
return p;
int ans=-1;
for (auto nxt : c) if (nxt != p) {
if (nxt <= t) ans = nxt;
}
return ans;
} else { //i'm preorder
int p = c[sz(c)-1];
if (sz(c) == 1 || t < s || t > c[sz(c)-1]) //either going out of my subtree, there is no subtree
return p;
int ans=-1;
for (auto nxt : c) if (nxt != p) {
if (nxt >= t){
ans = nxt;
break;
}
}
return ans;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
492 KB |
Invalid labels (values out of range). scenario=2, k=1000, vertex=1, label=1008 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
500 KB |
Invalid labels (values out of range). scenario=1, k=1000, vertex=1, label=1507 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
609 ms |
924 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
981 ms |
756 KB |
Output is correct |
2 |
Incorrect |
743 ms |
1188 KB |
Wrong query response. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
545 ms |
1076 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |