#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] = 0;
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++;
}
}
}
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 = 1000;
for (int el : order) {
labels[el] = id++;
}
}
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
if (s / 1000 == t / 1000) {
if (s < t) {
return s + 1;
} else {
return s - 1;
}
} else {
if (s % 1000 == 0) {
return 0;
} else {
return s - 1;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
320 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=1008 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
328 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=1007 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
495 ms |
528 KB |
Output is correct |
2 |
Correct |
492 ms |
516 KB |
Output is correct |
3 |
Correct |
891 ms |
528 KB |
Output is correct |
4 |
Correct |
665 ms |
400 KB |
Output is correct |
5 |
Correct |
578 ms |
400 KB |
Output is correct |
6 |
Correct |
463 ms |
644 KB |
Output is correct |
7 |
Correct |
453 ms |
532 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
6 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Incorrect |
1 ms |
312 KB |
Invalid labels (duplicates values). scenario=1, label=1000 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
966 ms |
400 KB |
Output is correct |
2 |
Correct |
707 ms |
512 KB |
Output is correct |
3 |
Correct |
542 ms |
512 KB |
Output is correct |
4 |
Correct |
3 ms |
444 KB |
Output is correct |
5 |
Correct |
5 ms |
472 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Incorrect |
1 ms |
328 KB |
Invalid labels (duplicates values). scenario=0, label=1000 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
501 ms |
528 KB |
Partially correct |
2 |
Partially correct |
460 ms |
508 KB |
Partially correct |
3 |
Partially correct |
890 ms |
400 KB |
Partially correct |
4 |
Partially correct |
651 ms |
400 KB |
Partially correct |
5 |
Partially correct |
548 ms |
400 KB |
Partially correct |
6 |
Partially correct |
440 ms |
520 KB |
Partially correct |
7 |
Partially correct |
471 ms |
528 KB |
Partially correct |
8 |
Partially correct |
3 ms |
468 KB |
Partially correct |
9 |
Partially correct |
5 ms |
472 KB |
Partially correct |
10 |
Partially correct |
2 ms |
472 KB |
Partially correct |
11 |
Incorrect |
5 ms |
320 KB |
Invalid labels (duplicates values). scenario=0, label=1000 |
12 |
Halted |
0 ms |
0 KB |
- |