malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int mx=2e5+10;   const int INF=0x3f3f3f;   long long tes[mx][2][2];   bool flg[mx][2][2];   int hd[mx],nx[mx*2],t[mx*2],vl[mx*2];   int sum;      struct Node   {       int x,y,z;       long long jud;       bool operator < (const Node &nd) const       {           return jud>nd.jud;       }   };      void add(int x,int y,int z)   {       t[++sum]=y;       nx[sum]=hd[x];       vl[sum]=z;       hd[x]=sum;   }      void chg()   {       priority_queue<Node> q;       q.push({1,0,0,0});       memset(tes,0x3f,sizeof(tes));       tes[1][0][0]=0;       while(!q.empty())       {           Node upp=q.top();           q.pop();           int x=upp.x,y=upp.y,z=upp.z;           if(flg[x][y][z])               continue;           flg[x][y][z]=1;           for(int i=hd[x];i;i=nx[i])           {               int a=vl[i],b=t[i];               if(tes[b][y][z]>tes[x][y][z]+a)               {                   tes[b][y][z]=tes[x][y][z]+a;                   q.push({b,y,z,tes[b][y][z]});               }               if(!y)               {                   if(tes[b][y^1][z]>tes[x][y][z])                   {                       tes[b][y^1][z]=tes[x][y][z];                       q.push({b,y^1,z,tes[b][y^1][z]});                   }               }               if(!z)               {                   if(tes[b][y][z^1]>tes[x][y][z]+a*2)                   {                       tes[b][y][z^1]=tes[x][y][z]+a*2;                       q.push({b,y,z^1,tes[b][y][z^1]});                   }               }               if(!y&&!z)               {                   if(tes[b][y^1][z^1]>tes[x][y][z]+a)                   {                       tes[b][y^1][z^1]=tes[x][y][z]+a;                       q.push({b,y^1,z^1,tes[b][y^1][z^1]});                   }               }           }       }   }      int main()   {       int n,m;       scanf( %d %d ,&n,&m);       for(int i=1;i<=m;i++)       {           int x,y,z;           scanf( %d %d %d ,&x,&y,&z);           add(x,y,z);           add(y,x,z);       }       chg();       for(int i=2;i<=n;i++)           cout<<tes[i][1][1]<<   ;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 2e5 + 5;   pair<long long, long long> a[MAXN];   long long s;   long long n;   bool check(long long x) {     long long sum = 0, cnt = 0;     vector<long long> nums;     for (long long i = 0; i < n; i++) {       if (a[i].first >= x) {         sum += a[i].first;         cnt++;       } else {         if (a[i].second < x) {           sum += a[i].first;         } else {           nums.push_back(a[i].first);         }       }     }     long long left = max((long long)0, (n + 1) / 2 - cnt);     if (left > nums.size()) return 0;     for (long long i = 0; i < nums.size() - left; i++) {       sum += nums[i];     }     for (long long i = nums.size() - left; i < nums.size(); i++) {       sum += x;     }     return (sum <= s);   }   int main() {     long long q;     cin >> q;     while (q--) {       cin >> n >> s;       for (long long i = 0; i < n; i++) {         cin >> a[i].first >> a[i].second;       }       sort(a, a + n);       long long l = 1, r = 1e9 + 100;       while (l + 1 < r) {         long long m = (l + r) >> 1;         if (check(m)) {           l = m;         } else {           r = m;         }       }       cout << l <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, res, tmp, m;   vector<int> v;   bool check(int val) {     int m = n - val;     return m % (2 * k + 1) <= k;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> k;     int i = min(n, k + 1);     while (!check(i)) i--;     while (i <= n) {       if (i <= n) v.push_back(i);       i += 2 * k + 1;     }     if (v[v.size() - 1] + k < n) v.push_back(n);     cout << v.size() <<   n ;     for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 300 + 5;   int n, m, p;   int grid[MAX][MAX];   int dp[MAX][MAX];   vector<pair<int, int> > pos[MAX * MAX];   vector<int> col[MAX];   int main() {     scanf( %d %d %d , &n, &m, &p);     for (int i = int(0); i < int(n); i++) {       for (int j = int(0); j < int(m); j++) {         scanf( %d , &grid[i][j]);         if (grid[i][j] == 1) {           dp[i][j] = i + j;         } else {           dp[i][j] = 1 << 30;         }         pos[grid[i][j]].emplace_back(i, j);       }     }     bool visited[MAX];     for (int i = int(1); i < int(p); i++) {       memset(visited, false, sizeof visited);       for (int c = int(0); c < int(m); c++) {         col[c].clear();       }       for (auto &each : pos[i + 1]) {         col[each.second].push_back(each.first);       }       for (auto &each : pos[i]) {         visited[each.first] = true;       }       for (int r = int(0); r < int(n); r++) {         if (visited[r]) {           int best = 1 << 30;           for (int c = int(0); c < int(m); c++) {             best++;             if (grid[r][c] == i) {               best = min(best, dp[r][c]);             }             for (auto &each : col[c]) {               dp[each][c] = min(dp[each][c], best + abs(each - r));             }           }           best = 1 << 30;           for (int c = int(m - 1); c >= int(0); c--) {             best++;             if (grid[r][c] == i) {               best = min(best, dp[r][c]);             }             for (auto &each : col[c]) {               dp[each][c] = min(dp[each][c], best + abs(each - r));             }           }         }       }     }     printf( %d n , dp[pos[p][0].first][pos[p][0].second]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef vector<int> vi;   typedef vector<int> vll;   typedef pair<int, int> pii;   #define F first   #define S second   #define PB push_back   #define MP make_pair   #define ALL(v) v.begin(), v.end()   #define rALL(v) v.rbegin(), v.rend()   #define INF 1000000007LL   #define MOD 998244353LL      const int LIM = 2e5 + 5;      void solve()   {       int n, x, f, res = 0;       cin >> n;       for(int i = 0; i < n; i++)       {           cin >> x;           f = 0;           for(int j = 1; j * j <= x; j++)               if(j * j == x)               {                   f = 1;                   break;               }           if(f == 0)               res = 1;       }          if(res)           cout <<  YES n ;       else           cout <<  NO n ;          }      int main()   {       ios_base::sync_with_stdio(false);       cin.tie(NULL);          int t = 1;       cin >> t;       while (t--)       {           solve();       }          return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     int n;     cin >> n;     cin >> a >> b;     int ans = 0;     for (int i = 0; i < n - 1; i++) {       if (a[i] != b[i]) {         ans++;         if (a[i + 1] != b[i + 1] && a[i] != a[i + 1]) {           swap(a[i], a[i + 1]);         } else           a[i] = b[i];       }     }     if (a[n - 1] != b[n - 1]) ans++;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef int matrix[140][140];   const int modp = 12345;   int k, N, mod[30], base[30], cnt[30], num[30][30];   int legal[140], ans;   long long n;   matrix a, b;   void mul(matrix a, matrix b) {     matrix c;     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++) c[i][j] = 0;     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++)         for (int k = 0; k < N; k++)           c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % modp;     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++) a[i][j] = c[i][j];   }   int gcd(int x, int y) {     if (y == 0) return x;     return gcd(y, x % y);   }   int main() {     cin >> n >> k;     for (int i = 0; i < 26; i++) mod[i] = 1;     for (int i = 1; i <= k; i++) {       char type[4];       int p, x;       scanf( %s , type);       p = type[0] -  A ;       scanf( %d , &x);       mod[p] *= x / gcd(x, mod[p]);       cnt[p]++;       num[p][cnt[p]] = x;     }     base[0] = 1;     for (int i = 0; i < 26; i++) base[i + 1] = base[i] * mod[i];     N = base[26];     for (int i = 0; i < N; i++) {       legal[i] = 1;       for (int j = 0; j < 26; j++)         if (cnt[j]) {           int res = 0, zt;           zt = i + base[j];           if ((i / base[j] + 1) % mod[j] == 0) zt -= base[j + 1];           b[i][zt]++;           for (int k = 1; k <= cnt[j]; k++)             if ((i / base[j]) % num[j][k] == 0) res = 1;           legal[i] &= res;         }     }     a[0][0] = 1;     for (; n; n >>= 1) {       if (n & 1) mul(a, b);       mul(b, b);     }     for (int i = 0; i < N; i++)       if (legal[i]) ans = (ans + a[0][i]) % modp;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k;     cin >> n >> k;     while (k > 0) {       if (n % 10 != 0 && k >= n % 10) {         k -= n % 10;         n -= n % 10;       } else if (n % 10 != 0 && k < n % 10) {         n -= k;         k -= k;       } else if (n % 10 == 0) {         n = n / 10;         k--;       }     }     cout << n << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   double eps = 1e-10;   using namespace std;   long long m, h1, a1, x_1, y_1, h2, a2, x_2, y_2, len1, len2, l1, l2, i1 = -1,                                                                        i2 = -1;   int idx1[1000006], idx2[1000006], cycle1[1000006], cycle2[1000006];   bool check(long long x) {     if (x < l2) {       if (cycle2[x] == a2)         return 1;       else         return 0;     }     x -= l2;     x %= len2;     return (cycle2[x + l2] == a2);   }   int main() {     cin >> m >> h1 >> a1 >> x_1 >> y_1 >> h2 >> a2 >> x_2 >> y_2;     for (int i = 0; i <= 1000000; i++) idx1[i] = idx2[i] = -1;     idx1[h1] = 0, idx2[h2] = 0;     cycle1[0] = h1, cycle2[0] = h2;     for (int i = 1; i <= m + 1; i++) {       int height = (x_1 * cycle1[i - 1] + y_1) % m;       if (idx1[height] != -1) {         len1 = i - idx1[height];         l1 = idx1[height];         break;       } else {         cycle1[i] = height;         idx1[height] = i;       }     }     for (int i = 1; i <= m + 1; i++) {       int height = (x_2 * cycle2[i - 1] + y_2) % m;       if (idx2[height] != -1) {         len2 = i - idx2[height];         l2 = idx2[height];         break;       } else {         cycle2[i] = height;         idx2[height] = i;       }     }     for (int i = 0; i < l1; i++) {       if (cycle1[i] == a1) {         if (check(i)) {           cout << i << endl;         } else {           puts( -1 );         }         return 0;       }     }     for (int i = l1; i < len1 + l1; i++) {       if (cycle1[i] == a1) {         i1 = i - l1;         break;       }     }     if (i1 == -1) {       puts( -1 );       return 0;     }     for (int k1 = 0; k1 < 1000002; k1++) {       long long t = l1 + (long long)k1 * len1 + i1;       if (check(t)) {         cout << t << endl;         return 0;       }     }     puts( -1 );   }
#include <bits/stdc++.h>   using namespace std;   bool debug = true;   template <typename T1, typename T2>   ostream& operator<<(ostream& os, pair<T1, T2> ptt) {     os << ptt.first <<  ,  << ptt.second;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, vector<T> vt) {     os <<  { ;     for (int i = 0; i < vt.size(); i++) {       os << vt[i] <<    ;     }     os <<  } ;     return os;   }   int n, k;   int a[200005];   int main(int argc, char* argv[]) {     int t;     cin >> t;     while (t--) {       cin >> n >> k;       for (int i = 0; i < n; i++) {         cin >> a[i];       }       int mx = 0;       for (int i = 0; i < n - k; i++) {         if (a[i + k] - a[i] < a[mx + k] - a[mx]) {           mx = i;         }       }       cout << (a[mx + k] + a[mx]) / 2 << endl;     }     return 0;   }
#include <bits/stdc++.h>   long long n, k, m;   long long dp[1010][110][2], pw[1010], PW[1010];   long long Solve(long long p, long long r, int f) {     if (p <= 0) return f;     if (~dp[p][r][f]) return dp[p][r][f];     if (f) return (9LL * PW[p - 1]) % m;     long long res = 0;     for (int i = ((p == 1) ? 1 : 0); i <= (9); ++i) {       long long nr = (r + (long long)i * pw[n - p]) % k;       res = (res + Solve(p - 1, nr, f || (!nr && i))) % m;     }     return dp[p][r][f] = res;   }   int main() {     scanf( %I64d%I64d%I64d , &n, &k, &m);     pw[0] = PW[0] = 1;     for (int i = 1; i <= (n); ++i)       pw[i] = (pw[i - 1] * 10) % k, PW[i] = (PW[i - 1] * 10) % m;     memset(dp, -1, sizeof(dp));     printf( %I64d n , Solve(n, 0, 0));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, b, c, d, e, i, j, ii, jj, zx, xc, p[10009], ji, F[10009], G[10009];   pair<int, int> k[10009];   vector<int> v;   vector<int>::iterator it;   int ask(int q, int w) {     int qw = 0;     cout <<  ?   << q <<     << w << endl;     cin >> qw;     return qw;   }   int fun(int q) {     int qw = 0;     if (q != k[0].first) {       qw = ask(q, k[0].first);     } else {       qw = ask(q, k[0].second);     }     for (j = 1; j <= ji; j++) {       if (q != k[j].first) {         e = ask(q, k[j].first);       } else {         e = ask(q, k[j].second);       }       qw &= e;     }     return qw;   }   void answer() {     cout <<  ! ;     for (j = 1; j <= a; j++) {       cout <<     << p[j];     }     exit(0);   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> a;     for (j = 0;; j++) {       if ((1 << j) >= a) break;       ji = j;     }     while (1) {       for (j = 0; j <= ji; j++) {         if (k[j].first == 0) break;       }       if (j == ji + 1) break;       c = rand() % a + 1;       d = rand() % a + 1;       if (c == d) continue;       e = ask(c, d);       for (jj = 0; jj <= ji; jj++) {         if ((e & (1 << jj)) == 0) {           k[jj].first = c;           k[jj].second = d;         }       }     }     for (i = 1; i <= a; i++) {       c = rand() % (a - i + 1) + 1;       G[i] = c;       v.push_back(i);     }     for (i = 1; i <= a; i++) {       F[i] = v[G[i] - 1];       it = v.begin() + (G[i] - 1);       v.erase(it);     }     p[F[1]] = fun(F[1]);     c = F[1];     for (i = 2; i <= a; i++) {       e = ask(c, F[i]);       if (p[c] == e) {         c = F[i];         p[c] = fun(c);       }     }     p[c] = 0;     for (i = 1; i <= a; i++) {       if (i == c) continue;       p[i] = ask(i, c);     }     answer();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   struct Node {     int u, w, next;   };   struct Node node[300010];   int p;   int f[100010], g[100010], num[100010], isgo[100010];   int judge(int n) {     while (n) {       if (n % 10 != 4 && n % 10 != 7) return 0;       n /= 10;     }     return 1;   }   void dfs(int u) {     isgo[u] = 1;     num[u] = 1;     f[u] = 0;     for (int now = node[u].next; now != -1; now = node[now].next) {       int v = node[now].u, w = node[now].w;       if (isgo[v] == 1) continue;       dfs(v);       if (w == 1)         f[u] += num[v];       else         f[u] += f[v];       num[u] += num[v];     }   }   void dp(int u) {     isgo[u] = 1;     for (int now = node[u].next; now != -1; now = node[now].next) {       int v = node[now].u;       int w = node[now].w;       if (isgo[v] == 1) continue;       if (w == 1)         g[v] = num[1] - num[v];       else         g[v] = g[u] + f[u] - f[v];       dp(v);     }   }   void add(int u, int v, int w) {     p++;     node[p].u = v, node[p].w = w;     node[p].next = node[u].next;     node[u].next = p;   }   int main() {     while (scanf( %d , &n) != EOF) {       for (int i = 1; i <= n; i++) node[i].next = -1;       p = n;       for (int i = 1; i < n; i++) {         int u, v, w;         scanf( %d %d %d , &u, &v, &w);         w = judge(w);         add(u, v, w), add(v, u, w);       }       memset(isgo, 0, sizeof(isgo));       dfs(1);       memset(isgo, 0, sizeof(isgo));       g[1] = 0;       dp(1);       long long ans = 0;       for (int i = 1; i <= n; i++)         ans +=             1LL * f[i] * (f[i] - 1) + 1LL * g[i] * (g[i] - 1) + 2LL * f[i] * g[i];       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool row[1100], col[1100];   int main() {     int n, m;     while (scanf( %d %d , &n, &m) != EOF) {       memset(row, true, sizeof(row));       memset(col, true, sizeof(col));       while (m--) {         int x, y;         scanf( %d %d , &x, &y);         row[x] = false;         col[y] = false;       }       int res = 0;       for (int i = 2; i <= n - 1; i++) {         if (n % 2 && i == n / 2 + 1) {           continue;         }         if (col[i]) {           res++;         }         if (row[i]) {           res++;         }       }       if (n % 2 && (col[n / 2 + 1] || row[n / 2 + 1])) {         res++;       }       printf( %d n , res);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, s;   long long row, col;   long long sr, sc;   long long tr, tc;   int main() {     scanf( %I64d %I64d %I64d , &n, &m, &s);     row = n / s + 1;     if (n % s == 0) row--;     col = m / s + 1;     if (m % s == 0) col--;     sr = n - ((row - 1) * s + 1);     sc = m - ((col - 1) * s + 1);     tr = (sr + 1) * row;     tc = (sc + 1) * col;     printf( %I64d n , min(n * m, tr * tc));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100005];   int main() {     int n, x;     scanf( %d%d , &n, &x);     int sum = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       sum += a[i];     }     if (n == 1) {       if (a[0] == x)         printf( YES n );       else         printf( NO n );       return 0;     }     if (sum + n - 1 == x)       printf( YES n );     else       printf( NO n );   }
#include <bits/stdc++.h>   using namespace std;   int x[5011], a, b, c, n;   int main() {     cin >> n;     printf( ? 1 2 n );     fflush(stdout);     scanf( %d , &a);     printf( ? 1 3 n );     fflush(stdout);     scanf( %d , &b);     printf( ? 2 3 n );     fflush(stdout);     scanf( %d , &c);     int q = a - c;     x[1] = (q + b) / 2;     x[2] = a - x[1];     x[3] = b - x[1];     for (int i = 4; i <= n; i++) {       printf( ? %d %d n , i - 1, i);       fflush(stdout);       scanf( %d , &q);       x[i] = q - x[i - 1];     }     printf( !  );     for (int i = 1; i <= n; i++) {       printf( %d  , x[i]);     }     fflush(stdout);   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 300000;   const long long inf = 1LL << 60;   struct edge {     long long from, to, dist;     edge(long long u, long long v, long long d) : from(u), to(v), dist(d) {}   };   struct HeapNode {     long long d;     long long u;     HeapNode(long long a, long long b) : d(a), u(b) {}     bool operator<(const HeapNode &rhs) const { return d > rhs.d; }   };   struct Dijkstra {     int n, m;     vector<edge> edges;     vector<int> G[maxn];     bool done[maxn];     long long d[maxn];     int p[maxn];     void init(int n) {       this->n = n;       for (int i = 0; i < n; ++i) G[i].clear();       edges.clear();     }     void add_edge(int from, int to, long long dist) {       edges.push_back(edge(from, to, dist));       m = edges.size();       G[from].push_back(m - 1);     }     void dijkstra(int s) {       priority_queue<HeapNode> Q;       for (int i = 0; i < n; ++i) d[i] = inf;       d[s] = 0;       Q.push(HeapNode(0, s));       memset(done, 0, sizeof(done));       while (!Q.empty()) {         HeapNode x = Q.top();         Q.pop();         int u = x.u;         if (done[u]) continue;         done[u] = true;         for (unsigned i = 0; i < G[u].size(); ++i) {           edge &e = edges[G[u][i]];           if (d[e.to] > d[u] + e.dist) {             d[e.to] = d[u] + e.dist;             p[e.to] = G[u][i];             Q.push(HeapNode(d[e.to], e.to));           }         }       }     }   } graph;   int main() {     int n, m;     scanf( %d %d , &n, &m);     graph.init(n + 10);     const int s = n + 5;     for (int i = 0; i < m; ++i) {       long long x, y, w;       scanf( %lld %lld %lld , &x, &y, &w);       graph.add_edge(x, y, w * 2);       graph.add_edge(y, x, w * 2);     }     for (int i = 1; i <= n; ++i) {       long long a;       scanf( %lld , &a);       graph.add_edge(s, i, a);     }     graph.dijkstra(s);     for (int i = 1; i <= n; ++i) printf( %lld  , graph.d[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   int pr[100002];   int lv[100002];   int st[100002], head;   int P(int x) {     head = 0;     while (pr[x] != -1) {       st[head++] = x;       x = pr[x];     }     while (head > 0) {       pr[st[--head]] = x;     }     return x;   }   void Union(int x, int y) {     x = P(x);     y = P(y);     if (x == y) return;     if (lv[x] > lv[y]) {       int t = x;       x = y;       y = t;     }     pr[x] = y;     if (lv[x] == lv[y]) {       lv[y]++;     }   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     int a, b;     int i;     int sol = 1;     for (i = 0; i < n; i++) {       pr[i] = -1;       lv[i] = 0;     }     for (i = 0; i < m; i++) {       scanf( %d %d , &a, &b);       a--;       b--;       if (P(a) != P(b)) {         Union(a, b);       } else         sol = (sol * 2) % 1000000009;       int pr;       pr = (sol - 1 + 1000000009) % 1000000009;       printf( %d n , pr);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, n;     cin >> a >> b >> n;     a = a * 10;     int f = 0;     for (int i = 0; i < 10; i++) {       if ((a + i) % b == 0) {         cout << a + i;         string s(n - 1,  0 );         cout << s << endl;         f = 1;         break;       }     }     if (!f) cout << -1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 10000;   const long long INFFLUJO = 1e14;   const double INFCOSTO = 1e14;   struct edge {     int u, v;     long long cap, flow;     double cost;     long long rem() { return cap - flow; }   };   int nodes;   vector<int> G[MAXN];   vector<edge> e;   void addEdge(int u, int v, long long cap, double cost) {     G[u].push_back(((int)e.size()));     e.push_back((edge){u, v, cap, 0, cost});     G[v].push_back(((int)e.size()));     e.push_back((edge){v, u, 0, 0, -cost});   }   double dist[MAXN], mnCost;   int pre[MAXN];   long long cap[MAXN], mxFlow;   bool in_queue[MAXN];   void flow(int s, int t) {     memset(in_queue, 0, sizeof(in_queue));     mxFlow = mnCost = 0;     while (1) {       fill(dist, dist + nodes, INFCOSTO);       dist[s] = 0;       memset(pre, -1, sizeof(pre));       pre[s] = 0;       memset(cap, 0, sizeof(cap));       cap[s] = INFFLUJO;       queue<int> q;       q.push(s);       in_queue[s] = 1;       while (((int)q.size())) {         int u = q.front();         q.pop();         in_queue[u] = 0;         for (auto it : G[u]) {           edge &E = e[it];           if (E.rem() && dist[E.v] > dist[u] + E.cost + 1e-9) {             dist[E.v] = dist[u] + E.cost;             pre[E.v] = it;             cap[E.v] = min(cap[u], E.rem());             if (!in_queue[E.v]) q.push(E.v), in_queue[E.v] = 1;           }         }       }       if (pre[t] == -1) break;       mxFlow += cap[t];       mnCost += cap[t] * dist[t];       for (int v = t; v != s; v = e[pre[v]].u) {         e[pre[v]].flow += cap[t];         e[pre[v] ^ 1].flow -= cap[t];       }     }   }   int x[500], y[500];   int main() {     int n;     scanf( %d , &n);     int mx = -1100000;     for (int i = 0; i < int(n); i++) {       scanf( %d %d , x + i, y + i);       mx = max(mx, y[i]);     }     int cnt = 0;     for (int i = 0; i < int(n); i++)       if (y[i] == mx) cnt++;     if (cnt > 1)       printf( -1 n );     else {       nodes = 2 * n + 2;       for (int i = 0; i < int(n); i++)         for (int j = 0; j < int(n); j++)           if (y[i] > y[j]) {             addEdge(i, n + j, 1,                     sqrt(1ll * (x[i] - x[j]) * (x[i] - x[j]) +                          1ll * (y[i] - y[j]) * (y[i] - y[j])));           }       for (int i = 0; i < int(n); i++) addEdge(2 * n, i, 2, 0);       for (int i = 0; i < int(n); i++)         if (y[i] != mx) addEdge(n + i, 2 * n + 1, 1, 0);       flow(2 * n, 2 * n + 1);       if (mxFlow != n - 1)         printf( -1 n );       else         printf( %.10lf n , mnCost);     }   }