malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 100009;   vector<int> edges[N];   vector<int> a;   int n, m;   int main() {     while (cin >> n >> m) {       a.clear();       for (int i = 1; i <= n; ++i) edges[i].clear(), a.push_back(i);       for (int i = 0; i < m; ++i) {         int ac, b;         cin >> ac >> b;         edges[ac].push_back(b);         edges[b].push_back(ac);       }       bool t = true;       int u, v;       for (int i = 0; i < 500; ++i) {         random_shuffle(a.begin(), a.end());         bool flg = true;         for (int j = 0; j < m && flg; ++j) {           u = a[j];           v = a[(j + 1) % n];           for (int k = 0; k < edges[u].size(); ++k)             if (edges[u][k] == v) flg = false;         }         if (flg) {           for (int j = 0; j < m; ++j)             cout << a[j] <<     << a[(j + 1) % n] << endl;           t = false;           break;         }       }       if (t) cout << -1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ans;   int main() {     int n, i;     long long a;     cin >> n;     ans = 0;     for (i = 1; i <= n; i++) {       cin >> a;       ans = ans + (1 + (a - 1) * (long long)i);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e4 + 5;   int dp[53][maxn], mxp[53][maxn], mxs[53][maxn], n, m, a[53][maxn], k,       sum[53][maxn], h1, h2, t1, t2;   pair<int, int> q1[maxn], q2[maxn];   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         scanf( %d , &a[i][j]), sum[i][j] = sum[i][j - 1] + a[i][j];     for (int i = 1; i <= m; ++i)       dp[1][i] = sum[1][min(i + k - 1, m)] - sum[1][i - 1];     for (int i = 1; i <= m; ++i)       mxp[1][i] = max(mxp[1][i - 1],                       dp[1][i] + sum[2][min(i + k - 1, m)] - sum[2][i - 1]);     for (int i = m; i >= 1; --i)       mxs[1][i] = max(mxs[1][i + 1],                       dp[1][i] + sum[2][min(i + k - 1, m)] - sum[2][i - 1]);     for (int i = 2; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         if (j + k <= m)           dp[i][j] = max(dp[i][j], mxs[i - 1][j + k] + sum[i][min(j + k - 1, m)] -                                        sum[i][j - 1]);         if (j - k >= 1)           dp[i][j] = max(dp[i][j], mxp[i - 1][j - k] + sum[i][min(j + k - 1, m)] -                                        sum[i][j - 1]);       }       h1 = h2 = 1;       t1 = t2 = 0;       for (int j = 1; j <= m; ++j) {         while (h1 <= t1 && q1[h1].first < j - k + 1) h1++;         int num = dp[i - 1][j] - sum[i][j - 1];         while (h1 <= t1 && q1[t1].second <= num) t1--;         q1[++t1] = {j, num};         if (h1 <= t1)           dp[i][j] = max(dp[i][j], q1[h1].second + sum[i][min(m, j + k - 1)]);       }       for (int j = m; j >= 1; --j) {         while (h2 <= t2 && q2[h2].first > j + k - 1) h2++;         if (h2 <= t2) dp[i][j] = max(dp[i][j], q2[h2].second - sum[i][j - 1]);         int num = dp[i - 1][j] + sum[i][min(j + k - 1, m)];         while (h2 <= t2 && q2[t2].second <= num) t2--;         q2[++t2] = {j, num};       }       for (int j = 1; j <= m; ++j) {         mxp[i][j] = max(mxp[i][j - 1], dp[i][j] + sum[i + 1][min(m, j + k - 1)] -                                            sum[i + 1][j - 1]);       }       for (int j = m; j >= 1; --j) {         mxs[i][j] = max(mxs[i][j + 1], dp[i][j] + sum[i + 1][min(m, j + k - 1)] -                                            sum[i + 1][j - 1]);       }     }     int ans = 0;     for (int i = 1; i <= m; ++i) {       if (i + k - 1 > m) break;       ans = max(ans, dp[n][i]);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int tot = 0;     for (int i = 0; i < n; i++) {       int a, b;       cin >> a >> b;       if (tot + a <= 500) {         tot += a;         cout <<  A ;       } else {         tot -= b;         cout <<  G ;       }     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());   const int maxn = 2e5 + 10;   const double pi = acos(-1);   int main() {     int cas;     cin >> cas;     double n;     while (cas--) {       cin >> n;       printf( %.10lf n , cos(pi / 4.0 / n) / sin(pi / 2.0 / n));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int a[1000001];   long long int b[1000001];   bool marked[1000001];   int main() {     long long int n, i, j, k, x, y, fin_ans = 0, sum = 0;     cin >> n >> k;     a[0] = 0;     for (i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];       fin_ans += a[i - 1] * a[i];     }     fin_ans += a[n] * a[1];     for (i = 0; i < k; i++) {       cin >> x;       b[i] = x;     }     long long val = 0;     for (j = 0; j < k; j++) {       marked[b[j]] = 1;       val += a[b[j]];       long long to_mul = 0;       if (b[j] != 1 && b[j] != n) {         to_mul = sum - val - a[b[j] + 1];         if (!marked[b[j] - 1]) {           to_mul -= a[b[j] - 1];         }       }       if (b[j] == 1) {         to_mul = sum - val - a[b[j] + 1];         to_mul -= a[n];       }       if (b[j] == n) {         to_mul = sum - val;         if (!marked[b[j] - 1]) to_mul -= a[b[j] - 1];         if (!marked[1]) to_mul -= a[1];       }       fin_ans += (a[b[j]] * to_mul);     }     cout << fin_ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<bool> visited;   vector<vector<int>> adj;   vector<int> depth;   void dfs(int v, int d) {     if (visited[v]) {       return;     }     visited[v] = true;     depth[d]++;     for (int i : adj[v]) {       dfs(i, d + 1);     }   }   int main() {     int n;     cin >> n;     visited.resize(n + 1);     adj.resize(n + 1);     for (int i = 2; i <= n; i++) {       int to;       cin >> to;       adj[to].push_back(i);     }     depth.resize(n + 1);     dfs(1, 0);     int collected = 0;     for (int i : depth) {       collected += i % 2;     }     cout << collected << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int P[111111];   int sz[111111];   int find(int x) { return (P[x] == x ? x : P[x] = find(P[x])); }   void Union(int x, int y, int type) {     x = find(x), y = find(y);     if (sz[x] < sz[y]) swap(x, y);     if (x == y) {       if (type == -1) P[x] = 0;       return;     }     if (type == -1) return;     sz[x] += sz[y];     P[y] = x;   }   int main() {     int N, K;     cin >> N >> K;     for (int i = 1; i <= N; i++) P[i] = i, sz[i] = 1;     while (K--) {       int u, v;       cin >> u >> v;       Union(u, v, 1);     }     cin >> K;     while (K--) {       int u, v;       cin >> u >> v;       Union(u, v, -1);     }     int best = 0;     for (int i = 1; i <= N; i++)       if (find(i)) best = max(best, sz[find(i)]);     cout << best << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int arr[5009], n;     cin >> n;     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr, arr + n);     int cnt = 0;     int ans = 0;     int chk;     bool fs = false;     while (cnt < n) {       fs = false;       for (int i = n - 1; i >= 0; i--) {         if (!fs && arr[i]) {           chk = arr[i];           fs = true;           cnt++;           ans++;           arr[i] = 0;           continue;         }         if (arr[i] < chk && arr[i]) {           cnt++;           chk = arr[i];           arr[i] = 0;         }       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = numeric_limits<int>::max();   const long long LLINF = numeric_limits<long long>::max();   const unsigned long long ULLINF = numeric_limits<unsigned long long>::max();   const double PI = acos(-1.0);   int sz = 1;   vector<int> compressed;   vector<pair<int, pair<int, int>>> queries;   map<int, int> order;   vector<int> t;   vector<set<int>> vert;   void build(int n) {     while (sz < n) sz <<= 1;     t.resize(sz + sz, 0);   }   void update(int i) {     i += sz;     if (vert[i - sz].size() == 0)       t[i] = 0;     else       t[i] = *vert[i - sz].rbegin();     while ((i >> 1) > 0) {       i >>= 1;       t[i] = max(t[i + i], t[i + i + 1]);     }   }   int query(int v, int tl, int tr, int l, int r) {     if (l > r) return 0;     if (tl == l && tr == r) return t[v];     int tm = (tl + tr) >> 1;     return max(query(v + v, tl, tm, l, min(r, tm)),                query(v + v + 1, tm + 1, tr, max(tm + 1, l), r));   }   int getX(int v, int tl, int tr, int l, int y) {     if (t[v] <= y) return INF;     if (tr <= l) return INF;     if (tl == tr) return tl;     int mid = (tl + tr) >> 1;     if (tl > l) {       if (t[v + v] > y)         return getX(v + v, tl, mid, l, y);       else         return getX(v + v + 1, mid + 1, tr, l, y);     }     return min(getX(v + v, tl, mid, l, y), getX(v + v + 1, mid + 1, tr, l, y));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     queries.resize(n);     set<int> d;     for (int i = 0; i < n; i++) {       string type;       cin >> type;       if (type ==  add )         queries[i].first = 0;       else if (type ==  remove )         queries[i].first = 1;       else         queries[i].first = 2;       cin >> queries[i].second.first >> queries[i].second.second;       queries[i].second.first, queries[i].second.second;       d.insert(queries[i].second.first);     }     for (auto k : d) {       order[k] = compressed.size();       compressed.push_back(k);     }     build(compressed.size());     vert.resize(compressed.size());     for (auto q : queries) {       if (q.first == 0) {         vert[order[q.second.first]].insert(q.second.second);         update(order[q.second.first]);       } else if (q.first == 1) {         vert[order[q.second.first]].erase(q.second.second);         update(order[q.second.first]);       } else {         int ans = getX(1, 0, sz - 1, order[q.second.first], q.second.second);         if (ans == INF)           cout <<  -1 n ;         else {           int y = *vert[ans].upper_bound(q.second.second);           cout << compressed[ans] <<     << y <<   n ;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   const int OO = (int)1e9 + 7;   const int MAX = 109;   char c1, c2, c3;   string s1, s2, s3;   long long n, m, k, t, a, b, c, d, e, f, x, y, z, sol = 0, ans = 0;   long long ar[1000009];   map<long long, bool> vis;   int fun(int i) {     int ret = 0;     for (int i = 0; i < n; i++) {       if (ar[i] % m == 0 && vis[ar[i] / m]) continue;       vis[ar[i]] = 1;       ret++;     }     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> ar[i];     sort(ar, ar + n);     cout << fun(0);     cout <<   n n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   int a[110];   long long calc(long long first) {     if (first == 0) return 0;     int nn = 0;     while (first) {       a[nn++] = first % 2;       first /= 2;     }     reverse(a, a + nn);     int r = 0, ans = 0;     for (int i = 0; i < nn; i++)       if (!a[i]) r++;     if (r == 1) ans++;     r = 0;     a[nn] = 0;     for (int i = 0; i <= nn; i++)       if (a[i] == 0) {         r = i;         break;       }     ans += r - 1;     for (int i = 1; i < nn - 1; i++) ans += i;     return ans;   }   int main() {     long long first, second;     scanf( %I64d %I64d , &first, &second);     printf( %I64d n , calc(second) - calc(first - 1));   }
#include <bits/stdc++.h>   using namespace std;   vector<int> graph[123490];   bool attacked[123490], visited[123490];   int n, m, parent[123490];   int dist, last;   void dfs(int u, int depth) {     if (attacked[u]) {       if (dist < depth) {         dist = depth;         last = u;       } else {         if (dist == depth) {           last = min(last, u);         }       }     }     visited[u] = true;     for (int i = (int)0; i <= (int)graph[u].size() - 1; i++) {       int v = graph[u][i];       if (!visited[v]) {         parent[v] = u;         dfs(v, depth + 1);       }     }   }   vector<int> path;   void augment_path(int v) {     visited[v] = true;     path.push_back(v);     if (parent[v] == -1) return;     augment_path(parent[v]);   }   int all = 0;   bool dfs2(int u) {     visited[u] = true;     int ans = 0;     for (int i = (int)0; i <= (int)graph[u].size() - 1; i++) {       int v = graph[u][i];       if (!visited[v]) {         ans |= dfs2(v);       }     }     if (attacked[u]) ans = 1;     all += ans;     return ans;   }   int main() {     cin >> n >> m;     int u, v;     for (int i = (int)1; i <= (int)n - 1; i++) {       cin >> u >> v;       graph[u].push_back(v);       graph[v].push_back(u);     }     int tmp = 123490;     for (int i = (int)1; i <= (int)m; i++) {       cin >> u;       attacked[u] = true;       tmp = min(tmp, u);     }     dist = -1;     dfs(tmp, 0);     tmp = last;     memset(parent, -1, sizeof parent);     memset(visited, 0, sizeof visited);     dist = -1;     dfs(last, 0);     cout << min(tmp, last) << endl;     memset(visited, 0, sizeof visited);     dfs2(tmp);     cout << (all * 2) - 2 - dist << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int a[N], b[N], par[N], val[N], sz[N], lst[N];   vector<int> his;   pair<int, int> get(int v) {     if (par[v] == v) return make_pair(v, val[v]);     pair<int, int> g = get(par[v]);     g.second ^= val[v];     return g;   }   bool merge(int u, int v) {     pair<int, int> gu = get(u), gv = get(v);     u = gu.first;     v = gv.first;     if (u == v) return false;     if (sz[v] < sz[u]) swap(u, v), swap(gu, gv);     par[u] = v;     val[u] = gu.second ^ gv.second ^ 1;     sz[v] += sz[u];     his.push_back(u);     return true;   }   void undo(int cnt) {     while (cnt--) {       int u = his.back();       his.pop_back();       sz[par[u]] -= sz[u];       par[u] = u;       val[u] = 0;     }   }   void solve(int l, int r, int R) {     if (r < l) return;     int m = (l + r) >> 1, cnt = 0;     for (int i = l; i < m; i++)       if (merge(a[i], b[i])) cnt++;     if (l < r) {       bool f = merge(a[m], b[m]);       solve(m + 1, r, R);       if (f) undo(1);     }     lst[m] = m;     for (int i = R; i >= m; i--) {       if (get(a[i]) == get(b[i])) {         lst[m] = i;         break;       }       if (merge(a[i], b[i])) cnt++;     }     undo(cnt);     cnt = 0;     for (int i = R; i > lst[m]; i--)       if (merge(a[i], b[i])) cnt++;     solve(l, m - 1, lst[m]);     undo(cnt);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m, q;     cin >> n >> m >> q;     for (int i = 1; i <= m; i++) cin >> a[i] >> b[i], lst[i] = m + 1;     for (int i = 1; i <= n; i++) par[i] = i, sz[i] = 1;     int ptr = 1;     while (ptr <= m && get(a[ptr]) != get(b[ptr])) merge(a[ptr], b[ptr]), ptr++;     if (m < ptr) {       while (q--) cout <<  NO n ;       return 0;     }     undo(his.size());     solve(1, ptr, m);     while (q--) {       int l, r;       cin >> l >> r;       cout << (ptr < l || r < lst[l] ?  YES  :  NO ) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[100005];   vector<int> all, empty;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       (x *= 10) += ch -  0 ;       ch = getchar();     }     return x * f;   }   vector<int> solve(int x) {     if (x > 19) return empty;     bool flag = false;     for (int v : all)       if (v & 1) {         flag = true;         break;       }     if (!flag) {       for (int &v : all) v >>= 1;       return solve(x + 1);     }     vector<int> backup, nega, posi, res;     backup = all;     for (int &v : all) {       if (v & 1)         v = (v + 1) >> 1;       else         v = v >> 1;     }     {       sort(all.begin(), all.end());       all.erase(unique(all.begin(), all.end()), all.end());     };     nega = solve(x + 1);     all = backup;     for (int &v : all) {       if (v & 1)         v = (v - 1) >> 1;       else         v = v >> 1;     }     {       sort(all.begin(), all.end());       all.erase(unique(all.begin(), all.end()), all.end());     };     posi = solve(x + 1);     nega.push_back(-(1 << x)), posi.push_back(1 << x);     return nega.size() < posi.size() ? nega : posi;   }   int main() {     n = read();     for (int i = 1; i <= n; i++) all.push_back(read());     vector<int> res = solve(0);     sort(res.begin(), res.end());     printf( %lld n , res.size());     for (int v : res) printf( %d  , v);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long int> g[100005];   vector<pair<long long int, long long int> > ed;   vector<long long int> w;   vector<long long int> eff;   long long int vis[100005];   long long int val[100005];   long long int rec(long long int i) {     if (vis[i] != 1) {       vis[i] = 1;       long long int cur = 1, j;       for (j = 0; j < g[i].size(); ++j) {         cur += rec(g[i][j]);       }       val[i] = cur;       return cur;     } else       return 0;   }   int main() {     long long int n, i, y, r, c;     cin >> n;     for (i = 0; i < n - 1; ++i) {       long long int t1, t2, t3;       cin >> t1 >> t2 >> t3;       g[t1].push_back(t2);       g[t2].push_back(t1);       ed.push_back(make_pair(t1, t2));       w.push_back(t3);     }     rec(1);     for (i = 0; i < n - 1; ++i) {       long long int ef = 0;       if (val[ed[i].first] > val[ed[i].second]) {         ef = val[ed[i].second] * (n - val[ed[i].second]);       } else {         ef = val[ed[i].first] * (n - val[ed[i].first]);       }       eff.push_back(ef);     }     double ans = 0;     for (i = 0; i < eff.size(); ++i) {       ans = ans + (eff[i] * (double)w[i]);     }     cin >> y;     for (i = 0; i < y; ++i) {       cin >> r >> c;       ans = ans - (eff[r - 1] * (double)(w[r - 1] - (double)c));       w[r - 1] = c;       printf( %0.8lf n , ans * ((n - 2) * 6) / (n * (n - 1) * (n - 2)));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = 2.0 * acos(0.0);   const double EPS = 1e-9;   const int MOD = 1000003;   const int INF = 1000000000;   const long long LINF = 1000000000000000000LL;   vector<string> vs;   bool row[500010], col[500010];   int main() {     int n, m, ret = 1;     cin >> n >> m;     string str;     for (int i = int(0); i <= int(n - 1); i++) {       cin >> str, vs.push_back(str);       for (int j = int(0); j <= int(m - 1); j++)         if (vs[i][j] !=  . ) row[i] = col[j] = true;     }     bool val = true, par;     for (int i = int(0); i <= int(n - 1); i++) {       if (!row[i])         ret = 2 * ret % MOD;       else {         for (int j = int(0); j <= int(m - 1); j++)           if (vs[i][j] !=  . )             par = (vs[i][j] <  3  && j % 2 == 0) || (vs[i][j] >=  3  && j % 2);         for (int j = int(0); j <= int(m - 1); j++)           if (vs[i][j] !=  . ) {             if (j % 2)               val &= par ? vs[i][j] >=  3  : vs[i][j] <  3 ;             else               val &= par ? vs[i][j] <  3  : vs[i][j] >=  3 ;           }       }     }     for (int j = int(0); j <= int(m - 1); j++) {       if (!col[j])         ret = 2 * ret % MOD;       else {         for (int i = int(0); i <= int(n - 1); i++)           if (vs[i][j] !=  . )             par = ((vs[i][j] ==  1  || vs[i][j] ==  4 ) && i % 2 == 0) ||                   (!(vs[i][j] ==  1  || vs[i][j] ==  4 ) && i % 2);         for (int i = int(0); i <= int(n - 1); i++)           if (vs[i][j] !=  . ) {             if (i % 2)               val &= par ? !(vs[i][j] ==  1  || vs[i][j] ==  4 )                          : (vs[i][j] ==  1  || vs[i][j] ==  4 );             else               val &= par ? (vs[i][j] ==  1  || vs[i][j] ==  4 )                          : !(vs[i][j] ==  1  || vs[i][j] ==  4 );           }       }     }     if (!val) ret = 0;     printf( %d n , ret);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, x, y, a, b, t;   long long q[55][55];   long long g[55][55];   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> q[i][j];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> g[i][j];         if (g[i][j] < q[i][j]) swap(g[i][j], q[i][j]);         if (q[i][j] <= q[i - 1][j] || q[i][j] <= q[i][j - 1]) t = 1;         if (g[i][j] <= g[i - 1][j] || g[i][j] <= g[i][j - 1]) t = 1;       }     if (t == 1)       cout <<  Impossible ;     else       cout <<  Possible ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, parent[2005] = {};   int ans = -1e9;   int solve(int x, int byk) {     byk += 1;     if (parent[x] == -1) return byk;     return solve(parent[x], byk);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> parent[i];     }     for (int i = 1; i <= n; i++) {       ans = max(ans, solve(i, 0));     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   vector<long long> adj[200005];   void solve() {     long long n, m;     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     vector<long long> cnt(n + 1);     vector<long long> a(n + 1);     queue<long long> q;     for (long long i = 1; i < n + 1; i++) {       cin >> a[i];       if (!a[i]) q.push(i);     }     vector<long long> ans;     vector<long long> vis(n + 1);     while (!q.empty()) {       long long p = q.front();       q.pop();       cnt[p]++;       ans.push_back(p);       for (auto x : adj[p]) {         cnt[x]++;         if (cnt[x] == a[x]) q.push(x);       }     }     cout << ans.size() <<   n ;     for (auto x : ans) cout << x <<    ;     cout <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     t = 1;     for (long long i = 0; i < t; i++) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n];       for (int i = 0; i < n; i++) cin >> arr[i];       for (int i = n - 1; i >= 0; i--) cout << arr[i] <<    ;       cout << endl;     }     return 0;   }