#include <bits/stdc++.h>
using namespace std;
vector<int> st, en, d;
vector<vector<int>> adj;
int t;
void dfs(int curr, int par) {
st[curr] = t++;
for(int next : adj[curr]) {
d[next] = d[curr] + 1;
if(next == par) continue;
dfs(next, curr);
}
en[curr] = t++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
adj.resize(n);
st.resize(n);
en.resize(n);
d.resize(n);
for(int i = 0; i < n - 1; i++) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
vector<int> ans(n);
dfs(0, -1);
for(int i = 0; i < n; i++) {
if(d[i] % 2 == 0) ans[i] = st[i] / 2;
else ans[i] = en[i] / 2;
}
return ans;
}
int find_next_station(int s, int t, vector<int> c) {
bool odd = false;
s *= 2;
t *= 2;
for(int i = 0; i < (int) c.size(); i++) {
c[i] *= 2;
}
if(c[0] < s) odd = true;
if(c.size() == 1) return c[0] / 2;
if(odd) {
for(int i = 1; i < (int) c.size(); i++) {
if(t >= c[i] && t <= s) return c[i] / 2;
}
return c[0] / 2;
}
else {
if(c.size() == 1) return c[0] / 2;
for(int i = (int) c.size() - 1; i >= 0; i--) {
if(t <= c[i] && t >= s) return c[i] / 2;
}
return c[0] / 2;
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
296 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3036 ms |
1248 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2468 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1001 ms |
484 KB |
Output is correct |
2 |
Runtime error |
1269 ms |
2097156 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2809 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |