func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<vector<int> > v(200002);   bool ab[200002];   int dist[200002];   queue<int> q;   int cur, i, n, h[200002], r[200002], p[200002];   void dfs() {     while (!q.empty()) {       cur = q.front();       q.pop();       ab[cur] = true;       for (i = 0; i < v[cur].size(); i++)         if (ab[v[cur][i]] == false) {           ab[v[cur][i]] = true;           q.push(v[cur][i]);           dist[v[cur][i]] = dist[cur] + 1;         }     }   }   int a, b;   int main() {     cin >> n;     pair<int, int> fg[n];     for (i = 1; i < n; i++) {       cin >> a >> b;       fg[i] = make_pair(a, b);       v[a].push_back(b);       v[b].push_back(a);     }     q.push(1);     ab[1] = true;     dfs();     for (i = 1; i < n; i++) {       if (dist[fg[i].first] < dist[fg[i].second])         p[fg[i].second] = fg[i].first;       else         p[fg[i].first] = fg[i].second;     }     for (i = 0; i < n; i++) {       cin >> h[i];       r[h[i]] = i + 1;     }     for (i = 1; i < n; i++)       if ((r[p[h[i]]] < r[p[h[i - 1]]]) || (dist[h[i]] < dist[h[i - 1]])) {         cout <<  NO ;         return 0;       }     cout <<  YES ;     return 0;   }   