#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long power(long long x, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) {
      res = (res * x);
    }
    n >>= 1;
    if (n != 0) {
      x = (x * x);
    }
  }
  return res;
}
long long powerMOD(long long x, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) {
      res = (res * x) % MOD;
    }
    n >>= 1;
    x = (x * x) % MOD;
  }
  return res;
}
bool mycompare(pair<long long, long long> &a, pair<long long, long long> &b) {
  if (a.first == b.first) {
    return a.second < b.second;
  }
  return a.first > b.first;
}
bool mycompare1(pair<int, int> &a, pair<int, int> &b) {
  return a.second < b.second;
}
long long cnt[100000 + 2] = {0};
long long SUM[100000 + 2] = {0};
long long vis[100000 + 2] = {0};
long long pos = -1, tot = 0;
void dfs(vector<long long> a[], long long ind, long long parent,
         vector<long long> &color, long long n) {
  long long i, j = 0, k;
  vis[ind] = true;
  cnt[ind]++;
  SUM[ind] = color[ind];
  for (int i = 0; i < a[ind].size(); i++) {
    if (!vis[a[ind][i]]) {
      dfs(a, a[ind][i], ind, color, n);
      SUM[ind] += SUM[a[ind][i]];
      cnt[ind] += cnt[a[ind][i]];
    }
  }
  k = 1;
  if (parent != -1) {
    if (tot - SUM[ind] != color[parent] * (n - cnt[ind])) k = 0;
  }
  if (k) {
    for (int i = 0; i < a[ind].size(); i++) {
      if (!k) break;
      if (a[ind][i] != parent) {
        if (SUM[a[ind][i]] != color[a[ind][i]] * cnt[a[ind][i]]) k = 0;
      }
    }
  }
  if (k) pos = ind + 1;
}
void solve() {
  long long i, j, k, l, n, m, x;
  cin >> n;
  vector<long long> a[n], color(n);
  for (int i = 0; i < n - 1; i++) {
    cin >> l >> x;
    a[l - 1].push_back(x - 1);
    a[x - 1].push_back(l - 1);
  }
  for (int i = 0; i < n; i++) {
    cin >> color[i];
    tot += color[i];
  }
  dfs(a, 0, -1, color, n);
  if (pos == -1)
    cout << "NO\n";
  else {
    cout << "YES\n";
    cout << pos;
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  int t = 1, i;
  for (int i = 0; i < t; i++) solve();
  return 0;
}
