Submission #547034

# Submission time Handle Problem Language Result Execution time Memory
547034 2022-04-09T09:06:41 Z cig32 Swapping Cities (APIO20_swap) C++17
17 / 100
2000 ms 24708 KB
#include "bits/stdc++.h"
using namespace std;
//#define int long long
const int MAXN = 2e5 + 10;
const int MOD = 1e9 + 7;
#define ll __int128
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
  int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
ll read() { // read int128
  int x; cin >> x; return (ll)x;
}
long long bm(long long b, long long p) {
  if(p==0) return 1 % MOD;
  long long r = bm(b, p >> 1);
  if(p&1) return (((r*r) % MOD) * b) % MOD;
  return (r*r) % MOD;
}
long long inv(long long b) { 
  return bm(b, MOD-2);
}
long long f[MAXN];
long long nCr(int n, int r) { 
  long long ans = f[n]; ans *= inv(f[r]); ans %= MOD;
  ans *= inv(f[n-r]); ans %= MOD; return ans;
}
void precomp() { 
  for(int i=0; i<MAXN; i++) f[i] = (i == 0 ? 1 % MOD : (f[i-1] * i) % MOD);
}
int fastlog(int x) {
  if(x == 0) return -1;
  return 32 - __builtin_clz(x) - 1;
}
void gay(int i) {
  cout << "Case #" << i << ": ";
}
#include "swap.h"
void init(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W);

int getMinimumFuelCapacity(int X, int Y);

