#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
int dfs_cnt = 0;
vector< vector<int> > g;
vector<int> d, dfs_in, dfs_out;
void dfs(int u, int p) {
dfs_in[u] = dfs_cnt++;
for (auto& v : g[u]) {
if (v != p) {
d[v] = d[u] + 1;
dfs(v, u);
}
}
dfs_out[u] = dfs_cnt++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
g.resize(n);
d.assign(n, 0);
dfs_in.resize(n); dfs_out.resize(n);
for (int i = 0; i < n - 1; i++) {
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
dfs(0, -1);
set<int> st;
for (int i = 0; i < n; i++) {
if (d[i] % 2 == 0) st.insert(dfs_in[i]);
else st.insert(dfs_out[i]);
}
int cur = 0;
map<int, int> mp;
for (auto& x : st) mp[x] = cur++;
vector<int> ans(n);
for (int i = 0; i < n; i++) {
if (d[i] % 2 == 0) ans[i] = mp[dfs_in[i]];
else ans[i] = mp[dfs_out[i]];
}
return ans;
}
int find_next_station(int s, int t, vector<int> c) {
for (auto& x : c) if (x == t) return t;
sort(c.begin(), c.end());
if (s < c[0]) { // in
for (int i = 0; i < (int) c.size() - 1; i++) if (s < t && t < c[i]) return c[i];
return c.back();
} else { // out
for (int i = (int) c.size() - 1; i >= 1; i--) if (c[i] < t && t < s) return c[i];
return c[0];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
416 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3066 ms |
1628 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1941 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
867 ms |
492 KB |
Output is correct |
2 |
Runtime error |
1195 ms |
2097156 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3009 ms |
2097156 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |