# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
64199 |
2018-08-03T13:36:13 Z |
gs14004 |
None (KOI18_family) |
C++17 |
|
866 ms |
100404 KB |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <deque>
#include <bitset>
#include <iostream>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int MAXN = 300005;
const int mod = 1e9 + 7;
int n, m, k;
int a[MAXN], b[MAXN];
int r1, r2;
vector<int> g1[MAXN], g2[MAXN];
int s1[MAXN], e1[MAXN], s2[MAXN], e2[MAXN];
int d1[MAXN], d2[MAXN];
int piv;
void dfs1(int x){
s1[x] = piv;
if(x <= k){
piv++;
}
for(auto &i : g1[x]){
d1[i] = d1[x] + 1;
dfs1(i);
}
e1[x] = piv;
}
void dfs2(int x){
s2[x] = piv;
if(x <= k){
piv++;
}
for(auto &i : g2[x]){
d2[i] = d2[x] + 1;
dfs2(i);
}
e2[x] = piv;
}
struct disj{
int pa[MAXN], sz[MAXN];
void init(int n){
iota(pa, pa + n + 1, 0);
fill(sz, sz + n + 1, 1);
}
int find(int x){
return pa[x] = (pa[x] == x ? x : find(pa[x]));
}
int getsz(int x){
return sz[find(x)];
}
bool uni(int p, int q){
p = find(p);
q = find(q);
if(p == q) return 0;
sz[p] += sz[q];
pa[q] = p; return 1;
}
}disj;
struct event{
int ty, l, de, pos;
bool operator<(const event &e)const{
return pi(l, -de) < pi(e.l, -e.de);
}
};
int idx1[MAXN], idx2[MAXN];
int main(){
scanf("%d %d %d",&n,&m,&k);
for(int i=1; i<=n; i++){
scanf("%d",&a[i]);
if(a[i]) g1[a[i]].push_back(i);
else r1 = i;
}
for(int i=1; i<=m; i++){
scanf("%d",&b[i]);
if(b[i]) g2[b[i]].push_back(i);
else r2 = i;
}
dfs1(r1);
piv = 0;
dfs2(r2);
disj.init(k);
vector<event> ev;
for(int i=1; i<=k; i++){
idx1[i] = i;
idx2[i] = i;
}
for(int i=k+1; i<=n; i++){
ev.push_back({1, e1[i] - s1[i], d1[i], i});
}
for(int i=k+1; i<=m; i++){
ev.push_back({2, e2[i] - s2[i], d2[i], i});
}
sort(ev.begin(), ev.end());
for(int i=0; i<ev.size(); i++){
if(ev[i].ty == 1){
idx1[ev[i].pos] = idx1[g1[ev[i].pos][0]];
for(auto &j : g1[ev[i].pos]){
disj.uni(idx1[j], idx1[ev[i].pos]);
}
if(disj.getsz(idx1[ev[i].pos]) != ev[i].l){
puts("NO");
return 0;
}
}
else{
idx2[ev[i].pos] = idx2[g2[ev[i].pos][0]];
for(auto &j : g2[ev[i].pos]){
disj.uni(idx2[j], idx2[ev[i].pos]);
}
if(disj.getsz(idx2[ev[i].pos]) != ev[i].l){
puts("NO");
return 0;
}
}
}
puts("YES");
}
Compilation message
family.cpp: In function 'int main()':
family.cpp:115:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<ev.size(); i++){
~^~~~~~~~~~
family.cpp:88:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d",&n,&m,&k);
~~~~~^~~~~~~~~~~~~~~~~~~~~
family.cpp:90:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a[i]);
~~~~~^~~~~~~~~~~~
family.cpp:95:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&b[i]);
~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
14456 KB |
Output is correct |
2 |
Correct |
15 ms |
14576 KB |
Output is correct |
3 |
Correct |
18 ms |
14688 KB |
Output is correct |
4 |
Correct |
16 ms |
14688 KB |
Output is correct |
5 |
Correct |
15 ms |
14688 KB |
Output is correct |
6 |
Correct |
18 ms |
14840 KB |
Output is correct |
7 |
Correct |
20 ms |
14888 KB |
Output is correct |
8 |
Correct |
19 ms |
14888 KB |
Output is correct |
9 |
Correct |
17 ms |
14888 KB |
Output is correct |
10 |
Correct |
19 ms |
14888 KB |
Output is correct |
11 |
Correct |
16 ms |
14888 KB |
Output is correct |
12 |
Correct |
17 ms |
14888 KB |
Output is correct |
13 |
Correct |
17 ms |
14888 KB |
Output is correct |
14 |
Correct |
17 ms |
14888 KB |
Output is correct |
15 |
Correct |
16 ms |
14888 KB |
Output is correct |
16 |
Correct |
16 ms |
14888 KB |
Output is correct |
17 |
Correct |
20 ms |
14888 KB |
Output is correct |
18 |
Correct |
16 ms |
14888 KB |
Output is correct |
19 |
Correct |
17 ms |
14888 KB |
Output is correct |
20 |
Correct |
17 ms |
14888 KB |
Output is correct |
21 |
Correct |
15 ms |
14888 KB |
Output is correct |
22 |
Correct |
16 ms |
14888 KB |
Output is correct |
23 |
Correct |
17 ms |
14888 KB |
Output is correct |
24 |
Correct |
18 ms |
14888 KB |
Output is correct |
25 |
Correct |
17 ms |
14892 KB |
Output is correct |
26 |
Correct |
15 ms |
14896 KB |
Output is correct |
27 |
Correct |
18 ms |
14900 KB |
Output is correct |
28 |
Correct |
16 ms |
14904 KB |
Output is correct |
29 |
Correct |
15 ms |
14908 KB |
Output is correct |
30 |
Correct |
16 ms |
14912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
14456 KB |
Output is correct |
2 |
Correct |
15 ms |
14576 KB |
Output is correct |
3 |
Correct |
18 ms |
14688 KB |
Output is correct |
4 |
Correct |
16 ms |
14688 KB |
Output is correct |
5 |
Correct |
15 ms |
14688 KB |
Output is correct |
6 |
Correct |
18 ms |
14840 KB |
Output is correct |
7 |
Correct |
20 ms |
14888 KB |
Output is correct |
8 |
Correct |
19 ms |
14888 KB |
Output is correct |
9 |
Correct |
17 ms |
14888 KB |
Output is correct |
10 |
Correct |
19 ms |
14888 KB |
Output is correct |
11 |
Correct |
16 ms |
14888 KB |
Output is correct |
12 |
Correct |
17 ms |
14888 KB |
Output is correct |
13 |
Correct |
17 ms |
14888 KB |
Output is correct |
14 |
Correct |
17 ms |
14888 KB |
Output is correct |
15 |
Correct |
16 ms |
14888 KB |
Output is correct |
16 |
Correct |
16 ms |
14888 KB |
Output is correct |
17 |
Correct |
20 ms |
14888 KB |
Output is correct |
18 |
Correct |
16 ms |
14888 KB |
Output is correct |
19 |
Correct |
17 ms |
14888 KB |
Output is correct |
20 |
Correct |
17 ms |
14888 KB |
Output is correct |
21 |
Correct |
15 ms |
14888 KB |
Output is correct |
22 |
Correct |
16 ms |
14888 KB |
Output is correct |
23 |
Correct |
17 ms |
14888 KB |
Output is correct |
24 |
Correct |
18 ms |
14888 KB |
Output is correct |
25 |
Correct |
17 ms |
14892 KB |
Output is correct |
26 |
Correct |
15 ms |
14896 KB |
Output is correct |
27 |
Correct |
18 ms |
14900 KB |
Output is correct |
28 |
Correct |
16 ms |
14904 KB |
Output is correct |
29 |
Correct |
15 ms |
14908 KB |
Output is correct |
30 |
Correct |
16 ms |
14912 KB |
Output is correct |
31 |
Correct |
18 ms |
14916 KB |
Output is correct |
32 |
Correct |
20 ms |
14920 KB |
Output is correct |
33 |
Correct |
16 ms |
15052 KB |
Output is correct |
34 |
Correct |
20 ms |
15052 KB |
Output is correct |
35 |
Correct |
18 ms |
15064 KB |
Output is correct |
36 |
Correct |
16 ms |
15064 KB |
Output is correct |
37 |
Correct |
19 ms |
15064 KB |
Output is correct |
38 |
Correct |
16 ms |
15064 KB |
Output is correct |
39 |
Correct |
17 ms |
15064 KB |
Output is correct |
40 |
Correct |
18 ms |
15064 KB |
Output is correct |
41 |
Correct |
19 ms |
15064 KB |
Output is correct |
42 |
Correct |
18 ms |
15064 KB |
Output is correct |
43 |
Correct |
18 ms |
15064 KB |
Output is correct |
44 |
Correct |
18 ms |
15064 KB |
Output is correct |
45 |
Correct |
18 ms |
15064 KB |
Output is correct |
46 |
Correct |
19 ms |
15120 KB |
Output is correct |
47 |
Correct |
16 ms |
15120 KB |
Output is correct |
48 |
Correct |
21 ms |
15120 KB |
Output is correct |
49 |
Correct |
18 ms |
15120 KB |
Output is correct |
50 |
Correct |
17 ms |
15120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
14456 KB |
Output is correct |
2 |
Correct |
15 ms |
14576 KB |
Output is correct |
3 |
Correct |
18 ms |
14688 KB |
Output is correct |
4 |
Correct |
16 ms |
14688 KB |
Output is correct |
5 |
Correct |
15 ms |
14688 KB |
Output is correct |
6 |
Correct |
18 ms |
14840 KB |
Output is correct |
7 |
Correct |
20 ms |
14888 KB |
Output is correct |
8 |
Correct |
19 ms |
14888 KB |
Output is correct |
9 |
Correct |
17 ms |
14888 KB |
Output is correct |
10 |
Correct |
19 ms |
14888 KB |
Output is correct |
11 |
Correct |
16 ms |
14888 KB |
Output is correct |
12 |
Correct |
17 ms |
14888 KB |
Output is correct |
13 |
Correct |
17 ms |
14888 KB |
Output is correct |
14 |
Correct |
17 ms |
14888 KB |
Output is correct |
15 |
Correct |
16 ms |
14888 KB |
Output is correct |
16 |
Correct |
16 ms |
14888 KB |
Output is correct |
17 |
Correct |
20 ms |
14888 KB |
Output is correct |
18 |
Correct |
16 ms |
14888 KB |
Output is correct |
19 |
Correct |
17 ms |
14888 KB |
Output is correct |
20 |
Correct |
17 ms |
14888 KB |
Output is correct |
21 |
Correct |
15 ms |
14888 KB |
Output is correct |
22 |
Correct |
16 ms |
14888 KB |
Output is correct |
23 |
Correct |
17 ms |
14888 KB |
Output is correct |
24 |
Correct |
18 ms |
14888 KB |
Output is correct |
25 |
Correct |
17 ms |
14892 KB |
Output is correct |
26 |
Correct |
15 ms |
14896 KB |
Output is correct |
27 |
Correct |
18 ms |
14900 KB |
Output is correct |
28 |
Correct |
16 ms |
14904 KB |
Output is correct |
29 |
Correct |
15 ms |
14908 KB |
Output is correct |
30 |
Correct |
16 ms |
14912 KB |
Output is correct |
31 |
Correct |
18 ms |
14916 KB |
Output is correct |
32 |
Correct |
20 ms |
14920 KB |
Output is correct |
33 |
Correct |
16 ms |
15052 KB |
Output is correct |
34 |
Correct |
20 ms |
15052 KB |
Output is correct |
35 |
Correct |
18 ms |
15064 KB |
Output is correct |
36 |
Correct |
16 ms |
15064 KB |
Output is correct |
37 |
Correct |
19 ms |
15064 KB |
Output is correct |
38 |
Correct |
16 ms |
15064 KB |
Output is correct |
39 |
Correct |
17 ms |
15064 KB |
Output is correct |
40 |
Correct |
18 ms |
15064 KB |
Output is correct |
41 |
Correct |
19 ms |
15064 KB |
Output is correct |
42 |
Correct |
18 ms |
15064 KB |
Output is correct |
43 |
Correct |
18 ms |
15064 KB |
Output is correct |
44 |
Correct |
18 ms |
15064 KB |
Output is correct |
45 |
Correct |
18 ms |
15064 KB |
Output is correct |
46 |
Correct |
19 ms |
15120 KB |
Output is correct |
47 |
Correct |
16 ms |
15120 KB |
Output is correct |
48 |
Correct |
21 ms |
15120 KB |
Output is correct |
49 |
Correct |
18 ms |
15120 KB |
Output is correct |
50 |
Correct |
17 ms |
15120 KB |
Output is correct |
51 |
Correct |
22 ms |
15396 KB |
Output is correct |
52 |
Correct |
24 ms |
15564 KB |
Output is correct |
53 |
Correct |
18 ms |
15744 KB |
Output is correct |
54 |
Correct |
17 ms |
15744 KB |
Output is correct |
55 |
Correct |
19 ms |
15744 KB |
Output is correct |
56 |
Correct |
18 ms |
15744 KB |
Output is correct |
57 |
Correct |
25 ms |
15744 KB |
Output is correct |
58 |
Correct |
18 ms |
15808 KB |
Output is correct |
59 |
Correct |
21 ms |
15940 KB |
Output is correct |
60 |
Correct |
27 ms |
15940 KB |
Output is correct |
61 |
Correct |
21 ms |
16244 KB |
Output is correct |
62 |
Correct |
19 ms |
16296 KB |
Output is correct |
63 |
Correct |
18 ms |
16296 KB |
Output is correct |
64 |
Correct |
18 ms |
16296 KB |
Output is correct |
65 |
Correct |
16 ms |
16296 KB |
Output is correct |
66 |
Correct |
19 ms |
16296 KB |
Output is correct |
67 |
Correct |
23 ms |
16296 KB |
Output is correct |
68 |
Correct |
24 ms |
16296 KB |
Output is correct |
69 |
Correct |
23 ms |
16336 KB |
Output is correct |
70 |
Correct |
20 ms |
16388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
14456 KB |
Output is correct |
2 |
Correct |
15 ms |
14576 KB |
Output is correct |
3 |
Correct |
18 ms |
14688 KB |
Output is correct |
4 |
Correct |
16 ms |
14688 KB |
Output is correct |
5 |
Correct |
15 ms |
14688 KB |
Output is correct |
6 |
Correct |
18 ms |
14840 KB |
Output is correct |
7 |
Correct |
20 ms |
14888 KB |
Output is correct |
8 |
Correct |
19 ms |
14888 KB |
Output is correct |
9 |
Correct |
17 ms |
14888 KB |
Output is correct |
10 |
Correct |
19 ms |
14888 KB |
Output is correct |
11 |
Correct |
16 ms |
14888 KB |
Output is correct |
12 |
Correct |
17 ms |
14888 KB |
Output is correct |
13 |
Correct |
17 ms |
14888 KB |
Output is correct |
14 |
Correct |
17 ms |
14888 KB |
Output is correct |
15 |
Correct |
16 ms |
14888 KB |
Output is correct |
16 |
Correct |
16 ms |
14888 KB |
Output is correct |
17 |
Correct |
20 ms |
14888 KB |
Output is correct |
18 |
Correct |
16 ms |
14888 KB |
Output is correct |
19 |
Correct |
17 ms |
14888 KB |
Output is correct |
20 |
Correct |
17 ms |
14888 KB |
Output is correct |
21 |
Correct |
15 ms |
14888 KB |
Output is correct |
22 |
Correct |
16 ms |
14888 KB |
Output is correct |
23 |
Correct |
17 ms |
14888 KB |
Output is correct |
24 |
Correct |
18 ms |
14888 KB |
Output is correct |
25 |
Correct |
17 ms |
14892 KB |
Output is correct |
26 |
Correct |
15 ms |
14896 KB |
Output is correct |
27 |
Correct |
18 ms |
14900 KB |
Output is correct |
28 |
Correct |
16 ms |
14904 KB |
Output is correct |
29 |
Correct |
15 ms |
14908 KB |
Output is correct |
30 |
Correct |
16 ms |
14912 KB |
Output is correct |
31 |
Correct |
18 ms |
14916 KB |
Output is correct |
32 |
Correct |
20 ms |
14920 KB |
Output is correct |
33 |
Correct |
16 ms |
15052 KB |
Output is correct |
34 |
Correct |
20 ms |
15052 KB |
Output is correct |
35 |
Correct |
18 ms |
15064 KB |
Output is correct |
36 |
Correct |
16 ms |
15064 KB |
Output is correct |
37 |
Correct |
19 ms |
15064 KB |
Output is correct |
38 |
Correct |
16 ms |
15064 KB |
Output is correct |
39 |
Correct |
17 ms |
15064 KB |
Output is correct |
40 |
Correct |
18 ms |
15064 KB |
Output is correct |
41 |
Correct |
19 ms |
15064 KB |
Output is correct |
42 |
Correct |
18 ms |
15064 KB |
Output is correct |
43 |
Correct |
18 ms |
15064 KB |
Output is correct |
44 |
Correct |
18 ms |
15064 KB |
Output is correct |
45 |
Correct |
18 ms |
15064 KB |
Output is correct |
46 |
Correct |
19 ms |
15120 KB |
Output is correct |
47 |
Correct |
16 ms |
15120 KB |
Output is correct |
48 |
Correct |
21 ms |
15120 KB |
Output is correct |
49 |
Correct |
18 ms |
15120 KB |
Output is correct |
50 |
Correct |
17 ms |
15120 KB |
Output is correct |
51 |
Correct |
22 ms |
15396 KB |
Output is correct |
52 |
Correct |
24 ms |
15564 KB |
Output is correct |
53 |
Correct |
18 ms |
15744 KB |
Output is correct |
54 |
Correct |
17 ms |
15744 KB |
Output is correct |
55 |
Correct |
19 ms |
15744 KB |
Output is correct |
56 |
Correct |
18 ms |
15744 KB |
Output is correct |
57 |
Correct |
25 ms |
15744 KB |
Output is correct |
58 |
Correct |
18 ms |
15808 KB |
Output is correct |
59 |
Correct |
21 ms |
15940 KB |
Output is correct |
60 |
Correct |
27 ms |
15940 KB |
Output is correct |
61 |
Correct |
21 ms |
16244 KB |
Output is correct |
62 |
Correct |
19 ms |
16296 KB |
Output is correct |
63 |
Correct |
18 ms |
16296 KB |
Output is correct |
64 |
Correct |
18 ms |
16296 KB |
Output is correct |
65 |
Correct |
16 ms |
16296 KB |
Output is correct |
66 |
Correct |
19 ms |
16296 KB |
Output is correct |
67 |
Correct |
23 ms |
16296 KB |
Output is correct |
68 |
Correct |
24 ms |
16296 KB |
Output is correct |
69 |
Correct |
23 ms |
16336 KB |
Output is correct |
70 |
Correct |
20 ms |
16388 KB |
Output is correct |
71 |
Correct |
96 ms |
22460 KB |
Output is correct |
72 |
Correct |
89 ms |
22460 KB |
Output is correct |
73 |
Correct |
58 ms |
22460 KB |
Output is correct |
74 |
Correct |
125 ms |
25624 KB |
Output is correct |
75 |
Correct |
101 ms |
25652 KB |
Output is correct |
76 |
Correct |
841 ms |
72656 KB |
Output is correct |
77 |
Correct |
866 ms |
72656 KB |
Output is correct |
78 |
Correct |
510 ms |
72656 KB |
Output is correct |
79 |
Correct |
645 ms |
72656 KB |
Output is correct |
80 |
Correct |
782 ms |
79164 KB |
Output is correct |
81 |
Correct |
93 ms |
79164 KB |
Output is correct |
82 |
Correct |
60 ms |
79164 KB |
Output is correct |
83 |
Correct |
76 ms |
79164 KB |
Output is correct |
84 |
Correct |
104 ms |
79164 KB |
Output is correct |
85 |
Correct |
113 ms |
79164 KB |
Output is correct |
86 |
Correct |
491 ms |
79164 KB |
Output is correct |
87 |
Correct |
428 ms |
81560 KB |
Output is correct |
88 |
Correct |
478 ms |
81560 KB |
Output is correct |
89 |
Correct |
666 ms |
91052 KB |
Output is correct |
90 |
Correct |
772 ms |
100404 KB |
Output is correct |