int n, m;
vector<pair<int,int> > adj[101010];
struct edge {
  int f, t, w;
};
class cmp {
  public:
  bool operator() (edge x, edge y) {
    return x.w>y.w;
  }
};
vector<edge> mst;
map<pair<int, int>, bool> inmst;
edge e[101010];
int dsu[101010];
int set_of(int u) {
  if(dsu[u]==u) return u;
  return dsu[u]= set_of(dsu[u]);
}
void union_(int u, int v) {
  dsu[set_of(u)] = set_of(v);
}
void init(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
  n = N, m = M;
  for(int i=0; i<m; i++) {
    adj[U[i]].push_back({V[i], W[i]});
    adj[V[i]].push_back({U[i], W[i]});
    e[i] = {U[i], V[i], W[i]};
  }
  for(int i=0; i<n; i++) dsu[i] = i;
}
int getMinimumFuelCapacity(int X, int Y) {
  int lb = 1, rb = MOD;
  while(lb < rb) {
    int mid = (lb + rb) >> 1;
    for(int i=0; i<n; i++) dsu[i] = i;
    int deg[n];
    for(int i=0; i<n; i++) deg[i] = 0;
    for(int i=0; i<m; i++) {
      if(e[i].w <= mid) {
        deg[e[i].f]++;
        deg[e[i].t]++;
      }
      if(e[i].w <= mid && set_of(e[i].f) != set_of(e[i].t)) {
        union_(e[i].f, e[i].t);
      }
    }
    int ma = 0;
    for(int i=0; i<n; i++ ){
      if(set_of(X)== set_of(i)) ma = max(ma, deg[i]);
    }
    int cntnodes = 0, cntedges = 0;
    for(int i=0; i<n; i++) {
      if(set_of(X) == set_of(i)) cntnodes++;
    }
    for(int i=0; i<m; i++) {
      if(e[i].w <= mid && set_of(e[i].f) == set_of(X)) cntedges++;
    }
    if(set_of(X) == set_of(Y) && (ma >= 3 || cntnodes != cntedges + 1)) {
      rb = mid;
    } 
    else {
      lb = mid +1 ;
    }
  }
  return (lb == MOD ? -1 : lb);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 4 ms 2724 KB Output is correct
5 Correct 5 ms 2772 KB Output is correct
6 Correct 6 ms 2704 KB Output is correct
7 Correct 6 ms 2772 KB Output is correct
8 Correct 6 ms 2772 KB Output is correct
9 Correct 226 ms 9804 KB Output is correct
10 Correct 535 ms 11488 KB Output is correct
11 Correct 574 ms 11344 KB Output is correct
12 Correct 685 ms 11724 KB Output is correct
13 Correct 711 ms 11724 KB Output is correct
14 Execution timed out 2075 ms 10192 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Execution timed out 2080 ms 16520 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 4 ms 2724 KB Output is correct
5 Correct 5 ms 2772 KB Output is correct
6 Correct 6 ms 2704 KB Output is correct
7 Correct 6 ms 2772 KB Output is correct
8 Correct 6 ms 2772 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 6 ms 2788 KB Output is correct
11 Correct 6 ms 2772 KB Output is correct
12 Correct 6 ms 2772 KB Output is correct
13 Correct 6 ms 2644 KB Output is correct
14 Correct 5 ms 2752 KB Output is correct
15 Correct 6 ms 2772 KB Output is correct
16 Correct 6 ms 2700 KB Output is correct
17 Correct 6 ms 2772 KB Output is correct
18 Correct 7 ms 2720 KB Output is correct
19 Correct 5 ms 2784 KB Output is correct
20 Correct 7 ms 2772 KB Output is correct
21 Correct 7 ms 2784 KB Output is correct
22 Correct 5 ms 2772 KB Output is correct
23 Correct 5 ms 2772 KB Output is correct
24 Correct 8 ms 2832 KB Output is correct
25 Correct 8 ms 2832 KB Output is correct
26 Correct 7 ms 2828 KB Output is correct
27 Correct 6 ms 2704 KB Output is correct
28 Correct 8 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 4 ms 2724 KB Output is correct
6 Correct 5 ms 2772 KB Output is correct
7 Correct 6 ms 2704 KB Output is correct
8 Correct 6 ms 2772 KB Output is correct
9 Correct 6 ms 2772 KB Output is correct
10 Correct 226 ms 9804 KB Output is correct
11 Correct 535 ms 11488 KB Output is correct
12 Correct 574 ms 11344 KB Output is correct
13 Correct 685 ms 11724 KB Output is correct
14 Correct 711 ms 11724 KB Output is correct
15 Correct 6 ms 2788 KB Output is correct
16 Correct 6 ms 2772 KB Output is correct
17 Correct 6 ms 2772 KB Output is correct
18 Correct 6 ms 2644 KB Output is correct
19 Correct 5 ms 2752 KB Output is correct
20 Correct 6 ms 2772 KB Output is correct
21 Correct 6 ms 2700 KB Output is correct
22 Correct 6 ms 2772 KB Output is correct
23 Correct 7 ms 2720 KB Output is correct
24 Correct 5 ms 2784 KB Output is correct
25 Correct 7 ms 2772 KB Output is correct
26 Correct 7 ms 2784 KB Output is correct
27 Correct 5 ms 2772 KB Output is correct
28 Correct 5 ms 2772 KB Output is correct
29 Correct 8 ms 2832 KB Output is correct
30 Correct 8 ms 2832 KB Output is correct
31 Correct 7 ms 2828 KB Output is correct
32 Correct 6 ms 2704 KB Output is correct
33 Correct 8 ms 2772 KB Output is correct
34 Correct 24 ms 4032 KB Output is correct
35 Correct 680 ms 11456 KB Output is correct
36 Correct 689 ms 11512 KB Output is correct
37 Correct 723 ms 11524 KB Output is correct
38 Correct 689 ms 11424 KB Output is correct
39 Correct 708 ms 11432 KB Output is correct
40 Correct 679 ms 10768 KB Output is correct
41 Correct 727 ms 11776 KB Output is correct
42 Correct 702 ms 11524 KB Output is correct
43 Correct 653 ms 11468 KB Output is correct
44 Correct 796 ms 12428 KB Output is correct
45 Runtime error 76 ms 24708 KB Execution killed with signal 11
46 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 4 ms 2724 KB Output is correct
5 Correct 5 ms 2772 KB Output is correct
6 Correct 6 ms 2704 KB Output is correct
7 Correct 6 ms 2772 KB Output is correct
8 Correct 6 ms 2772 KB Output is correct
9 Correct 226 ms 9804 KB Output is correct
10 Correct 535 ms 11488 KB Output is correct
11 Correct 574 ms 11344 KB Output is correct
12 Correct 685 ms 11724 KB Output is correct
13 Correct 711 ms 11724 KB Output is correct
14 Execution timed out 2075 ms 10192 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 4 ms 2724 KB Output is correct
6 Correct 5 ms 2772 KB Output is correct
7 Correct 6 ms 2704 KB Output is correct
8 Correct 6 ms 2772 KB Output is correct
9 Correct 6 ms 2772 KB Output is correct
10 Correct 226 ms 9804 KB Output is correct
11 Correct 535 ms 11488 KB Output is correct
12 Correct 574 ms 11344 KB Output is correct
13 Correct 685 ms 11724 KB Output is correct
14 Correct 711 ms 11724 KB Output is correct
15 Execution timed out 2075 ms 10192 KB Time limit exceeded
16 Halted 0 ms 0 KB -