#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> adj;
vector<int> lab;
int cnt;
void dfs (int u, int p = -1) {
for (int v : adj[u]) {
if (v ^ p) {
dfs(v, u);
}
}
lab[u] = cnt++;
}
bool subtask2 () {
for (int i = 0; i < (int)adj.size(); ++i) {
vector<int> y{(i - 1) / 2, 2 * i + 1, 2 * i + 2};
if (!i) {
y.erase(y.begin());
}
sort(adj[i].begin(), adj[i].end());
while (y.size() > adj[i].size()) {
y.pop_back();
}
if (y != adj[i]) {
return 0;
}
}
return 1;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
adj.assign(n, {});
lab.resize(n);
cnt = 0;
for (int i = 0; i < n - 1; ++i) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
if (!subtask2()) {
for (int i = 0; i < n; ++i) {
if (adj[i].size() == 1) {
dfs(i);
break;
}
}
return lab;
}
iota(lab.begin(), lab.end(), 0);
return lab;
}
int find_next_station(int s, int t, vector<int> c) {
sort(c.begin(), c.end());
vector<int> y{(s - 1) / 2, 2 * s + 1, 2 * s + 2};
if (!s) {
y.erase(y.begin());
}
while (y.size() > c.size()) {
y.pop_back();
}
if (y != c) {
return s - (t < s) + (t > s);
}
int e = t;
while (e) {
int p = (e - 1) / 2;
if (p == s) {
return e;
}
e = p;
}
return (s - 1) / 2;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
551 ms |
528 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
468 ms |
584 KB |
Output is correct |
2 |
Correct |
528 ms |
548 KB |
Output is correct |
3 |
Correct |
884 ms |
400 KB |
Output is correct |
4 |
Correct |
793 ms |
400 KB |
Output is correct |
5 |
Correct |
730 ms |
488 KB |
Output is correct |
6 |
Correct |
517 ms |
528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
612 ms |
604 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
934 ms |
400 KB |
Output is correct |
2 |
Incorrect |
816 ms |
520 KB |
Wrong query response. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
611 ms |
616 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |