General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
48669584 Practice:
utkarshahuja1
1037D - 42 GNU C++17 Wrong answer on test 4 31 ms 4936 KB 2019-01-21 13:01:34 2019-01-21 13:01:34
 
 
→ Source
//
//  main.cpp
//  test
//
//  Created by Utkarsh Ahuja on 16/01/19.
//  Copyright © 2019 Utkarsh Ahuja. All rights reserved.
//

#include <vector>
#include <algorithm>
#include <queue>
#include <iostream>
#include <map>
using namespace std;
int sz = 2e5 + 5;
vector <vector<int>> graph(sz), level(sz);

string bfs(int a[], int n) {
    
    queue<pair<int,int>> q;
    q.push({1,0});
    bool visited[n + 1]= {0};
    //memset(visited, false, sizeof(visited));
    while (!q.empty()) {
        
        auto temp = q.front();
        q.pop();
        visited[temp.first] = 1;
        level[temp.second].push_back(temp.first);
        for (int i = 0;i < graph[temp.first].size(); ++i) {
            
            if(!visited[graph[temp.first][i]]) {
                
                q.push({graph[temp.first][i], temp.second + 1});
                
            }
            
        }
    }
    
    
    int elements = 0;
    int i = 0;
    map<int,int> m;
    while(elements < n) {
        
        for(int j = 0;j < level[i].size(); ++j)
            m[level[i][j]] = 1;
        
        for(int j = elements; j < level[i].size() + elements; ++j)
         if (m[a[j]] == 0)
            return "No";
        elements += level[i].size();
        i++;
        m.clear();
    }
    return "Yes";
    
    
}



int main(int argc, const char * argv[]) {
    // insert code here...
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, x, y;
    cin >> n;
    int a[n];
    for(int i = 0; i < n - 1; ++i) {
        cin >> x >> y;
        graph[x].push_back(y);
        graph[y].push_back(x);
        
    }
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    
    cout << bfs(a,n);
    return 0;
}
 
 
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details