#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int INF=1e9;
const int MAXN=3e5+10;
vector<int>adj1[MAXN],adj2[MAXN];
vector<int>v1[MAXN],v2[MAXN];
int min1[MAXN],max1[MAXN],min2[MAXN],max2[MAXN];
bool vi[MAXN];
int N1,N2,K,i,j;
int pa1[MAXN],pa2[MAXN];
int chk[MAXN];
int cnt;
int csize(vector<int>V1,vector<int>V2)
{
cnt++;
int i;
for(i=0;i<V1.size();i++)
chk[V1[i]]=cnt;
int c=0;
for(i=0;i<V2.size();i++)
if(chk[V2[i]]==cnt)
c++;
return c;
}
void pc1(int h,int s)
{
adj1[pa1[h]].push_back(h);
if(vi[h])
return;
vi[h]=true;
if(pa1[h]!=-1)
pc1(pa1[h],s);
return;
}
void pc2(int h,int s)
{
adj2[pa2[h]].push_back(h);
if(vi[h])
return;
vi[h]=true;
if(pa2[h]!=-1)
pc2(pa2[h],s);
return;
}
void pc3(int h,int t)
{
v1[h].push_back(t);
if(pa1[h]!=-1)
pc3(pa1[h],t);
return;
}
void pc4(int h,int t)
{
v2[h].push_back(t);
if(pa2[h]!=-1)
pc4(pa2[h],t);
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>N1>>N2>>K;
for(i=0;i<N1;i++)
{
cin>>pa1[i];
pa1[i]--;
}
for(i=0;i<N2;i++)
{
cin>>pa2[i];
pa2[i]--;
}
fill(vi,vi+N1,false);
for(i=0;i<K;i++)
pc1(i,i);
fill(vi,vi+N2,false);
for(i=0;i<K;i++)
pc2(i,i);
for(i=0;i<K;i++)
pc3(i,i);
for(i=0;i<K;i++)
pc4(i,i);
for(i=0;i<N1;i++)
{
min1[i]=INF;
max1[i]=0;
for(j=0;j<v1[i].size();i++)
{
if(min1[i]>v1[i][j])
min1[i]=v1[i][j];
if(max1[i]<v1[i][j])
max1[i]=v1[i][j];
}
}
for(i=0;i<N2;i++)
{
min2[i]=INF;
max2[i]=0;
for(j=0;j<v2[i].size();i++)
{
if(min2[i]>v2[i][j])
min2[i]=v2[i][j];
if(max2[i]<v2[i][j])
max2[i]=v2[i][j];
}
}
for(i=0;i<N1;i++)
{
for(j=0;j<N2;j++)
{
if(max1[i]>=min2[j]&&max2[j]>=min1[i])
{
int co=csize(v1[i],v2[j]);
if(co>0&&co!=min(v1[i].size(),v2[j].size()))
return cout<<"NO",0;
}
}
}
cout<<"YES";
return 0;
}
Compilation message
family.cpp: In function 'int csize(std::vector<int>, std::vector<int>)':
family.cpp:19:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<V1.size();i++)
~^~~~~~~~~~
family.cpp:22:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<V2.size();i++)
~^~~~~~~~~~
family.cpp: In function 'int main()':
family.cpp:91:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=0;j<v1[i].size();i++)
~^~~~~~~~~~~~~
family.cpp:103:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=0;j<v2[i].size();i++)
~^~~~~~~~~~~~~
family.cpp:118:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(co>0&&co!=min(v1[i].size(),v2[j].size()))
~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
28536 KB |
Output is correct |
2 |
Correct |
26 ms |
28648 KB |
Output is correct |
3 |
Correct |
25 ms |
28684 KB |
Output is correct |
4 |
Correct |
26 ms |
28748 KB |
Output is correct |
5 |
Correct |
26 ms |
28796 KB |
Output is correct |
6 |
Correct |
28 ms |
28796 KB |
Output is correct |
7 |
Correct |
31 ms |
28808 KB |
Output is correct |
8 |
Correct |
30 ms |
28980 KB |
Output is correct |
9 |
Correct |
30 ms |
28980 KB |
Output is correct |
10 |
Correct |
34 ms |
28980 KB |
Output is correct |
11 |
Correct |
28 ms |
28980 KB |
Output is correct |
12 |
Correct |
31 ms |
28980 KB |
Output is correct |
13 |
Correct |
35 ms |
28980 KB |
Output is correct |
14 |
Correct |
42 ms |
28980 KB |
Output is correct |
15 |
Correct |
35 ms |
28980 KB |
Output is correct |
16 |
Correct |
42 ms |
28980 KB |
Output is correct |
17 |
Correct |
30 ms |
28980 KB |
Output is correct |
18 |
Correct |
35 ms |
28980 KB |
Output is correct |
19 |
Correct |
29 ms |
28980 KB |
Output is correct |
20 |
Correct |
33 ms |
28980 KB |
Output is correct |
21 |
Correct |
36 ms |
28980 KB |
Output is correct |
22 |
Correct |
27 ms |
28980 KB |
Output is correct |
23 |
Correct |
28 ms |
28980 KB |
Output is correct |
24 |
Correct |
27 ms |
28980 KB |
Output is correct |
25 |
Correct |
30 ms |
28980 KB |
Output is correct |
26 |
Correct |
33 ms |
28980 KB |
Output is correct |
27 |
Correct |
32 ms |
28980 KB |
Output is correct |
28 |
Correct |
33 ms |
28980 KB |
Output is correct |
29 |
Correct |
30 ms |
28980 KB |
Output is correct |
30 |
Correct |
27 ms |
28980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
28536 KB |
Output is correct |
2 |
Correct |
26 ms |
28648 KB |
Output is correct |
3 |
Correct |
25 ms |
28684 KB |
Output is correct |
4 |
Correct |
26 ms |
28748 KB |
Output is correct |
5 |
Correct |
26 ms |
28796 KB |
Output is correct |
6 |
Correct |
28 ms |
28796 KB |
Output is correct |
7 |
Correct |
31 ms |
28808 KB |
Output is correct |
8 |
Correct |
30 ms |
28980 KB |
Output is correct |
9 |
Correct |
30 ms |
28980 KB |
Output is correct |
10 |
Correct |
34 ms |
28980 KB |
Output is correct |
11 |
Correct |
28 ms |
28980 KB |
Output is correct |
12 |
Correct |
31 ms |
28980 KB |
Output is correct |
13 |
Correct |
35 ms |
28980 KB |
Output is correct |
14 |
Correct |
42 ms |
28980 KB |
Output is correct |
15 |
Correct |
35 ms |
28980 KB |
Output is correct |
16 |
Correct |
42 ms |
28980 KB |
Output is correct |
17 |
Correct |
30 ms |
28980 KB |
Output is correct |
18 |
Correct |
35 ms |
28980 KB |
Output is correct |
19 |
Correct |
29 ms |
28980 KB |
Output is correct |
20 |
Correct |
33 ms |
28980 KB |
Output is correct |
21 |
Correct |
36 ms |
28980 KB |
Output is correct |
22 |
Correct |
27 ms |
28980 KB |
Output is correct |
23 |
Correct |
28 ms |
28980 KB |
Output is correct |
24 |
Correct |
27 ms |
28980 KB |
Output is correct |
25 |
Correct |
30 ms |
28980 KB |
Output is correct |
26 |
Correct |
33 ms |
28980 KB |
Output is correct |
27 |
Correct |
32 ms |
28980 KB |
Output is correct |
28 |
Correct |
33 ms |
28980 KB |
Output is correct |
29 |
Correct |
30 ms |
28980 KB |
Output is correct |
30 |
Correct |
27 ms |
28980 KB |
Output is correct |
31 |
Correct |
31 ms |
28980 KB |
Output is correct |
32 |
Correct |
31 ms |
28980 KB |
Output is correct |
33 |
Correct |
30 ms |
28980 KB |
Output is correct |
34 |
Correct |
31 ms |
28980 KB |
Output is correct |
35 |
Correct |
33 ms |
28980 KB |
Output is correct |
36 |
Correct |
45 ms |
28980 KB |
Output is correct |
37 |
Correct |
32 ms |
28980 KB |
Output is correct |
38 |
Correct |
36 ms |
28980 KB |
Output is correct |
39 |
Correct |
47 ms |
28980 KB |
Output is correct |
40 |
Correct |
42 ms |
28980 KB |
Output is correct |
41 |
Correct |
30 ms |
28980 KB |
Output is correct |
42 |
Correct |
33 ms |
28980 KB |
Output is correct |
43 |
Correct |
31 ms |
28980 KB |
Output is correct |
44 |
Correct |
25 ms |
28980 KB |
Output is correct |
45 |
Correct |
31 ms |
28980 KB |
Output is correct |
46 |
Correct |
35 ms |
28980 KB |
Output is correct |
47 |
Correct |
29 ms |
28980 KB |
Output is correct |
48 |
Correct |
34 ms |
28980 KB |
Output is correct |
49 |
Correct |
29 ms |
28980 KB |
Output is correct |
50 |
Correct |
27 ms |
28980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
28536 KB |
Output is correct |
2 |
Correct |
26 ms |
28648 KB |
Output is correct |
3 |
Correct |
25 ms |
28684 KB |
Output is correct |
4 |
Correct |
26 ms |
28748 KB |
Output is correct |
5 |
Correct |
26 ms |
28796 KB |
Output is correct |
6 |
Correct |
28 ms |
28796 KB |
Output is correct |
7 |
Correct |
31 ms |
28808 KB |
Output is correct |
8 |
Correct |
30 ms |
28980 KB |
Output is correct |
9 |
Correct |
30 ms |
28980 KB |
Output is correct |
10 |
Correct |
34 ms |
28980 KB |
Output is correct |
11 |
Correct |
28 ms |
28980 KB |
Output is correct |
12 |
Correct |
31 ms |
28980 KB |
Output is correct |
13 |
Correct |
35 ms |
28980 KB |
Output is correct |
14 |
Correct |
42 ms |
28980 KB |
Output is correct |
15 |
Correct |
35 ms |
28980 KB |
Output is correct |
16 |
Correct |
42 ms |
28980 KB |
Output is correct |
17 |
Correct |
30 ms |
28980 KB |
Output is correct |
18 |
Correct |
35 ms |
28980 KB |
Output is correct |
19 |
Correct |
29 ms |
28980 KB |
Output is correct |
20 |
Correct |
33 ms |
28980 KB |
Output is correct |
21 |
Correct |
36 ms |
28980 KB |
Output is correct |
22 |
Correct |
27 ms |
28980 KB |
Output is correct |
23 |
Correct |
28 ms |
28980 KB |
Output is correct |
24 |
Correct |
27 ms |
28980 KB |
Output is correct |
25 |
Correct |
30 ms |
28980 KB |
Output is correct |
26 |
Correct |
33 ms |
28980 KB |
Output is correct |
27 |
Correct |
32 ms |
28980 KB |
Output is correct |
28 |
Correct |
33 ms |
28980 KB |
Output is correct |
29 |
Correct |
30 ms |
28980 KB |
Output is correct |
30 |
Correct |
27 ms |
28980 KB |
Output is correct |
31 |
Correct |
31 ms |
28980 KB |
Output is correct |
32 |
Correct |
31 ms |
28980 KB |
Output is correct |
33 |
Correct |
30 ms |
28980 KB |
Output is correct |
34 |
Correct |
31 ms |
28980 KB |
Output is correct |
35 |
Correct |
33 ms |
28980 KB |
Output is correct |
36 |
Correct |
45 ms |
28980 KB |
Output is correct |
37 |
Correct |
32 ms |
28980 KB |
Output is correct |
38 |
Correct |
36 ms |
28980 KB |
Output is correct |
39 |
Correct |
47 ms |
28980 KB |
Output is correct |
40 |
Correct |
42 ms |
28980 KB |
Output is correct |
41 |
Correct |
30 ms |
28980 KB |
Output is correct |
42 |
Correct |
33 ms |
28980 KB |
Output is correct |
43 |
Correct |
31 ms |
28980 KB |
Output is correct |
44 |
Correct |
25 ms |
28980 KB |
Output is correct |
45 |
Correct |
31 ms |
28980 KB |
Output is correct |
46 |
Correct |
35 ms |
28980 KB |
Output is correct |
47 |
Correct |
29 ms |
28980 KB |
Output is correct |
48 |
Correct |
34 ms |
28980 KB |
Output is correct |
49 |
Correct |
29 ms |
28980 KB |
Output is correct |
50 |
Correct |
27 ms |
28980 KB |
Output is correct |
51 |
Execution timed out |
3048 ms |
30464 KB |
Time limit exceeded |
52 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
28536 KB |
Output is correct |
2 |
Correct |
26 ms |
28648 KB |
Output is correct |
3 |
Correct |
25 ms |
28684 KB |
Output is correct |
4 |
Correct |
26 ms |
28748 KB |
Output is correct |
5 |
Correct |
26 ms |
28796 KB |
Output is correct |
6 |
Correct |
28 ms |
28796 KB |
Output is correct |
7 |
Correct |
31 ms |
28808 KB |
Output is correct |
8 |
Correct |
30 ms |
28980 KB |
Output is correct |
9 |
Correct |
30 ms |
28980 KB |
Output is correct |
10 |
Correct |
34 ms |
28980 KB |
Output is correct |
11 |
Correct |
28 ms |
28980 KB |
Output is correct |
12 |
Correct |
31 ms |
28980 KB |
Output is correct |
13 |
Correct |
35 ms |
28980 KB |
Output is correct |
14 |
Correct |
42 ms |
28980 KB |
Output is correct |
15 |
Correct |
35 ms |
28980 KB |
Output is correct |
16 |
Correct |
42 ms |
28980 KB |
Output is correct |
17 |
Correct |
30 ms |
28980 KB |
Output is correct |
18 |
Correct |
35 ms |
28980 KB |
Output is correct |
19 |
Correct |
29 ms |
28980 KB |
Output is correct |
20 |
Correct |
33 ms |
28980 KB |
Output is correct |
21 |
Correct |
36 ms |
28980 KB |
Output is correct |
22 |
Correct |
27 ms |
28980 KB |
Output is correct |
23 |
Correct |
28 ms |
28980 KB |
Output is correct |
24 |
Correct |
27 ms |
28980 KB |
Output is correct |
25 |
Correct |
30 ms |
28980 KB |
Output is correct |
26 |
Correct |
33 ms |
28980 KB |
Output is correct |
27 |
Correct |
32 ms |
28980 KB |
Output is correct |
28 |
Correct |
33 ms |
28980 KB |
Output is correct |
29 |
Correct |
30 ms |
28980 KB |
Output is correct |
30 |
Correct |
27 ms |
28980 KB |
Output is correct |
31 |
Correct |
31 ms |
28980 KB |
Output is correct |
32 |
Correct |
31 ms |
28980 KB |
Output is correct |
33 |
Correct |
30 ms |
28980 KB |
Output is correct |
34 |
Correct |
31 ms |
28980 KB |
Output is correct |
35 |
Correct |
33 ms |
28980 KB |
Output is correct |
36 |
Correct |
45 ms |
28980 KB |
Output is correct |
37 |
Correct |
32 ms |
28980 KB |
Output is correct |
38 |
Correct |
36 ms |
28980 KB |
Output is correct |
39 |
Correct |
47 ms |
28980 KB |
Output is correct |
40 |
Correct |
42 ms |
28980 KB |
Output is correct |
41 |
Correct |
30 ms |
28980 KB |
Output is correct |
42 |
Correct |
33 ms |
28980 KB |
Output is correct |
43 |
Correct |
31 ms |
28980 KB |
Output is correct |
44 |
Correct |
25 ms |
28980 KB |
Output is correct |
45 |
Correct |
31 ms |
28980 KB |
Output is correct |
46 |
Correct |
35 ms |
28980 KB |
Output is correct |
47 |
Correct |
29 ms |
28980 KB |
Output is correct |
48 |
Correct |
34 ms |
28980 KB |
Output is correct |
49 |
Correct |
29 ms |
28980 KB |
Output is correct |
50 |
Correct |
27 ms |
28980 KB |
Output is correct |
51 |
Execution timed out |
3048 ms |
30464 KB |
Time limit exceeded |
52 |
Halted |
0 ms |
0 KB |
- |