malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 333333;   vector<pair<int, int> > graph[N];   int vis[N], d[N];   bool has[N];   int n, m;   int dfs(int u) {     vis[u] = true;     int cnt = 0;     for (auto e : graph[u]) {       if (!vis[e.first]) {         if (dfs(e.first)) {           has[e.second] = true;           cnt++;         }       }     }     return cnt % 2 != d[u];   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = (1); i <= (n); i++) {       cin >> d[i];     }     for (int i = (1); i <= (m); i++) {       int u, v;       cin >> u >> v;       graph[u].push_back(make_pair(v, i));       graph[v].push_back(make_pair(u, i));     }     int cnt = 0;     for (int i = (1); i <= (n); i++) {       cnt += d[i] == 1;     }     for (int i = (1); i <= (n); i++) {       if (d[i] == -1) {         if (cnt & 1) {           d[i] = 1;           cnt++;         } else {           d[i] = 0;         }       }     }     if (cnt & 1) {       cout << -1 <<   n ;       return 0;     }     dfs(1);     vector<int> v;     for (int i = (1); i <= (m); i++) {       if (has[i]) {         v.push_back(i);       }     }     cout << (int)(v).size() <<   n ;     for (auto x : v) {       cout << x <<    ;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     int sol = 0;     for (int i = 1; i <= n; i++) {       int cnt = 1;       for (int j = i - 1; j >= 1; j--) {         if (a[j] > a[j + 1])           break;         else           cnt++;       }       for (int k = i + 1; k <= n; k++) {         if (a[k] > a[k - 1])           break;         else           cnt++;       }       sol = max(sol, cnt);     }     cout << sol;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, p[1000010], cur[1000010 * 2];   int main() {     long long ans = 0, sum = 0;     int l = 0, r = 0, temp = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &p[i]);     for (int i = 1; i <= n; i++) {       sum += abs(p[i] - i);       if (p[i] >= i) {         l++;         cur[p[i] - i]++;       } else         r++;     }     ans = sum;     for (int i = 0; i < n - 1; i++) {       l -= cur[i];       r += cur[i];       sum = sum - l + r - abs(p[n - i] - n - 1) + p[n - i] - 1;       cur[p[n - i] + i]++;       l++, r--;       if (sum < ans) {         ans = sum;         temp = i + 1;       }     }     printf( %lld %d n , ans, temp);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, w, one = 0, two = 0, sum = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> w;       if (w == 100) {         one++;       } else {         two++;       }       sum += w;     }     if (two % 2 == 0) {       if (one % 2 == 0) {         cout <<  YES ;       } else {         cout <<  NO ;       }     } else {       one -= 2;       if (one < 0) {         cout <<  NO ;         return 0;       }       if (one % 2 == 0) {         cout <<  YES ;       } else {         cout <<  NO ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 2000 * 1000 * 1000;   int calc(int sweet, string str) {     int mx = -1;     for (register int i = (0); i < (int)(((int)(str).size())); ++i)       if (sweet > 0 && str[i] ==  H ) {         mx = max(mx, i);         str[i] =  . ;         sweet--;       }     int pos = 0;     vector<pair<int, int> > v;     for (register int i = (0); i < (int)(((int)(str).size())); ++i)       if (str[i] ==  H ) {         while (pos < ((int)(str).size()) && str[pos] !=  S ) pos++;         if (pos == ((int)(str).size())) return INF;         str[pos] =  . ;         if (pos > i)           v.push_back(pair<int, int>(i, pos));         else           mx = max(mx, i);       }     sort((v).begin(), (v).end());     vector<pair<int, int> > u;     for (register int i = (0); i < (int)(((int)(v).size())); ++i)       if (u.empty() || u.back().second < v[i].first)         u.push_back(v[i]);       else         u.back().second = v[i].second;     if (u.empty()) return mx + 1;     mx = max(mx, u.back().second);     int res = mx + 1;     for (__typeof((u).begin()) it = (u).begin(); it != (u).end(); ++it)       res += 2 * (it->second - it->first);     int ans = res;     for (int i = ((int)(u).size()) - 1; i >= 0; i--) {       res -= u[i].second - u[i].first;       res += i + 1 == ((int)(u).size()) ? mx - u.back().second                                         : u[i + 1].first - u[i].second;       ans = min(ans, res);     }     return ans;   }   int main() {     int n, t;     string s;     cin >> n >> t >> s;     if (calc(n, s) > t) {       cout << -1 << endl;       return 0;     }     int mn = 0, mx = n;     while (mn < mx) {       int mid = (mn + mx) / 2;       if (calc(mid, s) <= t)         mx = mid;       else         mn = mid + 1;     }     cout << mn << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e17;   int n, s, e, nxt[5001];   long long x[5001], a[5001], b[5001], c[5001], d[5001];   long long dp[5001][5001];   inline long long dis(int s, int e) {     return (s < e) ? d[s] + a[e] : c[s] + b[e];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> s >> e;     s--, e--;     for (int i = 0; i < n; i++) cin >> x[i];     for (int i = 0; i < n; i++) cin >> a[i], a[i] += x[i];     for (int i = 0; i < n; i++) cin >> b[i], b[i] -= x[i];     for (int i = 0; i < n; i++) cin >> c[i], c[i] += x[i];     for (int i = 0; i < n; i++) cin >> d[i], d[i] -= x[i];     long long ans = dis(s, e);     nxt[s] = e;     for (int i = 0; i < n; i++) {       if (i == s || i == e) continue;       long long minv = INF, ind = i;       for (int j = s; j != e; j = nxt[j]) {         long long val = dis(j, i) + dis(i, nxt[j]) - dis(j, nxt[j]);         if (val < minv) {           minv = val;           ind = j;         }       }       ans += minv;       nxt[i] = nxt[ind];       nxt[ind] = i;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, M, P, Q;   int A[101], B[101];   int w[202][202];   bool V[202];   vector<int> path;   bool dfs(int n) {     path.push_back(n);     V[n] = 1;     if (n == N + N + 1) return 1;     for (int i = 0; i <= N + N + 1; i++)       if (!V[i] && w[n][i]) {         if (dfs(i)) return 1;       }     path.pop_back();     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> N >> M;     for (int i = 1; i <= N; i++) cin >> A[i], w[0][i] = A[i], P += A[i];     for (int i = 1; i <= N; i++)       cin >> B[i], w[N + i][N + N + 1] = B[i], Q += B[i];     for (int i = 1; i <= N; i++) w[i][N + i] = 1e9;     for (int i = 1; i <= M; i++) {       int a, b;       cin >> a >> b;       w[a][N + b] = 1e9;       w[b][N + a] = 1e9;     }     int ans = 0;     while (dfs(0)) {       int flow = 2e9;       for (int i = 1; i < ((int)(path).size()); i++)         flow = min(flow, w[path[i - 1]][path[i]]);       for (int i = 1; i < ((int)(path).size()); i++) {         w[path[i - 1]][path[i]] -= flow;         w[path[i]][path[i - 1]] += flow;       }       ans += flow;       path.clear();       for (int i = 0; i <= N + N + 1; i++) V[i] = 0;     }     if (P != Q || ans != P) {       puts( NO );       return 0;     }     puts( YES );     for (int i = 1; i <= N; i++, puts(  ))       for (int j = 1; j <= N; j++) {         printf( %d  , w[N + j][i]);       }   }
#include <bits/stdc++.h>   using namespace std;   const long double PI = 4 * atan(1);   const int32_t MOD = 1e9 + 7;   int power(int x, unsigned int y) {     int temp;     if (y == 0) return 1;     temp = power(x, y / 2);     if (y % 2 == 0)       return temp * temp % MOD;     else       return x * temp % MOD * temp % MOD;   }   void solve() {     string s;     cin >> s;     int n = s.length();     string s1, s2;     cin >> s1 >> s2;     int m1 = s1.length(), m2 = s2.length();     int j = -1, k = -1;     bool f1 = 0, f2 = 0;     j = s.find(s1);     k = s.find(s2, s1.length() + j);     if (j != -1 && k != -1) f1 = 1;     reverse(s.begin(), s.end());     j = -1, k = -1;     j = s.find(s1);     k = s.find(s2, s1.length() + j);     if (j != -1 && k != -1) f2 = 1;     if (f1 && f2)       cout <<  both n ;     else if (f1)       cout <<  forward n ;     else if (f2)       cout <<  backward n ;     else       cout <<  fantasy n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 111111;   vector<int> g[N];   bool s[N], f[N], used[N], foo[N], bar[N];   int q[N], qb, qe;   int main() {     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 1; i <= n; i++) cin >> s[i];     for (int i = 1; i <= n; i++) cin >> f[i];     vector<int> x;     q[qe++] = 1;     used[1] = true;     if (s[1] != f[1]) {       x.push_back(1);       foo[1] = 1;     }     while (qb < qe) {       int u = q[qb++];       for (int i = 0; i < g[u].size(); i++) {         int v = g[u][i];         if (used[v]) continue;         q[qe++] = v;         used[v] = true;         if ((s[v] ^ bar[u]) != f[v]) {           x.push_back(v);           foo[v] = bar[u] ^ 1;           bar[v] = foo[u];         } else {           foo[v] = bar[u];           bar[v] = foo[u];         }       }     }     cout << x.size() << endl;     for (int i = 0; i < x.size(); i++) cout << x[i] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int d[200], f[200][200];   int c[200];   int dis[200][200];   long long fa[200];   int ans[200];   void floyed() {     for (int k = 1; k <= n; ++k)       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= n; ++j)           dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);   }   void dfs_1(int x) {     for (int i = 1; i <= n; ++i) f[x][i] = d[dis[x][i]] + m;     for (int i = 1; i <= n; ++i) {       if (dis[x][i] == 1 && (fa[x] != i)) {         fa[i] = x;         dfs_1(i);         for (int j = 1; j <= n; ++j) f[x][j] += min(f[i][j] - m, f[i][c[i]]);       }     }     c[x] = 1;     for (int i = 1; i <= n; ++i)       if (f[x][c[x]] > f[x][i]) c[x] = i;   }   void dfs_2(int x, int y) {     ans[x] = y;     for (int i = 1; i <= n; ++i) {       if (dis[i][x] == 1 && (fa[i] == x)) {         if (f[i][y] - m >= f[i][c[i]])           dfs_2(i, c[i]);         else           dfs_2(i, y);       }     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n - 1; ++i) scanf( %d , &d[i]);     memset(dis, 53, sizeof(dis));     for (int i = 1; i <= n - 1; ++i) {       int x, y;       scanf( %d%d , &x, &y);       dis[x][y] = 1;       dis[y][x] = 1;     }     for (int i = 1; i <= n; ++i) dis[i][i] = 0;     floyed();     dfs_1(1);     cout << f[1][c[1]] << endl;     dfs_2(1, c[1]);     for (int i = 1; i <= n; ++i) printf( %d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   constexpr auto Inf = 0X3F3F3F3F;   using namespace std;   namespace IO {   inline long long read() {     long long o = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >  /  && c <  : ) {       o = o * 10 + c -  0 ;       c = getchar();     }     return o * f;   }   inline char recd() {     char o;     while ((o = getchar()) <  0  || o >  9 )       ;     return o;   }   inline double reod() {     double o = read(), f = 1;     char c;     while ((c = getchar()) >  /  && c <  : ) o += (c -  0 ) / (f *= 10);     return o;   }   }  // namespace IO   using namespace IO;   const int SIZE = 2E5 + 7, Mod = 1E9 + 7;   vector<pair<int, pair<long long, int> > > vec[SIZE];   long long TS = 0;   struct Node {     long long w;     int c, cost;     Node(long long w, long long c, long long cost) : w(w), c(c), cost(cost){};     bool operator<(const Node& Tmp) const {       return (w - w / 2) * c < (Tmp.w - Tmp.w / 2) * Tmp.c;     }   };   priority_queue<Node> oque, sque;   int DFS(int now, int F) {     int son = 0;     for (int pos = 0; pos < vec[now].size(); pos++) {       int v = vec[now][pos].first;       if (v != F) {         int s = DFS(v, now);         TS += s * vec[now][pos].second.first;         son += s;         if (vec[now][pos].second.second == 1)           oque.push(               Node(vec[now][pos].second.first, s, vec[now][pos].second.second));         else           sque.push(               Node(vec[now][pos].second.first, s, vec[now][pos].second.second));       }     }     return son == 0 ? 1 : son;   }   long long aw[int(2E6)], bw[int(2E6)];   int main() {     int T = read();     while (T--) {       int N = read();       long long S = read(), Tmp;       for (int pos = 1, u, v, w, c; pos < N; pos++) {         u = read(), v = read(), w = read(), c = read();         vec[u].push_back({v, {w, c}});         vec[v].push_back({u, {w, c}});       }       DFS(1, 0);       int ans = Inf, aInd = 1, bInd = 1;       long long d = TS - S;       Tmp = d;       while (Tmp > 0 && !oque.empty()) {         Node now = oque.top();         oque.pop();         Tmp -= (now.w - now.w / 2) * now.c;         aw[aInd] = aw[aInd - 1] + (now.w - now.w / 2) * now.c;         aInd++, now.w /= 2;         if (now.w) oque.push(now);       }       Tmp = d;       while (Tmp > 0 && !sque.empty()) {         Node now = sque.top();         sque.pop();         Tmp -= (now.w - now.w / 2) * now.c;         bw[bInd] = bw[bInd - 1] + (now.w - now.w / 2) * now.c;         bInd++, now.w /= 2;         if (now.w) sque.push(now);       }       int L = 0, R = bInd - 1;       while (L < aInd && R >= 0) {         while (R >= 0 && aw[L] + bw[R] >= d) ans = min(ans, L + (R << 1)), R--;         L++;       }       printf( %d n , TS <= S ? 0 : ans);       for (int pos = 1; pos <= N; pos++) vec[pos].clear();       TS = 0;       while (!oque.empty()) oque.pop();       while (!sque.empty()) sque.pop();     }   }
#include <bits/stdc++.h>   using namespace std;   int read() {     char ch = getchar();     int x = 0, fl = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) fl = -1;     for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch -  0 );     return x * fl;   }   const int N = 300005;   const long long INF = 1e18;   int n, m, s, dep[N], ff[N], fa[N][21], de[N];   long long dis[N];   bool vis[N];   vector<pair<int, int> > adj[N];   vector<int> bdj[N];   priority_queue<pair<long long, int> > q;   void dij() {     for (int i = 1; i <= n; i++) dis[i] = INF;     while (!q.empty()) q.pop();     dis[s] = 0LL;     q.push(make_pair(0LL, s));     while (!q.empty()) {       int x = q.top().second;       q.pop();       if (vis[x]) continue;       vis[x] = 1;       for (auto e : adj[x]) {         int y = e.first;         long long w = e.second;         if (dis[y] > dis[x] + w) {           dis[y] = dis[x] + w;           q.push(make_pair(-dis[y], y));         }       }     }   }   int lca(int x, int y) {     if (dep[x] < dep[y]) swap(x, y);     for (int i = 20; ~i; i--)       if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];     for (int i = 20; ~i; i--)       if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];     return (x == y) ? x : fa[x][0];   }   queue<int> Q;   int ver[N], nxt[N], fst[N], tot, siz[N], ans;   void addedge(int x, int y) {     ver[++tot] = y;     nxt[tot] = fst[x];     fst[x] = tot;   }   void dfs(int x) {     siz[x] = 1;     for (int i = fst[x]; i; i = nxt[i]) {       int y = ver[i];       dfs(y);       siz[x] += siz[y];     }   }   int main() {     n = read();     m = read();     s = read();     for (int i = 1; i <= m; i++) {       int x = read(), y = read(), w = read();       adj[x].push_back(make_pair(y, w));       adj[y].push_back(make_pair(x, w));     }     dij();     for (int x = 1; x <= n; x++) {       for (auto e : adj[x]) {         int y = e.first;         long long w = e.second;         if (dis[y] == dis[x] + w) {           bdj[x].push_back(y);           de[y]++;         }       }     }     memset(ff, -1, sizeof(ff));     dep[0] = 1;     for (int i = 1; i <= n; i++) {       if (!de[i] && dis[i] < INF) {         ff[i] = 0;         Q.push(i);       }     }     while (!Q.empty()) {       int x = Q.front();       Q.pop();       dep[x] = dep[ff[x]] + 1;       fa[x][0] = ff[x];       for (int i = 1; i <= 20; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];       for (auto y : bdj[x]) {         if (ff[y] == -1)           ff[y] = x;         else           ff[y] = lca(ff[y], x);         de[y]--;         if (!de[y]) Q.push(y);       }     }     for (int i = 1; i <= n; i++) addedge(ff[i], i);     dfs(0);     for (int i = 1; i <= n; i++)       if (i != s) ans = max(ans, siz[i]);     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void O_o() {     ios::sync_with_stdio(0);     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);   }   int main() {     O_o();     int x, y;     bool flag;     vector<int> vec;     cin >> x;     y = x;     while (x != 0) {       vec.push_back(x % 10);       x = x / 10;     }     for (int i = 0; i < vec.size(); i++) {       if (vec[i] == 4 || vec[i] == 7)         flag = 1;       else {         flag = 0;         break;       }     }     if (flag)       cout <<  YES ;     else if (y % 7 == 0 || y % 4 == 0 || y == 799 || y == 94 || y == 141)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e6 + 100;   const long long MAXL = 21;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long x, r, l;     cin >> x >> l >> r;     long long ans = 0;     long long a = 1;     while (2 * a <= x) a = 2 * a;     for (long long i = l; i <= r; i++) ans += bool(x & (a / (i & -i)));     cout << ans;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   #pragma warning(disable : 4786)   using namespace std;   int MIN(int a, int b) { return a < b ? a : b; }   int MAX(int a, int b) { return a > b ? a : b; }   int GCD(int a, int b) {     while (b) b ^= a ^= b ^= a %= b;     return a;   }   int LCM(int a, int b) { return a * (b / GCD(a, b)); }   void SWAP(int &a, int &b) {     a = a ^ b;     b = a ^ b;     a = a ^ b;   }   const double PI = acos(-1);   const double EPS = 1e-11;   int arr[310][310], memo[310][310][310], N, M;   int dp(int i, int j, int k) {     int l = i + j - k;     if (i == N - 1 && j == M - 1) {       return arr[i][j];     }     if (i == N || j == M || k >= N || l >= N) {       return -(1 << 29);       ;     }     int &ret = memo[i][j][k];     if (ret != -1) {       return ret;     }     int res, r1, val;     res = -(1 << 29);     ;     if (i == k && j == l) {       val = arr[i][j];     } else {       val = arr[i][j] + arr[k][l];     }     r1 = dp(i + 1, j, k + 1) + val;     res = MAX(res, r1);     r1 = dp(i + 1, j, k) + val;     res = MAX(res, r1);     r1 = dp(i, j + 1, k + 1) + val;     res = MAX(res, r1);     r1 = dp(i, j + 1, k) + val;     res = MAX(res, r1);     return ret = res;   }   int main() {     int T, res, n, i, ind, m, j;     while (scanf( %d , &n) != EOF) {       int a = -(1 << 29);       ;       memset(memo, -1, sizeof(memo));       memset(arr, 0, sizeof(arr));       m = n;       for (i = 0; i < (n); i++) {         for (j = 0; j < (m); j++) {           scanf( %d , &arr[i][j]);         }       }       N = n;       M = m;       res = dp(0, 0, 0);       printf( %d n , res);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Mod = 1e9 + 7;   const int N = 1e3 + 100;   const int M = 3e4 + 100;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   inline long long dpow(long long a, long long b) {     long long r = 1, t = a;     while (b) {       if (b & 1) r = (r * t) % Mod;       b >>= 1;       t = (t * t) % Mod;     }     return r;   }   inline long long fpow(long long a, long long b) {     long long r = 1, t = a;     while (b) {       if (b & 1) r = (r * t);       b >>= 1;       t = (t * t);     }     return r;   }   vector<pair<int, int> > G[N << 1];   vector<int> g;   int dfn[N], low[N], n, m, cnt;   int val[M], sp, tp;   int edge[M], res;   bool vis[N], cut[M];   int ID[5], ans;   bool path(int x) {     if (x == tp) return true;     vis[x] = true;     for (auto it : G[x]) {       int v = it.first, id = it.second;       if (!vis[v] && path(v)) {         edge[++res] = id;         return true;       }     }     return false;   }   bool dfs(int x, int no) {     if (x == tp) return true;     vis[x] = true;     for (auto it : G[x]) {       int v = it.first;       int id = it.second;       if (id != no && !vis[v] && dfs(v, no)) {         g.push_back(id);         return true;       }     }     return false;   }   void tarjan(int x, int fa, int no) {     dfn[x] = low[x] = ++cnt;     for (auto it : G[x]) {       int v = it.first, id = it.second;       if (id == fa || id == no) continue;       if (!dfn[v]) {         tarjan(v, id, no);         low[x] = min(low[x], low[v]);         if (low[v] > dfn[x]) cut[id] = true;       } else         low[x] = min(low[x], dfn[v]);     }   }   int main() {     cin >> n >> m >> sp >> tp;     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d %d %d , &u, &v, &val[i]);       G[u].push_back({v, i});       G[v].push_back({u, i});     }     if (!path(sp)) printf( 0 n0 n ), exit(0);     ans = INT_MAX;     for (int i = 1; i <= res; i++) {       int ii = edge[i];       memset(vis, 0, sizeof(vis)), g.clear();       if (!dfs(sp, ii)) {         if (val[ii] < ans) ans = val[ii], ID[1] = ii, ID[2] = 0;       } else {         cnt = 0;         memset(dfn, 0, sizeof(dfn)), memset(low, 0, sizeof(low));         memset(cut, 0, sizeof(cut));         for (int j = 1; j <= n; j++) {           if (!dfn[j]) tarjan(j, 0, ii);         }         for (auto it : g) {           if (cut[it] && val[it] + val[ii] < ans)             ans = val[it] + val[ii], ID[1] = ii, ID[2] = it;         }       }     }     if (ans == INT_MAX)       printf( -1 n );     else {       printf( %d n , ans);       if (!ID[2])         printf( 1 n%d n , ID[1]);       else         printf( 2 n%d %d n , ID[1], ID[2]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, p, k;   long long int cost[200010];   long long int price() {     long long int dp[200010] = {0};     sort(cost, cost + n);     long long int ans = 0;     for (long long int i = 0; i < n; i++) {       if (i < k - 1) {         dp[i] = cost[i] + (i == 0 ? 0 : dp[i - 1]);       } else if (i == k - 1) {         dp[i] = cost[i];       } else {         dp[i] = dp[i - k] + cost[i];       }       if (dp[i] <= p) ans = i + 1;     }     return ans;   }   int main() {     int t;     cin >> t;     while (t--) {       cin >> n >> p >> k;       for (int i = 0; i < n; i++) {         cin >> cost[i];       };       cout << price() << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int ans;   int visited[1001];   int cc = 0;   vector<int> arr[1001];   void dfs(int node) {     visited[node]++;     if (visited[node] == 2) {       ans = node;       return;     }     for (auto child : arr[node]) {       if (visited[node] < 2) dfs(child);     }   }   int main() {     int n, v, a, b;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a;       arr[i].push_back(a);     }     for (int i = 1; i <= n; i++) {       memset(visited, 0, sizeof(visited));       dfs(i);       cout << ans <<    ;     }     return 0;   }