func_code_string: #include <bits/stdc++.h>   using namespace std;   int n;   vector<int> tree[300003];   int colors[300003];   int blueC[300003];   int redC[300003];   int ans = 0;   pair<int, int> dfs(int nd, int pr) {     int blue = (colors[nd] == 2);     int red = (colors[nd] == 1);     for (int i = 0; i < (int)tree[nd].size(); i++) {       if (tree[nd][i] == pr) continue;       pair<int, int> sub = dfs(tree[nd][i], nd);       if ((bool)sub.first ^ (bool)sub.second) {         if (sub.first)           ans += (blueC[0] == sub.first);         else           ans += (redC[0] == sub.second);       }       blue += sub.first;       red += sub.second;     }     return make_pair(blue, red);   }   void solve() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &colors[i]);     int u, v;     for (int i = 1; i < n; i++) {       scanf( %d %d , &u, &v);       tree[u].push_back(v);       tree[v].push_back(u);     }     memset(blueC, 0, sizeof(blueC));     memset(redC, 0, sizeof(redC));     for (int i = 1; i <= n; i++) {       if (colors[i] == 1)         redC[0]++;       else if (colors[i] == 2)         blueC[0]++;     }     dfs(1, 0);     printf( %d , ans);   }   int main() { solve(); }   