結果

問題 No.1773 Love Triangle
ユーザー cureskolcureskol
提出日時 2021-12-08 13:52:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 2,597 bytes
コンパイル時間 2,380 ms
コンパイル使用メモリ 184,976 KB
実行使用メモリ 6,132 KB
最終ジャッジ日時 2023-09-23 05:45:16
合計ジャッジ時間 12,339 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 75 ms
5,396 KB
testcase_19 AC 3 ms
4,384 KB
testcase_20 AC 6 ms
4,380 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 6 ms
4,384 KB
testcase_23 AC 6 ms
4,380 KB
testcase_24 AC 36 ms
4,636 KB
testcase_25 AC 32 ms
4,384 KB
testcase_26 AC 3 ms
4,384 KB
testcase_27 AC 3 ms
4,384 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 2 ms
4,384 KB
testcase_30 AC 60 ms
4,868 KB
testcase_31 AC 48 ms
5,116 KB
testcase_32 AC 39 ms
5,428 KB
testcase_33 AC 14 ms
4,660 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 13 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 103 ms
5,984 KB
testcase_39 AC 101 ms
5,956 KB
testcase_40 AC 102 ms
5,976 KB
testcase_41 AC 110 ms
5,964 KB
testcase_42 AC 106 ms
5,920 KB
testcase_43 AC 103 ms
5,900 KB
testcase_44 AC 105 ms
6,056 KB
testcase_45 AC 101 ms
5,928 KB
testcase_46 AC 106 ms
5,936 KB
testcase_47 AC 103 ms
5,968 KB
testcase_48 AC 105 ms
5,960 KB
testcase_49 AC 107 ms
5,980 KB
testcase_50 AC 103 ms
5,968 KB
testcase_51 AC 104 ms
5,960 KB
testcase_52 AC 102 ms
5,908 KB
testcase_53 AC 103 ms
5,924 KB
testcase_54 AC 102 ms
5,920 KB
testcase_55 AC 105 ms
5,964 KB
testcase_56 AC 102 ms
6,020 KB
testcase_57 AC 102 ms
5,904 KB
testcase_58 AC 107 ms
5,892 KB
testcase_59 AC 106 ms
5,976 KB
testcase_60 AC 107 ms
6,024 KB
testcase_61 AC 109 ms
5,960 KB
testcase_62 AC 106 ms
5,956 KB
testcase_63 AC 107 ms
5,896 KB
testcase_64 AC 107 ms
5,932 KB
testcase_65 AC 107 ms
6,020 KB
testcase_66 AC 106 ms
5,944 KB
testcase_67 AC 106 ms
5,956 KB
testcase_68 AC 107 ms
5,904 KB
testcase_69 AC 106 ms
5,940 KB
testcase_70 AC 107 ms
6,020 KB
testcase_71 AC 107 ms
6,024 KB
testcase_72 AC 106 ms
5,960 KB
testcase_73 AC 107 ms
5,960 KB
testcase_74 AC 107 ms
5,960 KB
testcase_75 AC 107 ms
5,908 KB
testcase_76 AC 107 ms
5,952 KB
testcase_77 AC 106 ms
5,952 KB
testcase_78 AC 1 ms
4,384 KB
testcase_79 AC 5 ms
5,936 KB
testcase_80 AC 6 ms
5,892 KB
testcase_81 AC 107 ms
6,132 KB
testcase_82 AC 106 ms
5,912 KB
testcase_83 AC 30 ms
4,384 KB
testcase_84 AC 47 ms
4,624 KB
testcase_85 AC 82 ms
5,708 KB
testcase_86 AC 23 ms
4,380 KB
testcase_87 AC 50 ms
4,900 KB
testcase_88 AC 35 ms
5,900 KB
testcase_89 AC 37 ms
4,700 KB
testcase_90 AC 97 ms
5,968 KB
testcase_91 AC 66 ms
5,152 KB
testcase_92 AC 19 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/modint>
using namespace atcoder;
using mint=modint1000000007;
ostream& operator<<(ostream &os,mint a){os<<a.val();return os;}

#define REP(i,n) for(int i=0;i<(n);i++)

#define REP_(i,n) for(int i=0;i<(n);i++)
template<typename K>
struct Matrix{
  typedef vector<K> vec;
  typedef vector<vec> mat;
  size_t r,c;
  mat M;

  Matrix(size_t r,size_t c):r(r),c(c),M(r,vec(c,K())){}
  Matrix(mat A):M(A){}

  vec& operator[](size_t k){return M[k];}
  const vec& operator[](size_t k)const{return M[k];}

  friend Matrix operator+(const Matrix &A,const Matrix &B){
    assert(A.r==B.r&&A.c==B.c);
    Matrix res(A);
    REP_(i,A.r)REP_(j,A.c)res[i][j]+=B[i][j];
    return res;
  }

  void operator+=(const Matrix &B){
    assert(r==B.r&&c==B.c);
    REP_(i,r)REP_(j,c)M[i][j]+=B[i][j];
  }

  friend Matrix operator*(const Matrix &A,const Matrix &B){
    assert(A.c==B.r);
    Matrix res(A.r,B.c);
    REP_(i,A.r)REP_(k,A.c)REP_(j,B.c)res[i][j]+=A[i][k]*B[k][j];
    return res;
  }

  void operator*=(const Matrix &B){
    M(M*B);
  }

  static Matrix I(size_t n){
    Matrix res(n,n);
    REP_(i,n)res[i][i]=K(1);
    return res;
  }

  Matrix pow(long long n)const{
    assert(n>=0&&r==c);
    Matrix A(M),res=I(r);
    while(n){
      if(n&1)res*=A;
      A*=A;
      n>>=1;
    }
    return res;
  }

  int rank() const{
    Matrix A(M);
    int res=0;
    for(int k=0;k<c;k++){
      for(int i=res+1;i<r&&A[res][k]==0;i++)
        if(A[i][k]!=0)swap(A[i],A[res]);
      if(A[res][k]==0)continue;
      for(int l=k+1;l<c;l++)A[res][l]/=A[res][k];
      for(int j=res+1;j<r;j++)
        for(int l=k+1;l<c;l++)
          A[j][l]-=A[j][k]*A[res][l];
      res++;
    }
    return res;
  }

  K det() const{
    assert(r==c);
    Matrix A=M;
    K res(1);
    REP_(i,r){
      for(int j=i+1;j<c&&A[i][i]==0;j++)
        if(A[j][i]!=0)swap(A[i],A[j]),res*=-1;
      res*=A[i][i];
      if(A[i][i]==0)return res;
      for(int k=i+1;k<c;k++)A[i][k]/=A[i][i];
      for(int j=i+1;j<r;j++)
        for(int k=i+1;k<c;k++)
          A[j][k]-=A[j][i]*A[i][k];
    }
    return res;
  }
};
#undef REP_

random_device seed_gen;
mt19937_64 rnd(seed_gen());
#define RND(a,b) uniform_int_distribution<int>(a,b)(rnd);

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,m;cin>>n>>m;
  Matrix<mint> M(n,n);
  REP(_,m){
    int u,v,w;cin>>u>>v>>w;u--;v--;w--;
    mint a=RND(1,1000000006);
    M[u][v]+=a;M[v][w]+=a;M[w][u]+=a;
    M[v][u]-=a;M[w][v]-=a;M[u][w]-=a;
  }
  cout<<(M.rank()>>1)<<endl;
}



0