malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void print(vector<int> v) {     size_t sz = v.size();     for (int i : v) {       cout << i <<    ;     }   }   vector<int> a, b, c;   int main(void) {     int n, m;     scanf( %d , &n);     a.resize(n);     int x;     for (unsigned i = 0; i < n; i++) {       scanf( %d , &x);       a[i] = x;       c.push_back(x);     }     scanf( %d , &m);     b.resize(m);     for (unsigned i = 0; i < m; i++) {       scanf( %d , &x);       b[i] = x;       c.push_back(x);     }     int a1 = 0, a2 = 0;     int ans = INT_MIN;     int co = m + n;     sort(a.begin(), a.end());     sort(b.begin(), b.end());     sort(c.begin(), c.end());     c.push_back(c[co - 1] + 1);     co++;     int i = 0;     for (i = 0; i < co; i++) {       int p1, p2 = 0;       int val = c[i] - 1;       int l = 0, h = n - 1, mid;       while (l <= h) {         mid = (l + h) / 2;         if (a[mid] <= val)           l = mid + 1;         else           h = mid - 1;       }       p1 = 3 * (n - l) + 2 * l;       l = 0;       h = m - 1;       while (l <= h) {         mid = (l + h) / 2;         if (b[mid] <= val)           l = mid + 1;         else           h = mid - 1;       }       p2 = 3 * (m - l) + 2 * l;       if ((p1 - p2) > ans) {         ans = p1 - p2;         a1 = p1;         a2 = p2;       } else if ((p1 - p2) == ans) {         if (p1 > a1) {           a1 = p1;           a2 = p2;         }       }     }     printf( %d:%d , a1, a2);   }
#include <bits/stdc++.h>   int main() {     int count;     std::vector<int> visitors;     std::cin >> count;     for (int i = 0; i < 2 * count; ++i) {       int value;       std::cin >> value;       visitors.push_back(value);     }     int counter = 0;     for (int i = 0; i < 2 * count; i += 2) {       if (visitors[i] != visitors[i + 1]) {         for (int j = 2 * count - 1; j > i + 1; j--) {           if (visitors[j] == visitors[i]) {             for (int k = j; k > i + 1; k--) {               std::swap(visitors[k], visitors[k - 1]);               counter++;             }             break;           }         }       }     }     std::cout << counter << std::endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<vector<int>> v(n);     int mat[4][4] = {         {8, 9, 1, 13}, {3, 12, 7, 5}, {0, 2, 4, 11}, {6, 10, 15, 14}};     int ans[n][n];     for (int i = 0; i < n * n; i++) {       int x = i / n;       v[x].push_back(i);     }     int count = 0;     for (int i = 0; i < n; i += 4) {       for (int j = 0; j < n; j += 4) {         for (int k = i; k < i + 4; k++) {           for (int l = j; l < j + 4; l++) {             ans[k][l] = count++;           }         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (j == 0)           cout << ans[i][j];         else           cout <<     << ans[i][j];       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int A[maxn], MAX = 0;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> A[i];     sort(A, A + n);     int ans = 0;     for (int i = 0; i < n; i++)       if (ans * A[i] + ans <= i) ans++;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, q, i, s1, s[100010], a[100010], k[100010], t, at, dp, sum, now;   bool cmp(long long a, long long b) { return a > b; }   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];     }     cin >> q;     for (i = 0; i < q; i++) {       cin >> k[i];     }     sort(a, a + n, cmp);     s[0] = 0;     for (i = 0; i < n; i++) {       s[i + 1] = s[i] + a[i];     }     s1 = 0;     for (i = 0; i < n; i++) {       s1 += a[i] * i;     }     for (i = 0; i < q; i++) {       if (i != 0) cout <<    ;       if (k[i] == 1) {         cout << s1;         continue;       }       t = 1;       dp = 1;       now = k[i];       sum = 0;       while (t + now < n) {         at = s[t + now] - s[t];         at = at * dp;         sum += at;         t = t + now;         now = now * k[i];         dp++;       }       at = s[n] - s[t];       at = at * dp;       sum += at;       cout << sum;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 + 5;   int arr[maxn][maxn];   int main() {     int m, n, k, p, sum = 0;     bool bol = false;     cin >> n >> m >> k;     if (n % 2 != m % 2) {       cout << 0 << endl;       return 0;     }     if (m > n) {       bol = true;       swap(n, m);     }     for (int i = 0; i < k; i++) {       int x, y, z;       cin >> x >> y >> z;       if (bol) swap(x, y);       arr[x - 1][y - 1] = z;     }     cin >> p;     for (int i = 0, x, tmp; i < n; i++) {       x = 0;       tmp = 1;       for (int j = 0; j < m; j++) {         tmp *= arr[i][j];         if (arr[i][j]) x++;       }       if (x != m)         sum += m - x - 1;       else if (tmp != -1) {         cout << 0 << endl;         return 0;       }     }     sum -= m - 1;     int ans = 1;     for (int i = 0; i < sum; i++) {       ans *= 2;       ans %= p;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   const long long INF = 1e17, N = 2e5 + 1;   using namespace std;   int a[N], n, m, k, sum[N], t[N];   int getime(int idx) { return min(idx, n - idx + 1); }   int getlen(int l, int r) {     if (l > r) swap(l, r);     int tmp = (r - l) / m;     if ((r - l) % m != 0) tmp++;     return tmp;   }   int f(int tmp) {     for (int i = 1; i <= n; i++) {       sum[i] = 0;     }     for (int i = 1; i <= n; i++) {       a[i] = t[i];     }     int idx = 1;     for (int i = (n / 2) - tmp + 1; i <= ((n + 1) / 2) + tmp; i++) {       while (sum[i] != k && idx <= n) {         if (a[idx] == 0 || getlen(idx, i) > getime(i)) {           idx++;         } else {           int tmp = min(k - sum[i], a[idx]);           a[idx] -= tmp;           sum[i] += tmp;         }       }       if (sum[i] != k) {         return 0;       }     }     return 1;   }   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       cin >> t[i];     }     int l = 0, r = n / 2;     while (l != r) {       int mid = (l + r + 1) >> 1;       if (f(mid)) {         l = mid;       } else {         r = mid - 1;       }     }     cout << (n / 2) - l;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> tree;   void build(vector<long long> &arr, long long ind, long long l, long long r) {     if (l == r) {       tree[ind] = arr[l];       return;     }     long long mid = (l + r) / 2;     build(arr, ind * 2, l, mid);     build(arr, ind * 2 + 1, mid + 1, r);     tree[ind] = max(tree[ind * 2], tree[ind * 2 + 1]);   }   long long getMax(long long ind, long long tl, long long tr, long long l,                    long long r) {     if (l > r) return 0;     if (l == tl && r == tr) return tree[ind];     long long tm = (tl + tr) / 2;     long long a = getMax(ind * 2, tl, tm, l, min(r, tm));     long long b = getMax(ind * 2 + 1, tm + 1, tr, max(l, tm + 1), r);     return max(a, b);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     vector<long long> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     long long count = 1;     for (int i = n - 2; i >= 0; i--) {       if (a[i] < a[i + 1]) {         count++;       } else {         break;       }     }     cout << n - count;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[26] = {0};     string s;     cin >> s;     transform(s.begin(), s.end(), s.begin(), ::tolower);     for (int i = 0; i < n; i++) arr[s[i] -  a ]++;     for (int i = 0; i < 26; i++) {       if (arr[i] == 0) {         puts( NO );         return 0;       }     }     puts( YES );   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const double pi = acos(-1);   int n, i, j, k, t;   long double a[100004], b[100004], val[100003];   int x[100004], c[100003];   vector<int> adj[100005];   int par[100003];   bool bisa = true;   void dfs(int v, int p) {     val[v] = b[v] - a[v];     for (int x : adj[v]) {       if (x != p) {         dfs(x, v);         if (val[x] > 0)           val[v] += val[x];         else           val[v] += val[x] * c[x];       }     }     if (val[v] < 0 && fabsl(val[v]) > 1e17L / c[v]) {       puts( NO );       exit(0);     }   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; ++i) scanf( %Lf , b + i);     for (i = 1; i <= n; ++i) scanf( %Lf , a + i);     for (i = 2; i <= n; ++i) {       scanf( %d %d , x + i, c + i);       adj[x[i]].push_back(i);       adj[i].push_back(x[i]);     }     dfs(1, 1);     puts(val[1] >= 0 ?  YES  :  NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }   long long lcm(long long a, long long b) { return (a * (b / gcd(a, b))); }   long long bigmod(long long b, long long p, long long m) {     if (p == 0) return 1;     if (p % 2 == 0) {       long long temp = bigmod(b, p / 2, m);       return (temp * temp) % m;     }     return (bigmod(b, p - 1, m) * (b % m)) % m;   }   char inp[10010];   string scan() {     scanf( %s , inp);     string s;     for (int i = 0; inp[i]; i++) s += inp[i];     return s;   }   vector<vector<int> > v;   vector<bool> visited;   int visit[100];   void dfs(int node) {     visit[node] = 1;     for (int i = 0; i < (int)v[node].size(); i++)       if (!visit[v[node][i]]) dfs(v[node][i]);   }   int connectedcomponenetscnt(int head) {     int cnt = 0;     for (int i = 1; i < 500; i++) {       if (!visit[i]) {         dfs(i);         cnt++;       }     }     return cnt;   }   int com(string s, string t) {     for (int i = 0; i < min(s.length(), t.length()); i++) {       if (s[i] > t[i]) return 1;       if (s[i] < t[i]) return 0;     }     if (s.length() > t.length()) return 1;     return 0;   }   int n, m, x;   int a[1001];   int memo[1001][1001][2];   int dp(int i, int sum, int k) {     if (sum % m == 0 && k) return 1;     if (i == m) return 0;     int &ret = memo[i][sum][k];     if (ret != -1) return ret;     ret = 0;     for (int j = 0; j <= a[i]; j++) {       if (j > 0 || k)         ret = ret + dp(i + 1, (sum + i * j) % m, 1);       else         ret = ret + dp(i + 1, (sum + i * j) % m, 0);     }     return ret;   }   int main() {     memset(memo, -1, sizeof(memo));     memset(a, 0, sizeof(a));     cin >> n >> m;     int yes = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &x);       x = x % m;       if (x == 0) yes = 1;       a[x]++;     }     for (int i = 1; i < m; i++)       if (a[i] >= m) yes = 1;     if (yes)       cout <<  YES ;     else if (dp(1, 0, 0))       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int>> vc;   vector<pair<int, int>> vc2;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       vc.push_back(make_pair(x, y));     }     vc2 = vc;     sort(vc.begin(), vc.end(),          [](const pair<int, int> &left, const pair<int, int> &right) {            if (left.first != right.first)              return left.first < right.first;            else              return left.second > right.second;          });     int mini = vc[0].first;     int maxi = vc[0].second;     for (int i = 1; i < vc.size(); i++) {       if (vc[i].first >= mini && vc[i].second <= maxi)         continue;       else {         cout << -1;         return 0;       }     }     for (int i = 0; i < vc2.size(); i++) {       if (vc2[i].first == mini && vc2[i].second == maxi) {         cout << i + 1;         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   int N, M;   int pwr[MAXN], jump[MAXN], cnt[MAXN];   int len;   void recalc(int pos) {     int nxt = pos + pwr[pos];     if (nxt < N && (nxt / len) == (pos / len)) {       jump[pos] = jump[nxt];       cnt[pos] = cnt[nxt] + 1;     } else {       jump[pos] = nxt;       cnt[pos] = 1;     }   }   int main(int argc, char *argv[]) {     scanf( %d%d , &N, &M);     for (int i = 0, _i = N; i < _i; ++i) {       scanf( %d , pwr + i);     }     len = (int)sqrt((double)N);     for (int i = N - 1; i >= 0; i--) {       recalc(i);     }     for (int i = 0, _i = M; i < _i; ++i) {       int type, a;       scanf( %d%d , &type, &a);       --a;       if (type) {         int cur = a, ret = 0;         while (true) {           ret += cnt[cur];           if (jump[cur] >= N) break;           cur = jump[cur];         }         while (cur + pwr[cur] < N) cur += pwr[cur];         printf( %d %d n , cur + 1, ret);       } else {         int b;         scanf( %d , &b);         pwr[a] = b;         int ablock = a / len;         for (int i = a; i >= 0 && (i / len) == ablock; i--) recalc(i);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e17 + 9;   double ans = 0;   vector<int> adj[100009];   int vis[100009];   double dfs(int x, double prof) {     vis[x] = 1;     double ret = 1 / prof;     for (auto e : adj[x]) {       if (vis[e] == -1) ret += dfs(e, prof + 1);     }     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     memset(vis, -1, sizeof vis);     cout << fixed << setprecision(6);     long long n;     cin >> n;     long long m = n - 1;     while (m--) {       long long a, b;       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     cout << dfs(1, 1) <<   n ;     return 0;   }
#include <bits/stdc++.h>   int a[2 * 1000010];   int main() {     int n, l, t, i, j, nn, k, left;     scanf( %d%d%d , &n, &l, &t);     nn = 2 * n;     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = n; i < nn; i++) a[i] = l + a[i - n];     k = 2 * t / l;     left = 2 * t - k * l;     double ans = 1.0 * (n - 1) * n * k;     for (i = 0, j = 0; i < n; i++) {       while (j < nn && a[j] - a[i] <= left) j++;       ans += j - 1 - i;     }     printf( %lf n , ans / 4);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = (int)(1e9 + 1337);   const long long LINF = (long long)(4e18);   const double EPS = (double)(1e-11);   int n;   int m;   int ans;   vector<vector<int> > g;   vector<set<int> > s;   vector<set<int> > fbd;   int a[1000010];   void dfs(int v, int p) {     int cur = 1;     for (auto &it : s[v]) {       if (a[it] != -1) fbd[v].insert(a[it]);     }     for (auto &it : s[v]) {       if (a[it] != -1) continue;       while (fbd[v].count(cur)) cur++;       ans = max(ans, cur);       a[it] = cur;       cur++;     }     for (int i = 0; i < (int)g[v].size(); i++) {       int to = g[v][i];       if (p == to) continue;       dfs(to, v);     }   }   void solve() {     cin >> n >> m;     g.resize(n + 1);     s.resize(n + 1);     fbd.resize(n + 1);     int tk = 0;     for (int i = 1; i <= n; i++) {       int k;       cin >> k;       tk = max(k, tk);       for (int j = 0; j < k; j++) {         int tt;         cin >> tt;         s[i].insert(tt);       }     }     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     memset(a, -1, sizeof a);     dfs(1, 0);     if (ans == 0) ans = 1;     cout << ans <<   n ;     for (int i = 1; i <= m; i++) {       if (a[i] == -1) a[i] = 1;       cout << a[i] <<    ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     int l, r, t, c;     int res = 0;     cin >> n >> m;     n++;     int a[n];     int b[n];     for (int i = 0; i < n; i++) {       a[i] = 10000;       b[i] = 0;     }     while (m--) {       cin >> l >> r >> t >> c;       for (int i = l; i <= r; i++) {         if (a[i] > t) {           a[i] = t;           b[i] = c;         }       }     }     for (int i = 0; i < n; i++) {       res += b[i];     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long max(long long x, long long y) { return x > y ? x : y; }   long long min(long long x, long long y) { return x < y ? x : y; }   void _(long long& a, long long b) {     a = (a % 1000000007 + b % 1000000007) % 1000000007;     a = (a + 1000000007) % 1000000007;   }   long long cl(long long a, long long b) { return (a / b) + (!(!(a % b))); }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string s, t;     cin >> s >> t;     long long a, b;     a = b = 0;     for (long long i = 0; i < s.size(); ++i) {       a += s[i] ==  1 ;     }     for (long long i = 0; i < t.size(); ++i) {       b += t[i] ==  1 ;     }     if (a + (a & 1) >= b)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s;     scanf( %d %d , &n, &s);     long long arr[n];     for (int i = 0; i < n; i++) scanf( %lld , &arr[i]);     sort(arr, arr + n);     long long val = arr[n / 2];     long long cnt = abs(s - val);     for (int i = 0; i < (n / 2); i++) {       if (arr[i] > s) {         cnt += abs(arr[i] - s);       }     }     for (int i = (n / 2) + 1; i < n; i++) {       if (arr[i] < s) {         cnt += abs(arr[i] - s);       }     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100;   const int inf = 0x3f3f3f3f;   const int mod = 1e9 + 7;   void MOD(int &x) {     if (x >= mod) x -= mod;   }   void MOD(long long &x) {     if (x >= mod) x -= mod;   }   long long powmod(long long x, long long n) {     long long ret = 1;     for (; n > 0; n >>= 1, x = x * x % mod)       if (n & 1) ret = ret * x % mod;     return ret;   }   int n, m, k;   vector<pair<int, int> > v[maxn];   bool vis[maxn];   struct edge {     int x, y, w;     long long sta;   } E[maxn];   int cnt = 0;   int dfs(int p, int w, int limt, long long sta) {     if (limt < w || cnt >= k) return 0;     if (p == m + 1) {       cnt++;       return 1;     }     int r = 0, u = E[p].x, v = E[p].y;     if (!(sta & E[p].sta)) {       r = dfs(p + 1, w + E[p].w, limt, sta | E[p].sta);     }     if (r >= k) return r;     r += dfs(p + 1, w, limt, sta);     return r;   }   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= m; ++i) {       int x, y, w;       cin >> x >> y >> w;       E[i] = {x, y, w};       long long s = 1ll << (x + n);       s |= 1ll << y;       E[i].sta = s;     }     int l = 0, r = n * 1000;     while (l < r) {       int mid = l + r >> 1;       cnt = 0;       int x = dfs(1, 0, mid, 0);       x = cnt;       if (x >= k)         r = mid;       else         l = mid + 1;     }     cout << l <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (1e6) + 1, M = (1e7) + 1;   int n, k, a[N], dp[M];   bool check(int x) {     fill(dp + 1, dp + M, 0);     for (int i = x; i <= (1e7); i++) dp[i] = max(dp[i >> 1] + dp[i + 1 >> 1], 1);     long long sum = 0;     for (int i = 0; i < n; i++) sum += dp[a[i]];     return (sum >= k);   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , a + i);     int l = 0, r = 1e7;     while (l < r) {       int mid = (l + r + 1) >> 1;       if (check(mid))         l = mid;       else         r = mid - 1;     }     if (!l)       printf( -1 );     else       printf( %d , l);   }
#include <bits/stdc++.h>   using namespace std;   void fun() {}   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     fun();     long long int c, v, u, a, l, p = 0, ans = 1;     cin >> c >> v >> u >> a >> l;     p += v;     while (p < c) {       v += a;       p += min(v, u) - l;       ans++;     }     cout << ans;     cerr <<  time elapsed :   << 1.0 * clock() / CLOCKS_PER_SEC <<   sec  n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   int sz[N];   vector<int> g[N], g2[N];   signed main() {     int n;     std::cin >> n;     int sum = 0;     vector<int> nonOnes, ones;     for (int i = 0; i < n; ++i) {       std::cin >> sz[i];       sum += sz[i];       if (sz[i] > 1) {         nonOnes.push_back(i);       } else {         ones.push_back(i);       }     }     if (sum < 2 * n - 2) {       std::cout <<  NO ;       return 0;     }     for (int i = 1; i < nonOnes.size(); ++i) {       sz[nonOnes[i - 1]]--;       sz[nonOnes[i]]--;       g[nonOnes[i - 1]].push_back(nonOnes[i]);       g2[nonOnes[i - 1]].push_back(nonOnes[i]);       g2[nonOnes[i]].push_back(nonOnes[i - 1]);     }     bool f = false, s = false;     for (auto d : ones) {       bool fl = false;       if (!f && sz[nonOnes[0]]) {         g[d].push_back(nonOnes[0]);         g2[d].push_back(nonOnes[0]);         g2[nonOnes[0]].push_back(d);         sz[nonOnes[0]]--;         f = true;         continue;       }       if (!s && sz[nonOnes.back()]) {         g[d].push_back(nonOnes.back());         g2[d].push_back(nonOnes.back());         g2[nonOnes.back()].push_back(d);         sz[nonOnes.back()]--;         s = true;         continue;       }       for (auto x : nonOnes) {         if (sz[x]) {           g[d].push_back(x);           g2[x].push_back(d);           g2[d].push_back(d);           sz[x]--;           fl = true;           break;         }       }       if (!fl) {         std::cout <<  NO ;         return 0;       }     }     int answ = 0, m = 0;     for (int i = 0; i < n; ++i) {       m += g[i].size();     }     for (int i = 0; i < n; ++i) {       vector<int> d(n, 1e9);       std::queue<int> bfs;       d[i] = 0;       bfs.push(i);       while (!bfs.empty()) {         int v = bfs.front();         bfs.pop();         for (auto e : g2[v]) {           if (d[e] > d[v] + 1) {             answ = std::max(answ, d[v] + 1);             d[e] = d[v] + 1;             bfs.push(e);           }         }       }     }     std::cout <<  YES   << answ <<   n  << m <<   n ;     for (int i = 0; i < n; ++i) {       for (auto e : g[i]) {         std::cout << i + 1 <<     << e + 1 <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     vector<int> adj[n];     int deg[n];     for (int i = 0; i < n; i++) {       deg[i] = 0;     }     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       adj[a].push_back(b);       adj[b].push_back(a);       deg[a]++;       deg[b]++;     }     vector<int> li;     for (int i = 0; i < n; i++) {       if (deg[i] == 1) {         li.push_back(i);       }     }     for (int i = 0; i < li.size(); i++) {       int now = li[i];       for (int j = 0; j < adj[now].size(); j++) {         int to = adj[now][j];         deg[to]--;         if (deg[to] == 1) {           li.push_back(to);         }       }     }     if (li.size() != n) {       cout <<  No  << endl;       return 0;     }     bool v[n];     int deep[n];     for (int i = 0; i < n; i++) {       v[i] = false;       deep[i] = -1;     }     v[li[n - 1]] = true;     deep[li[n - 1]] = 0;     bool ok = true;     for (int i = n - 1; i >= 0; i--) {       int now = li[i];       if (!v[now] || deep[now] > k) {         ok = false;         break;       }       int red = adj[now].size();       if (i < n - 1) {         red--;       }       if (red < 3 && deep[now] != k) {         ok = false;         break;       }       for (int j = 0; j < adj[now].size(); j++) {         int to = adj[now][j];         if (!v[to]) {           v[to] = true;           deep[to] = deep[now] + 1;         }       }     }     cout << (ok ?  Yes  :  No ) << endl;   }