#include <bits/stdc++.h>
using namespace std;
int cnt;
vector<int> ret, sub;
vector<vector<int>> adj;
void dfs(int v, int p, bool ismax) {
ret[v] = cnt;
sub[v] = 1;
cnt += (!ismax);
for (auto to : adj[v]) {
if (to == p) continue;
dfs(to, v, !ismax);
if (ismax) ret[v] += sub[to];
sub[v] += sub[to];
}
cnt += ismax;
//if (ret[v] >= 1000) cout << endl << "========= error ===========" << endl;
return;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
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]);
}
sub.assign(n, 0);
ret.assign(n, 0);
cnt = 0;
dfs(0, 0, 0);
return ret;
}
int find_next_station(int s, int t, vector<int> c) {
bool ismax = (s > c[0]);
if (ismax) {
if (t > s) return c[0];
for (int i=1; i<(int)c.size(); i++) {
if (t < c[i]) return c[i-1];
}
return c[c.size()-1];
}
else {
if (t < s) return c[c.size()-1];
for (int i=c.size()-2; i>=0; i++) {
if (t > c[i]) return c[i+1];
}
return c[0];
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
487 ms |
656 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
402 ms |
612 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
543 ms |
656 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
754 ms |
492 KB |
Output is correct |
2 |
Incorrect |
606 ms |
400 KB |
Wrong query response. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
497 ms |
616 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |