malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <class t>   t mag(t a) {     return a > 0 ? a : -a;   }   template <class T>   T cdiv(T num, T den) {     return (num / den) + (num % den > 0);   }   std::ifstream term( /dev/tty );   std::string tempstring;   using ll = int_fast64_t;   using ii = pair<ll, ll>;   using vi = vector<int>;   using vl = vector<ll>;   using vii = vector<ii>;   int tc = 1;   const ll sij = 40001000;   const ll mod = 1000000007ll;   ll n, m;   bool vis[1510][1510];   string vec[1510];   int mx[] = {0, 0, -1, 1}, my[] = {-1, 1, 0, 0};   ii st;   ll msk[1510][1510], msy[1510][1510];   int esc(int tcase) {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> vec[i];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (vec[i][j] ==  S ) {           st = {i, j};         }       }     }     st.first = st.first + n * mod;     st.second = st.second + m * mod;     msk[st.first % n][st.second % m] = st.first;     msy[st.first % n][st.second % m] = st.second;     queue<ii> q;     q.push(st);     while (!q.empty()) {       ii cr = q.front();       q.pop();       for (int i = 0; i < 4; i++) {         ll gx = cr.first + mx[i], gy = cr.second + my[i];         if (vec[gx % n][gy % m] ==  # ) continue;         if (msk[gx % n][gy % m] == 0) {           q.push({gx, gy});           msk[gx % n][gy % m] = gx;           msy[gx % n][gy % m] = gy;           continue;         }         if (msk[gx % n][gy % m] != gx or msy[gx % n][gy % m] != gy) {           cout <<  Yes ;           return 0;         }       }     }     cout <<  No ;     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     for (int i = 1; i <= tc; i++) esc(i);   }
#include <bits/stdc++.h>   using namespace std;   char ch, B[1 << 20], *S = B, *T = B;   long long aa, bb;   long long rd() {     while (ch = (S == T && (T = (S = B) + fread(B, 1, 1 << 20, stdin), S == T)                      ? 0                      : *S++),            !(ch >=  0  && ch <=  9 ) && ch !=  - )       ;     ch ==  -  ? aa = bb = 0 : (aa = ch -  0 , bb = 1);     while (ch = (S == T && (T = (S = B) + fread(B, 1, 1 << 20, stdin), S == T)                      ? 0                      : *S++),            (ch >=  0  && ch <=  9 ))       aa = aa * 10 + ch -  0 ;     return bb ? aa : -aa;   }   const long long MAXN = 1e5 + 10;   long long n, k, ans, b[MAXN], tr[MAXN];   struct Node {     long long pos, l, r, q, len;   } a[MAXN];   bool cmp1(Node a, Node b) { return a.len > b.len; }   bool cmp2(Node a, Node b) { return a.q < b.q; }   inline void add(long long x, long long c) {     while (x <= n) {       tr[x] += c;       x += (x & (-x));     }   }   long long sum(long long x) {     long long ret = 0;     while (x) {       ret += tr[x];       x -= (x & (-x));     }     return ret;   }   long long query(long long l, long long r) { return sum(r) - sum(l - 1); }   inline void cdq(long long l, long long r) {     if (l == r) return;     long long mid = (l + r) >> 1;     cdq(l, mid);     cdq(mid + 1, r);     long long L = l, R = l - 1;     for (register long long i = mid + 1; i <= r; ++i) {       while (L <= mid && a[i].q - a[L].q > k) {         add(a[L].pos, -1);         ++L;       }       while (R < mid && a[R + 1].q - a[i].q <= k) {         ++R;         add(a[R].pos, 1);       }       ans += query(a[i].l, a[i].r);     }     for (register long long i = L; i <= R; ++i) add(a[i].pos, -1);     sort(a + l, a + r + 1, cmp2);   }   inline void work() {     n = rd();     k = rd();     for (register long long i = 1; i <= n; ++i) {       a[i].pos = rd();       a[i].len = rd();       a[i].q = rd();       b[i] = a[i].pos;     }     sort(b + 1, b + n + 1);     long long cnt = unique(b + 1, b + n + 1) - b - 1;     for (register long long i = 1; i <= n; ++i) {       a[i].l = lower_bound(b + 1, b + cnt + 1, a[i].pos - a[i].len) - b;       a[i].r = upper_bound(b + 1, b + cnt + 1, a[i].pos + a[i].len) - b - 1;       a[i].pos = lower_bound(b + 1, b + cnt + 1, a[i].pos) - b;     }     sort(a + 1, a + n + 1, cmp1);     cdq(1, n);     printf( %lld n , ans);   }   signed main() {     work();     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, i, sum1, sum2, sum3;     scanf( %d , &n);     sum1 = 0;     for (i = 0; i < n; i++) {       int a;       scanf( %d , &a);       sum1 ^= a;     }     sum2 = 0;     for (i = 0; i < n - 1; i++) {       int b;       scanf( %d , &b);       sum2 ^= b;     }     sum3 = 0;     for (i = 0; i < n - 2; i++) {       int c;       scanf( %d , &c);       sum3 ^= c;     }     printf( %d n%d n , sum1 ^ sum2, sum2 ^ sum3);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = ~0U >> 1;   const long long INF = ~0ULL >> 1;   template <class T>   inline void read(T &n) {     char c;     int flag = 1;     for (c = getchar(); !(c >=  0  && c <=  9  || c ==  - ); c = getchar())       ;     if (c ==  - )       flag = -1, n = 0;     else       n = c -  0 ;     for (c = getchar(); c >=  0  && c <=  9 ; c = getchar()) n = n * 10 + c -  0 ;     n *= flag;   }   int v[100][100], d[100][100];   char str[10000];   int n;   void p0() {     for (int j = 1; j <= 4; j += 3)       for (int i = 1; i <= 4; i += 2)         if (!v[i][j] && !v[i + 1][j]) {           v[i][j] = v[i + 1][j] = 1;           printf( %d %d n , i, j);           return;         }     assert(0);   }   void p1() {     for (int i = 1; i <= 4; i++)       if (!v[i][2] && !v[i][3]) {         v[i][2] = v[i][3] = 1;         printf( %d %d n , i, 2);         return;       }     assert(0);   }   int main(int argc, char *argv[]) {     scanf( %s , str);     n = strlen(str);     for (int i = (0); i < (n); ++i) {       if (str[i] ==  0 ) {         p0();       } else {         p1();       }       for (int x = (1); x <= (4); ++x)         for (int y = (1); y <= (4); ++y) {           d[x][y] = false;           bool ok = true;           for (int z = (1); z <= (4); ++z)             if (!v[x][z]) ok = false;           if (ok) d[x][y] = true;           ok = true;           for (int z = (1); z <= (4); ++z)             if (!v[z][y]) ok = false;           if (ok) d[x][y] = true;         }       for (int x = (1); x <= (4); ++x)         for (int y = (1); y <= (4); ++y)           if (d[x][y]) v[x][y] = 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   int main() {     cin >> s;     s =     + s;     int dem = 0;     for (int i = 1; i <= s.size() - 1; i++) {       if (s[i] < 97 && (s[i] -  0 ) % 2 != 0)         dem++;       else if (s[i] ==  a  || s[i] ==  e  || s[i] ==  i  || s[i] ==  o  ||                s[i] ==  u )         dem++;     }     cout << dem;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, i, j, k, l;   long long p[10004], ans;   int main() {     cin >> n >> m >> k;     for (int i_ = 0; i_ < n; ++i_) cin >> p[i_];     ;     ans = 0;     if (n & 1) {       if (m >= n / 2 + 1) {         int mn = 2e9;         for (i = 0; i < n; i += 2) mn = ((mn) < (p[i]) ? (mn) : (p[i]));         l = m / (n / 2 + 1);         ans = ((mn) < (l * k) ? (mn) : (l * k));       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int x, int y) {     if (x)       return (gcd(y % x, x));     else       return y;   }   int main() {     int a, b, n;     cin >> a >> b >> n;     for (int i = 0; i < 1000; i++) {       int x = gcd(a, n);       if (x <= n)         n -= x;       else {         cout << 1;         return 0;       }       x = gcd(b, n);       if (x <= n)         n -= x;       else {         cout << 0;         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1001010;   int a[maxn];   void solve() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     int cnt = 0;     for (int i = 0; i < n and a[i] >= i; ++i, ++cnt) {     }     for (int i = n - 1; i >= 0 and a[i] >= n - 1 - i; --i, ++cnt) {     }     cout << (cnt > n ?  Yes  :  No ) << endl;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int mark[201000 << 2];   int A[201000], n, m;   struct ST {     int val[2], las, len;     void update(ST a, ST b) {       b.val[1] -= a.las;       b.val[0] += a.las;       if (b.len & 1)         b.las -= a.las;       else         b.las += a.las;       val[0] = min(a.val[0], b.val[a.len & 1]);       val[1] = min(a.val[1], b.val[(a.len & 1) ^ 1]);       las = b.las;       len = a.len + b.len;       return;     }   } node[201000 << 2];   void build(int u, int L, int R) {     if (L == R) {       node[u].val[0] = 0;       node[u].val[1] = node[u].las = A[L];       node[u].len = 1;       return;     }     build((u << 1), L, ((L + R) >> 1));     build(((u << 1) | 1), (((L + R) >> 1) + 1), R);     node[u].update(node[(u << 1)], node[((u << 1) | 1)]);   }   void down(int u, int L, int R) {     if (!mark[u]) return;     node[u].val[1] += mark[u];     if (node[u].len & 1) node[u].las += mark[u];     if (L < R) mark[(u << 1)] += mark[u], mark[((u << 1) | 1)] += mark[u];     mark[u] = 0;     return;   }   void change(int u, int L, int R, int l, int r, int k) {     down(u, L, R);     if (L == l && R == r) {       mark[u] += k;       down(u, L, R);       return;     }     if (r < (((L + R) >> 1) + 1))       down(((u << 1) | 1), (((L + R) >> 1) + 1), R),           change((u << 1), L, ((L + R) >> 1), l, r, k);     else if (l > ((L + R) >> 1))       down((u << 1), L, ((L + R) >> 1)),           change(((u << 1) | 1), (((L + R) >> 1) + 1), R, l, r, k);     else {       change((u << 1), L, ((L + R) >> 1), l, ((L + R) >> 1), k);       change(((u << 1) | 1), (((L + R) >> 1) + 1), R, (((L + R) >> 1) + 1), r, k);     }     node[u].update(node[(u << 1)], node[((u << 1) | 1)]);   }   ST query(int u, int L, int R, int l, int r) {     down(u, L, R);     if (L == l && R == r) return node[u];     if (r < (((L + R) >> 1) + 1))       return query((u << 1), L, ((L + R) >> 1), l, r);     else if (l > ((L + R) >> 1))       return query(((u << 1) | 1), (((L + R) >> 1) + 1), R, l, r);     else {       ST a = query((u << 1), L, ((L + R) >> 1), l, ((L + R) >> 1));       ST b =           query(((u << 1) | 1), (((L + R) >> 1) + 1), R, (((L + R) >> 1) + 1), r);       a.update(a, b);       return a;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &A[i]);     build(1, 1, n);     for (scanf( %d , &m); m; m--) {       int t, L, R, k;       scanf( %d %d %d , &t, &L, &R);       L++, R++;       if (t == 1) {         scanf( %d , &k);         change(1, 1, n, L, R, k);       } else {         ST ans = query(1, 1, n, L, R);         if (ans.val[0] >= 0 && ans.val[1] >= 1 && ans.las - (ans.len & 1) == 0)           printf( 1 n );         else           printf( 0 n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[101];     bool f = 1;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 1) f = 0;     }     if (f)       puts( EASY );     else       puts( HARD );   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 7;   const int inf = INT_MAX;   const long long inff = 1e18;   const long long mod = 1e9 + 7;   long long n, p, k;   long long a[maxn];   set<long long> s;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> p >> k;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       long long now = a[i];       a[i] = a[i] * a[i] % p * a[i] % p * a[i] % p;       a[i] = (a[i] + p - k * now % p) % p;       s.insert(a[i]);     }     sort(a + 1, a + n + 1);     long long ans = 0;     for (long long i : s) {       long long now =           upper_bound(a + 1, a + n + 1, i) - lower_bound(a + 1, a + n + 1, i);       ans = (ans + now * (now - 1) / 2);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   typedef struct {     int dollar;     int cent;   } money;   money q[110];   int w[110];   int main() {     int i, j, n, m, k = 0, l = 0;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) scanf( %d%d , &q[i].dollar, &q[i].cent);     for (i = 1; i <= n; i++) {       if (q[i].dollar < m || (q[i].dollar == m && q[i].cent == 0)) {         if (!k) k = 1;         if (q[i].cent == 0)           continue;         else           l = (l > 100 - q[i].cent) ? l : 100 - q[i].cent;       }     }     if (!k)       printf( -1 n );     else       printf( %d n , l);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int a[maxn];   set<int> S;   long long qpow(long long a, long long b, long long mod) {     long long ret = 1LL;     while (b) {       if (b & 1) ret = ret * a % mod;       a = a * a % mod;       b >>= 1;     }     return ret;   }   long long inv(long long x, long long mod) { return qpow(x, mod - 2, mod); }   int main(void) {     int n, m;     scanf( %d %d , &m, &n);     if (n + n < m) {       for (int i = 1; i <= n; i++) scanf( %d , a + i), S.insert(a[i]);       if (n == 1) {         printf( %d 0 n , a[1]);         return 0;       }       int kd = (a[2] - a[1] + m) % m;       int cnt = 0;       for (int i = 1; i <= n; i++) {         int nxt = (a[i] + kd) % m;         if (S.find(nxt) != S.end()) cnt++;       }       int k = n - cnt;       if (!k) {         printf( %d %d n , a[1], kd);         return 0;       }       int d = (long long)kd * inv(k, m) % m;       cnt = 0;       for (int i = 0; i < n; i++)         if (S.find((a[1] - (long long)i * d % m + m) % m) != S.end()) cnt++;       if (cnt == n) {         printf( %I64d %d n , (a[1] - (long long)(n - 1) * d % m + m) % m, d);         return 0;       }       for (int i = 1; i < n; i++) {         if (S.find((a[1] + (long long)(i - n) * d % m + m) % m) != S.end()) cnt--;         if (S.find((a[1] + (long long)i * d % m + m) % m) != S.end()) cnt++;         if (cnt == n) {           printf( %I64d %d n , (a[1] + (long long)(i - n + 1) * d % m + m) % m,                  d);           return 0;         }       }       puts( -1 );     } else {       for (int i = 0; i < m; i++) S.insert(i);       for (int i = 1; i <= n; i++) scanf( %d , a + i), S.erase(a[i]);       n = m - n;       set<int>::iterator it = S.begin();       for (int i = 1; i <= n; i++) a[i] = *(it++);       if (n == 0) {         printf( 0 1 n );         return 0;       }       if (n == 1) {         printf( %d 1 n , (a[1] + n) % m);         return 0;       }       int kd = (a[2] - a[1] + m) % m;       int cnt = 0;       for (int i = 1; i <= n; i++) {         int nxt = (a[i] + kd) % m;         if (S.find(nxt) != S.end()) cnt++;       }       int k = n - cnt;       if (!k) {         printf( %d %d n , (a[1] + (long long)n * kd) % m, kd);         return 0;       }       int d = (long long)kd * inv(k, m) % m;       cnt = 0;       for (int i = 0; i < n; i++)         if (S.find((a[1] - (long long)i * d % m + m) % m) != S.end()) cnt++;       if (cnt == n) {         printf( %I64d %d n ,                (a[1] - (long long)(n - 1) * d % m + m + (long long)n * d) % m, d);         return 0;       }       for (int i = 1; i < n; i++) {         if (S.find((a[1] + (long long)(i - n) * d % m + m) % m) != S.end()) cnt--;         if (S.find((a[1] + (long long)i * d % m + m) % m) != S.end()) cnt++;         if (cnt == n) {           printf(                %I64d %d n ,               (a[1] + (long long)(i - n + 1) * d % m + m + (long long)n * d) % m,               d);           return 0;         }       }       puts( -1 );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, z;     cin >> x >> y >> z;     int t = x * y / z;     t = (int)sqrt(t);     x = x / t;     z = y / t;     y = t;     cout << 4 * x + 4 * z + 4 * y <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     map<char, long long> mp1, mp2;     mp1[ v ] = 1;     mp1[ < ] = 2;     mp1[ ^ ] = 3;     mp1[ > ] = 4;     mp2[ v ] = 1;     mp2[ > ] = 2;     mp2[ ^ ] = 3;     mp2[ < ] = 4;     char a, b;     long long n;     cin >> a >> b;     cin >> n;     n = n % 4;     long long one, two;     one = (mp1[a] + n) % 4;     if (one == 0) one = 4;     two = (mp2[a] + n) % 4;     if (two == 0) two = 4;     long long f1 = 0, f2 = 0;     if (one == mp1[b]) f1 = 1;     if (two == mp2[b]) f2 = 1;     if (f1 == 1 && f2 == 0) {       cout <<  cw  << endl;       return 0;     } else if (f1 == 0 && f2 == 1) {       cout <<  ccw  << endl;       return 0;     }     cout <<  undefined  << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 10;   int inf = (int)3e15;   int mod = (int)1e9 + 7;   int sz = 500, timer = 0;   vector<int> gr[MAX];   int n, q, odd[MAX], even[MAX], h[MAX], tin[MAX], tout[MAX], mus[MAX], o[MAX];   vector<pair<int, int>> tmp;   void calc(int v, int p) {     tin[v] = ++timer;     h[v] = h[p] + 1;     for (auto u : gr[v]) {       if (u != p) calc(u, v);     }     tout[v] = ++timer;   }   void dfs_rebuild(int v, int p) {     odd[v] += even[p];     even[v] += odd[p];     for (auto u : gr[v]) {       if (u != p) dfs_rebuild(u, v);     }   }   void rebuild() {     for (int i = 1; i <= n; i++) {       even[i] = 0;       odd[i] = 0;     }     for (int i = 0; i < tmp.size(); i++) mus[tmp[i].first] += tmp[i].second;     for (int i = 1; i <= n; i++) even[i] = mus[i];     tmp.clear();     dfs_rebuild(1, 0);   }   void out_val(int v) {     int ans = even[v] - odd[v] + o[v];     for (int i = 0; i < tmp.size(); i++) {       int u = tmp[i].first;       int val = tmp[i].second;       if (tin[u] <= tin[v] && tout[u] >= tout[v]) {         if ((h[v] - h[u]) % 2 == 1)           ans -= val;         else           ans += val;       }     }     cout << ans <<   n ;   }   void solve() {     cin >> n >> q;     for (int i = 1; i <= n; i++) {       cin >> o[i];     }     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       gr[a].push_back(b);       gr[b].push_back(a);     }     calc(1, 0);     for (int i = 0; i < q; i++) {       int a;       cin >> a;       if (a == 1) {         int b, c;         cin >> b >> c;         tmp.push_back({b, c});         if (tmp.size() == 2000) rebuild();       } else {         int c;         cin >> c;         out_val(c);       }     }   }   int main() {     ios::sync_with_stdio(0);     int q;     q = 1;     while (q--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   istream &operator>>(istream &is, vector<pair<T1, T2>> &v) {     for (pair<T1, T2> &t : v) is >> t.first >> t.second;     return is;   }   template <typename T>   istream &operator>>(istream &is, vector<T> &v) {     for (T &t : v) is >> t;     return is;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (const T &t : v) {       os << t <<    ;     }     os <<   n ;     return os;   }   double pi = acos(-1.0);   long long md = 1000000007;   long long abst(long long a) { return a < 0 ? -a : a; }   struct HASH {     size_t operator()(const pair<long long, long long> &x) const {       return (size_t)x.first * 37U + (size_t)x.second;     }   };   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   long long Pow(long long n, long long x) {     long long ans = 1;     while (x > 0) {       if (x & 1) ans = (ans * n) % md;       n = (n * n) % md;       x = x >> 1;     }     return ans;   }   vector<long long> fact, inv;   void inverse(long long n) {     inv.resize(n + 1);     inv[0] = 1;     for (long long i = 1; i <= n; i++) inv[i] = Pow(fact[i], md - 2);   }   void factorial(long long n) {     fact.resize(n + 1);     fact[0] = 1;     for (long long i = 1; i <= n; i++) fact[i] = (fact[i - 1] * i) % md;   }   long long max(long long a, long long b) { return a > b ? a : b; }   long long min(long long a, long long b) { return a < b ? a : b; }   void solve() {     long long n;     cin >> n;     vector<long long> v(n);     cin >> v;     vector<long long> ans(2 * n);     vector<long long> vis(2 * n + 1, -1);     for (long long i = 0; i < n; i++) {       ans[2 * i] = v[i];       vis[v[i]] = 1;     }     long long ptr;     for (long long i = 1; i < 2 * n; i += 2) {       ptr = -1;       for (long long j = 1; j <= 2 * n; j++)         if (vis[j] == -1 && j > ans[i - 1]) {           ptr = j;           break;         }       if (ptr == -1) {         cout << -1 <<   n ;         return;       }       ans[i] = ptr;       vis[ptr] = 1;     }     cout << ans;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   const int N = 2e5 + 10;   int n, k, a[N], b[N], idx[N], kp = -1;   char lc =  a  - 1, res[N];   int main() {     ios_base::sync_with_stdio(false), cout.tie(nullptr), cin.tie(nullptr);     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];       idx[a[i]] = i;     }     for (int i = 0; i < n; i++) {       cin >> b[i];     }     for (int i = 0; i < n; i++) {       if (kp < i && k > 0) {         lc++;         k--;       }       res[b[i]] = lc;       kp = max(kp, idx[b[i]]);     }     if (k == 0) {       cout <<  YES n  << (res + 1);     } else {       cout <<  NO n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int k, n, root, par[100005];   vector<int> v[100005];   bool vis[100005], fr;   void findroot(int u, int l) {     int i;     if (v[u].size() == 1 && l == 2 * k) {       fr = true;       root = u;     }     for (i = 0; i < v[u].size(); i++) {       if (fr) break;       if (!vis[v[u][i]]) {         vis[v[u][i]] = true;         par[v[u][i]] = u;         findroot(v[u][i], l + 1);       }     }   }   void dfs(int u, int l) {     int i;     if (v[u].size() == 1 && l != k) fr = true;     if (u != root && l != k && v[u].size() < 4) fr = true;     for (i = 0; i < v[u].size(); i++) {       if (fr) break;       if (!vis[v[u][i]]) {         vis[v[u][i]] = true;         dfs(v[u][i], l + 1);       }     }   }   int main() {     int i, x, y, leaf, cnt = 0;     cin >> n >> k;     for (i = 0; i < n - 1; i++) {       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     if (n == 1) {       cout <<  No n ;       return 0;     }     for (i = 1; i <= n; i++)       if (v[i].size() == 1) {         leaf = i;         break;       }     memset(vis, false, sizeof(vis));     vis[leaf] = true;     fr = false;     findroot(leaf, 0);     if (!fr) {       cout <<  No n ;       return 0;     }     while (cnt != k) {       root = par[root];       cnt++;     }     if (v[root].size() < 3) {       cout <<  No n ;       return 0;     }     memset(vis, false, sizeof(vis));     vis[root] = true;     fr = false;     dfs(root, 0);     if (fr) {       cout <<  No n ;     } else       cout <<  Yes n ;     return 0;   }