#ifndef EVAL
#include "stub.cpp"
#endif
#include "stations.h"
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pii pair<int, int>
#define pb push_back
#define szof(s) (int)s.size()
#define all(s) s.begin(), s.end()
using namespace std;
const int MAXN = 1005;
vector <int> g[MAXN];
int cnt[MAXN];
void clean() {
for (int i = 0; i < MAXN; i++) {
cnt[i] = 0;
}
for (int i = 0; i < MAXN; i++) {
g[i].clear();
}
}
void dfs(int v, int par, vector <int> &order) {
order.pb(v);
for (int to : g[v]) {
if (to != par) {
dfs(to, v, order);
}
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
clean(); // на всякий случай
for (int i = 0; i <= n - 2; i++) {
int x = u[i];
int y = v[i];
g[x].pb(y);
g[y].pb(x);
cnt[x]++;
cnt[y]++;
}
int root = 0;
bool flag = 0;
for (int i = 0; i < n; i++) {
if (cnt[i] >= 3) {
root = i;
flag = 1;
}
}
vector <int> labels(n);
if (flag) {
labels[root] = 1e6;
int sub = 1;
for (int son : g[root]) {
vector <int> order;
dfs(son, root, order);
int id = sub * 1000;
for (int el : order) {
labels[el] = id++;
}
sub++;
}
}
else { // просто бамбук
int up = -1;
for (int i = 0; i < n; i++) {
if (cnt[i] == 1) {
up = i;
break;
}
}
vector <int> order;
dfs(up, -1, order);
int id = 0;
for (int el : order) {
labels[el] = id++;
}
}
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
if (s == 1e6) {
return t / 1000 * 1000;
}
if (s / 1000 == t / 1000) {
if (s < t) {
return s + 1;
} else {
return s - 1;
}
} else {
if (s % 1000 == 0) {
return 1e6;
} else {
return s - 1;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
579 ms |
644 KB |
Output is correct |
2 |
Correct |
518 ms |
504 KB |
Output is correct |
3 |
Correct |
926 ms |
520 KB |
Output is correct |
4 |
Correct |
677 ms |
508 KB |
Output is correct |
5 |
Correct |
634 ms |
528 KB |
Output is correct |
6 |
Correct |
592 ms |
764 KB |
Output is correct |
7 |
Correct |
461 ms |
512 KB |
Output is correct |
8 |
Correct |
4 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
316 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=1007 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
526 ms |
616 KB |
Output is correct |
2 |
Correct |
477 ms |
528 KB |
Output is correct |
3 |
Correct |
874 ms |
512 KB |
Output is correct |
4 |
Correct |
669 ms |
600 KB |
Output is correct |
5 |
Correct |
625 ms |
400 KB |
Output is correct |
6 |
Correct |
405 ms |
528 KB |
Output is correct |
7 |
Correct |
463 ms |
728 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
464 KB |
Output is correct |
10 |
Correct |
1 ms |
476 KB |
Output is correct |
11 |
Correct |
598 ms |
556 KB |
Output is correct |
12 |
Correct |
471 ms |
656 KB |
Output is correct |
13 |
Correct |
483 ms |
768 KB |
Output is correct |
14 |
Correct |
448 ms |
656 KB |
Output is correct |
15 |
Correct |
62 ms |
532 KB |
Output is correct |
16 |
Correct |
77 ms |
548 KB |
Output is correct |
17 |
Correct |
102 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
942 ms |
400 KB |
Output is correct |
2 |
Correct |
626 ms |
528 KB |
Output is correct |
3 |
Correct |
570 ms |
528 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
595 ms |
400 KB |
Output is correct |
8 |
Correct |
900 ms |
400 KB |
Output is correct |
9 |
Correct |
694 ms |
400 KB |
Output is correct |
10 |
Correct |
643 ms |
516 KB |
Output is correct |
11 |
Incorrect |
6 ms |
476 KB |
Wrong query response. |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
585 ms |
644 KB |
Output is correct |
2 |
Correct |
501 ms |
504 KB |
Output is correct |
3 |
Correct |
873 ms |
400 KB |
Output is correct |
4 |
Correct |
647 ms |
508 KB |
Output is correct |
5 |
Correct |
619 ms |
508 KB |
Output is correct |
6 |
Correct |
494 ms |
528 KB |
Output is correct |
7 |
Correct |
430 ms |
516 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Incorrect |
400 ms |
516 KB |
Wrong query response. |
12 |
Halted |
0 ms |
0 KB |
- |