Submission #403457

# Submission time Handle Problem Language Result Execution time Memory
403457 2021-05-13T07:54:40 Z zaneyu None (KOI18_family) C++14
0 / 100
1 ms 460 KB
/*input
3 2 1

2 3 0

2 0
*/
#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];
vector<int> vv[maxn],vv2[maxn];
void dfs(int u){
    if(!sz(v[u])) vv[u].pb(u);
    for(int x:v[u]){
        dfs(x);
        for(auto z:vv[x]) vv[u].pb(z);
    }
}
void dfs2(int u){
    if(!sz(v2[u])) vv2[u].pb(u);
    for(int x:v2[u]){
        dfs2(x);
        for(auto z:vv2[x]) vv2[u].pb(z);
    }  
}
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n,m,k;
    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);
    REP(i,n) sort(ALL(v[i]));
    REP(i,m) sort(ALL(v2[i]));
    REP(i,m){
        bool ok=0;
        REP(j,n){
            if(v[i]==v2[j]){
                ok=1;
            }
        }
        if(!ok){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
}

Compilation message

family.cpp: In function 'int main()':
family.cpp:55:17: warning: 'r2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   55 |     dfs(r1),dfs2(r2);
      |             ~~~~^~~~
family.cpp:55:8: warning: 'r1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   55 |     dfs(r1),dfs2(r2);
      |     ~~~^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -