複製代碼
- #include<bits/stdc++.h>
- #define ll long long
- #define INF 0x3f3f3f3f
- #define MOD 1000000007
- #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- using namespace std;
- const int MXN = 200005;
- void sol(){
- ll ans = 0, n = 0, m = 0, k = 1;
- cin >> n;
- vector<vector<int> > path(n + 1);
- vector<int> ordered(n), index(n + 1);
- for(int i = 0; i < n - 1; ++i){
- int s, t;
- cin >> s >> t;
- path[s].emplace_back(t);
- path[t].emplace_back(s);
- }
- for(int i = 0; i < n; ++i){
- cin >> ordered[i];
- index[ordered[i]] = i;
- }
- for(int i = 1; i <= n; ++i){
- sort(path[i].begin(), path[i].end(), [&](int a, int b){
- return index[a] < index[b];
- });
- }
- queue<int> q;
- vector<int> vis(n + 1), res;
- q.push(1);
- while(!q.empty()){
- int p = q.front(); q.pop();
- vis[p] = 1;
- res.emplace_back(p);
- for(int i : path[p]){
- if(!vis[i]) q.push(i);
- }
- }
- for(int i = 0; i < n; ++i){
- if(ordered[i] != res[i]){
- cout << "No\n";
- return;
- }
- }
- cout << "Yes\n";
- }
- int main(){
- //io
- int t = 1;
- while(t--){
- sol();
- }
- }
歡迎光臨 冰楓論壇 (https://bingfong.com/) | Powered by 冰楓 |