malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   namespace flyinthesky {   const int MAXN = 500000 + 5;   struct edge {     int u, v, w;     bool operator<(const edge &b) const { return w < b.w; }   } ed[MAXN], ed2[MAXN];   struct whw {     int id, fr, t;   };   struct ask {     int id;     bool operator<(const ask &b) const { return ed[id].w < ed[b.id].w; }   };   int n, m, q, ans[MAXN], maxw = 0, f[MAXN], sz[MAXN];   vector<whw> a[MAXN];   vector<ask> que[MAXN];   stack<pair<int, int> > s;   int find(int x) { return x == f[x] ? x : find(f[x]); }   void mg(int a, int b) {     int x = a, y = b;     if (sz[x] > sz[y]) swap(x, y);     f[x] = y, sz[y] += sz[x], s.push(make_pair(x, y));   }   void cc(int tms) {     while (tms-- && !s.empty()) {       pair<int, int> p = s.top();       s.pop();       int x = p.first, y = p.second;       f[x] = x, sz[y] -= sz[x];     }   }   void clean() { memset(ans, 0, sizeof ans); }   int solve() {     cin >> n >> m;     clean();     for (int i = 1; i <= m; ++i)       scanf( %d%d%d , &ed[i].u, &ed[i].v, &ed[i].w), maxw = max(maxw, ed[i].w),                                                      ed2[i] = ed[i];     sort(ed2 + 1, ed2 + 1 + m);     cin >> q;     for (int i = 1; i <= q; ++i) {       int Ki;       scanf( %d , &Ki);       for (int x, j = 1; j <= Ki; ++j)         scanf( %d , &x), que[i].push_back((ask){x});       sort(que[i].begin(), que[i].end());       int lst = 0;       for (int j = 1; j < (int)que[i].size(); ++j) {         int id = que[i][j].id, lid = que[i][j - 1].id;         if (ed[id].w != ed[lid].w) {           a[ed[lid].w].push_back((whw){i, lst, j - 1});           lst = j;         }       }       a[ed[que[i][(int)que[i].size() - 1].id].w].push_back(           (whw){i, lst, (int)que[i].size() - 1});     }     for (int i = 0; i <= n; ++i) f[i] = i, sz[i] = 1;     int now = 1;     for (int i = 1; i <= maxw; ++i) {       for (int j = 0; j < (int)a[i].size(); ++j) {         int fl = 0, tms = 0;         whw &ct = a[i][j];         for (int k = ct.fr; k <= ct.t; ++k) {           edge &e = ed[que[ct.id][k].id];           int x = find(e.u), y = find(e.v);           if (x == y) {             fl = 1;             break;           } else             mg(x, y), ++tms;         }         if (fl) ans[ct.id] = 1;         cc(tms);       }       while (ed2[now].w == i) {         int x = find(ed2[now].u), y = find(ed2[now].v);         if (x != y) mg(x, y);         ++now;       }     }     for (int i = 1; i <= q; ++i) printf( %s , ans[i] == 1 ?  NO n  :  YES n );     return 0;   }   }  // namespace flyinthesky   int main() {     flyinthesky::solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool cmp(long long int a, long long int b) { return b < a; }   int main() {     long long int n;     cin >> n;     long long int a[n + 1];     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);     }     sort(a + 1, a + n + 1, cmp);     long long int ans = 0;     a[0] = 0;     for (int i = 1; i <= n / 4; i++) {       a[i] += a[i - 1];     }     for (int i = 1; i <= n / 4; i = i * 4) {       ans += a[i];     }     for (int i = n / 4; i <= n; i++) {       ans += a[i];     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, b, d;     int a[100000 + 10];     cin >> n >> b >> d;     for (int i = 0; i < n; i++) cin >> a[i];     int p = 0, emp = 0;     int temp = 0;     for (int i = 0; i < n; i++) {       if (a[i] > b) continue;       temp += a[i];       if (temp > d) {         emp++;         temp = 0;       }     }     cout << emp;   }
#include <bits/stdc++.h>   const int N = 100000 + 10;   int n;   std::vector<int> adj[N];   bool flag[N];   void dfs(int a, int fa = -1) {     if (adj[a].size() > 2) return;     flag[a] = true;     for (int i = 0; i < adj[a].size(); ++i) {       int b = adj[a][i];       if (b != fa) dfs(b, a);     }   }   int main() {     scanf( %d , &n);     for (int i = n - 1; i--;) {       int a, b;       scanf( %d%d , &a, &b);       adj[a].push_back(b);       adj[b].push_back(a);     }     for (int i = 1; i <= n; ++i)       if (adj[i].size() == 1) dfs(i);     static int cnt[N];     for (int i = 1; i <= n; ++i)       for (int j = 0; j < adj[i].size(); ++j) cnt[i] += flag[adj[i][j]];     for (int i = 1; i <= n; ++i) {       if (flag[i]) continue;       int cur = 0;       for (int j = 0; j < adj[i].size(); ++j) {         int t = adj[i][j];         if (!flag[t] && adj[t].size() - std::min(cnt[t], 2) > 1) ++cur;       }       if (cur > 2) return puts( No ), 0;     }     puts( Yes );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.1415926535897932384626433;   const long long M = 1e9;   map<long long, set<long long>> ms;   long long a[200100];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, m, x, t = 0, s = 0, p, r;     cin >> n >> m;     for (long long i = 0; i < n; i++) {       cin >> a[i];       ms[a[i] % m].insert(i);     }     r = n / m;     for (auto i : ms) {       if (i.first == m - 1) break;       if (i.second.size() > r) {         p = i.second.size() - r;         for (auto j : i.second) {           p--;           while ((ms[t].size() >= r || t <= i.first) && t < m - 1) t++;           ms[t].insert(j);           a[j] += (t - i.first);           s += (t - i.first);           ms[i.first].erase(j);           if (p == 0) break;         }       }     }     t = 0;     bool q = true;     for (auto i : ms[m - 1]) {       while (q && ms[t].size() >= r && t < m - 1) t++;       if (t >= m - 1) break;       if (q) {         p = ms[t].size();         q = false;       }       if (p < r) {         a[i] += t + 1;         s += t + 1;         p++;         if (p == r) {           q = true;           t++;         }       }     }     cout << s << endl;     for (long long i = 0; i < n; i++) cout << a[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300009;   vector<long long> visited[N];   map<pair<int, int>, int> mp;   set<int> s;   int n, m;   void dfs(int j) {     set<int> q;     for (auto i : s) {       if (mp[{j, i}] != 1) {         q.insert(i);       }     }     for (auto p : q) {       s.erase(p);     }     for (auto p : q) {       dfs(p);     }   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       mp[{x, y}] = 1;       mp[{y, x}] = 1;     }     for (int i = 1; i <= n; i++) {       s.insert(i);     }     int cnt = 0;     while (!s.empty()) {       dfs(*s.begin());       cnt++;     }     cout << cnt - 1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[300300], q, p, x, y, l[300300], b[300300];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     cin >> q;     for (int i = 1; i <= q; i++) {       cin >> p;       if (p == 1) {         cin >> x >> y;         a[x] = y;         l[x] = i;       }       if (p == 2) {         cin >> x;         b[i] = x;       }     }     for (int i = q - 1; i >= 0; i--) b[i] = max(b[i], b[i + 1]);     for (int i = 1; i <= n; i++) cout << max(a[i], b[l[i]]) <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N;   char buf[20];   set<int> B, S, Q;   const int INF = 1e9;   inline int get_b() { return ((int)(B).size()) ? *B.rbegin() : -INF; }   inline int get_s() { return ((int)(S).size()) ? *S.begin() : INF; }   int main() {     scanf( %d , &N);     long long ans = 1;     const int MOD = 1e9 + 7;     for (int a = 0; a < N; a++) {       scanf( %s , buf);       int x;       scanf( %d , &x);       if (buf[1] ==  D ) {         int bv = get_b();         int sv = get_s();         if (bv < x && x < sv)           Q.insert(x);         else if (x < bv)           B.insert(x);         else           S.insert(x);       } else {         if (B.find(x) != B.end()) {           if (get_b() != x) ans = 0;           B.erase(x);           for (int e : Q) S.insert(e);           Q.clear();         } else if (S.find(x) != S.end()) {           if (get_s() != x) ans = 0;           S.erase(x);           for (int e : Q) B.insert(e);           Q.clear();         } else {           ans = (ans * 2) % MOD;           for (int e : Q) {             if (e < x)               B.insert(e);             else if (e > x)               S.insert(e);           }           Q.clear();         }       }     }     ans = ans * (int)(Q.size() + 1) % MOD;     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   const int INF = 1 << 29;   inline int two(int n) { return 1 << n; }   inline int test(int n, int b) { return (n >> b) & 1; }   inline void set_bit(int& n, int b) { n |= two(b); }   inline void unset_bit(int& n, int b) { n &= ~two(b); }   inline int last_bit(int n) { return n & (-n); }   inline int ones(int n) {     int res = 0;     while (n && ++res) n -= n & (-n);     return res;   }   template <class T>   void chmax(T& a, const T& b) {     a = max(a, b);   }   template <class T>   void chmin(T& a, const T& b) {     a = min(a, b);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m, k, cnt = 0;     cin >> n >> m >> k;     vector<char> V;     for (int i = 0; i < n - 1; i++) {       ++cnt;       V.push_back( U );     }     for (int i = 0; i < m - 1; i++) {       ++cnt;       V.push_back( L );     }     int flag = 1;     for (int i = 0; i < m - 1; i++) V.push_back( R ), ++cnt;     for (int i = 0; i < n - 1; i++) {       ++cnt;       V.push_back( D );       if (flag == 1) {         for (int i = 0; i < m - 1; i++) V.push_back( L ), ++cnt;       } else {         for (int i = 0; i < m - 1; i++) V.push_back( R ), ++cnt;       }       flag *= -1;     }     cout << cnt;     cout << endl;     for (auto u : V) cout << u;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int n, m, len[maxn << 2];   bool first[maxn << 2];   long long mm[maxn], rr[maxn], ss[maxn], last[maxn << 2];   vector<long long> summ[maxn << 2], sumr[maxn << 2];   vector<int> tree[maxn << 2];   bool cmp(int a, int b) { return mm[a] * rr[b] < mm[b] * rr[a]; }   void build(int cur, int l, int r) {     len[cur] = 0;     first[cur] = true, last[cur] = -1;     tree[cur].clear();     tree[cur].push_back(0);     for (int i = l; i <= r; i++)       if (mm[i] != 0 && rr[i] != 0) tree[cur].push_back(i), len[cur]++;     sort(tree[cur].begin() + 1, tree[cur].end(), cmp);     summ[cur].clear();     sumr[cur].clear();     summ[cur].push_back(0);     sumr[cur].push_back(0);     long long sr = 0, sm = 0;     for (int i = 1; i <= len[cur]; i++) {       sr += rr[tree[cur][i]];       sm += mm[tree[cur][i]];       sumr[cur].push_back(sr);       summ[cur].push_back(sm);     }     if (l != r) {       build((cur << 1), l, ((l + r) >> 1));       build((cur << 1 | 1), ((l + r) >> 1) + 1, r);     }   }   int find(int cur, long long t) {     int l = 1, r = len[cur];     while (l <= r) {       if (t * rr[tree[cur][((l + r) >> 1)]] >= mm[tree[cur][((l + r) >> 1)]])         l = ((l + r) >> 1) + 1;       else         r = ((l + r) >> 1) - 1;     }     return l - 1;   }   long long ask(int cur, int l, int r, long long t) {     if (l == r && first[cur]) {       long long ret = min(mm[l], t * rr[l] + ss[l]);       ss[l] = 0, first[cur] = false;       return ret;     }     if (last[cur] != -1) {       long long delta = t - last[cur];       int mid = find(cur, delta);       long long ret = 0;       ret += summ[cur][mid];       ret += (sumr[cur][len[cur]] - sumr[cur][mid]) * delta;       return ret;     }     long long ret = 0;     ret += ask((cur << 1), l, ((l + r) >> 1), t);     ret += ask((cur << 1 | 1), ((l + r) >> 1) + 1, r, t);     return ret;   }   void down(int cur) {     if (last[cur] != -1) {       first[(cur << 1)] = first[(cur << 1 | 1)] = false;       last[(cur << 1)] = last[(cur << 1 | 1)] = last[cur];       last[cur] = -1;     }   }   long long query(int cur, int l, int r, int ql, int qr, long long t) {     if (ql <= l && r <= qr) {       long long ret = ask(cur, l, r, t);       first[cur] = false, last[cur] = t;       return ret;     }     down(cur);     long long ret = 0;     if (ql <= ((l + r) >> 1))       ret += query((cur << 1), l, ((l + r) >> 1), ql, qr, t);     if (qr > ((l + r) >> 1))       ret += query((cur << 1 | 1), ((l + r) >> 1) + 1, r, ql, qr, t);     return ret;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d%I64d%I64d , &ss[i], &mm[i], &rr[i]);     build(1, 1, n);     scanf( %d , &m);     int qq = 0;     while (m--) {       ++qq;       int t, l, r;       scanf( %d%d%d , &t, &l, &r);       printf( %I64d n , query(1, 1, n, l, r, t));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6;   const long long INF = 1e18;   const long long mod = 1e9 + 7;   long long y;   long long n, m;   vector<long long> v;   void rec(long long x) {     if (x > m) {       return;     }     if (x == m) {       cout <<  YES  << endl;       y = 1;     }     rec(x * 2);     rec(x * 10 + 1);     if (y) {       v.push_back(x);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     rec(n);     if (!y) {       cout <<  NO ;       return 0;     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     for (int i = 0; i < v.size() - 1; i++) {       if (v[i] / 2 == v[i + 1] || v[i] / 10 == v[i + 1]) {         continue;       }       v.erase(v.begin() + i + 1);       i--;     }     cout << v.size() << endl;     for (int i = v.size() - 1; i >= 0; i--) {       cout << v[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> a;   vector<pair<pair<int, int>, int> > b;   vector<int> k;   vector<int> ans;   signed main() {     ios_base::sync_with_stdio(0);     int n, m;     cin >> n;     a.resize(n);     b.resize(n);     ans.resize(n);     for (int i = 0; i < n; i++) {       cin >> b[i].first.first >> b[i].second;     }     cin >> m;     b.resize(n + m);     k.resize(m);     for (int i = 0; i < n; i++) {       b[i].first.second = i + m;     }     for (int i = n; i < m + n; i++) {       cin >> b[i].first.first >> b[i].second >> k[i - n];       b[i].first.second = i - n;     }     sort(b.begin(), b.end());     set<pair<int, int> > d;     bool poss = true;     for (int i = 0; i < n + m; i++) {       if (b[i].first.second < m)         d.insert(make_pair(b[i].second, b[i].first.second));       else {         set<pair<int, int> >::iterator it =             d.upper_bound(make_pair(b[i].second - 1, m));         if (it == d.end()) {           poss = false;           continue;         }         k[it->second]--;         ans[b[i].first.second - m] = it->second + 1;         if (k[it->second] == 0) d.erase(it);       }     }     if (poss) {       cout <<  YES  << endl;       for (int i = 0; i < n; i++) {         cout << ans[i] <<    ;       }       cout << endl;     } else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[100010], cnt[100010];   int main() {     int max1 = 0, max2 = 0;     cin >> n;     ;     for (int i = 1; i <= n; i++) {       cin >> a[i];       ;     }     for (int i = 1; i <= n; i++) {       if (a[i] > max1) {         max2 = max1;         max1 = a[i];         cnt[a[i]]--;       } else {         if (a[i] > max2) {           cnt[max1]++;           max2 = a[i];         }       }     }     int ans, max3 = -100000;     for (int i = 1; i <= n; i++) {       if (cnt[i] > max3) {         max3 = cnt[i];         ans = i;       }     }     cout << ans;     ;   }
#include <bits/stdc++.h>   using namespace std;   class Solution {    public:     Solution(int _n) : N(_n) {}     void guess(long long n, int k) {       long long l = 1;       long long r = n;       int M = min(4LL * k, n);       mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());       string ans;       for (int i = 0; i < N; ++i) {         if (r - l + 1 <= M) {           uniform_int_distribution<long long> dist(l, r);           long long p = dist(gen);           cout << p <<     << p << endl;           fflush(stdout);           cin >> ans;           if (ans[0] ==  y  || ans[0] ==  Y ) {             return;           }         } else {           long long m = l + (r - l) / 2;           cout << l <<     << m << endl;           fflush(stdout);           cin >> ans;           if (ans[0] ==  y  || ans[0] ==  Y ) {             r = m;           } else {             l = m + 1;           }         }         l = max(1LL, l - k);         r = min(n, r + k);       }     }       private:     int N;   };   int main(int argc, char** argv) {     ios::sync_with_stdio(false);     cin.tie(0);     long long n;     int k;     long long p;     cin >> n >> k;     Solution sol(4500);     sol.guess(n, k);     return 0;   }
#include <bits/stdc++.h>   int main() {     char ch[116];     int i, j = 1, k, m, n, c, s, e;     scanf( %d %d  , &n, &m);     while (j <= n) {       scanf( %s , ch);       for (i = 0; ch[i] !=   0 ; i++) {         if (ch[i] ==  B ) {           s = i;           while (ch[++i] ==  B )             ;           e = i - 1;           c = (e - s + 1) / 2;           printf( %d %d , j + c, s + 1 + c);           return 0;         }       }       j++;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<pair<int, int>, int> > v, ans;   vector<pair<int, int> > an;   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int val, state;       cin >> val >> state;       v.push_back(make_pair(make_pair(val, !state), i));     }     sort(v.begin(), v.end());     int cur = 2;     for (int i = 0; i < m; i++) {       if (!v[i].first.second) {         if (cur > n) {           cout << -1;           return 0;         }         ans.push_back(make_pair(make_pair(cur, 1), v[i].second));         for (int j = 2; j < cur; j++) {           if (an.size() < m) {             an.push_back(make_pair(cur, j));           } else {             break;           }         }         cur++;       } else {         if (an.size() == 0) {           cout << -1;           return 0;         } else {           ans.push_back(make_pair(an[an.size() - 1], v[i].second));           an.pop_back();         }       }     }     int k = ans.size();     vector<pair<int, int> > out(k, make_pair(0, 0));     for (int i = 0; i < k; i++) {       out[ans[i].second] = ans[i].first;     }     for (int i = 0; i < k; i++) {       cout << out[i].first <<     << out[i].second << endl;     }     return 0;   }
#include <bits/stdc++.h>   int modul(long long x, long long y) {     if (x < y)       return y - x;     else       return x - y;   }   long long rez, n, i, ant, x;   int main() {     scanf( %I64d , &n);     ant = 0;     for (i = 1; i <= n; i++) {       scanf( %I64d , &x);       rez += modul(x, ant);       ant = x;     }     printf( %I64d , rez);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cin.ignore();     vector<vector<string> > templa(n);     for (int c = 0; c < n; c++) {       string s;       getline(cin, s);       for (int c2 = 0; c2 < s.size(); c2++)         if ((s[c2] >=  a  && s[c2] <=  z ) || (s[c2] >=  A  && s[c2] <=  Z ) ||             (s[c2] >=  0  && s[c2] <=  9 ))           continue;         else           s[c2] =    ;       stringstream ss(s);       bool first = true;       while (!ss.eof()) {         string z;         ss >> z;         if (z.size() > 0 && !first) {           templa[c].push_back(z);         }         first = false;       }     }     int m;     cin >> m;     vector<pair<string, string> > var(m);     for (int c = 0; c < m; c++) cin >> var[c].first >> var[c].second;     int k;     cin >> k;     cin.ignore();     vector<vector<string> > appel(k);     for (int c = 0; c < k; c++) {       string s;       getline(cin, s);       for (int c2 = 0; c2 < s.size(); c2++)         if ((s[c2] >=  a  && s[c2] <=  z ) || (s[c2] >=  A  && s[c2] <=  Z ) ||             (s[c2] >=  0  && s[c2] <=  9 ))           continue;         else           s[c2] =    ;       stringstream ss(s);       while (!ss.eof()) {         string z;         ss >> z;         if (z.size() > 0) {           appel[c].push_back(z);         }       }       int res = 0;       for (int c2 = 0; c2 < templa.size(); c2++) {         if (templa[c2][0] != appel[c][0] || templa[c2].size() != appel[c].size())           continue;         for (int c3 = 1; c3 < templa[c2].size(); c3++) {           if (templa[c2][c3] ==  T ) continue;           for (int c4 = 0; c4 < var.size(); c4++) {             if (appel[c][c3] == var[c4].second) {               if (templa[c2][c3] != var[c4].first) goto end;             }           }         }         res++;       end:;       }       cout << res << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int s = (int)1e5 + 10;   int a[s], p[s];   int main() {     int x, y;     int s = 0;     int i = 0, j = 0;     cin >> x >> y;     while (i != x || j != y) {       if (i == 0 && j == 0) {         i = 1;         j = 0;         continue;       }       if (i >= 0 && j <= 0) {         if (i == 1 - j) {           s++;         }       } else if (abs(i) == abs(j)) {         s++;       }       if (abs(j) < abs(i)) {         if (i > 0)           j++;         else           j--;       } else if (abs(j) > abs(i)) {         if (j < 0)           i++;         else           i--;       } else if (abs(i) == abs(j)) {         if (i > 0 && j > 0)           i--;         else if (i < 0 && j > 0)           j--;         else if (i < 0 && j < 0)           i++;         else if (i > 0 && j < 0)           i++;       }     }     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     if (n % 2 == 0)       cout << a[n / 2 - 1];     else       cout << a[(n + 1) / 2 - 1];     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3)   #pragma GCC optimize( Ofast )   #pragma GCC optimize( inline )   using std::pair;   using std::set;   using std::vector;   template <class T>   inline void read(T &x) {     T f = 1;     x = 0;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = (x << 1) + (x << 3) + (s & 15);       s = getchar();     }     x *= f;   }   template <class T>   inline T fabs(T a) {     return a > 0 ? a : -a;   }   template <class T>   inline T max(T a, T b) {     return a > b ? a : b;   }   template <class T>   inline T min(T a, T b) {     return a < b ? a : b;   }   template <class T>   inline T po(T a) {     return a * a;   }   const long long maxn = 1e6 + 5;   struct Edge {     long long u, v, w;   } e[maxn];   inline bool cmp(Edge a, Edge b) { return a.w > b.w; }   long long fa[maxn], m, n, cnt, fx, fy, ans, siz[maxn], MAX, val[maxn];   inline long long find(long long x) {     return (fa[x] == x) ? x : fa[x] = find(fa[x]);   }   signed main() {     read(n);     read(m);     for (long long i = 1; i <= n; i++) fa[i] = i, siz[i] = 1, read(val[i]);     for (long long i = 1; i <= m; i++)       read(e[i].u), read(e[i].v), e[i].w = min(val[e[i].u], val[e[i].v]);     std::sort(e + 1, e + m + 1, cmp);     for (long long i = 1; i <= m; i++) {       fx = find(e[i].u);       fy = find(e[i].v);       if (fx == fy) continue;       ans += siz[fx] * siz[fy] * e[i].w;       fa[fx] = fy;       siz[fy] += siz[fx];       cnt++;       if (cnt == (n - 1)) break;     }     MAX = ((n * (n - 1)) >> 1);     printf( %.6Lf , ((long double)(ans)) / ((long double)(MAX)));   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, p, x;     cin >> t;     for (int u = 0; u < t; u++) {       cin >> n >> p;       x = 2 * n + p;       for (int i = 0; i < n; i++) {         for (int j = i + 1; j < n; j++) {           cout << i + 1 <<     << j + 1 <<   n ;           x--;           if (x == 0) {             break;           }         }         if (x == 0) {           break;         }       }     }     return 0;   }