malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int n;       int m;       cin >> n >> m;       int count = 0;       for (int j = 0; j < n - 1; j++) {         string s;         cin >> s;         if (s[m - 1] ==  R ) {           count++;         }       }       string s;       cin >> s;       for (int i = 0; i < m - 1; i++) {         if (s[i] !=  R ) {           count++;         }       }       cout << count <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 100;   const int MOD = 1e9 + 7;   vector<long long> child[MAXN];   long long dpzooj[MAXN];   long long dpfard[MAXN];   void dfs(long long v) {     if (child[v].size() == 0) {       dpzooj[v] = 1, dpfard[v] = 1;       return;     }     for (auto u : child[v]) dfs(u);     long long tempzooj = 1;     long long tempfard = 0;     long long fardtafard = 0;     long long zoojtafard = 1;     long long hamezooj = 1;     for (auto u : child[v]) {       long long tempz = (tempfard * dpfard[u] + tempzooj * dpzooj[u]) % MOD;       long long tempf = (tempfard * dpzooj[u] + tempzooj * dpfard[u]) % MOD;       tempfard = tempf;       tempzooj = tempz;       long long ff = (fardtafard + zoojtafard * dpfard[u]) % MOD;       long long zf = (zoojtafard + fardtafard * dpfard[u]) % MOD;       fardtafard = ff;       zoojtafard = zf;       hamezooj = (hamezooj * dpzooj[u]) % MOD;     }     dpfard[v] = ((tempzooj - hamezooj + MOD) * 2 + hamezooj) % MOD;     dpzooj[v] = ((tempfard - fardtafard + MOD) * 2 + fardtafard + 1) % MOD;   }   int32_t main() {     long long n;     cin >> n;     for (long long i = 2; i <= n; i++) {       long long x;       cin >> x;       child[x].push_back(i);     }     dfs(1);     cout << (dpzooj[1] + dpfard[1] - 1 + MOD) % MOD;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1ll << 50;   const int maxn = 400005;   const int maxm = 65;   const long long mod = 1e9 + 7;   int ehead[maxn], ecnt = 1;   struct edge {     int u, v;     long long w;     int next;   } edg[maxn];   void add(int u, int v, long long w) {     edg[++ecnt] = (edge){u, v, w, ehead[u]};     ehead[u] = ecnt;     edg[++ecnt] = (edge){v, u, w, ehead[v]};     ehead[v] = ecnt;   }   long long pw2[maxm];   bool tag[maxm];   long long bas[maxm];   int tot;   void insert(long long val) {     for (int i = 60; i >= 0; i--)       if ((val >> i) & 1) tag[i] = true;     for (int i = 60; i >= 0; i--)       if ((val >> i) & 1) {         if (bas[i])           val ^= bas[i];         else {           bas[i] = val;           ++tot;           break;         }       }   }   long long p0[maxn], zero[maxm], one[maxm];   bool vis[maxn];   int n, m;   long long ans;   void dfs(int u, int parj) {     vis[u] = true;     for (int i = 60; i >= 0; i--) ((p0[u] >> i) & 1) ? one[i]++ : zero[i]++;     for (int j = ehead[u]; j; j = edg[j].next)       if (j != parj && j != (parj ^ 1)) {         int v = edg[j].v;         if (vis[v])           insert(edg[j].w ^ p0[u] ^ p0[v]);         else           p0[v] = p0[u] ^ edg[j].w, dfs(v, j);       }   }   int main() {     scanf( %d %d , &n, &m);     pw2[0] = 1ll;     for (int i = 1; i <= 60; i++) pw2[i] = pw2[i - 1] * 2 % mod;     for (int i = 1; i <= m; i++) {       int u, v;       long long w;       scanf( %d %d %lld , &u, &v, &w);       add(u, v, w);     }     for (int i = 1; i <= n; i++)       if (!vis[i]) {         memset(bas, 0, sizeof bas);         memset(tag, 0, sizeof tag);         memset(zero, 0, sizeof zero);         memset(one, 0, sizeof one);         tot = 0;         dfs(i, 0);         for (int j = 60; j >= 0; j--) {           long long _zero, _one, sum = 0;           if (tag[j])             _zero = _one = pw2[tot - 1];           else             _zero = pw2[tot], _one = 0;           (sum += (zero[j] - 1) * zero[j] / 2 % mod * _one) %= mod;           (sum += (one[j] - 1) * one[j] / 2 % mod * _one) %= mod;           (sum += zero[j] * one[j] * _zero) %= mod;           (ans += sum * pw2[j]) %= mod;         }       }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 301;   int main() {     int n;     scanf( %d , &n);     vector<map<int, int> > rank(n);     for (int i = 0; i < (n); ++i) {       for (int j = 0; j < (n); ++j) {         int a;         scanf( %d , &a);         --a;         rank[i][a] = j;       }     }     vector<int> my(n);     for (int i = 0; i < (n); ++i) {       scanf( %d , &my[i]);       --my[i];     }     vector<int> ans(n), val(n);     fill(val.begin(), val.end(), n);     for (int i = 0; i < (n); ++i) {       int tar = -1;       for (int j = 0; j < (n); ++j)         if (my[j] <= i) {           tar = my[j];           break;         }       for (int j = 0; j < (n); ++j) {         if (j == tar) continue;         int r = rank[j][tar];         if (val[j] > r) {           val[j] = r;           ans[j] = i;         }       }       for (int j = 0; j < (n); ++j)         if (my[j] != tar && my[j] <= i) {           int k = my[j];           int r = rank[tar][k];           if (val[tar] > r) {             val[tar] = r;             ans[tar] = i;           }           break;         }     }     for (int i = 0; i < (n); ++i) {       printf( %d , ans[i] + 1);       if (i < n - 1)         putchar(   );       else         putchar(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, base, number1 = 0, number2 = 0;     int temp;     vector<int> numbers;     cin >> n >> base;     while (n--) cin >> temp, numbers.insert(numbers.begin(), temp);     for (long long int i = 0, j = 1; i < numbers.size(); i++, j *= base)       number1 += j * numbers[i];     numbers.clear();     cin >> n >> base;     while (n--) cin >> temp, numbers.insert(numbers.begin(), temp);     for (long long int i = 0, j = 1; i < numbers.size(); i++, j *= base)       number2 += j * numbers[i];     if (number1 == number2)       cout <<  =  << endl;     else if (number1 < number2)       cout <<  <  << endl;     else       cout <<  >  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[10];   int main() {     int n;     while (scanf( %d , &n) != EOF) {       memset(a, 0, sizeof(a));       for (int i = 1; i <= n; ++i) a[i % 9]++;       long long ans = 0;       for (int i = 0; i < 9; ++i)         for (int j = 0; j < 9; ++j) ans += a[i] * a[j] * a[(i * j) % 9];       for (int i = 1; i <= n; ++i) ans -= n / i;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, kk;     cin >> n >> kk;     vector<string> v(n);     unordered_map<string, int> mp;     for (int i = 0; i < n; i++) {       cin >> v[i];       mp[v[i]]++;     }     int ans = 0;     string req;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         req =   ;         for (int k = 0; k < kk; k++) {           if (v[i][k] == v[j][k])             req.push_back(v[i][k]);           else {             if (v[i][k] ==  T  && v[j][k] ==  T ) req.push_back( T );             if (v[i][k] ==  S  && v[j][k] ==  S ) req.push_back( S );             if (v[i][k] ==  E  && v[j][k] ==  E ) req.push_back( E );             if (v[i][k] ==  T  && v[j][k] ==  S ) req.push_back( E );             if (v[i][k] ==  S  && v[j][k] ==  T ) req.push_back( E );             if (v[i][k] ==  T  && v[j][k] ==  E ) req.push_back( S );             if (v[i][k] ==  E  && v[j][k] ==  T ) req.push_back( S );             if (v[i][k] ==  S  && v[j][k] ==  E ) req.push_back( T );             if (v[i][k] ==  E  && v[j][k] ==  S ) req.push_back( T );           }         }         if (mp[req]) ans++;       }     }     cout << ans / 3 << endl;   }   signed main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int a[maxn], b[maxn], s[maxn], n;   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i] >> b[i];     int cnt = max(a[0], b[0]);     for (int i = 1; i < n; i++) {       if (max(a[i], b[i]) <= cnt)         cnt = max(a[i], b[i]);       else if (max(a[i], b[i]) > cnt && min(a[i], b[i]) <= cnt)         cnt = min(a[i], b[i]);       else {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<pair<int, int>> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i].first;       a[i].second = i;     }     sort(a.begin() + 1, a.end());     reverse(a.begin() + 1, a.end());     int nxt = 1;     vector<pair<int, int>> ans;     for (int i = 0; i < n; ++i) {       if (nxt == i) {         cout << -1 << endl;         return 0;       }       int nxt2 = nxt;       for (int j = nxt; j < nxt + a[i].first && j < n; ++j) {         ans.push_back(make_pair(a[i].second, a[nxt2].second));         ++nxt2;       }       nxt = nxt2;     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); ++i) {       cout << ans[i].first + 1 <<     << ans[i].second + 1 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 3e5 + 9;   int sz[MAX], ans[MAX], p[MAX], n, q;   vector<int> g[MAX];   int dfs(int v) {     sz[v] = 1;     for (auto u : g[v]) sz[v] += dfs(u);     return sz[v];   }   void calc(int v) {     int bes = -1;     for (auto u : g[v]) {       calc(u);       if (sz[u] >= ceil(sz[v] / 2.0)) bes = u;     }     if (bes == -1) {       ans[v] = v;       return;     }     int t = ans[bes];     while (sz[t] < ceil(sz[v] / 2.0)) t = p[t];     ans[v] = t;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> q;     for (int i = 1; i < n; i++) cin >> p[i], p[i]--, g[p[i]].push_back(i);     dfs(0), calc(0);     while (q--) {       int x;       cin >> x, x--;       cout << ans[x] + 1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum = 0;     string x;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x;       if (x ==  ABSINTH  || x ==  BEER  || x ==  BRANDY  || x ==  CHAMPAGNE  ||           x ==  GIN  || x ==  RUM  || x ==  SAKE  || x ==  TEQUILA  ||           x ==  VODKA  || x ==  WHISKEY  || x ==  WINE  || x ==  0  || x ==  1  ||           x ==  2  || x ==  3  || x ==  4  || x ==  5  || x ==  6  || x ==  7  ||           x ==  8  || x ==  9  || x ==  10  || x ==  11  || x ==  12  ||           x ==  13  || x ==  14  || x ==  15  || x ==  16  || x ==  17 )         sum++;     }     cout << sum <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000000;   bool can[2];   int a[N];   int main() {     ios::sync_with_stdio(false);     int n, x, y, l;     cin >> n >> l >> x >> y;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     set<int> q;     for (int i = 0; i < n; i++) {       q.insert(a[i]);     }     for (int i = 0; i < n; i++) {       if (q.find(-x + a[i]) != q.end()) can[0] = 1;       if (q.find(-y + a[i]) != q.end()) can[1] = 1;     }     if (!can[0] && !can[1]) {       for (int i = 0; i < n; i++) {         if (q.find(a[i] - x - y) != q.end()) {           cout <<  1 n  << a[i] - x <<   n ;           return 0;         }         if (q.find(a[i] + x - y) != q.end()) {           if (0 <= a[i] + x && a[i] + x <= l)             cout <<  1 n  << a[i] + x <<   n ;           else if (0 <= a[i] - y && a[i] - y <= l)             cout <<  1 n  << a[i] - y <<   n ;           else             continue;           return 0;         }       }     }     vector<int> ans;     if (!can[0]) ans.push_back(x);     if (!can[1]) ans.push_back(y);     cout << ans.size() <<   n ;     while (ans.size()) {       cout << ans.back() <<    ;       ans.pop_back();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool chkmin(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool chkmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   const int oo = 0x3f3f3f3f;   const int maxn = 200000, max0 = 100000, maxabs = 1e9;   struct node;   node *newnode();   struct node {     node *c[2];     int Max;     int label;     node() : Max(0), label(0) { memset(c, 0, sizeof c); }     void update() {       Max = 0;       for (int i = (0), _end_ = (2); i < _end_; ++i)         if (c[i]) chkmax(Max, c[i]->Max);     }     void flag_label(int _label) {       label += _label;       Max += _label;     }     void push_down() {       if (label) {         for (int i = (0), _end_ = (2); i < _end_; ++i) {           if (!c[i]) c[i] = newnode();           c[i]->flag_label(label);         }         label = 0;       }     }     inline int get_Max() { return this ? Max : 0; }   };   node *nd_pool;   int nd_res = 0;   node *newnode() {     if (!nd_res) nd_pool = new node[max0], nd_res = max0;     return nd_pool + (--nd_res);   }   node *rt;   int seg_x, seg_y, seg_z;   void add(node *&rt, int l, int r) {     if (!rt) rt = newnode();     if (seg_x <= l && r <= seg_y) {       rt->flag_label(seg_z);       return;     }     int mid = (l + r) >> 1;     rt->push_down();     if (seg_x < mid) add(rt->c[0], l, mid);     if (seg_y > mid) add(rt->c[1], mid, r);     rt->update();   }   inline bool seg_add(int first, int second, int z) {     if (first >= second) return 0;     seg_x = first, seg_y = second, seg_z = z;     add(rt, 0, maxabs + 1);     return 1;   }   inline void find(node *rt, int l, int r) {     assert(rt);     if (r - l <= 1) {       seg_y = l;       return;     }     rt->push_down();     int mid = (l + r) >> 1;     if (rt->c[0]->get_Max() >= seg_x)       find(rt->c[0], l, mid);     else       find(rt->c[1], mid, r);   }   int n, d;   pair<int, int> a[maxn + 5];   inline bool cmp(const pair<int, int> &first, const pair<int, int> &second) {     return first.second < second.second;   }   inline int find(int first) {     if (first > rt->get_Max()) return oo;     seg_x = first;     seg_y = oo;     find(rt, 0, maxabs + 1);     return seg_y;   }   int main() {     scanf( %d%d , &n, &d);     for (int i = (0), _end_ = (n); i < _end_; ++i)       scanf( %d%d , &a[i].first, &a[i].second), ++a[i].second,           chkmax(a[i].first, 0), chkmax(a[i].second, 0);     int now = 0;     sort(a, a + n, cmp);     int lst = 0;     for (int i = (0), _end_ = (n); i < _end_; ++i) {       seg_add(lst, a[i].second, now);       int tmp = -1;       while ((tmp = find(now + 1) + d) < a[i].second) {         ++now;         chkmax(tmp, lst);         seg_add(tmp, a[i].second, 1);       }       seg_add(a[i].first, a[i].second, 1);       chkmax(lst, a[i].second);     }     printf( %d n , rt->get_Max());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, t, a, b, at, bt;     cin >> x >> t >> a >> b >> at >> bt;     int btek = b;     set<int> my;     my.insert(0);     int ttek1 = t;     while (btek > 0 && ttek1 > 0) {       my.insert(btek);       int atek = a;       int ttek2 = t;       while (atek > 0 && ttek2 > 0) {         my.insert(atek);         my.insert(atek + btek);         ttek2--;         atek -= at;       }       ttek1--;       btek -= bt;     }     if (my.find(x) != my.end())       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     int n, i, ct = 0;     cin >> n >> s;     s =     + s;     for (i = 1; i <= n - 10; i++) {       if (s[i] ==  8 ) ct++;     }     if (ct > (n - 11) / 2)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   struct Query {     int idx, k;   };   int n, m;   int c[N], ans[N], cnt[N], pref[N];   vector<Query> qs[N];   vector<int> adj[N];   void read() {     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> c[i];     for (int i = 1; i <= n - 1; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int i = 1; i <= m; i++) {       int v, k;       cin >> v >> k;       qs[v].push_back({i, k});     }   }   int idx = 0;   int fs[N], ed[N], euler[N], sz[N];   void findSz(int u, int p) {     sz[u] = 1;     fs[u] = ++idx;     euler[idx] = u;     for (auto& v : adj[u]) {       if (v != p) {         findSz(v, u);         sz[u] += sz[v];       }     }     ed[u] = idx;   }   void dfs(int u, int p, bool keep) {     int mx = -1, bigChild = -1;     for (auto& v : adj[u]) {       if (v != p && mx < sz[v]) mx = sz[v], bigChild = v;     }     for (auto& v : adj[u]) {       if (v != p && v != bigChild) dfs(v, u, 0);     }     if (bigChild != -1) dfs(bigChild, u, 1);     for (auto& v : adj[u]) {       if (v != p && v != bigChild) {         for (int i = fs[v]; i <= ed[v]; i++) {           pref[cnt[c[euler[i]]]]--;           cnt[c[euler[i]]]++;         }       }     }     pref[cnt[c[u]]]--;     cnt[c[u]]++;     for (auto& q : qs[u]) ans[q.idx] = N - pref[q.k - 1];     if (!keep) {       for (int i = fs[u]; i <= ed[u]; i++) {         cnt[c[euler[i]]]--;         pref[cnt[c[euler[i]]]]++;       }     }   }   void solve() {     findSz(1, 0);     memset(cnt, 0, sizeof cnt);     for (int i = 0; i < N; i++) pref[i] = N;     dfs(1, 0, 1);     for (int i = 1; i <= m; i++) cout << ans[i] <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     read();     solve();     return 0;   }
#include<bits/stdc++.h>   using namespace std;   #define N 2005   int read(){    int w=0,f=1;    char c=   ;    while(c< 0 ||c> 9 )f=(c== - ?-f:f),c=getchar();    while(c>= 0 &&c<= 9 )w=w*10+c- 0 ,c=getchar();    return w*f;   }   int T,n,ans[N],cnt;   bool vis[N];   bool check(int x){    printf( ? %d %d n ,x,1);    for(int i=1;i<=x;i++)     printf( %d%c ,i,i==x?  n :   );    printf( %d n ,ans[2]);    fflush(stdout);    return read()?1:0;   }   signed main(){    T=read();    while(T--){     n=read(),cnt=2;     for(int i=1;i<=n;i++)      vis[i]=0;     bool fl=0;     for(int i=2;i<=n&&!fl;i++){      printf( ? %d %d n ,i-1,1);      for(int j=1;j<i;j++)       printf( %d%c ,j,j==i-1?  n :   );      printf( %d n ,i);      fflush(stdout);      if(read())ans[2]=i,fl=1;     }     int l=1,r=ans[2]-2;     ans[1]=ans[2]-1;     while(l<=r){      int mid=(l+r)>>1;      if(check(mid))ans[1]=mid,r=mid-1;      else l=mid+1;     }     for(int i=ans[2]+1;i<=n;i++){      printf( ? 1 1 n%d n%d n ,ans[2],i);      fflush(stdout);      if(read())ans[++cnt]=i;     }     for(int i=1;i<=cnt;i++)      vis[ans[i]]=1;     printf( ! %d  ,n-cnt);     for(int i=1;i<=n;i++)      if(!vis[i])printf( %d%c ,i,i==n-cnt?  n :   );     fflush(stdout);    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const int MOD = (int)1e9 + 7;   const int N = (int)3e5 + 7;   int n, p, k, a[N];   map<int, int> cnt;   inline int add(int a, int b) { return (a += b) >= p ? a - p : a; }   inline int mul(int a, int b) { return 1ll * a * b % p; }   void Init() {     cnt.clear();     for (int i = (1); i < (n + 1); ++i) scanf( %d , a + i);   }   int Solve() {     long long ans = 0;     for (int i = (1); i < (n + 1); ++i) {       int tmp = mul(mul(a[i], a[i]), mul(a[i], a[i]));       tmp = add(tmp, p - mul(k, a[i]));       ans += cnt[tmp];       cnt[tmp]++;     }     return printf( %lld n , ans);   }   int main() {     while (~scanf( %d%d%d , &n, &p, &k)) {       Init();       Solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int on[10001];   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     int n, t, r, ans = 0;     cin >> n >> t >> r;     for (int i = 0; i < n; ++i) {       int w;       cin >> w;       w += 400;       int cnt = 0;       for (int j = w; j > w - t; --j) {         if (on[j]) {           ++cnt;         }       }       int todo = max(r - cnt, 0);       for (int j = w; j > w - t; --j) {         if (!on[j] and todo > 0) {           on[j] = 1;           todo -= 1;           ++ans;         }       }       if (todo > 0) {         cout << -1;         return 0;       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, cnt = 0, i, l;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> l;       if (l == 1) {         cnt += 1;       }     }     if (cnt > 0) {       cout <<  HARD ;     } else {       cout <<  EASY ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, L, R;   int a, b;   int lo = -1, hi = 1e9 + 1;   const int MAXN = 111111;   const int INF = 1e9;   vector<pair<int, int> > adj[MAXN];   int sz[MAXN], chk[MAXN];   int q[MAXN], f[MAXN], g[MAXN], d[MAXN], h[MAXN];   void dfs(int u, int p) {     sz[u] = 1;     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i].first;       if (v != p) {         dfs(v, u);         sz[u] += sz[v];       }     }   }   int get_center(int u) {     int s = sz[u];     while (1) {       int r = 0;       for (int i = 0; i < adj[u].size(); i++) {         int v = adj[u][i].first;         if (chk[v]) continue;         if (sz[v] > sz[r]) r = v;       }       if (sz[r] <= s / 2) return u;       sz[u] = s - sz[r], u = r;     }   }   bool cmp(pair<int, int> a, pair<int, int> b) {     return sz[a.first] < sz[b.first];   }   void go(int u, int p, int mid, int s) {     f[u] = s, d[u] = d[p] + 1;     if (d[u] > R) return;     if (f[h[d[u]]] < s) h[d[u]] = u;     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i].first;       if (v == p || chk[v]) continue;       go(v, u, mid, s + (adj[u][i].second >= mid ? 1 : -1));     }   }   bool check(int u, int mid, int &x, int &y) {     f[u] = d[u] = 0, f[0] = -INF, g[0] = u;     for (int j = 1; j <= R && j <= sz[u]; j++) g[j] = 0;     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i].first;       if (chk[v]) continue;       for (int j = 1; j <= R && j <= sz[v]; j++) h[j] = 0;       go(v, u, mid, (adj[u][i].second >= mid ? 1 : -1));       int head = 0, tail = 0;       for (int j = 1, k = min(sz[v], R - 1); j <= min(R, sz[v]); j++) {         if (h[j] == 0) break;         for (; k >= max(0, L - j); k--) {           if (g[k] == 0) continue;           while (head < tail && f[g[q[tail - 1]]] <= f[g[k]]) tail--;           q[tail++] = k;         }         while (head < tail && q[head] > R - j) head++;         if (head < tail && f[g[q[head]]] + f[h[j]] >= 0) {           x = g[q[head]], y = h[j];           return 1;         }       }       for (int j = 1; j <= min(R, sz[v]); j++)         if (f[g[j]] < f[h[j]]) g[j] = h[j];     }     return 0;   }   void process(int u) {     sort((adj[u]).begin(), (adj[u]).end(), cmp);     hi = 1e9 + 1;     int x = 0, y = 0;     while (hi - lo > 1) {       int mid = lo + hi >> 1;       if (check(u, mid, x, y))         a = x, b = y, lo = mid;       else         hi = mid;     }   }   void solve(int u) {     u = get_center(u);     process(u), chk[u] = 1;     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i].first;       if (!chk[v]) solve(v);     }   }   int main() {     cin >> n >> L >> R;     for (int i = 1; i < n; i++) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       adj[u].push_back(make_pair(v, w));       adj[v].push_back(make_pair(u, w));     }     dfs(1, 0);     solve(1);     printf( %d %d n , a, b);     return 0;   }
#include <bits/stdc++.h>   const int N = 200020;   int _, n, m, x, y, flag, a[N], c[N], d[N];   std::queue<int> q;   std::pair<int, int> b[N];   std::vector<int> g[N], ans;   void f(int u) {     if (++a[u] > g[u].size() && !c[u]) q.push(u), c[u] = 1;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &x, &y);       b[i] = {x, y};       g[x].push_back(i);       g[y].push_back(i);     }     for (int i = 1; i <= n; i++) f(i);     for (; q.size(); q.pop())       for (int u : g[q.front()])         if (!d[u]) ans.push_back(u), f(b[u].first), f(b[u].second), d[u] = 1;     if (ans.size() == m) {       puts( ALIVE );       reverse(ans.begin(), ans.end());       for (int j : ans) printf( %d  , j);     } else       puts( DEAD );   }