func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename T>   struct outputer;   struct outputable {};   template <typename T>   inline auto sqr(T x) -> decltype(x * x) {     return x * x;   }   template <typename T1, typename T2>   inline bool umx(T1& a, T2 b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <typename T1, typename T2>   inline bool umn(T1& a, T2 b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   const int N = 200000;   struct Input {     int n;     int a[N];     vector<int> e[N];     bool read() {       if (!(cin >> n)) {         return 0;       }       for (int i = int(0); i < int(n); ++i) {         scanf( %d , &a[i]);         --a[i];       }       for (int i = int(0); i < int(n - 1); ++i) {         int x, y;         scanf( %d%d , &x, &y);         --x;         --y;         e[x].emplace_back(y);         e[y].emplace_back(x);       }       return 1;     }     void init(const Input& input) { *this = input; }   };   struct Data : Input {     int ans;     void write() { cout << ans << endl; }   };   namespace Main {   struct Solution : Data {     int mx;     array<int, 2> calc(int v, int pr) {       array<int, 2> res{0, 0};       if (a[v] != -1) {         res[a[v]] = 1;       }       for (int to : e[v]) {         if (to == pr) {           continue;         }         array<int, 2> cur = calc(to, v);         for (int t = int(0); t < int(2); ++t) {           umx(mx, res[t] + cur[!t]);         }         for (int t = int(0); t < int(2); ++t) {           umx(res[t], cur[t]);           if (a[v] == t) {             umx(res[t], cur[!t] + 1);           }         }       }       for (int t = int(0); t < int(2); ++t) {         umx(mx, res[t]);       }       return res;     }     void solve() {       mx = 0;       calc(0, -1);       ans = mx / 2 + 1;     }     void clear() {       for (int i = int(0); i < int(n); ++i) {         e[i] = vector<int>();       }     }   };   }  // namespace Main   Main::Solution sol;   int main() {     cout.setf(ios::showpoint | ios::fixed);     cout.precision(20);     int t;     cin >> t;     for (int i = int(0); i < int(t); ++i) {       sol.read();       sol.solve();       sol.write();       sol.clear();     }     return 0;   }   