# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
403461 |
2021-05-13T07:58:14 Z |
lyc |
None (KOI18_family) |
C++14 |
|
3000 ms |
196892 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;
int K;
struct Tree {
int N;
vector<int> g[mxN];
int pa[mxN][14];
int _lca[mxK][mxK];
int dep[mxN];
void read() {
FOR(i,1,N){
int P; cin >> P;
g[P].push_back(i);
}
}
void dfs(int u) {
FOR(k,1,13) pa[u][k] = (pa[u][k-1] == -1 ? -1 : pa[pa[u][k-1]][k-1]);
for (int& v : g[u]) {
pa[v][0] = u;
dep[v] = dep[u]+1;
dfs(v);
}
}
int lca(int a, int b) {
if (dep[a] < dep[b]) swap(a,b);
RFOR(k,13,0) if (pa[a][k] != -1 && dep[pa[a][k]] >= dep[b]) {
a = pa[a][k];
}
if (a == b) return a;
RFOR(k,13,0) if (pa[a][k] != pa[b][k]) {
a = pa[a][k], b = pa[b][k];
}
return pa[a][0];
}
void run() {
memset(pa,-1,sizeof pa);
dep[0] = 0;
dfs(0);
FOR(i,1,N){
FOR(j,i+1,N){
_lca[i][j] = _lca[j][i] = dep[lca(i,j)];
}
}
}
int cmp(int i, int j, int k) {
if (_lca[i][j] == _lca[j][k]) return 0;
return _lca[i][j] < _lca[j][k] ? -1 : 1;
}
} A, B;
bool chk(int i, int j, int k) {
int x = A.cmp(i,j,k), y = B.cmp(i,j,k);
if (x == 0 || y == 0) return 0;
return ((x < 0) ^ (y < 0));
}
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,i+1,K){
FOR(k,j+1,K){
die |= chk(i,j,k);
die |= chk(i,k,j);
die |= chk(j,i,k);
}
}
}
cout << (die ? "NO" : "YES") << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1356 KB |
Output is correct |
3 |
Correct |
1 ms |
1356 KB |
Output is correct |
4 |
Correct |
2 ms |
1484 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
2 ms |
1484 KB |
Output is correct |
7 |
Correct |
1 ms |
1484 KB |
Output is correct |
8 |
Correct |
2 ms |
1356 KB |
Output is correct |
9 |
Correct |
2 ms |
1484 KB |
Output is correct |
10 |
Correct |
1 ms |
1356 KB |
Output is correct |
11 |
Correct |
2 ms |
1484 KB |
Output is correct |
12 |
Correct |
2 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1356 KB |
Output is correct |
14 |
Correct |
12 ms |
3916 KB |
Output is correct |
15 |
Correct |
10 ms |
3856 KB |
Output is correct |
16 |
Correct |
12 ms |
3916 KB |
Output is correct |
17 |
Correct |
9 ms |
3300 KB |
Output is correct |
18 |
Correct |
7 ms |
3020 KB |
Output is correct |
19 |
Correct |
12 ms |
3948 KB |
Output is correct |
20 |
Correct |
10 ms |
3916 KB |
Output is correct |
21 |
Correct |
13 ms |
3916 KB |
Output is correct |
22 |
Correct |
8 ms |
3276 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
6 ms |
3020 KB |
Output is correct |
25 |
Correct |
1 ms |
1100 KB |
Output is correct |
26 |
Correct |
2 ms |
1484 KB |
Output is correct |
27 |
Correct |
2 ms |
1228 KB |
Output is correct |
28 |
Correct |
1 ms |
1356 KB |
Output is correct |
29 |
Correct |
1 ms |
1484 KB |
Output is correct |
30 |
Correct |
3 ms |
1484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1356 KB |
Output is correct |
3 |
Correct |
1 ms |
1356 KB |
Output is correct |
4 |
Correct |
2 ms |
1484 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
2 ms |
1484 KB |
Output is correct |
7 |
Correct |
1 ms |
1484 KB |
Output is correct |
8 |
Correct |
2 ms |
1356 KB |
Output is correct |
9 |
Correct |
2 ms |
1484 KB |
Output is correct |
10 |
Correct |
1 ms |
1356 KB |
Output is correct |
11 |
Correct |
2 ms |
1484 KB |
Output is correct |
12 |
Correct |
2 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1356 KB |
Output is correct |
14 |
Correct |
12 ms |
3916 KB |
Output is correct |
15 |
Correct |
10 ms |
3856 KB |
Output is correct |
16 |
Correct |
12 ms |
3916 KB |
Output is correct |
17 |
Correct |
9 ms |
3300 KB |
Output is correct |
18 |
Correct |
7 ms |
3020 KB |
Output is correct |
19 |
Correct |
12 ms |
3948 KB |
Output is correct |
20 |
Correct |
10 ms |
3916 KB |
Output is correct |
21 |
Correct |
13 ms |
3916 KB |
Output is correct |
22 |
Correct |
8 ms |
3276 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
6 ms |
3020 KB |
Output is correct |
25 |
Correct |
1 ms |
1100 KB |
Output is correct |
26 |
Correct |
2 ms |
1484 KB |
Output is correct |
27 |
Correct |
2 ms |
1228 KB |
Output is correct |
28 |
Correct |
1 ms |
1356 KB |
Output is correct |
29 |
Correct |
1 ms |
1484 KB |
Output is correct |
30 |
Correct |
3 ms |
1484 KB |
Output is correct |
31 |
Correct |
1 ms |
1356 KB |
Output is correct |
32 |
Correct |
1 ms |
1356 KB |
Output is correct |
33 |
Correct |
2 ms |
1484 KB |
Output is correct |
34 |
Correct |
2 ms |
1316 KB |
Output is correct |
35 |
Correct |
1 ms |
1228 KB |
Output is correct |
36 |
Correct |
21 ms |
3440 KB |
Output is correct |
37 |
Correct |
7 ms |
3020 KB |
Output is correct |
38 |
Correct |
19 ms |
3788 KB |
Output is correct |
39 |
Correct |
14 ms |
4172 KB |
Output is correct |
40 |
Correct |
11 ms |
3888 KB |
Output is correct |
41 |
Correct |
1 ms |
1356 KB |
Output is correct |
42 |
Correct |
1 ms |
1356 KB |
Output is correct |
43 |
Correct |
2 ms |
1484 KB |
Output is correct |
44 |
Correct |
2 ms |
1484 KB |
Output is correct |
45 |
Correct |
2 ms |
1356 KB |
Output is correct |
46 |
Correct |
12 ms |
3788 KB |
Output is correct |
47 |
Correct |
7 ms |
3400 KB |
Output is correct |
48 |
Correct |
102 ms |
4220 KB |
Output is correct |
49 |
Correct |
11 ms |
4180 KB |
Output is correct |
50 |
Correct |
8 ms |
3532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1356 KB |
Output is correct |
3 |
Correct |
1 ms |
1356 KB |
Output is correct |
4 |
Correct |
2 ms |
1484 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
2 ms |
1484 KB |
Output is correct |
7 |
Correct |
1 ms |
1484 KB |
Output is correct |
8 |
Correct |
2 ms |
1356 KB |
Output is correct |
9 |
Correct |
2 ms |
1484 KB |
Output is correct |
10 |
Correct |
1 ms |
1356 KB |
Output is correct |
11 |
Correct |
2 ms |
1484 KB |
Output is correct |
12 |
Correct |
2 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1356 KB |
Output is correct |
14 |
Correct |
12 ms |
3916 KB |
Output is correct |
15 |
Correct |
10 ms |
3856 KB |
Output is correct |
16 |
Correct |
12 ms |
3916 KB |
Output is correct |
17 |
Correct |
9 ms |
3300 KB |
Output is correct |
18 |
Correct |
7 ms |
3020 KB |
Output is correct |
19 |
Correct |
12 ms |
3948 KB |
Output is correct |
20 |
Correct |
10 ms |
3916 KB |
Output is correct |
21 |
Correct |
13 ms |
3916 KB |
Output is correct |
22 |
Correct |
8 ms |
3276 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
6 ms |
3020 KB |
Output is correct |
25 |
Correct |
1 ms |
1100 KB |
Output is correct |
26 |
Correct |
2 ms |
1484 KB |
Output is correct |
27 |
Correct |
2 ms |
1228 KB |
Output is correct |
28 |
Correct |
1 ms |
1356 KB |
Output is correct |
29 |
Correct |
1 ms |
1484 KB |
Output is correct |
30 |
Correct |
3 ms |
1484 KB |
Output is correct |
31 |
Correct |
1 ms |
1356 KB |
Output is correct |
32 |
Correct |
1 ms |
1356 KB |
Output is correct |
33 |
Correct |
2 ms |
1484 KB |
Output is correct |
34 |
Correct |
2 ms |
1316 KB |
Output is correct |
35 |
Correct |
1 ms |
1228 KB |
Output is correct |
36 |
Correct |
21 ms |
3440 KB |
Output is correct |
37 |
Correct |
7 ms |
3020 KB |
Output is correct |
38 |
Correct |
19 ms |
3788 KB |
Output is correct |
39 |
Correct |
14 ms |
4172 KB |
Output is correct |
40 |
Correct |
11 ms |
3888 KB |
Output is correct |
41 |
Correct |
1 ms |
1356 KB |
Output is correct |
42 |
Correct |
1 ms |
1356 KB |
Output is correct |
43 |
Correct |
2 ms |
1484 KB |
Output is correct |
44 |
Correct |
2 ms |
1484 KB |
Output is correct |
45 |
Correct |
2 ms |
1356 KB |
Output is correct |
46 |
Correct |
12 ms |
3788 KB |
Output is correct |
47 |
Correct |
7 ms |
3400 KB |
Output is correct |
48 |
Correct |
102 ms |
4220 KB |
Output is correct |
49 |
Correct |
11 ms |
4180 KB |
Output is correct |
50 |
Correct |
8 ms |
3532 KB |
Output is correct |
51 |
Execution timed out |
3099 ms |
196892 KB |
Time limit exceeded |
52 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1356 KB |
Output is correct |
3 |
Correct |
1 ms |
1356 KB |
Output is correct |
4 |
Correct |
2 ms |
1484 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
2 ms |
1484 KB |
Output is correct |
7 |
Correct |
1 ms |
1484 KB |
Output is correct |
8 |
Correct |
2 ms |
1356 KB |
Output is correct |
9 |
Correct |
2 ms |
1484 KB |
Output is correct |
10 |
Correct |
1 ms |
1356 KB |
Output is correct |
11 |
Correct |
2 ms |
1484 KB |
Output is correct |
12 |
Correct |
2 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1356 KB |
Output is correct |
14 |
Correct |
12 ms |
3916 KB |
Output is correct |
15 |
Correct |
10 ms |
3856 KB |
Output is correct |
16 |
Correct |
12 ms |
3916 KB |
Output is correct |
17 |
Correct |
9 ms |
3300 KB |
Output is correct |
18 |
Correct |
7 ms |
3020 KB |
Output is correct |
19 |
Correct |
12 ms |
3948 KB |
Output is correct |
20 |
Correct |
10 ms |
3916 KB |
Output is correct |
21 |
Correct |
13 ms |
3916 KB |
Output is correct |
22 |
Correct |
8 ms |
3276 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
6 ms |
3020 KB |
Output is correct |
25 |
Correct |
1 ms |
1100 KB |
Output is correct |
26 |
Correct |
2 ms |
1484 KB |
Output is correct |
27 |
Correct |
2 ms |
1228 KB |
Output is correct |
28 |
Correct |
1 ms |
1356 KB |
Output is correct |
29 |
Correct |
1 ms |
1484 KB |
Output is correct |
30 |
Correct |
3 ms |
1484 KB |
Output is correct |
31 |
Correct |
1 ms |
1356 KB |
Output is correct |
32 |
Correct |
1 ms |
1356 KB |
Output is correct |
33 |
Correct |
2 ms |
1484 KB |
Output is correct |
34 |
Correct |
2 ms |
1316 KB |
Output is correct |
35 |
Correct |
1 ms |
1228 KB |
Output is correct |
36 |
Correct |
21 ms |
3440 KB |
Output is correct |
37 |
Correct |
7 ms |
3020 KB |
Output is correct |
38 |
Correct |
19 ms |
3788 KB |
Output is correct |
39 |
Correct |
14 ms |
4172 KB |
Output is correct |
40 |
Correct |
11 ms |
3888 KB |
Output is correct |
41 |
Correct |
1 ms |
1356 KB |
Output is correct |
42 |
Correct |
1 ms |
1356 KB |
Output is correct |
43 |
Correct |
2 ms |
1484 KB |
Output is correct |
44 |
Correct |
2 ms |
1484 KB |
Output is correct |
45 |
Correct |
2 ms |
1356 KB |
Output is correct |
46 |
Correct |
12 ms |
3788 KB |
Output is correct |
47 |
Correct |
7 ms |
3400 KB |
Output is correct |
48 |
Correct |
102 ms |
4220 KB |
Output is correct |
49 |
Correct |
11 ms |
4180 KB |
Output is correct |
50 |
Correct |
8 ms |
3532 KB |
Output is correct |
51 |
Execution timed out |
3099 ms |
196892 KB |
Time limit exceeded |
52 |
Halted |
0 ms |
0 KB |
- |