# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
403606 |
2021-05-13T10:02:19 Z |
lyc |
None (KOI18_family) |
C++14 |
|
600 ms |
196940 KB |
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
//const int mxN = 3e5+5;
//const int mxK = 3e5+5;
const int mxN = 5005;
const int mxK = 5005;
const int inf = 1e9+5;
int K;
struct Tree {
int N;
vector<int> g[mxN];
int pa[mxN];
int dep[mxN];
int _lca[mxK][mxK];
void read() {
FOR(i,1,N){
int P; cin >> P;
g[P].push_back(i);
}
}
void dfs(int u) {
for (int& v : g[u]) {
pa[v] = u;
dep[v] = dep[u]+1;
dfs(v);
}
}
int lca(int a, int b) {
if (_lca[a][b] != -1) return _lca[a][b];
if (a == b) return a;
if (dep[a] > dep[b]) {
return _lca[a][b] = lca(pa[a],b);
} else {
return _lca[a][b] = lca(a,pa[b]);
}
}
void run() {
memset(pa,-1,sizeof pa);
dep[0] = 0;
dfs(0);
memset(_lca,-1,sizeof _lca);
}
inline int lcd(int a, int b) {
return dep[lca(a,b)];
}
} A, B;
int mn[mxN];
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> A.N >> B.N >> K;
A.read();
B.read();
A.run();
B.run();
bool die = 0;
FOR(i,1,K){
FOR(j,1,A.N) mn[j] = inf;
FOR(j,1,K) if (j != i) {
int a = A.lcd(i,j), b = B.lcd(i,j);
mn[a] = min(mn[a],b);
}
RFOR(j,A.N-1,1) mn[j] = min(mn[j+1],mn[j]);
FOR(j,1,K) if (j != i) {
int a = A.lcd(i,j), b = B.lcd(i,j);
if (a < A.N) die |= b > mn[a+1];
}
}
cout << (die ? "NO" : "YES") << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
196548 KB |
Output is correct |
2 |
Correct |
80 ms |
196556 KB |
Output is correct |
3 |
Correct |
81 ms |
196612 KB |
Output is correct |
4 |
Correct |
90 ms |
196624 KB |
Output is correct |
5 |
Correct |
86 ms |
196548 KB |
Output is correct |
6 |
Correct |
79 ms |
196600 KB |
Output is correct |
7 |
Correct |
81 ms |
196648 KB |
Output is correct |
8 |
Correct |
80 ms |
196620 KB |
Output is correct |
9 |
Correct |
80 ms |
196584 KB |
Output is correct |
10 |
Correct |
81 ms |
196632 KB |
Output is correct |
11 |
Correct |
88 ms |
196664 KB |
Output is correct |
12 |
Correct |
80 ms |
196676 KB |
Output is correct |
13 |
Correct |
82 ms |
196648 KB |
Output is correct |
14 |
Correct |
80 ms |
196644 KB |
Output is correct |
15 |
Correct |
82 ms |
196676 KB |
Output is correct |
16 |
Correct |
91 ms |
196564 KB |
Output is correct |
17 |
Correct |
85 ms |
196656 KB |
Output is correct |
18 |
Correct |
81 ms |
196664 KB |
Output is correct |
19 |
Correct |
82 ms |
196628 KB |
Output is correct |
20 |
Correct |
93 ms |
196556 KB |
Output is correct |
21 |
Correct |
81 ms |
196552 KB |
Output is correct |
22 |
Correct |
81 ms |
196636 KB |
Output is correct |
23 |
Correct |
82 ms |
196580 KB |
Output is correct |
24 |
Correct |
81 ms |
196548 KB |
Output is correct |
25 |
Correct |
80 ms |
196612 KB |
Output is correct |
26 |
Correct |
80 ms |
196584 KB |
Output is correct |
27 |
Correct |
85 ms |
196608 KB |
Output is correct |
28 |
Correct |
79 ms |
196556 KB |
Output is correct |
29 |
Correct |
83 ms |
196572 KB |
Output is correct |
30 |
Correct |
81 ms |
196696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
196548 KB |
Output is correct |
2 |
Correct |
80 ms |
196556 KB |
Output is correct |
3 |
Correct |
81 ms |
196612 KB |
Output is correct |
4 |
Correct |
90 ms |
196624 KB |
Output is correct |
5 |
Correct |
86 ms |
196548 KB |
Output is correct |
6 |
Correct |
79 ms |
196600 KB |
Output is correct |
7 |
Correct |
81 ms |
196648 KB |
Output is correct |
8 |
Correct |
80 ms |
196620 KB |
Output is correct |
9 |
Correct |
80 ms |
196584 KB |
Output is correct |
10 |
Correct |
81 ms |
196632 KB |
Output is correct |
11 |
Correct |
88 ms |
196664 KB |
Output is correct |
12 |
Correct |
80 ms |
196676 KB |
Output is correct |
13 |
Correct |
82 ms |
196648 KB |
Output is correct |
14 |
Correct |
80 ms |
196644 KB |
Output is correct |
15 |
Correct |
82 ms |
196676 KB |
Output is correct |
16 |
Correct |
91 ms |
196564 KB |
Output is correct |
17 |
Correct |
85 ms |
196656 KB |
Output is correct |
18 |
Correct |
81 ms |
196664 KB |
Output is correct |
19 |
Correct |
82 ms |
196628 KB |
Output is correct |
20 |
Correct |
93 ms |
196556 KB |
Output is correct |
21 |
Correct |
81 ms |
196552 KB |
Output is correct |
22 |
Correct |
81 ms |
196636 KB |
Output is correct |
23 |
Correct |
82 ms |
196580 KB |
Output is correct |
24 |
Correct |
81 ms |
196548 KB |
Output is correct |
25 |
Correct |
80 ms |
196612 KB |
Output is correct |
26 |
Correct |
80 ms |
196584 KB |
Output is correct |
27 |
Correct |
85 ms |
196608 KB |
Output is correct |
28 |
Correct |
79 ms |
196556 KB |
Output is correct |
29 |
Correct |
83 ms |
196572 KB |
Output is correct |
30 |
Correct |
81 ms |
196696 KB |
Output is correct |
31 |
Correct |
81 ms |
196624 KB |
Output is correct |
32 |
Correct |
81 ms |
196632 KB |
Output is correct |
33 |
Correct |
89 ms |
196632 KB |
Output is correct |
34 |
Correct |
88 ms |
196644 KB |
Output is correct |
35 |
Correct |
82 ms |
196684 KB |
Output is correct |
36 |
Correct |
85 ms |
196652 KB |
Output is correct |
37 |
Correct |
79 ms |
196636 KB |
Output is correct |
38 |
Correct |
81 ms |
196656 KB |
Output is correct |
39 |
Correct |
81 ms |
196612 KB |
Output is correct |
40 |
Correct |
101 ms |
196676 KB |
Output is correct |
41 |
Correct |
80 ms |
196580 KB |
Output is correct |
42 |
Correct |
79 ms |
196552 KB |
Output is correct |
43 |
Correct |
80 ms |
196572 KB |
Output is correct |
44 |
Correct |
82 ms |
196548 KB |
Output is correct |
45 |
Correct |
81 ms |
196612 KB |
Output is correct |
46 |
Correct |
81 ms |
196628 KB |
Output is correct |
47 |
Correct |
79 ms |
196656 KB |
Output is correct |
48 |
Correct |
85 ms |
196548 KB |
Output is correct |
49 |
Correct |
81 ms |
196676 KB |
Output is correct |
50 |
Correct |
82 ms |
196620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
196548 KB |
Output is correct |
2 |
Correct |
80 ms |
196556 KB |
Output is correct |
3 |
Correct |
81 ms |
196612 KB |
Output is correct |
4 |
Correct |
90 ms |
196624 KB |
Output is correct |
5 |
Correct |
86 ms |
196548 KB |
Output is correct |
6 |
Correct |
79 ms |
196600 KB |
Output is correct |
7 |
Correct |
81 ms |
196648 KB |
Output is correct |
8 |
Correct |
80 ms |
196620 KB |
Output is correct |
9 |
Correct |
80 ms |
196584 KB |
Output is correct |
10 |
Correct |
81 ms |
196632 KB |
Output is correct |
11 |
Correct |
88 ms |
196664 KB |
Output is correct |
12 |
Correct |
80 ms |
196676 KB |
Output is correct |
13 |
Correct |
82 ms |
196648 KB |
Output is correct |
14 |
Correct |
80 ms |
196644 KB |
Output is correct |
15 |
Correct |
82 ms |
196676 KB |
Output is correct |
16 |
Correct |
91 ms |
196564 KB |
Output is correct |
17 |
Correct |
85 ms |
196656 KB |
Output is correct |
18 |
Correct |
81 ms |
196664 KB |
Output is correct |
19 |
Correct |
82 ms |
196628 KB |
Output is correct |
20 |
Correct |
93 ms |
196556 KB |
Output is correct |
21 |
Correct |
81 ms |
196552 KB |
Output is correct |
22 |
Correct |
81 ms |
196636 KB |
Output is correct |
23 |
Correct |
82 ms |
196580 KB |
Output is correct |
24 |
Correct |
81 ms |
196548 KB |
Output is correct |
25 |
Correct |
80 ms |
196612 KB |
Output is correct |
26 |
Correct |
80 ms |
196584 KB |
Output is correct |
27 |
Correct |
85 ms |
196608 KB |
Output is correct |
28 |
Correct |
79 ms |
196556 KB |
Output is correct |
29 |
Correct |
83 ms |
196572 KB |
Output is correct |
30 |
Correct |
81 ms |
196696 KB |
Output is correct |
31 |
Correct |
81 ms |
196624 KB |
Output is correct |
32 |
Correct |
81 ms |
196632 KB |
Output is correct |
33 |
Correct |
89 ms |
196632 KB |
Output is correct |
34 |
Correct |
88 ms |
196644 KB |
Output is correct |
35 |
Correct |
82 ms |
196684 KB |
Output is correct |
36 |
Correct |
85 ms |
196652 KB |
Output is correct |
37 |
Correct |
79 ms |
196636 KB |
Output is correct |
38 |
Correct |
81 ms |
196656 KB |
Output is correct |
39 |
Correct |
81 ms |
196612 KB |
Output is correct |
40 |
Correct |
101 ms |
196676 KB |
Output is correct |
41 |
Correct |
80 ms |
196580 KB |
Output is correct |
42 |
Correct |
79 ms |
196552 KB |
Output is correct |
43 |
Correct |
80 ms |
196572 KB |
Output is correct |
44 |
Correct |
82 ms |
196548 KB |
Output is correct |
45 |
Correct |
81 ms |
196612 KB |
Output is correct |
46 |
Correct |
81 ms |
196628 KB |
Output is correct |
47 |
Correct |
79 ms |
196656 KB |
Output is correct |
48 |
Correct |
85 ms |
196548 KB |
Output is correct |
49 |
Correct |
81 ms |
196676 KB |
Output is correct |
50 |
Correct |
82 ms |
196620 KB |
Output is correct |
51 |
Correct |
600 ms |
196692 KB |
Output is correct |
52 |
Correct |
514 ms |
196804 KB |
Output is correct |
53 |
Correct |
375 ms |
196864 KB |
Output is correct |
54 |
Correct |
316 ms |
196804 KB |
Output is correct |
55 |
Correct |
584 ms |
196772 KB |
Output is correct |
56 |
Correct |
568 ms |
196676 KB |
Output is correct |
57 |
Correct |
438 ms |
196876 KB |
Output is correct |
58 |
Correct |
398 ms |
196804 KB |
Output is correct |
59 |
Correct |
573 ms |
196920 KB |
Output is correct |
60 |
Correct |
515 ms |
196768 KB |
Output is correct |
61 |
Correct |
393 ms |
196940 KB |
Output is correct |
62 |
Correct |
395 ms |
196940 KB |
Output is correct |
63 |
Correct |
446 ms |
196676 KB |
Output is correct |
64 |
Correct |
157 ms |
196676 KB |
Output is correct |
65 |
Correct |
81 ms |
196688 KB |
Output is correct |
66 |
Correct |
456 ms |
196812 KB |
Output is correct |
67 |
Correct |
575 ms |
196784 KB |
Output is correct |
68 |
Correct |
195 ms |
196804 KB |
Output is correct |
69 |
Correct |
435 ms |
196832 KB |
Output is correct |
70 |
Correct |
469 ms |
196780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
196548 KB |
Output is correct |
2 |
Correct |
80 ms |
196556 KB |
Output is correct |
3 |
Correct |
81 ms |
196612 KB |
Output is correct |
4 |
Correct |
90 ms |
196624 KB |
Output is correct |
5 |
Correct |
86 ms |
196548 KB |
Output is correct |
6 |
Correct |
79 ms |
196600 KB |
Output is correct |
7 |
Correct |
81 ms |
196648 KB |
Output is correct |
8 |
Correct |
80 ms |
196620 KB |
Output is correct |
9 |
Correct |
80 ms |
196584 KB |
Output is correct |
10 |
Correct |
81 ms |
196632 KB |
Output is correct |
11 |
Correct |
88 ms |
196664 KB |
Output is correct |
12 |
Correct |
80 ms |
196676 KB |
Output is correct |
13 |
Correct |
82 ms |
196648 KB |
Output is correct |
14 |
Correct |
80 ms |
196644 KB |
Output is correct |
15 |
Correct |
82 ms |
196676 KB |
Output is correct |
16 |
Correct |
91 ms |
196564 KB |
Output is correct |
17 |
Correct |
85 ms |
196656 KB |
Output is correct |
18 |
Correct |
81 ms |
196664 KB |
Output is correct |
19 |
Correct |
82 ms |
196628 KB |
Output is correct |
20 |
Correct |
93 ms |
196556 KB |
Output is correct |
21 |
Correct |
81 ms |
196552 KB |
Output is correct |
22 |
Correct |
81 ms |
196636 KB |
Output is correct |
23 |
Correct |
82 ms |
196580 KB |
Output is correct |
24 |
Correct |
81 ms |
196548 KB |
Output is correct |
25 |
Correct |
80 ms |
196612 KB |
Output is correct |
26 |
Correct |
80 ms |
196584 KB |
Output is correct |
27 |
Correct |
85 ms |
196608 KB |
Output is correct |
28 |
Correct |
79 ms |
196556 KB |
Output is correct |
29 |
Correct |
83 ms |
196572 KB |
Output is correct |
30 |
Correct |
81 ms |
196696 KB |
Output is correct |
31 |
Correct |
81 ms |
196624 KB |
Output is correct |
32 |
Correct |
81 ms |
196632 KB |
Output is correct |
33 |
Correct |
89 ms |
196632 KB |
Output is correct |
34 |
Correct |
88 ms |
196644 KB |
Output is correct |
35 |
Correct |
82 ms |
196684 KB |
Output is correct |
36 |
Correct |
85 ms |
196652 KB |
Output is correct |
37 |
Correct |
79 ms |
196636 KB |
Output is correct |
38 |
Correct |
81 ms |
196656 KB |
Output is correct |
39 |
Correct |
81 ms |
196612 KB |
Output is correct |
40 |
Correct |
101 ms |
196676 KB |
Output is correct |
41 |
Correct |
80 ms |
196580 KB |
Output is correct |
42 |
Correct |
79 ms |
196552 KB |
Output is correct |
43 |
Correct |
80 ms |
196572 KB |
Output is correct |
44 |
Correct |
82 ms |
196548 KB |
Output is correct |
45 |
Correct |
81 ms |
196612 KB |
Output is correct |
46 |
Correct |
81 ms |
196628 KB |
Output is correct |
47 |
Correct |
79 ms |
196656 KB |
Output is correct |
48 |
Correct |
85 ms |
196548 KB |
Output is correct |
49 |
Correct |
81 ms |
196676 KB |
Output is correct |
50 |
Correct |
82 ms |
196620 KB |
Output is correct |
51 |
Correct |
600 ms |
196692 KB |
Output is correct |
52 |
Correct |
514 ms |
196804 KB |
Output is correct |
53 |
Correct |
375 ms |
196864 KB |
Output is correct |
54 |
Correct |
316 ms |
196804 KB |
Output is correct |
55 |
Correct |
584 ms |
196772 KB |
Output is correct |
56 |
Correct |
568 ms |
196676 KB |
Output is correct |
57 |
Correct |
438 ms |
196876 KB |
Output is correct |
58 |
Correct |
398 ms |
196804 KB |
Output is correct |
59 |
Correct |
573 ms |
196920 KB |
Output is correct |
60 |
Correct |
515 ms |
196768 KB |
Output is correct |
61 |
Correct |
393 ms |
196940 KB |
Output is correct |
62 |
Correct |
395 ms |
196940 KB |
Output is correct |
63 |
Correct |
446 ms |
196676 KB |
Output is correct |
64 |
Correct |
157 ms |
196676 KB |
Output is correct |
65 |
Correct |
81 ms |
196688 KB |
Output is correct |
66 |
Correct |
456 ms |
196812 KB |
Output is correct |
67 |
Correct |
575 ms |
196784 KB |
Output is correct |
68 |
Correct |
195 ms |
196804 KB |
Output is correct |
69 |
Correct |
435 ms |
196832 KB |
Output is correct |
70 |
Correct |
469 ms |
196780 KB |
Output is correct |
71 |
Runtime error |
29 ms |
8908 KB |
Execution killed with signal 11 |
72 |
Halted |
0 ms |
0 KB |
- |