This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*input
7 8 4
7 7 6 6 0 5 5
6 7 7 8 0 5 5 5
*/
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define f first
#define s second
#define sz(x) (int)x.size()
const int maxn=2e3+5;
vector<int> v[maxn],v2[maxn];
bool vv[maxn][maxn],vv2[maxn][maxn];
int k;
void dfs(int u){
if(u<k) vv[u][u]=1;
for(int x:v[u]){
dfs(x);
REP(j,k) if(vv[x][j]) vv[u][j]=1;
}
}
void dfs2(int u){
if(u<k) vv2[u][u]=1;
for(int x:v2[u]){
dfs2(x);
REP(j,k) if(vv2[x][j]) vv2[u][j]=1;
}
}
bool cmp(vector<int> &a,vector<int> &b){
if(sz(a)==sz(b)) return a<b;
return sz(a)<sz(b);
}
bool match[maxn];
int main(){
ios::sync_with_stdio(false),cin.tie(0);
int n,m;
cin>>n>>m>>k;
int r1,r2;
REP(i,n){
int x;
cin>>x;
--x;
if(x!=-1) v[x].pb(i);
else r1=i;
}
REP(i,m){
int x;
cin>>x;
--x;
if(x!=-1) v2[x].pb(i);
else r2=i;
}
dfs(r1),dfs2(r2);
int p=0;
REP(i,m){
vector<int> vvv;
REP(j,k) if(vv[i][j]) vvv.pb(j);
REP(j,n){
int cnt=0,c2=0;
REP(asd,k) if(vv2[j][asd]) ++cnt;
for(auto x:vvv){
if(vv2[j][x]) c2++;
}
if(c2 and c2!=min(cnt,sz(vvv))){
cout<<"NO\n";
return 0;
}
}
}
cout<<"YES\n";
}
Compilation message (stderr)
family.cpp: In function 'int main()':
family.cpp:62:9: warning: unused variable 'p' [-Wunused-variable]
62 | int p=0;
| ^
family.cpp:61:17: warning: 'r2' may be used uninitialized in this function [-Wmaybe-uninitialized]
61 | dfs(r1),dfs2(r2);
| ~~~~^~~~
family.cpp:61:8: warning: 'r1' may be used uninitialized in this function [-Wmaybe-uninitialized]
61 | dfs(r1),dfs2(r2);
| ~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |