Основное
 
 
Отправитель Задача Язык Вердикт Время Память Отослано Протест.  
48669584 Дорешивание:
utkarshahuja1
1037D - 42 C++17 (GCC 7-32) Неправильный ответ на тесте 4 31 мс 4936 КБ 2019-01-21 13:01:34 2019-01-21 13:01:34
→ Исходный код
//
//  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;
}
?
Время: ? ms, память: ? КБ
Вердикт: ?
Ввод
?
Вывод участника
?
Ответ жюри
?
Комментарий чекера
?
Диагностика
?
Показать детали тестирования