結果

問題 No.1690 Power Grid
ユーザー LayCurseLayCurse
提出日時 2021-08-28 23:21:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 3,000 ms
コード長 16,497 bytes
コンパイル時間 3,031 ms
コンパイル使用メモリ 226,332 KB
実行使用メモリ 84,536 KB
最終ジャッジ日時 2023-09-18 20:24:09
合計ジャッジ時間 5,146 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
15,700 KB
testcase_01 AC 4 ms
17,688 KB
testcase_02 AC 7 ms
30,056 KB
testcase_03 AC 3 ms
11,760 KB
testcase_04 AC 3 ms
11,532 KB
testcase_05 AC 3 ms
13,600 KB
testcase_06 AC 51 ms
80,084 KB
testcase_07 AC 51 ms
81,284 KB
testcase_08 AC 51 ms
81,304 KB
testcase_09 AC 51 ms
81,000 KB
testcase_10 AC 51 ms
80,996 KB
testcase_11 AC 52 ms
84,348 KB
testcase_12 AC 5 ms
19,804 KB
testcase_13 AC 7 ms
29,980 KB
testcase_14 AC 13 ms
44,548 KB
testcase_15 AC 50 ms
84,368 KB
testcase_16 AC 51 ms
84,300 KB
testcase_17 AC 28 ms
63,432 KB
testcase_18 AC 18 ms
50,932 KB
testcase_19 AC 52 ms
84,288 KB
testcase_20 AC 51 ms
84,284 KB
testcase_21 AC 51 ms
84,236 KB
testcase_22 AC 49 ms
84,536 KB
testcase_23 AC 50 ms
84,212 KB
testcase_24 AC 50 ms
84,232 KB
testcase_25 AC 51 ms
84,352 KB
testcase_26 AC 51 ms
84,336 KB
testcase_27 AC 4 ms
17,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("inline")
#include<bits/stdc++.h>
using namespace std;
template<class T> struct cLtraits_identity{
  using type = T;
}
;
template<class T> using cLtraits_try_make_signed =
  typename conditional<
    is_integral<T>::value,
    make_signed<T>,
    cLtraits_identity<T>
    >::type;
