#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
template<class T, class U>
void ckmin(T &a, U b)
{
if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
if (a < b) a = b;
}
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
const int MAXN = 1013;
const int INF = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
int N, K, T;
vi edge[MAXN];
int st[MAXN], ft[MAXN], depth[MAXN];
vi ans;
//inside each vtx, we store start time and finish time.
void dfs(int u, int p)
{
st[u] = T;
T++;
for (int v : edge[u])
{
if (v == p) continue;
depth[v] = depth[u] + 1;
dfs(v, u);
}
ft[u] = T;
T++;
}
vi label(int n, int k, vi U, vi V)
{
N = n; K = k; T = 0;
FOR(i, 0, N)
{
edge[i].clear();
}
ans.clear();
FOR(i, 0, N - 1)
{
int u = U[i], v = V[i];
edge[u].PB(v);
edge[v].PB(u);
}
depth[0] = 0;
dfs(0, N);
ans.resize(N);
FOR(i, 0, N)
{
if (depth[i] % 2)
{
ans[i] = ft[i];
}
else
{
ans[i] = st[i];
}
}
return ans;
}
int find_next_station(int u, int v, vi ch)
{
sort(ALL(ch));
//figure out if you're a st or ft.
//case 1: you're an st. then any neighbor will have ft > u.
if (u < ch[0])
{
int ft = -1;
//you're an st. your ft is the second largest neighbor unless you are the root, and then it's the largest + 1.
if (u == 0)
{
ft = ch.back() + 1;
}
else
{
ft = (SZ(ch) > 1 ? ch[SZ(ch) - 2] : u) + 1;
}
if (u <= v && v <= ft)
{
//you're going to an ft, which still is >= v.
FOR(i, 0, SZ(ch))
{
if (ch[i] >= v) return ch[i];
}
}
else
{
return ch.back();
}
}
else
{
//you're an ft. your st is the smallest child - 1, unless you only have a parent.
int st = -1;
if (SZ(ch) == 1)
{
st = ch[0] + 1;
}
else
{
st = ch[0] - 1;
}
if (st <= v && v <= u)
{
//you're going to an st, which is <= v.
FORD(i, SZ(ch), 0)
{
if (ch[i] <= v) return ch[i];
}
}
else
{
return ch[0];
}
}
assert(false);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
340 KB |
Invalid labels (values out of range). scenario=2, k=1000, vertex=1, label=1990 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
328 KB |
Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1022 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
654 ms |
640 KB |
Output is correct |
2 |
Correct |
453 ms |
648 KB |
Output is correct |
3 |
Correct |
1134 ms |
644 KB |
Output is correct |
4 |
Correct |
803 ms |
508 KB |
Output is correct |
5 |
Correct |
779 ms |
528 KB |
Output is correct |
6 |
Correct |
516 ms |
768 KB |
Output is correct |
7 |
Correct |
672 ms |
508 KB |
Output is correct |
8 |
Correct |
3 ms |
596 KB |
Output is correct |
9 |
Correct |
6 ms |
448 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
644 ms |
400 KB |
Output is correct |
12 |
Correct |
560 ms |
760 KB |
Output is correct |
13 |
Correct |
529 ms |
840 KB |
Output is correct |
14 |
Correct |
551 ms |
504 KB |
Output is correct |
15 |
Correct |
66 ms |
528 KB |
Output is correct |
16 |
Correct |
70 ms |
528 KB |
Output is correct |
17 |
Correct |
139 ms |
528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1124 ms |
508 KB |
Output is correct |
2 |
Correct |
794 ms |
516 KB |
Output is correct |
3 |
Correct |
649 ms |
508 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
5 ms |
448 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
815 ms |
648 KB |
Output is correct |
8 |
Correct |
1027 ms |
400 KB |
Output is correct |
9 |
Correct |
788 ms |
400 KB |
Output is correct |
10 |
Correct |
825 ms |
528 KB |
Output is correct |
11 |
Correct |
7 ms |
608 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
8 ms |
596 KB |
Output is correct |
14 |
Correct |
4 ms |
468 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
602 ms |
520 KB |
Output is correct |
17 |
Correct |
586 ms |
516 KB |
Output is correct |
18 |
Correct |
693 ms |
528 KB |
Output is correct |
19 |
Correct |
561 ms |
512 KB |
Output is correct |
20 |
Correct |
580 ms |
400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
616 ms |
676 KB |
Partially correct |
2 |
Partially correct |
496 ms |
624 KB |
Partially correct |
3 |
Correct |
1103 ms |
528 KB |
Output is correct |
4 |
Correct |
775 ms |
516 KB |
Output is correct |
5 |
Correct |
681 ms |
528 KB |
Output is correct |
6 |
Partially correct |
587 ms |
628 KB |
Partially correct |
7 |
Partially correct |
487 ms |
520 KB |
Partially correct |
8 |
Correct |
3 ms |
596 KB |
Output is correct |
9 |
Correct |
5 ms |
476 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Partially correct |
471 ms |
508 KB |
Partially correct |
12 |
Partially correct |
547 ms |
528 KB |
Partially correct |
13 |
Correct |
1166 ms |
508 KB |
Output is correct |
14 |
Correct |
771 ms |
516 KB |
Output is correct |
15 |
Correct |
573 ms |
528 KB |
Output is correct |
16 |
Partially correct |
570 ms |
512 KB |
Partially correct |
17 |
Correct |
647 ms |
512 KB |
Output is correct |
18 |
Partially correct |
590 ms |
720 KB |
Partially correct |
19 |
Partially correct |
627 ms |
736 KB |
Partially correct |
20 |
Partially correct |
454 ms |
520 KB |
Partially correct |
21 |
Correct |
68 ms |
528 KB |
Output is correct |
22 |
Partially correct |
91 ms |
572 KB |
Partially correct |
23 |
Partially correct |
144 ms |
656 KB |
Partially correct |
24 |
Correct |
9 ms |
528 KB |
Output is correct |
25 |
Correct |
7 ms |
596 KB |
Output is correct |
26 |
Correct |
5 ms |
596 KB |
Output is correct |
27 |
Correct |
4 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
596 KB |
Output is correct |
29 |
Correct |
555 ms |
516 KB |
Output is correct |
30 |
Correct |
554 ms |
528 KB |
Output is correct |
31 |
Correct |
539 ms |
512 KB |
Output is correct |
32 |
Correct |
551 ms |
528 KB |
Output is correct |
33 |
Correct |
551 ms |
528 KB |
Output is correct |
34 |
Partially correct |
436 ms |
620 KB |
Partially correct |
35 |
Partially correct |
442 ms |
632 KB |
Partially correct |
36 |
Partially correct |
512 ms |
640 KB |
Partially correct |
37 |
Partially correct |
626 ms |
792 KB |
Partially correct |
38 |
Partially correct |
515 ms |
640 KB |
Partially correct |
39 |
Partially correct |
506 ms |
720 KB |
Partially correct |
40 |
Partially correct |
521 ms |
748 KB |
Partially correct |
41 |
Partially correct |
602 ms |
736 KB |
Partially correct |
42 |
Partially correct |
61 ms |
528 KB |
Partially correct |
43 |
Partially correct |
153 ms |
528 KB |
Partially correct |
44 |
Partially correct |
179 ms |
516 KB |
Partially correct |
45 |
Partially correct |
211 ms |
528 KB |
Partially correct |
46 |
Partially correct |
386 ms |
528 KB |
Partially correct |
47 |
Partially correct |
388 ms |
620 KB |
Partially correct |
48 |
Partially correct |
82 ms |
748 KB |
Partially correct |
49 |
Partially correct |
77 ms |
864 KB |
Partially correct |