func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<long long> graph[300005];   long long col[300005];   long long ans, r, b;   pair<long long, long long> dfs(long long x, long long p = -1) {     long long a1, b1;     a1 = 0;     b1 = 0;     if (col[x] == 1) a1++;     if (col[x] == 2) b1++;     for (long long i = 0; i < graph[x].size(); i++) {       if (graph[x][i] == p) continue;       auto temp = dfs(graph[x][i], x);       if (temp.first == r && temp.second == 0) ans++;       if (temp.first == 0 && temp.second == b) ans++;       a1 += temp.first;       b1 += temp.second;     }     return {a1, b1};   }   signed main() {     long long t, i, j, a, n, a1, a2, b1, b2;     cin >> n;     b = 0;     r = 0;     ans = 0;     for (i = 1; i <= n; i++) {       cin >> j;       col[i] = j;       if (j == 1) r++;       if (j == 2) b++;     }     for (i = 0; i < n - 1; i++) {       cin >> a1 >> b1;       graph[a1].push_back(b1);       graph[b1].push_back(a1);     }     dfs(1);     cout << ans << endl;   }   