template <class S, class T> struct cLtraits_common_type{
  using tS = typename cLtraits_try_make_signed<S>::type;
  using tT = typename cLtraits_try_make_signed<T>::type;
  using type = typename common_type<tS,tT>::type;
}
;
void*wmem;
char memarr[96000000];
template<class S, class T> inline auto min_L(S a, T b)
-> typename cLtraits_common_type<S,T>::type{
  return (typename cLtraits_common_type<S,T>::type) a <= (typename cLtraits_common_type<S,T>::type) b ? a : b;
}
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
template<class T> inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){
  walloc1d(arr, x2-x1, mem);
  (*arr) -= x1;
}
struct Rand{
  unsigned x;
  unsigned y;
  unsigned z;
  unsigned w;
  Rand(void){
    x=123456789;
    y=362436069;
    z=521288629;
    w=(unsigned)time(NULL);
  }
  Rand(unsigned seed){
    x=123456789;
    y=362436069;
    z=521288629;
    w=seed;
  }
  inline unsigned get(void){
    unsigned t;
    t = (x^(x<<11));
    x=y;
    y=z;
    z=w;
    w = (w^(w>>19))^(t^(t>>8));
    return w;
  }
  inline double getUni(void){
    return get()/4294967296.0;
  }
  inline int get(int a){
    return (int)(a*getUni());
  }
  inline int get(int a, int b){
    return a+(int)((b-a+1)*getUni());
  }
  inline long long get(long long a){
    return(long long)(a*getUni());
  }
  inline long long get(long long a, long long b){
    return a+(long long)((b-a+1)*getUni());
  }
  inline double get(double a, double b){
    return a+(b-a)*getUni();
  }
  inline int getExp(int a){
    return(int)(exp(getUni()*log(a+1.0))-1.0);
  }
  inline int getExp(int a, int b){
    return a+(int)(exp(getUni()*log((b-a+1)+1.0))-1.0);
  }
}
;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void my_putchar_unlocked(const int k){
  putchar_unlocked(k);
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(unsigned x){
  int s=0;
  char f[10];
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(unsigned long long x){
  int s=0;
  char f[21];
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
int WRITER_DOUBLE_DIGIT = 15;
inline int writerDigit_double(){
  return WRITER_DOUBLE_DIGIT;
}
inline void writerDigit_double(int d){
  WRITER_DOUBLE_DIGIT = d;
}
inline void wt_L(double x){
  const int d = WRITER_DOUBLE_DIGIT;
  int k;
  int r;
  double v;
  if(x!=x || (x==x+1 && x==2*x)){
    my_putchar_unlocked('E');
    my_putchar_unlocked('r');
    my_putchar_unlocked('r');
    return;
  }
  if(x < 0){
    my_putchar_unlocked('-');
    x = -x;
  }
  x += 0.5 * pow(0.1, d);
  r = 0;
  v = 1;
  while(x >= 10*v){
    v *= 10;
    r++;
  }
  while(r >= 0){
    r--;
    k = floor(x / v);
    if(k >= 10){
      k = 9;
    }
    if(k <= -1){
      k = 0;
    }
    x -= k * v;
    v *= 0.1;
    my_putchar_unlocked(k + '0');
  }
  if(d > 0){
    my_putchar_unlocked('.');
    v = 1;
    for(r=(0);r<(d);r++){
      v *= 0.1;
      k = floor(x / v);
      if(k >= 10){
        k = 9;
      }
      if(k <= -1){
        k = 0;
      }
      x -= k * v;
      my_putchar_unlocked(k + '0');
    }
  }
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
inline void wt_L(string &x){
  int i=0;
  for(i=0;x[i]!='\0';i++){
    my_putchar_unlocked(x[i]);
  }
}
template<class S> inline void arrInsert(const int k, int &sz, S a[], const S aval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  a[k] = aval;
}
template<class S, class T> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  for(i=sz-1;i>k;i--){
    b[i] = b[i-1];
  }
  a[k] = aval;
  b[k] = bval;
}
template<class S, class T, class U> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval, U c[], const U cval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  for(i=sz-1;i>k;i--){
    b[i] = b[i-1];
  }
  for(i=sz-1;i>k;i--){
    c[i] = c[i-1];
  }
  a[k] = aval;
  b[k] = bval;
  c[k] = cval;
}
template<class S, class T, class U, class V> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval, U c[], const U cval, V d[], const V dval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  for(i=sz-1;i>k;i--){
    b[i] = b[i-1];
  }
  for(i=sz-1;i>k;i--){
    c[i] = c[i-1];
  }
  for(i=sz-1;i>k;i--){
    d[i] = d[i-1];
  }
  a[k] = aval;
  b[k] = bval;
  c[k] = cval;
  d[k] = dval;
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
struct unionFind{
  int*d;
  int N;
  int M;
  inline void malloc(const int n){
    d = (int*)std::malloc(n*sizeof(int));
    M = n;
  }
  inline void malloc(const int n, const int fg){
    d = (int*)std::malloc(n*sizeof(int));
    M = n;
    if(fg){
      init(n);
    }
  }
  inline void free(void){
    std::free(d);
  }
  inline void walloc(const int n, void **mem=&wmem){
    walloc1d(&d, n, mem);
    M = n;
  }
  inline void walloc(const int n, const int fg, void **mem=&wmem){
    walloc1d(&d, n, mem);
    M = n;
    if(fg){
      init(n);
    }
  }
  inline void init(const int n){
    int i;
    N = n;
    for(i=(0);i<(n);i++){
      d[i] = -1;
    }
  }
  inline void init(void){
    init(M);
  }
  inline int get(int a){
    int t = a;
    int k;
    while(d[t]>=0){
      t=d[t];
    }
    while(d[a]>=0){
      k=d[a];
      d[a]=t;
      a=k;
    }
    return a;
  }
  inline int connect(int a, int b){
    if(d[a]>=0){
      a=get(a);
    }
    if(d[b]>=0){
      b=get(b);
    }
    if(a==b){
      return 0;
    }
    if(d[a] < d[b]){
      d[a] += d[b];
      d[b] = a;
    }
    else{
      d[b] += d[a];
      d[a] = b;
    }
    return 1;
  }
  inline int operator()(int a){
    return get(a);
  }
  inline int operator()(int a, int b){
    return connect(a,b);
  }
  inline int& operator[](const int a){
    return d[a];
  }
  inline int size(int a){
    a = get(a);
    return -d[a];
  }
  inline int sizeList(int res[]){
    int i;
    int sz=0;
    for(i=(0);i<(N);i++){
      if(d[i]<0){
        res[sz++] = -d[i];
      }
    }
    return sz;
  }
  inline int comp(int res[], void *mem = wmem){
    int i;
    int sz=0;
    int*cnt;
    walloc1d(&cnt, N, &mem);
    for(i=(0);i<(N);i++){
      cnt[i] = 0;
    }
    for(i=(0);i<(N);i++){
      cnt[get(i)] = 1;
    }
    for(i=(0);i<(N);i++){
      if(cnt[i]){
        cnt[i] = sz++;
      }
    }
    for(i=(0);i<(N);i++){
      res[i] = cnt[get(i)];
    }
    return sz;
  }
}
;
int N;
int M;
int K;
int A[20];
int X[200];
int Y[200];
int Z[200];
long long baka(){
  int i;
  int j;
  int k;
  int ind[20];
  long long res = 4611686016279904256LL;
  long long tmp;
  long long tmp2;
  long long mat[20][20];
  for(i=(0);i<(N);i++){
    for(j=(0);j<(N);j++){
      mat[i][j] = 4611686016279904256LL;
    }
  }
  for(i=(0);i<(N);i++){
    mat[i][i] = 0;
  }
  for(i=(0);i<(M);i++){
    chmin(mat[X[i]][Y[i]], Z[i]);
    chmin(mat[Y[i]][X[i]], Z[i]);
  }
  for(k=(0);k<(N);k++){
    for(i=(0);i<(N);i++){
      for(j=(0);j<(N);j++){
        chmin(mat[i][j], mat[i][k] + mat[k][j]);
      }
    }
  }
  int hCmBdyQB;
  for(hCmBdyQB=(0);hCmBdyQB<(N);hCmBdyQB++){
    ind[hCmBdyQB] = hCmBdyQB;
  }
  do{
    {
      tmp = 0;
      for(i=(0);i<(K);i++){
        tmp += A[ind[i]];
      }
      for(i=(1);i<(K);i++){
        tmp2 = 4611686016279904256LL;
        for(j=(0);j<(i);j++){
          chmin(tmp2, mat[ind[j]][ind[i]]);
        }
        tmp += tmp2;
      }
      chmin(res, tmp);
    }
  }
  while(next_permutation(ind,ind+N));
  return res;
}
long long dist1[20][1200000];
long long dp1[1200000];
int bt[1200000];
int bc[1200000];
long long solve1(){
  int i;
  int j;
  int k;
  long long mat[20][20];
  long long res = 4611686016279904256LL;
  for(i=(0);i<(N);i++){
    for(j=(0);j<(N);j++){
      mat[i][j] = 4611686016279904256LL;
    }
  }
  for(i=(0);i<(N);i++){
    mat[i][i] = 0;
  }
  for(i=(0);i<(M);i++){
    chmin(mat[X[i]][Y[i]], Z[i]);
    chmin(mat[Y[i]][X[i]], Z[i]);
  }
  for(k=(0);k<(N);k++){
    for(i=(0);i<(N);i++){
      for(j=(0);j<(N);j++){
        chmin(mat[i][j], mat[i][k] + mat[k][j]);
      }
    }
  }
  for(i=(0);i<(N);i++){
    bt[1<<i] = i;
  }
  for(i=(1);i<(1<<N);i++){
    bc[i] = bc[i&(i-1)] + 1;
  }
  for(i=(0);i<(N);i++){
    dist1[i][0] = 4611686016279904256LL;
    for(j=(1);j<(1<<N);j++){
      k = (j & (-j));
      dist1[i][j] =min_L(dist1[i][j^k], mat[bt[k]][i]);
    }
  }
  for(i=(0);i<(N);i++){
    dist1[i][0] = A[i];
    for(j=(1);j<(1<<N);j++){
      dist1[i][j] += A[i];
    }
  }
  dp1[0] = 0;
  for(i=(1);i<(1<<N);i++){
    dp1[i] = 4611686016279904256LL;
  }
  for(i=(0);i<(1<<N);i++){
    for(j=(0);j<(N);j++){
      if(!((i) &(1<<(j)))){
        chmin(dp1[i|(1<<j)], dp1[i] + dist1[j][i]);
      }
    }
  }
  for(i=(0);i<(1<<N);i++){
    if(bc[i]==K){
      chmin(res, dp1[i]);
    }
  }
  return res;
}
long long uso1(){
  int s;
  int i;
  int j;
  int k;
  int cnt;
  long long mat[20][20];
  long long res = 4611686016279904256LL;
  long long tmp;
  long long tmp2;
  int use[20];
  long long mn[20];
  for(i=(0);i<(N);i++){
    for(j=(0);j<(N);j++){
      mat[i][j] = 4611686016279904256LL;
    }
  }
  for(i=(0);i<(N);i++){
    mat[i][i] = 0;
  }
  for(i=(0);i<(M);i++){
    chmin(mat[X[i]][Y[i]], Z[i]);
    chmin(mat[Y[i]][X[i]], Z[i]);
  }
  for(k=(0);k<(N);k++){
    for(i=(0);i<(N);i++){
      for(j=(0);j<(N);j++){
        chmin(mat[i][j], mat[i][k] + mat[k][j]);
      }
    }
  }
  for(s=(0);s<(N);s++){
    for(i=(0);i<(N);i++){
      use[i] = 0;
      mn[i] = 4611686016279904256LL;
    }
    mn[s] = A[s];
    cnt = 0;
    tmp = 0;
    while(cnt < K){
      tmp2 = 4611686016279904256LL;
      for(i=(0);i<(N);i++){
        if(!use[i] && tmp2 > mn[i]){
          k = i;
          tmp2 = mn[i];
        }
      }
      tmp += tmp2;
      use[k] = 1;
      cnt++;
      for(i=(0);i<(N);i++){
        if(!use[i]){
          chmin(mn[i], A[i] + mat[k][i]);
        }
      }
    }
    chmin(res, tmp);
  }
  return res;
}
int main(){
  wmem = memarr;
  int i;
  int j;
  int k;
  int m;
  long long r0;
  long long r1;
  long long u1;
  rd(N);
  rd(M);
  rd(K);
  {
    int d37S9NUa;
    for(d37S9NUa=(0);d37S9NUa<(N);d37S9NUa++){
      rd(A[d37S9NUa]);
    }
  }
  {
    int lXxUrvh5;
    for(lXxUrvh5=(0);lXxUrvh5<(M);lXxUrvh5++){
      rd(X[lXxUrvh5]);X[lXxUrvh5] += (-1);
      rd(Y[lXxUrvh5]);Y[lXxUrvh5] += (-1);
      rd(Z[lXxUrvh5]);
    }
  }
  wt_L(solve1());
  wt_L('\n');
  return 0;
  Rand rnd;
  unionFind uf;
  uf.walloc(20);
  puts("hoge");
  for(;;){
    int con = 0;
    N = rnd.get(1,8);
    K = rnd.get(1,N);
    M = 0;
    uf.init(N);
    while(con < N-1){
      i = rnd.get(N);
      j = rnd.get(N);
      k = rnd.get(1, 1000000000);
      if(i==j){
        continue;
      }
      for(m=(0);m<(M);m++){
        if(X[m]==i && Y[m]==j){
          goto o0VCpjj8;
        }
      }
      for(m=(0);m<(M);m++){
        if(X[m]==j && Y[m]==i){
          goto o0VCpjj8;
        }
      }
      con += uf(i,j);
      arrInsert(M,M,X,i,Y,j,Z,k);
      o0VCpjj8:;
    }
    for(i=(0);i<(N);i++){
      A[i] = rnd.get(1, 1000000000);
    }
    r0 = baka();
    r1 = solve1();
    u1 = uso1();
    wt_L(r0);
    wt_L(' ');
    wt_L(r1);
    wt_L(' ');
    wt_L(":");
    wt_L(' ');
    wt_L(u1);
    wt_L('\n');
    assert(r0==r1);
  }
  return 0;
}
// cLay version 20210819-1 [beta]

// --- original code ---
// int N, M, K, A[20], X[200], Y[200], Z[200];
// 
// ll baka(){
//   int i, j, k, ind[20];
//   ll res = ll_inf, tmp, tmp2;
//   ll mat[20][20];
// 
//   rep(i,N) rep(j,N) mat[i][j] = ll_inf;
//   rep(i,N) mat[i][i] = 0;
//   rep(i,M){
//     mat[X[i]][Y[i]] <?= Z[i];
//     mat[Y[i]][X[i]] <?= Z[i];
//   }
//   rep(k,N) rep(i,N) rep(j,N) mat[i][j] <?= mat[i][k] + mat[k][j];
// 
//   rep_perm(ind,N){
//     tmp = 0;
//     rep(i,K) tmp += A[ind[i]];
//     rep(i,1,K){
//       tmp2 = ll_inf;
//       rep(j,i) tmp2 <?= mat[ind[j]][ind[i]];
//       tmp += tmp2;
//     }
//     res <?= tmp;
//   }
// 
//   return res;
// }
// 
// 
// ll dist1[20][12d5];
// ll dp1[12d5];
// int bt[12d5], bc[12d5];
// ll solve1(){
//   int i, j, k;
//   ll mat[20][20], res = ll_inf;
// 
//   rep(i,N) rep(j,N) mat[i][j] = ll_inf;
//   rep(i,N) mat[i][i] = 0;
//   rep(i,M){
//     mat[X[i]][Y[i]] <?= Z[i];
//     mat[Y[i]][X[i]] <?= Z[i];
//   }
//   rep(k,N) rep(i,N) rep(j,N) mat[i][j] <?= mat[i][k] + mat[k][j];
// 
//   rep(i,N) bt[1<<i] = i;
//   rep(i,1,1<<N) bc[i] = bc[i&(i-1)] + 1;
//   rep(i,N){
//     dist1[i][0] = ll_inf;
//     rep(j,1,1<<N){
//       k = (j & (-j));
//       dist1[i][j] = min(dist1[i][j^k], mat[bt[k]][i]);
//     }
//   }
//   rep(i,N){
//     dist1[i][0] = A[i];
//     rep(j,1,1<<N) dist1[i][j] += A[i];
//   }
// 
//   dp1[0] = 0;
//   rep(i,1,1<<N) dp1[i] = ll_inf;
//   rep(i,1<<N) rep(j,N) if(!BIT_ith(i,j)){
//     dp1[i|(1<<j)] <?= dp1[i] + dist1[j][i];
//   }
// 
//   rep(i,1<<N) if(bc[i]==K) res <?= dp1[i];
//   return res;
// }
// 
// ll uso1(){
//   int i, j, k, cnt;
//   ll mat[20][20];
//   ll res = ll_inf, tmp, tmp2;
//   int use[20];
//   ll mn[20];
// 
//   rep(i,N) rep(j,N) mat[i][j] = ll_inf;
//   rep(i,N) mat[i][i] = 0;
//   rep(i,M){
//     mat[X[i]][Y[i]] <?= Z[i];
//     mat[Y[i]][X[i]] <?= Z[i];
//   }
//   rep(k,N) rep(i,N) rep(j,N) mat[i][j] <?= mat[i][k] + mat[k][j];
// 
//   rep(s,N){
//     rep(i,N) use[i] = 0, mn[i] = ll_inf;
//     mn[s] = A[s];
//     cnt = 0;
//     tmp = 0;
//     while(cnt < K){
//       tmp2 = ll_inf;
//       rep(i,N) if(!use[i] && tmp2 > mn[i]){
//         k = i;
//         tmp2 = mn[i];
//       }
//       tmp += tmp2;
//       use[k] = 1;
//       cnt++;
//       rep(i,N) if(!use[i]) mn[i] <?= A[i] + mat[k][i];
//     }
//     res <?= tmp;
//   }
// 
//   return res;
// }
// 
// {
//   int i, j, k, m;
//   ll r0, r1, u1;
//   rd(N,M,K,A(N),(X--,Y--,Z)(M));
// 
//   wt(solve1());
//   return 0;
// 
//   Rand rnd;
//   unionFind uf;
//   uf.walloc(20);
//   puts("hoge");
//   for(;;){
//     int con = 0;
//     N = rnd.get(1,8);
//     K = rnd.get(1,N);
//     M = 0;
//     uf.init(N);
//     while(con < N-1){
//       i = rnd.get(N);
//       j = rnd.get(N);
//       k = rnd.get(1, 1d9);
//       if(i==j) continue;
//       rep(m,M) if(X[m]==i && Y[m]==j) break_continue;
//       rep(m,M) if(X[m]==j && Y[m]==i) break_continue;
//       con += uf(i,j);
//       arrInsert(M,M,X,i,Y,j,Z,k);
//     }
//     rep(i,N) A[i] = rnd.get(1, 1d9);
// 
//     r0 = baka();
//     r1 = solve1();
//     u1 = uso1();
//     wt(r0,r1,":",u1);
//     assert(r0==r1);
//     // assert(r0==u1);
//   }
// }
0