#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]);
}
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[c.size() - 1] && t > s) {
return c[0];
}
if (s < c[0] && t < s) {
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 <= mid) {
right = mid;
}
else {
left = mid;
}
}
if (s < c[0]) {
return c[right];
}
return c[left];
*/
if (s < c[0]) {
if (t < s) {
return c[c.size() - 1];
}
forint(i, c.size()) {
if (c[i] >= t) {
return c[i];
}
}
}
else {
if (t > s) {
return c[0];
}
for (int i = c.size() - 1; i >= 0; i--) {
if (t >= c[i]) {
return c[i];
}
}
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:3:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
3 | #define forint(i, N) for (int i = 0; i < (N); i++)
| ^
stations.cpp:99:3: note: in expansion of macro 'forint'
99 | forint(i, c.size()) {
| ^~~~~~
stations.cpp:115:1: warning: control reaches end of non-void function [-Wreturn-type]
115 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
416 KB |
Invalid labels (values out of range). scenario=2, k=1000, vertex=0, label=1010 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
320 KB |
Invalid labels (values out of range). scenario=1, k=1000, vertex=0, label=1989 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
632 ms |
484 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1035 ms |
520 KB |
Output is correct |
2 |
Correct |
794 ms |
400 KB |
Output is correct |
3 |
Incorrect |
781 ms |
400 KB |
Wrong query response. |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
641 ms |
528 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |