#include<bits/stdc++.h>
#define X first
#define Y second
#define all(x) begin(x), end(x)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, b, a) for(int i = (b); i >= (a); i--)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define mxx max_element
#define mnn min_element
#define SQR(x) (1LL * (x) * (x))
#define MASK(i) (1LL << (i))
#define Point Vector
#define left Left
#define right Right
#define div Div
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair<db, db> pdb;
typedef pair<ld, ld> pld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef pair<ll, int> pli;
typedef pair<ll, pii> plii;
template<class A, class B>
bool maximize(A& x, B y) {
if (x < y) return x = y, true; else return false;
}
template<class A, class B>
bool minimize(A& x, B y) {
if (x > y) return x = y, true; else return false;
}
/* END OF TEMPLATE */
const int N = 3e3 + 7;
vector<int> v[N];
int st[N], ed[N], cnt = 0, high[N];
int lab[N];
void compress_label(int n) {
vector<int> E;
REP(i, 0, n) E.push_back(lab[i]);
sort(all(E));
REP(i, 0, n) lab[i] = lower_bound(all(E), lab[i]) - E.begin();
}
void dfs(int x, int par) {
st[x] = ++cnt;
for (auto y : v[x])
if (y != par) {
high[y] = high[x] + 1;
dfs(y, x);
}
ed[x] = ++cnt;
}
vector<int> label(int n, int k, vector<int> a, vector<int> b) {
REP(i, 0, n) v[i].clear();
REP(i, 0, n - 1) {
v[a[i]].push_back(b[i]);
v[b[i]].push_back(a[i]);
}
cnt = 0;
dfs(0, 0);
// REP(i, 0, n) cout<<st[i]<<" "<<ed[i]<<"\n";
REP(i, 0, n)
if (high[i] % 2 == 0) lab[i] = st[i]; else lab[i] = ed[i];
compress_label(n);
vector<int> res(lab, lab + n);
// for (auto x : res) cout<<x<<" "; cout<<"\n";
return res;
}
int find_next_station(int s, int t, vector<int> c) {
sort(all(c));
if (binary_search(all(c), t)) return t;
int n = c.size();
if (s < c[0]) {
// s thoi diem vao
if (s != 0) {
// check xem t co nam ngoai cay con goc s hay khong
if (n == 1 || t < s || t > c[n - 2]) return c[n - 1]; // return cha
}
for (auto x : c)
if (x > t) return x;
}
// s thoi diem ra
if (s != 0) {
if (n == 1 || t > s || t < c[1]) return c[0];
}
int res = 0;
for (auto x : c)
if (x <= t) res = x;
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
316 ms |
992 KB |
Output is correct |
2 |
Correct |
301 ms |
1260 KB |
Output is correct |
3 |
Correct |
547 ms |
684 KB |
Output is correct |
4 |
Correct |
356 ms |
684 KB |
Output is correct |
5 |
Correct |
455 ms |
684 KB |
Output is correct |
6 |
Correct |
308 ms |
980 KB |
Output is correct |
7 |
Correct |
249 ms |
940 KB |
Output is correct |
8 |
Correct |
2 ms |
760 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
1092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
273 ms |
940 KB |
Output is correct |
2 |
Correct |
319 ms |
876 KB |
Output is correct |
3 |
Correct |
549 ms |
684 KB |
Output is correct |
4 |
Correct |
408 ms |
684 KB |
Output is correct |
5 |
Correct |
349 ms |
684 KB |
Output is correct |
6 |
Correct |
276 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
358 ms |
1004 KB |
Output is correct |
2 |
Correct |
343 ms |
992 KB |
Output is correct |
3 |
Correct |
580 ms |
688 KB |
Output is correct |
4 |
Correct |
383 ms |
684 KB |
Output is correct |
5 |
Correct |
388 ms |
684 KB |
Output is correct |
6 |
Correct |
259 ms |
976 KB |
Output is correct |
7 |
Correct |
267 ms |
940 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
764 KB |
Output is correct |
11 |
Correct |
390 ms |
684 KB |
Output is correct |
12 |
Correct |
298 ms |
1096 KB |
Output is correct |
13 |
Correct |
308 ms |
1500 KB |
Output is correct |
14 |
Correct |
274 ms |
684 KB |
Output is correct |
15 |
Correct |
37 ms |
768 KB |
Output is correct |
16 |
Correct |
37 ms |
908 KB |
Output is correct |
17 |
Correct |
61 ms |
960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
493 ms |
684 KB |
Output is correct |
2 |
Correct |
423 ms |
684 KB |
Output is correct |
3 |
Correct |
345 ms |
684 KB |
Output is correct |
4 |
Correct |
1 ms |
768 KB |
Output is correct |
5 |
Correct |
3 ms |
768 KB |
Output is correct |
6 |
Correct |
1 ms |
764 KB |
Output is correct |
7 |
Correct |
332 ms |
684 KB |
Output is correct |
8 |
Correct |
549 ms |
940 KB |
Output is correct |
9 |
Correct |
394 ms |
684 KB |
Output is correct |
10 |
Correct |
328 ms |
684 KB |
Output is correct |
11 |
Correct |
4 ms |
764 KB |
Output is correct |
12 |
Correct |
2 ms |
764 KB |
Output is correct |
13 |
Correct |
2 ms |
1024 KB |
Output is correct |
14 |
Correct |
3 ms |
768 KB |
Output is correct |
15 |
Correct |
0 ms |
768 KB |
Output is correct |
16 |
Correct |
340 ms |
684 KB |
Output is correct |
17 |
Correct |
322 ms |
684 KB |
Output is correct |
18 |
Correct |
284 ms |
684 KB |
Output is correct |
19 |
Correct |
288 ms |
684 KB |
Output is correct |
20 |
Correct |
323 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
325 ms |
988 KB |
Output is correct |
2 |
Correct |
268 ms |
984 KB |
Output is correct |
3 |
Correct |
540 ms |
684 KB |
Output is correct |
4 |
Correct |
432 ms |
684 KB |
Output is correct |
5 |
Correct |
353 ms |
684 KB |
Output is correct |
6 |
Correct |
259 ms |
996 KB |
Output is correct |
7 |
Correct |
240 ms |
940 KB |
Output is correct |
8 |
Correct |
1 ms |
764 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
768 KB |
Output is correct |
11 |
Correct |
248 ms |
940 KB |
Output is correct |
12 |
Correct |
334 ms |
896 KB |
Output is correct |
13 |
Correct |
540 ms |
940 KB |
Output is correct |
14 |
Correct |
390 ms |
684 KB |
Output is correct |
15 |
Correct |
327 ms |
684 KB |
Output is correct |
16 |
Correct |
272 ms |
684 KB |
Output is correct |
17 |
Correct |
421 ms |
684 KB |
Output is correct |
18 |
Correct |
256 ms |
1228 KB |
Output is correct |
19 |
Correct |
250 ms |
1408 KB |
Output is correct |
20 |
Correct |
242 ms |
684 KB |
Output is correct |
21 |
Correct |
39 ms |
768 KB |
Output is correct |
22 |
Correct |
37 ms |
936 KB |
Output is correct |
23 |
Correct |
60 ms |
1188 KB |
Output is correct |
24 |
Correct |
3 ms |
768 KB |
Output is correct |
25 |
Correct |
3 ms |
768 KB |
Output is correct |
26 |
Correct |
2 ms |
768 KB |
Output is correct |
27 |
Correct |
1 ms |
768 KB |
Output is correct |
28 |
Correct |
0 ms |
1024 KB |
Output is correct |
29 |
Correct |
279 ms |
684 KB |
Output is correct |
30 |
Correct |
368 ms |
684 KB |
Output is correct |
31 |
Correct |
287 ms |
684 KB |
Output is correct |
32 |
Correct |
267 ms |
684 KB |
Output is correct |
33 |
Correct |
344 ms |
684 KB |
Output is correct |
34 |
Correct |
189 ms |
976 KB |
Output is correct |
35 |
Correct |
252 ms |
1428 KB |
Output is correct |
36 |
Correct |
248 ms |
988 KB |
Output is correct |
37 |
Correct |
246 ms |
1376 KB |
Output is correct |
38 |
Correct |
260 ms |
1140 KB |
Output is correct |
39 |
Correct |
241 ms |
1228 KB |
Output is correct |
40 |
Correct |
273 ms |
1232 KB |
Output is correct |
41 |
Correct |
300 ms |
1128 KB |
Output is correct |
42 |
Correct |
36 ms |
1008 KB |
Output is correct |
43 |
Correct |
59 ms |
944 KB |
Output is correct |
44 |
Correct |
68 ms |
964 KB |
Output is correct |
45 |
Correct |
87 ms |
1008 KB |
Output is correct |
46 |
Correct |
175 ms |
928 KB |
Output is correct |
47 |
Correct |
167 ms |
960 KB |
Output is correct |
48 |
Correct |
32 ms |
1300 KB |
Output is correct |
49 |
Correct |
36 ms |
1764 KB |
Output is correct |