malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int mm = 1111;   struct point {     double x, y;     point() {}     point(double _x, double _y) : x(_x), y(_y) {}   } g[mm];   point MakeVector(point &P, point &Q) { return point(Q.x - P.x, Q.y - P.y); }   double CrossProduct(point P, point Q) { return P.x * Q.y - P.y * Q.x; }   double MultiCross(point P, point Q, point R) {     return CrossProduct(MakeVector(Q, P), MakeVector(Q, R));   }   struct halfPlane {     point s, t;     double angle;     halfPlane() {}     halfPlane(point _s, point _t) : s(_s), t(_t) {}     halfPlane(double sx, double sy, double tx, double ty)         : s(sx, sy), t(tx, ty) {}     void GetAngle() { angle = atan2(t.y - s.y, t.x - s.x); }   } hp[mm], q[mm];   point IntersectPoint(halfPlane P, halfPlane Q) {     double a1 = CrossProduct(MakeVector(P.s, Q.t), MakeVector(P.s, Q.s));     double a2 = CrossProduct(MakeVector(P.t, Q.s), MakeVector(P.t, Q.t));     return point((P.s.x * a2 + P.t.x * a1) / (a2 + a1),                  (P.s.y * a2 + P.t.y * a1) / (a2 + a1));   }   bool cmp(halfPlane P, halfPlane Q) {     if (fabs(P.angle - Q.angle) < 1e-8) return MultiCross(P.s, P.t, Q.s) > 0;     return P.angle < Q.angle;   }   bool IsParallel(halfPlane P, halfPlane Q) {     return fabs(CrossProduct(MakeVector(P.s, P.t), MakeVector(Q.s, Q.t))) < 1e-8;   }   void HalfPlaneIntersect(int n, int &m) {     sort(hp, hp + n, cmp);     int i, l = 0, r = 1;     for (m = i = 1; i < n; ++i)       if (hp[i].angle - hp[i - 1].angle > 1e-8) hp[m++] = hp[i];     n = m;     m = 0;     q[0] = hp[0], q[1] = hp[1];     for (i = 2; i < n; ++i) {       if (IsParallel(q[r], q[r - 1]) || IsParallel(q[l], q[l + 1])) return;       while (l < r &&              MultiCross(hp[i].s, hp[i].t, IntersectPoint(q[r], q[r - 1])) > 0)         --r;       while (l < r &&              MultiCross(hp[i].s, hp[i].t, IntersectPoint(q[l], q[l + 1])) > 0)         ++l;       q[++r] = hp[i];     }     while (l < r &&            MultiCross(q[l].s, q[l].t, IntersectPoint(q[r], q[r - 1])) > 0)       --r;     while (l < r &&            MultiCross(q[r].s, q[r].t, IntersectPoint(q[l], q[l + 1])) > 0)       ++l;     q[++r] = q[l];     for (i = l; i < r; ++i) g[m++] = IntersectPoint(q[i], q[i + 1]);   }   int main() {     int n, m;     point a, b;     while (cin >> n) {       for (int i = 0; i < n; i++) cin >> g[i].x >> g[i].y;       for (int i = 0; i < n; i++) {         hp[i] = halfPlane(g[(i + 1) % n], g[i]);         hp[i].GetAngle();       }       a = g[0], b = g[1];       HalfPlaneIntersect(n, m);       if (m < 3) {         cout << 0 << endl;         continue;       }       int ans = 0;       if (a.x > b.x) swap(a, b);       int f2 = 0, f1 = 0;       for (int i = 0; i < m; i++)         if (g[i].y == a.y && g[(i + 1) % m].y == a.y) {           f2 = 1;           a = g[i], b = g[(i + 1) % m];           break;         } else if (g[i].y == a.y)           f1 = 1;       if (f1 && !f2)         cout << 1 << endl;       else if (f2) {         if (a.x > b.x) swap(a, b);         cout << int(b.x - a.x) + 1 << endl;       } else         cout << 0 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[200000 + 5];   int d[200000 + 5];   set<pair<int, int> > s;   set<pair<int, int> >::iterator it;   void djikstra() {     int u, v;     fill(d, d + n + 2, (int)100000000);     d[1] = 0;     s.insert(make_pair(d[1], 1));     while (!s.empty()) {       it = s.begin();       u = (*it).second;       s.erase(it);       v = a[u];       if (d[v] > (d[u] + 1)) {         if (d[v] != (int)100000000) s.erase(s.find(make_pair(d[v], v)));         d[v] = d[u] + 1;         s.insert(make_pair(d[v], v));       }       v = u - 1;       if (v >= 1 && d[v] > (d[u] + 1)) {         if (d[v] != (int)100000000) s.erase(s.find(make_pair(d[v], v)));         d[v] = d[u] + 1;         s.insert(make_pair(d[v], v));       }       v = u + 1;       if (v <= n && d[v] > (d[u] + 1)) {         if (d[v] != (int)100000000) s.erase(s.find(make_pair(d[v], v)));         d[v] = d[u] + 1;         s.insert(make_pair(d[v], v));       }     }   }   int main() {     int i;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     djikstra();     for (i = 1; i <= n; i++) printf( %d  , d[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   void sync_stdio() {     cin.tie(NULL);     ios_base::sync_with_stdio(false);   }   struct Sync_stdio {     Sync_stdio() {       cin.tie(NULL);       ios_base::sync_with_stdio(false);     }   } _sync_stdio;   vector<int> v;   vector<double> pref;   vector<double> inv;   vector<double> sum;   double get(int x, int y) {     return sum[y] - sum[x - 1] - (inv[y] - inv[x - 1]) * pref[x - 1];   }   vector<vector<double>> dp;   const double EPS = 1e-7;   void solve(int i, int l, int r, int optl, int optr) {     int mid = (l + r) / 2;     int optm = 0;     for (int j = (optl); j < (optr + 1); ++j) {       if (dp[i][mid] + EPS > dp[i - 1][j] + get(j + 1, mid)) {         dp[i][mid] = dp[i - 1][j] + get(j + 1, mid);         optm = j;       }     }     if (l <= mid - 1) {       solve(i, l, mid - 1, optl, optm);     }     if (mid + 1 <= r) {       solve(i, mid + 1, r, optm, optr);     }   }   int main() {     int n, k;     cin >> n >> k;     v.resize(n);     for (int __i = 0; __i < (n); ++__i) cin >> v[__i];     ;     pref.resize(n + 1);     inv.resize(n + 1);     sum.resize(n + 1);     for (int i = (1); i < (n + 1); ++i) {       pref[i] = pref[i - 1] + v[i - 1];       inv[i] = inv[i - 1] + 1.0 / v[i - 1];       sum[i] = sum[i - 1] + pref[i] / v[i - 1];     }     dp.assign(k + 1, vector<double>(n + 1, 1e18));     vector<vector<long long>> prev(k + 1, vector<long long>(n + 1, -1));     dp[0][0] = 0;     cout << fixed << setprecision(10);     for (int i = (1); i < (k + 1); ++i) {       solve(i, 1, n, 0, n);     }     cout << dp[k][n];     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int mod = 1e9 + 7;   const double eps = 1e-6;   const int N = 1e6 + 7;   int tr[N][26], id[N], idx;   char s[100007][1003], str[10007];   bool flag;   int n, m, len[N];   int res[N], cnt;   int trans(char c) {     if (c >=  A  && c <=  Z ) c = c -  A  +  a ;     return c;   }   void insert(int first) {     int p = 0;     for (int i = len[first] - 1; i >= 0; i--) {       int t = trans(s[first][i]) -  a ;       if (!tr[p][t]) tr[p][t] = ++idx;       p = tr[p][t];     }     id[p] = first;   }   void dfs(int first) {     if (flag) return;     if (first == n) {       for (int i = 0; i < cnt; i++) cout << s[res[i]] <<    ;       puts(  );       flag = true;       return;     }     int p = 0;     for (int i = first; i < n; i++) {       int t = str[i] -  a ;       if (!tr[p][t]) break;       p = tr[p][t];       if (id[p] != -1) {         res[cnt++] = id[p];         dfs(first + len[id[p]]);         cnt--;       }     }   }   int main() {     ios::sync_with_stdio(false);     memset(id, -1, sizeof(id));     cin >> n >> str >> m;     for (int i = 0; i <= m - 1; i++) {       cin >> s[i];       len[i] = strlen(s[i]);       insert(i);     }     dfs(0);     return 0;   }
#include <bits/stdc++.h>   int main() {     int x, y;     scanf( %d , &x);     if ((x % 4 == 0) || (x % 7 == 0) || (x % 47 == 0) || (x % 74 == 0) ||         (x % 447 == 0) || (x % 474 == 0) || (x % 477 == 0) || (x % 744 == 0) ||         (x % 774 == 0) || (x % 747 == 0)) {       printf( YES );     } else {       printf( NO );     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:200000000 )   using namespace std;   const int cs = 0x186A1;   const int up = 1001;   int n, ans;   int u[1005];   vector<int> p, s;   int main() {     for (int i = 2; i < up; i++)       if (!u[i])         for (int j = i * i; j < up; j += i) u[j] = 1;     for (int i = 2; i < up; i++)       if (!u[i]) p.push_back(i);     cin >> n;     for (auto i : p) {       int cur = i;       while (cur <= n) {         s.push_back(cur);         cur *= i;       }     }     cout << s.size() << endl;     for (auto i : s) cout << i <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     long long n, x, y;     cin >> n >> x >> y;     long long arr[n];     for (long long i = 0; i < n; i++) {       cin >> arr[i];     }     long long an = -1;     for (long long i = 0; i < n; i++) {       bool ans = true;       for (long long j = i - 1; j >= 0 && j >= i - x; j--) {         if (arr[j] < arr[i]) {           ans = false;           break;         }       }       for (long long j = i + 1; j < n && j <= i + y; j++) {         if (arr[j] < arr[i]) {           ans = false;           break;         }       }       if (ans) {         an = i;         break;       }     }     cout << an + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int p = 0;     char ch =  0 , var;     pair<int, char> sam[4];     string str[4];     for (int i = 0; i < 4; i++) {       cin >> str[i];       sam[i].first = str[i].size() - 2;       sam[i].second = (char)65 + i;     }     sort(sam, sam + 4);     if (sam[0].first <= sam[1].first / 2) {       var = sam[0].second;       p++;     }     if (sam[3].first >= sam[2].first * 2) {       var = sam[3].second;       p++;     }     if (p == 2 or p == 0)       cout <<  C ;     else       cout << var;   }
#include <bits/stdc++.h>   using namespace std;   int a[100], b[100], path[11];   int res;   bool check(int pos, int l1, int l2) {     if (pos == 0) {       return 1;     }     if (!l1 && !l2) return 1;     int l = l1 ? a[pos] : 0;     int r = l2 ? b[pos] : 9;     for (int i = l; i <= r; i++) {       if (path[i]) {         path[i]--;         if (check(pos - 1, l1 && l == i, l2 && r == i)) {           path[i]++;           return 1;         }         path[i]++;       }     }     return 0;   }   int c;   int solve(int u, int pos) {     int res = 0;     if (u == 9) {       path[u] = pos;       if (check(c, 1, 1)) return 1;       return 0;     }     for (int i = 0; i <= pos; i++) {       path[u] += i;       res += solve(u + 1, pos - i);       path[u] -= i;     }     return res;   }   int dig(int *p, long long x) {     int len = 0;     while (x) {       p[++len] = x % 10;       x /= 10;     }     c = len;     return len;   }   int main() {     long long l, r;     cin >> l >> r;     int pos = dig(a, l);     pos = dig(b, r);     cout << solve(0, pos) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> pri[3005];   long long ans;   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       int par, mon;       cin >> par >> mon;       pri[par].push_back(mon);     }     for (int i = 1; i <= m; i++) sort(pri[i].begin(), pri[i].end());     ans = 1e18 + 5;     for (int i = 1; i <= n; i++) {       long long cost = 0;       int need = i - pri[1].size();       vector<int> U;       for (int j = 2; j <= m; j++) {         int staIn = max(0, (int)pri[j].size() - (i - 1));         for (int k = 0; k < staIn; k++) {           cost += pri[j][k];           need--;         }         for (int k = staIn; k < pri[j].size(); k++) {           U.push_back(pri[j][k]);         }       }       sort(U.begin(), U.end());       if (need > 0) {         for (int j = 0; j < need; j++) cost += U[j];       }       ans = min(cost, ans);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool p(string s) {     int n = s.length();     for (int i = 0; i < n / 2; i++) {       if (s[i] != s[n - i - 1]) return 0;     }     return 1;   }   int main() {     std::ios::sync_with_stdio(false);     string s;     cin >> s;     int n = s.length();     for (char c =  a ; c <=  z ; c++) {       string tmp = s;       for (int i = 0; i <= n; i++) {         tmp.insert(tmp.begin() + i, c);         if (p(tmp)) {           cout << tmp << endl;           return 0;         }         tmp = s;       }     }     cout <<  NA  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     void solution();     solution();     return 0;   }   struct item {     int v;     int i;   };   bool operator<(item a, item b) { return a.v < b.v; }   const int maxn = 200000;   item a[maxn];   int c[maxn];   void solution() {     int n;     scanf( %i , &n);     set<int> s;     bool bad = false;     for (int i = 0; i < n; i++) {       scanf( %i , &a[i].v);       a[i].v += i;       a[i].i = i;       if (s.find(a[i].v) != s.end()) {         bad = true;       }       s.insert(a[i].v);     }     if (!bad) {       sort(a, a + n);       for (int i = 0; i < n; i++) {         c[i] = a[i].v - i;         if (c[i] < 0) {           bad = true;         }       }     }     if (!bad) {       for (int i = 0; i < n; i++) {         printf( %i  , c[i]);       }     }     if (bad) {       printf( :( );     }     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int a, b, c, d, e;     cin >> a >> b >> c >> d >> e;     int f[5] = {a, b, c, d, e}, mn = a + b + c + d + e, ans = a + b + c + d + e;     sort(f, f + 5);     map<int, int> mp;     for (int i = 0; i < 5; i++) {       mp[f[i]]++;       if (mp[f[i]] == 2)         ans = min(ans, mn - f[i] * 2);       else if (mp[f[i]] == 3)         ans = min(ans, mn - f[i] * 3);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long int fast_exp(long long int base, long long int exp1) {     long long int res = 1;     while (exp1 > 0) {       if (exp1 & 1) res = (res * base) % 1000000007;       base = (base * base) % 1000000007;       exp1 /= 2;     }     return res % 1000000007;   }   long long int pr[100001] = {0};   void isprime() {     pr[0] = 1;     pr[1] = 1;     for (long long int a = 2; a <= 100001; a++) {       if (!pr[a]) {         for (long long int b = a; b < 100001; b += a) {           pr[b] = a;         }       }     }   }   long long int comp = 1, tim = 0;   struct vertex {     vector<long long int> adj;     long long int vis = 0;     long long int parent = -1;     long long int dist = 0;     long long int component = 0;     long long int in = 0;     long long int out = 0;     long long int low = 0;     long long int child = 0;     long long int indeg = 0;     long long int outdeg = 0;     bool AP = false;   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     isprime();     long long int n;     cin >> n;     long long int x[n];     long long int dp[100001] = {0};     for (long long int a = 0; a < n; a++) {       long long int b;       cin >> b;       long long int k = b;       while (k > 1) {         long long int p = pr[k];         dp[b] = max(dp[b], dp[p] + 1);         while (k % p == 0) k /= p;       }       k = b;       while (k > 1) {         long long int p = pr[k];         dp[p] = max(dp[p], dp[b]);         while (k % p == 0) k /= p;       }       if (b == 1) dp[1] = 1;     }     cout << *max_element(dp, dp + 100001) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-12;   const int N = 2067;   int n, t;   long double f[N][N], ft[N][N];   struct Node {     int ss, sl, ts, tl;     long double p;   } node[N];   bool comp(Node c1, Node c2) {     return c1.tl * (1 - c1.p) * c2.p < c2.tl * (1 - c2.p) * c1.p;   }   bool equals(long double a, long double b) { return abs(a - b) < eps; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> t;     for (int i = 1; i <= n; i++) {       cin >> node[i].ss >> node[i].sl >> node[i].ts >> node[i].tl >> node[i].p;       node[i].p = 1 - node[i].p;     }     sort(node + 1, node + n + 1, comp);     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= t; j++) f[i][j] = f[i - 1][j], ft[i][j] = ft[i - 1][j];       for (int j = 0; j <= t - node[i].ts; j++) {         int ct = j + node[i].ts;         if (f[i][ct] < f[i - 1][j] + node[i].ss) {           f[i][ct] = f[i - 1][j] + node[i].ss;           ft[i][ct] = ft[i - 1][j] + node[i].ts;         } else if (equals(f[i][ct], f[i - 1][j] + node[i].ss)) {           ft[i][ct] = min(ft[i][ct], ft[i - 1][j] + node[i].ts);         }       }       for (int j = 0; j <= t - node[i].ts - node[i].tl; j++) {         int ct = j + node[i].ts + node[i].tl;         long double cs = f[i - 1][j] + node[i].ss + node[i].sl * node[i].p;         long double cp =             (ft[i - 1][j] + node[i].ts) * (1 - node[i].p) + ct * node[i].p;         if (f[i][ct] < cs) {           f[i][ct] = cs;           ft[i][ct] = cp;         } else if (equals(f[i][ct], cs)) {           ft[i][ct] = min(ft[i][ct], cp);         }       }     }     long double rs = 0;     long double rp = 0;     for (int i = 0; i <= t; i++) {       if (rs < f[n][i]) {         rs = f[n][i];         rp = ft[n][i];       } else if (equals(rs, f[n][i])) {         rp = min(rp, ft[n][i]);       }     }     cout << setprecision(12) << fixed << rs <<     << rp << endl;   }
#include <bits/stdc++.h>   using namespace std;   bool win(long long s, long long e) {     if (e % 2 == 1) {       return s % 2 == 0;     }     if (s > e / 2) {       return s % 2 == 1;     }     if (s > e / 4) return true;     return win(s, e / 4);   }   bool lose(long long s, long long e) {     if (s >= e / 2 + 1) {       return true;     }     return win(s, e / 2);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     int nw = 0, nl = 0;     vector<pair<long long, long long>> V(t);     for (int i = 0; i < t; ++i) cin >> V[i].first >> V[i].second;     reverse(V.begin(), V.end());     bool w = win(V[0].first, V[0].second);     bool l = lose(V[0].first, V[0].second);     for (int i = 1; i < V.size(); ++i) {       bool thisw = win(V[i].first, V[i].second);       bool thisl = lose(V[i].first, V[i].second);       if (w) {         if (!thisl) w = false;       } else {         if (thisw) w = true;       }       if (l) {         if (!thisl) l = false;       } else {         if (thisw) l = true;       }     }     cout << w <<     << l;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long q1 = 1000000007, q2 = 100003;   long long p1 = 1299827, p2 = 41;   bool v[100009];   long long sp[100009];   void sieve() {     for (long long i = 2; i < 100009; i += 2) sp[i] = 2;     for (long long i = 3; i < 100009; i += 2) {       if (!v[i]) {         sp[i] = i;         for (long long j = i; (j * i) < 100009; j += 2) {           if (!v[j * i]) v[j * i] = true, sp[j * i] = i;         }       }     }   }   set<long long> factorize(long long k) {     set<long long> ans;     while (k > 1) {       ans.insert(sp[k]);       k /= sp[k];     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<long long> used(100009, -1);     for (int i = 0; i < n; i++) {       long long x, y;       cin >> x >> y;       long long ans = 0;       for (long long j = 1; j * j <= x; j++) {         if (x % j == 0) {           if (used[j] == -1 || i - used[j] > y) {             ans++;           }           used[j] = i;           if (x / j != j && used[x / j] == -1 || i - used[x / j] > y) {             ans++;           }           used[x / j] = i;         }       }       if (used[x] == -1 || i - used[x] > y) {         ans++;       }       used[x] = i;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = (long long)1e9;   long long max(long long a, long long b, long long c) {     return max(a, max(b, c));   }   long long n;   long long house[200011];   long long mn[200011][2][2];   long long mx[200011][2][2];   long long f(long long i, long long j, long long k) {     if (i == -1) return 0;     if (mn[i][j][k] != -1) return mn[i][j][k];     long long res = INF;     if (house[i] == 0)       res = f(i - 1, 0, j);     else if (j + k == 0)       res = 1 + f(i - 1, 1, 0);     else if (j == 1)       res = f(i - 1, 0, 1);     else       res = f(i - 1, 0, 0);     return mn[i][j][k] = res;   }   long long g(long long i, long long j, long long k) {     if (i == -1) return 0;     if (mx[i][j][k] != -1) return mx[i][j][k];     long long res = 0;     if (house[i] == 0)       res = g(i - 1, 0, j);     else if (j + k == 2)       res = 1 + g(i - 1, 1, 1);     else if (j + k == 0) {       if (house[i] == 1)         res = 1 + max(g(i - 1, 1, 0), g(i - 1, 0, 1), g(i - 1, 0, 0));       else if (house[i] == 2)         res = 2 + max(g(i - 1, 1, 1), g(i - 1, 1, 0), g(i - 1, 0, 1));       else         res = 3 + g(i - 1, 1, 1);     } else if (j == 1) {       if (house[i] == 1)         res = 1 + max(g(i - 1, 1, 1), g(i - 1, 0, 1));       else         res = 2 + g(i - 1, 1, 1);     } else {       if (house[i] == 1)         res = 1 + max(g(i - 1, 0, 1), g(i - 1, 1, 0));       else         res = 2 + g(i - 1, 1, 1);     }     return mx[i][j][k] = res;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     memset(mn, -1, sizeof mn);     memset(mx, -1, sizeof mx);     cin >> n;     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       house[--x]++;     }     cout << f(n - 1, 0, 0) <<     << g(n - 1, 0, 0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int G[23][23], n, m;   bool check() {     for (int i = 1; i <= n; ++i) {       int cnt = 0;       for (int j = 1; j <= m; ++j) cnt += G[i][j] != j;       if (cnt > 2) return false;     }     return true;   }   int main(int argc, char const *argv[]) {     cin >> n >> m;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) scanf( %d , &G[i][j]);     if (check()) {       cout <<  YES  << endl;       return 0;     }     for (int i = 1; i <= m; ++i)       for (int j = i + 1; j <= m; ++j) {         for (int k = 1; k <= n; ++k) swap(G[k][i], G[k][j]);         if (check()) {           cout <<  YES  << endl;           return 0;         }         for (int k = 1; k <= n; ++k) swap(G[k][i], G[k][j]);       }     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> adj[100005];   map<int, int> mp;   map<int, int> mp1;   vector<int> rt;   int c[100005];   bool vis[100005];   bool bfs(int nd) {     int col = c[nd];     int fg = 0;     queue<int> q;     vis[nd] = true;     q.push(nd);     while (!q.empty()) {       int node = q.front();       q.pop();       for (int i = 0; i < adj[node].size(); i++) {         if (!vis[adj[node][i]]) {           if (c[adj[node][i]] != col) {             fg = 1;           }           vis[adj[node][i]] = true;           q.push(adj[node][i]);         }       }     }     if (fg == 0)       return true;     else       return false;   }   int ua[100005], va[100005];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d %d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);       ua[i] = u;       va[i] = v;     }     for (int i = 1; i <= n; i++) {       scanf( %d , &c[i]);     }     for (int i = 0; i < n - 1; i++) {       if (c[ua[i]] != c[va[i]]) {         memset(vis, false, sizeof(vis));         int fg = 0;         vis[ua[i]] = true;         for (int j = 0; j < adj[ua[i]].size(); j++) {           bool x1 = bfs(adj[ua[i]][j]);           if (x1 == false) {             fg = 1;             break;           }         }         if (fg == 0) {           printf( YES n );           printf( %d n , ua[i]);           return 0;         } else {           memset(vis, false, sizeof(vis));           vis[va[i]] = true;           fg = 0;           for (int j = 0; j < adj[va[i]].size(); j++) {             bool x2 = bfs(adj[va[i]][j]);             if (x2 == false) {               fg = 1;               break;             }           }           if (fg == 0) {             printf( YES n );             printf( %d n , va[i]);             return 0;           } else {             printf( NO n );             return 0;           }         }       }     }     printf( YES n1 n );     return 0;   }