malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1e2 + 5;   string grid[N];   bool found, vis[N][N];   ;   int n, m, k, cnt, ans;   vector<pair<int, pair<int, int> > > p;   int dr[] = {-1, 1, 0, 0};   int dc[] = {0, 0, -1, 1};   bool check(int r, int c) {     return r == 0 || r == n - 1 || c == 0 || c == m - 1;   }   bool valid(int r, int c) { return r >= 0 && r < n && c >= 0 && c < m; }   void dfs(int r, int c) {     vis[r][c] = 1;     if (check(r, c)) found = 1;     cnt++;     for (int i = 0; i < 4; i++) {       int rr = r + dr[i], cc = c + dc[i];       if (valid(rr, cc) && !vis[rr][cc] && grid[rr][cc] ==  . ) dfs(rr, cc);     }   }   void build(int r, int c) {     grid[r][c] =  * ;     for (int i = 0; i < 4; i++) {       int rr = r + dr[i], cc = c + dc[i];       if (valid(rr, cc)) {         if (grid[rr][cc] ==  . ) {           build(rr, cc);         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       cin >> grid[i];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (!vis[i][j] && grid[i][j] ==  . ) {           found = 0;           cnt = 0;           dfs(i, j);           if (found) continue;           p.push_back({cnt, {i, j}});         }       }     }     sort(p.begin(), p.end());     for (int i = 0; i < (int)p.size() - k; i++) {       ans += p[i].first;       build(p[i].second.first, p[i].second.second);     }     cout << ans <<   n ;     for (int i = 0; i < n; i++) {       cout << grid[i] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   constexpr int64_t P0 = 2000003;   constexpr int64_t P1 = 2000017;   constexpr int64_t M0 = 3000000000013;   constexpr int64_t M1 = 2000000000003;   class TaskC {    public:     struct Class {       int id;       int cnt;     };     struct Hash {       int64_t a, b;       Hash() : a(0), b(0) {}       void update(int addition) {         a = (a * P0 + addition) % M0;         b = (b * P1 + addition) % M1;       }       bool operator<(const Hash& other) const {         return std::tie(a, b) < std::tie(other.a, other.b);       }     };     void solve(std::istream& in, std::ostream& out) {       int n, m;       in >> n >> m;       vector<vector<int>> schools(n);       vector<Class> classes;       int timer = 0;       vector<Hash> hashes(m);       for (int i = 0; i < n; i++) {         int k;         in >> k;         auto& school = schools[i];         for (int j = 0; j < k; j++) {           int id;           in >> id;           --id;           school.push_back(id);         }         sort(school.begin(), school.end());         classes.clear();         int l = 0;         while (l < k) {           int id = school[l], cnt = 0;           while (l < k && school[l] == id) {             ++l;             ++cnt;           }           classes.push_back(Class{id, cnt});         }         sort(classes.begin(), classes.end(),              [](Class lhs, Class rhs) { return lhs.cnt < rhs.cnt; });         l = 0;         while (l < classes.size()) {           ++timer;           int cnt = classes[l].cnt;           while (l < classes.size() && classes[l].cnt == cnt) {             int id = classes[l].id;             ++l;             hashes[id].update(timer);           }         }       }       map<Hash, int> was;       int64_t result = 1;       int64_t MOD = (1000000000 + 7);       for (auto hash : hashes) {         ++was[hash];         result = (result * was[hash]) % MOD;       }       out << result <<   n ;     }   };   int main() {     std::ios_base::sync_with_stdio(false);     TaskC solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     in.tie(0);     out << std::fixed;     out.precision(20);     solver.solve(in, out);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   struct Node {     string str;     int pos;     friend bool operator<(Node const& n1, Node const& n2) {       return n2.str < n1.str;     }   };   priority_queue<Node> que;   int main() {     int k;     string str;     cin >> str;     cin >> k;     que.push({string{ z  + 1}, INF});     for (int i = 0; i < str.size(); ++i) {       que.push({string{str[i]}, i});     }     Node i;     while (k-- && !que.empty()) {       i = que.top();       que.pop();       if (i.pos == str.size() - 1 || i.pos == INF) continue;       que.push({i.str + str[i.pos + 1], i.pos + 1});     }     if (k && que.empty())       cout <<  No such line.  << endl;     else       cout << i.str << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char a[1000010], b[1000010];     while (scanf( %s%s , &a, &b) != EOF) {       int len1 = strlen(a);       int len2 = strlen(b);       int ans = 0;       if (len1 != len2) {         ans = 1;       } else {         if (len1 == 1) {           if (a[0] != b[0])             ans = 1;           else             ans = 0;         } else {           if (strcmp(a, b) == 0)             ans = 0;           else {             int j1 = 0, j2 = 0;             for (int i = 0; i < len1; i++)               if (a[i] ==  1 ) j1 = 1;             for (int i = 0; i < len1; i++)               if (b[i] ==  1 ) j2 = 1;             if (j1 && j2)               ans = 0;             else               ans = 1;           }         }       }       if (!ans)         printf( YES n );       else         printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr <<     << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   void inp_out() {}   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     inp_out();     long long int n, m;     cin >> n >> m;     vector<pair<long long int, long long int>> a(n);     long long int cnt = 0;     multiset<pair<long long int, long long int>> st;     vector<multiset<long long int>> adj(m + 1);     for (long long int i = 0; i < n; ++i) {       cin >> a[i].first >> a[i].second;       adj[a[i].first].insert(a[i].second);       if (a[i].first == 1)         ++cnt;       else         st.insert({a[i].second, a[i].first});     }     vector<long long int> ans(n + 1, 3e18);     for (long long int i = max(1ll, cnt); i <= n; ++i) {       vector<multiset<long long int>> temp_adj = adj;       multiset<pair<long long int, long long int>> temp_st = st;       long long int val = cnt, cost = 0;       for (long long int j = 2; j <= m; ++j) {         while (temp_adj[j].size() >= i) {           cost += *temp_adj[j].begin();           temp_st.erase(temp_st.find({*temp_adj[j].begin(), j}));           temp_adj[j].erase(temp_adj[j].begin());           ++val;         }       }       if (val > i) continue;       while (val < i) {         cost += (*temp_st.begin()).first;         temp_st.erase(temp_st.begin());         ++val;       }       ans[i] = cost;     }     long long int fa = *min_element(ans.begin(), ans.end());     cout << fa;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-11;   void fastIO() {     std::ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     fastIO();     int n, a;     cin >> n;     int tot = 0;     int mx = 0;     for (int i = 0; i < n; i++) {       cin >> a;       tot += a;       mx = max(mx, a);     }     double cond = (2.0 * tot) / n;     if (cond < mx) {       cout << mx << endl;     } else {       cout << ceil(cond + .00001) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int arr[n];     bool fl = false;     for (int i = 0; i < n; i++) {       scanf( %d , &arr[i]);       if (arr[i] == 1) {         fl = true;       }     }     if (fl == false)       printf( EASY );     else       printf( HARD );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[105];   int main() {     int n;     int k;     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> arr[i];     int count = 105;     int ans;     for (int i = 0; i < n; i++) {       if (k % arr[i] == 0) {         ans = k / arr[i];       }       count = min(count, ans);     }     cout << count;     return 0;   }
#include <bits/stdc++.h>   int memo[3][105], n;   char map[3][105];   int f(int x, int y) {     if (y >= n) return 2;     if (memo[x][y] == 0) {       if (map[x][y + 1] !=  . ) return memo[x][y] = 1;       int ret = 0;       if (map[x][y + 1] ==  .  && map[x][y + 2] ==  .  && map[x][y + 3] ==  . )         ret |= f(x, y + 3) - 1;       if (x > 0 && map[x - 1][y + 1] ==  .  && map[x - 1][y + 2] ==  .  &&           map[x - 1][y + 3] ==  . )         ret |= f(x - 1, y + 3) - 1;       if (x < 2 && map[x + 1][y + 1] ==  .  && map[x + 1][y + 2] ==  .  &&           map[x + 1][y + 3] ==  . )         ret |= f(x + 1, y + 3) - 1;       memo[x][y] = ret + 1;     }     return memo[x][y];   }   int main() {     int z, i;     char dap[3][10] = {  ,  NO ,  YES };     scanf( %d , &z);     while (z--) {       int m, x, y, t;       for (i = 0; i < 105; i++) memo[0][i] = memo[1][i] = memo[2][i] = 0;       scanf( %d%d%s%s%s , &n, &m, map[0], map[1], map[2]);       map[0][n] = map[0][n + 1] = map[0][n + 2] =  . ;       map[1][n] = map[1][n + 1] = map[1][n + 2] =  . ;       map[2][n] = map[2][n + 1] = map[2][n + 2] =  . ;       if (map[0][0] ==  s )         t = 0;       else if (map[1][0] ==  s )         t = 1;       else         t = 2;       printf( %s n , dap[f(t, 0)]);     }   }
#include <bits/stdc++.h>   using namespace std;   char tr[100005];   map<char, int> p;   char num[12] = { AHIMOTUVWXY };   char num1[27] = { ABCDEFGHIJKLMNOPQRSTUVWXYZ };   void init() {     int i;     for (i = 0; i < 26; i++) {       p[num1[i]] = 0;     }     for (i = 0; i < 11; i++) {       p[num[i]] = 1;     }   }   int main() {     init();     int n, i, j;     while (scanf( %s , tr) != EOF) {       n = strlen(tr);       for (i = 0, j = n - 1; i < n / 2; i++, j--) {         if (tr[i] != tr[j]) break;       }       if (i < n / 2) {         printf( NO n );         continue;       }       for (i = 0; i < n; i++) {         if (!p[tr[i]]) break;       }       if (i < n)         printf( NO n );       else         printf( YES n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[100];     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     int time = 10;     int solvedCount = 0;     int penalty = 0;     for (int i = 0; i < n; i++) {       time = time + a[i];       if (time <= 720) {         solvedCount++;         if (time > 360) penalty = penalty + (time - 360);       }     }     cout << solvedCount <<     << penalty << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;      void solve() {       int n; cin >> n;       map<int,int> m;       for(int i=0,x; i < n; ++i) {           cin >> x;           m[x]++;       }       map<int,int> m2;       for(auto p : m) {           m2[p.second]++;       }       int cnt,mn=n;       for(auto p1 : m2) {           cnt = 0;           for(auto p2 : m2) {               if(p1.first > p2.first) {                   cnt += p2.first * p2.second;               } else {                   cnt += (p2.first -p1.first) * p2.second;               }           }           mn = min(mn, cnt);       }       cout << mn << endl;   }   // 1,3,2,1,4,2   // 1 1 2 2   // 1:2   // 2:2      // 1 2 3 3 3 3 2 6 6   // 1 2 2 4   // 1:1   // 2:2   // 4:1   int main() {       int t; cin >> t; while(t--)       solve();   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:167772160 )   using namespace std;   const int inf = 1000000000;   long long k[1001], p[1001], f[1001], c[1001];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> k[i] >> c[i];     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++)         if (c[i] > c[j]) {           swap(c[i], c[j]);           swap(k[i], k[j]);         }     int t;     cin >> t;     for (int i = 1; i <= t; i++) cin >> p[i];     p[0] = 0;     for (int i = 1; i <= t; i++) f[i] = p[i] - p[i - 1];     f[t + 1] = 1000000000000LL;     int j = 1;     long long num = 0;     long long ans = 0;     for (int i = 1; i <= t + 1; i++) {       while (j <= n) {         long long mn = min(k[j] - num, f[i]);         ans += (long long)c[j] * mn * (long long)i;         if (mn == k[j] - num && mn == f[i]) {           ++j;           num = 0;           break;         } else if (mn == k[j] - num) {           ++j;           f[i] -= mn;           num = 0;         } else {           num += mn;           break;         }       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long b[150005], up[150005], a[150005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     bool fl = false;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> b[i];       up[i] = max(1ll, b[i]);       if (b[i] != 0) fl = true;     }     if (!fl) {       cout <<  YES n ;       for (int i = 1; i <= n; i++) cout << 1 <<    ;       exit(0);     }     for (int i = 1; i <= n; i++) {       if (i == 1)         up[i] = max(up[i], b[n] + 1);       else         up[i] = max(up[i], b[i - 1] + 1);     }     for (int i = 1; i <= n; i++) {       if (b[i] < up[i]) continue;       cout <<  YES n ;       a[i] = b[i];       int uk;       if (i == 1)         uk = n;       else         uk = i - 1;       while (uk != i) {         long long t = up[uk] / a[uk % n + 1];         if (t * a[uk % n + 1] + b[uk] >= up[uk])           a[uk] = t * a[uk % n + 1] + b[uk];         else           a[uk] = (t + 1) * a[uk % n + 1] + b[uk];         if (uk == 1)           uk = n;         else           uk--;       }       for (int j = 1; j <= n; j++) cout << a[j] <<    ;       exit(0);     }     cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   template <typename T>   inline void read(T &AKNOI) {     T x = 0, flag = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) flag = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     AKNOI = flag * x;   }   template <typename T>   inline void cmax(T &x, T y) {     if (x < y) x = y;   }   char s[N];   int len, n, m[N], mx, A[N], B[N][N], cost[10];   int cnt[10], rnk[N], rk2[N], dp[N][N];   void init() {     scanf( %s , s + 1);     len = strlen(s + 1);     mx = len;     for (int i = 1; i <= len; ++i) {       A[i] = s[len - i + 1] -  0 ;     }     read(n);     for (int i = 1; i <= n; ++i) {       scanf( %s , s + 1);       m[i] = strlen(s + 1);       cmax(mx, m[i]);       for (int j = 1; j <= m[i]; ++j) {         B[i][j] = s[m[i] - j + 1] -  0 ;       }     }     ++mx;     for (int i = 0; i <= 9; ++i) {       read(cost[i]);     }   }   void solve() {     for (int i = 1; i <= n; ++i) {       rnk[i] = i;     }     memset(dp, 0x80, sizeof(dp));     dp[0][0] = 0;     for (int d = 1, l, r; d <= mx; ++d) {       if (A[d] <= 9) {         l = r = A[d];       } else {         l = (d == len ? 1 : 0);         r = 9;       }       for (int k = l; k <= r; ++k) {         int sum = 0, jin = 0;         for (int i = 1; i <= n; ++i) {           int cur = k + B[i][d];           if (!cur) {             if (d <= m[i] || d <= len) {               sum += cost[0];             }           } else if (cur > 9) {             sum += cost[cur - 10];             ++jin;           } else {             sum += cost[cur];           }         }         for (int i = 0; i <= n; ++i) {           if (i) {             int cur = k + B[rnk[n - i + 1]][d];             if (cur == 9) {               sum += cost[0] - cost[9];               ++jin;             } else {               if (cur == 0 && d > m[rnk[n - i + 1]] && d > len) {                 sum += cost[1];               } else {                 sum += cost[cur % 10 + 1] - cost[cur % 10];               }             }           }           cmax(dp[d][jin], dp[d - 1][i] + sum);         }       }       for (int i = 0; i <= 9; ++i) {         cnt[i] = 0;       }       for (int i = 1; i <= n; ++i) {         ++cnt[B[i][d]];       }       for (int i = 1; i <= 9; ++i) {         cnt[i] += cnt[i - 1];       }       for (int i = n; i >= 1; --i) {         rk2[cnt[B[rnk[i]][d]]--] = rnk[i];       }       memcpy(rnk, rk2, sizeof(rnk));     }     printf( %d n , dp[mx][0]);   }   int main() {     init();     solve();     return 0;   }
#include <bits/stdc++.h>   const long long maxn = 1e4 + 10;   inline long long Max(long long a, long long b) { return a > b ? a : b; }   inline long long Min(long long a, long long b) { return a > b ? b : a; }   namespace FastIO {   inline long long read() {     long long f = 1, r = 0;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) {         f = -1;       }       c = getchar();     }     while (isdigit(c)) {       r = 10 * r + c -  0 ;       c = getchar();     }     return f * r;   }   inline void write(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   inline void writesp(long long x) { write(x), putchar(   ); }   inline void writeln(long long x) { write(x), puts(  ); }   };  // namespace FastIO   using namespace FastIO;   long long N;   inline bool ask(long long x1, long long y1, long long x2, long long y2) {     putchar( ? ), putchar(   );     writesp(x1), writesp(y1), writesp(x2), writeln(y2);     fflush(stdout);     std::string s;     std::cin >> s;     return s ==  YES ;   }   signed main() {     std::cin >> N;     long long nowx = 1, nowy = 1;     std::string s1 =   ;     while (true) {       if (nowx + nowy == N + 1) {         break;       }       if (nowx == N) {         nowy++, s1.push_back( R );       } else if (nowy == N) {         nowx++, s1.push_back( D );       } else {         if (ask(nowx + 1, nowy, N, N)) {           nowx++, s1.push_back( D );         } else {           nowy++, s1.push_back( R );         }       }     }     nowx = N, nowy = N;     std::string s2 =   ;     while (true) {       if (nowx + nowy == N + 1) {         break;       }       if (nowx == 1) {         nowy--, s2.push_back( R );       } else if (nowy == 1) {         nowx--, s2.push_back( D );       } else {         if (ask(1, 1, nowx, nowy - 1)) {           nowy--, s2.push_back( R );         } else {           nowx--, s2.push_back( D );         }       }     }     std::reverse(s2.begin(), s2.end());     putchar( ! ), putchar(   );     std::string res = s1 + s2;     std::cout << res << std::endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   long long gcd(long long x, long long y) {     if (!y) return x;     return gcd(y, x % y);   }   int main() {     scanf( %I64d%I64d%I64d , &n, &m, &k);     if (n * m * 2 % k) {       printf( NO );       return 0;     }     long long x = gcd(n * m * 2 / k, n), y = n * m * 2 / k / x;     if (y > m) x *= 2, y /= 2;     printf( YES n );     printf( %I64d 0 n0 %I64d n0 0 , x, y);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   const long long MAX = 1000004;   const long long INF = 1e18L + 5;   template <class T, class U>   void chmin(T &t, const U &u) {     if (t > u) t = u;   }   template <class T, class U>   void chmax(T &t, const U &u) {     if (t < u) t = u;   }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << H;     debug_out(T...);   }   template <typename Arg1>   void pn(Arg1 &&arg1) {     cout << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void pn(Arg1 &&arg1, Args &&...args) {     cout << arg1 <<   n ;     pn(args...);   }   template <typename Arg1>   void ps(Arg1 &&arg1) {     cout << arg1 <<    ;   }   template <typename Arg1, typename... Args>   void ps(Arg1 &&arg1, Args &&...args) {     cout << arg1 <<    ;     ps(args...);   }   template <typename Arg1>   void read(Arg1 &&arg1) {     cin >> arg1;   }   template <typename Arg1, typename... Args>   void read(Arg1 &&arg1, Args &&...args) {     cin >> arg1;     read(args...);   }   long long n, m;   char mat[51][51];   long long dx[] = {1, 0, -1, 0};   long long dy[] = {0, 1, 0, -1};   bool valid(long long x, long long y) {     if (x >= 0 && y >= 0 && x < n && y < m) return true;     return false;   }   vector<vector<long long>> vis(51, vector<long long>(51, 0));   void dfs(long long x, long long y) {     if (mat[x][y] ==  # ) return;     if (mat[x][y] ==  G ) {       mat[x][y] =  . ;     }     if (mat[x][y] ==  B ) {       return;     }     vis[x][y] = 1;     for (long long i = 0; i < 4; ++i) {       long long tx = x + dx[i];       long long ty = y + dy[i];       if (valid(tx, ty)) {         if (!vis[tx][ty]) dfs(tx, ty);       }     }   }   void solve() {     read(n, m);     bool pos = true;     for (long long i = 0; i < n; ++i)       for (long long j = 0; j < m; ++j) read(mat[i][j]);     for (long long i = 0; i < n; ++i) {       for (long long j = 0; j < m; ++j) {         if (mat[i][j] ==  B ) {           for (long long k = 0; k < 4; ++k) {             long long tx = i + dx[k];             long long ty = j + dy[k];             if (valid(tx, ty)) {               if (mat[tx][ty] ==  G ) {                 pos = false;               } else {                 if (mat[tx][ty] !=  B ) mat[tx][ty] =  # ;               }             }           }         }       }     }     if (pos) {       for (long long i = 0; i < n; ++i) {         for (long long j = 0; j < m; ++j) {           if (mat[i][j] ==  G ) {             for (long long k = 0; k < n; ++k)               for (long long l = 0; l < m; ++l) vis[k][l] = 0;             dfs(i, j);             if (vis[n - 1][m - 1] == 0) {               pos = false;             }           }         }       }       pn(pos ?  Yes  :  No );     } else       pn( No );   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long tc = 1;     cin >> tc;     while (tc--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 5;   int n, m, fa[N], b[N], ans;   struct edge {     int u, v, w;   } e[N];   bool cmp(edge x, edge y) { return x.w > y.w; }   int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }   int main() {     scanf( %d%d , &n, &m);     for (register int i = 1; i <= n + m; ++i) fa[i] = i;     for (register int i = 1, x, y, w; i <= m; ++i) {       scanf( %d%d%d , &x, &y, &w);       e[i] = (edge){x, y, w};     }     sort(e + 1, e + m + 1, cmp);     for (register int i = 1, x, y; i <= m; ++i) {       x = find(e[i].u), y = find(e[i].v);       if (x == y && !b[x]) {         b[x] = 1;         ans += e[i].w;       } else if (x != y && !(b[x] && b[y])) {         if (b[x] || b[y]) b[y] = 1;         fa[x] = y;         ans += e[i].w;       }     }     printf( %d n , ans);     return 0;   }