#include <bits/stdc++.h>
#define forint(i, N) for (int i = 0; i < (N); i++)
using namespace std;
vector<int> value;
vector<bool> visited;
int minval = 0;
void go(vector< vector<int> >& graph, int n, bool odd) {
visited[n] = true;
if (odd) {
for (auto& i : graph[n]) {
if (!visited[i]) {
go(graph, i, !odd);
}
}
value[n] = minval;
minval++;
}
else {
value[n] = minval;
minval++;
for (auto& i : graph[n]) {
if (!visited[i]) {
go(graph, i, !odd);
}
}
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector< vector<int> > graph(n);
visited.clear();
visited.resize(n);
fill(visited.begin(), visited.end(), false);
value.clear();
value.resize(n);
fill(value.begin(), value.end(), -1);
forint(i, n - 1) {
graph[u[i]].push_back(v[i]);
graph[v[i]].push_back(u[i]);
}
minval = 0;
go(graph, 0, true);
return value;
}
int find_next_station(int s, int t, vector<int> c) {
if (c.size() == 1) {
return c[0];
}
if (s < c[0]) {
if (t < s || t > c[c.size() - 1]) {
return c[c.size() - 1];
}
if (t <= c[0]) {
return c[0];
}
}
else {
if (t > s || t < c[0]) {
return c[0];
}
if (t >= c[c.size() - 1]) {
return c[c.size() - 1];
}
}
int left = 0;
int right = c.size() - 1;
while (left + 1 < right) {
if (t == c[left] || t == c[right]) {
return t;
}
int mid = (left + right) / 2;
if (t <= c[mid]) {
right = mid;
}
else {
left = mid;
}
}
if (s < c[0]) {
return c[right];
}
return c[left];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
605 ms |
656 KB |
Output is correct |
2 |
Correct |
574 ms |
528 KB |
Output is correct |
3 |
Correct |
869 ms |
400 KB |
Output is correct |
4 |
Correct |
801 ms |
400 KB |
Output is correct |
5 |
Correct |
705 ms |
528 KB |
Output is correct |
6 |
Correct |
598 ms |
464 KB |
Output is correct |
7 |
Correct |
543 ms |
528 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
6 ms |
464 KB |
Output is correct |
10 |
Correct |
2 ms |
428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
546 ms |
528 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
746 ms |
528 KB |
Output is correct |
2 |
Correct |
472 ms |
528 KB |
Output is correct |
3 |
Correct |
1269 ms |
520 KB |
Output is correct |
4 |
Correct |
723 ms |
480 KB |
Output is correct |
5 |
Correct |
675 ms |
520 KB |
Output is correct |
6 |
Correct |
528 ms |
616 KB |
Output is correct |
7 |
Correct |
480 ms |
484 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
476 KB |
Output is correct |
11 |
Incorrect |
805 ms |
400 KB |
Wrong query response. |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1071 ms |
400 KB |
Output is correct |
2 |
Correct |
828 ms |
520 KB |
Output is correct |
3 |
Correct |
611 ms |
404 KB |
Output is correct |
4 |
Correct |
3 ms |
464 KB |
Output is correct |
5 |
Correct |
5 ms |
476 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
752 ms |
488 KB |
Output is correct |
8 |
Correct |
820 ms |
404 KB |
Output is correct |
9 |
Correct |
837 ms |
400 KB |
Output is correct |
10 |
Correct |
610 ms |
488 KB |
Output is correct |
11 |
Incorrect |
4 ms |
488 KB |
Wrong query response. |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
513 ms |
592 KB |
Output is correct |
2 |
Correct |
533 ms |
608 KB |
Output is correct |
3 |
Correct |
944 ms |
400 KB |
Output is correct |
4 |
Correct |
653 ms |
400 KB |
Output is correct |
5 |
Correct |
676 ms |
400 KB |
Output is correct |
6 |
Correct |
485 ms |
476 KB |
Output is correct |
7 |
Correct |
565 ms |
488 KB |
Output is correct |
8 |
Correct |
4 ms |
468 KB |
Output is correct |
9 |
Correct |
7 ms |
464 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Incorrect |
620 ms |
528 KB |
Wrong query response. |
12 |
Halted |
0 ms |
0 KB |
- |