#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 tin[MAXN], tout[MAXN], tiktak = 0;
int pr[MAXN];
void clean() {
for (int i = 0; i < MAXN; i++) {
g[i].clear();
tin[i] = 0;
tout[i] = 0;
pr[i] = 0;
}
tiktak = 0;
}
void precalc(int v, int par) {
tin[v] = ++tiktak;
pr[v] = par;
for (int to : g[v]) {
if (to != par) {
precalc(to, v);
}
}
tout[v] = tiktak;
}
void up(int v, vector <int> &vec) {
vec.pb(v);
if (pr[v] != -1) {
up(pr[v], vec);
}
}
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);
}
precalc(0, -1);
vector <int> labels(n);
for (int i = 0; i < n; i++) {
// 10 битов для tin
// 10 битов для tout
labels[i] = tin[i] + (tout[i] << 10);
}
return labels;
}
bool father(int a, int b) {
int tin_a = 0;
int tout_a = 0;
int tin_b = 0;
int tout_b = 0;
for (int i = 0; i < 30; i++) {
if (a & (1 << i)) {
if (i <= 9) {
tin_a += (1 << i);
} else {
tout_a += (1 << (i - 10));
}
}
if (b & (1 << i)) {
if (i <= 9) {
tin_b += (1 << i);
} else {
tout_b += (1 << (i - 10));
}
}
}
return tin_a <= tin_b && tout_b <= tout_a;
}
int find_next_station(int s, int t, vector<int> c) {
if (father(s, t)) {
for (int el : c) {
if (father(s, el) && father(el, t)) {
return el;
}
}
}
for (int el : c) {
if (father(el, s)) {
return el;
}
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:106:1: warning: control reaches end of non-void function [-Wreturn-type]
106 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
316 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=10241 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
316 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=1019905 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
316 KB |
Invalid labels (values out of range). scenario=1, k=1000000, vertex=0, label=1020929 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
932 ms |
528 KB |
Output is correct |
2 |
Correct |
723 ms |
508 KB |
Output is correct |
3 |
Correct |
685 ms |
516 KB |
Output is correct |
4 |
Correct |
3 ms |
400 KB |
Output is correct |
5 |
Correct |
3 ms |
576 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
671 ms |
400 KB |
Output is correct |
8 |
Correct |
1162 ms |
496 KB |
Output is correct |
9 |
Correct |
634 ms |
492 KB |
Output is correct |
10 |
Correct |
600 ms |
400 KB |
Output is correct |
11 |
Correct |
6 ms |
468 KB |
Output is correct |
12 |
Correct |
7 ms |
596 KB |
Output is correct |
13 |
Correct |
6 ms |
480 KB |
Output is correct |
14 |
Correct |
4 ms |
572 KB |
Output is correct |
15 |
Correct |
3 ms |
596 KB |
Output is correct |
16 |
Correct |
602 ms |
516 KB |
Output is correct |
17 |
Correct |
546 ms |
516 KB |
Output is correct |
18 |
Correct |
486 ms |
556 KB |
Output is correct |
19 |
Correct |
534 ms |
520 KB |
Output is correct |
20 |
Correct |
508 ms |
516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
616 ms |
588 KB |
Partially correct |
2 |
Partially correct |
510 ms |
508 KB |
Partially correct |
3 |
Partially correct |
965 ms |
400 KB |
Partially correct |
4 |
Partially correct |
658 ms |
496 KB |
Partially correct |
5 |
Partially correct |
591 ms |
516 KB |
Partially correct |
6 |
Partially correct |
491 ms |
508 KB |
Partially correct |
7 |
Partially correct |
468 ms |
528 KB |
Partially correct |
8 |
Partially correct |
3 ms |
468 KB |
Partially correct |
9 |
Partially correct |
3 ms |
596 KB |
Partially correct |
10 |
Partially correct |
2 ms |
596 KB |
Partially correct |
11 |
Partially correct |
450 ms |
520 KB |
Partially correct |
12 |
Partially correct |
520 ms |
496 KB |
Partially correct |
13 |
Partially correct |
896 ms |
512 KB |
Partially correct |
14 |
Partially correct |
663 ms |
516 KB |
Partially correct |
15 |
Partially correct |
633 ms |
528 KB |
Partially correct |
16 |
Partially correct |
447 ms |
648 KB |
Partially correct |
17 |
Partially correct |
633 ms |
520 KB |
Partially correct |
18 |
Partially correct |
475 ms |
504 KB |
Partially correct |
19 |
Partially correct |
513 ms |
776 KB |
Partially correct |
20 |
Partially correct |
508 ms |
520 KB |
Partially correct |
21 |
Partially correct |
81 ms |
548 KB |
Partially correct |
22 |
Partially correct |
109 ms |
692 KB |
Partially correct |
23 |
Partially correct |
130 ms |
528 KB |
Partially correct |
24 |
Partially correct |
6 ms |
476 KB |
Partially correct |
25 |
Partially correct |
5 ms |
596 KB |
Partially correct |
26 |
Partially correct |
6 ms |
604 KB |
Partially correct |
27 |
Partially correct |
7 ms |
468 KB |
Partially correct |
28 |
Partially correct |
2 ms |
468 KB |
Partially correct |
29 |
Partially correct |
514 ms |
528 KB |
Partially correct |
30 |
Partially correct |
560 ms |
496 KB |
Partially correct |
31 |
Partially correct |
568 ms |
504 KB |
Partially correct |
32 |
Partially correct |
545 ms |
528 KB |
Partially correct |
33 |
Partially correct |
538 ms |
504 KB |
Partially correct |
34 |
Partially correct |
326 ms |
516 KB |
Partially correct |
35 |
Partially correct |
443 ms |
508 KB |
Partially correct |
36 |
Partially correct |
482 ms |
628 KB |
Partially correct |
37 |
Partially correct |
465 ms |
620 KB |
Partially correct |
38 |
Partially correct |
531 ms |
620 KB |
Partially correct |
39 |
Partially correct |
486 ms |
640 KB |
Partially correct |
40 |
Partially correct |
487 ms |
628 KB |
Partially correct |
41 |
Partially correct |
511 ms |
624 KB |
Partially correct |
42 |
Partially correct |
81 ms |
528 KB |
Partially correct |
43 |
Partially correct |
138 ms |
656 KB |
Partially correct |
44 |
Partially correct |
146 ms |
528 KB |
Partially correct |
45 |
Partially correct |
186 ms |
528 KB |
Partially correct |
46 |
Partially correct |
347 ms |
596 KB |
Partially correct |
47 |
Partially correct |
365 ms |
724 KB |
Partially correct |
48 |
Partially correct |
76 ms |
660 KB |
Partially correct |
49 |
Partially correct |
82 ms |
784 KB |
Partially correct |