結果

問題 No.1773 Love Triangle
ユーザー theory_and_metheory_and_me
提出日時 2021-12-16 00:02:21
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 988 ms / 2,000 ms
コード長 6,471 bytes
コンパイル時間 2,244 ms
コンパイル使用メモリ 217,584 KB
実行使用メモリ 5,316 KB
最終ジャッジ日時 2023-10-01 02:59:45
合計ジャッジ時間 54,168 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 676 ms
4,556 KB
testcase_19 AC 9 ms
4,380 KB
testcase_20 AC 38 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 35 ms
4,380 KB
testcase_23 AC 34 ms
4,376 KB
testcase_24 AC 328 ms
4,376 KB
testcase_25 AC 278 ms
4,376 KB
testcase_26 AC 10 ms
4,380 KB
testcase_27 AC 11 ms
4,376 KB
testcase_28 AC 5 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 531 ms
4,376 KB
testcase_31 AC 428 ms
4,380 KB
testcase_32 AC 343 ms
4,624 KB
testcase_33 AC 108 ms
4,380 KB
testcase_34 AC 4 ms
4,376 KB
testcase_35 AC 15 ms
4,376 KB
testcase_36 AC 109 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 938 ms
4,972 KB
testcase_39 AC 931 ms
4,828 KB
testcase_40 AC 926 ms
4,828 KB
testcase_41 AC 966 ms
5,068 KB
testcase_42 AC 956 ms
5,132 KB
testcase_43 AC 923 ms
4,832 KB
testcase_44 AC 930 ms
4,904 KB
testcase_45 AC 935 ms
4,880 KB
testcase_46 AC 948 ms
5,076 KB
testcase_47 AC 936 ms
4,828 KB
testcase_48 AC 962 ms
5,088 KB
testcase_49 AC 975 ms
5,176 KB
testcase_50 AC 934 ms
5,144 KB
testcase_51 AC 939 ms
4,832 KB
testcase_52 AC 925 ms
4,968 KB
testcase_53 AC 939 ms
5,088 KB
testcase_54 AC 921 ms
4,836 KB
testcase_55 AC 945 ms
5,124 KB
testcase_56 AC 928 ms
4,836 KB
testcase_57 AC 924 ms
4,904 KB
testcase_58 AC 957 ms
5,172 KB
testcase_59 AC 972 ms
5,140 KB
testcase_60 AC 961 ms
5,092 KB
testcase_61 AC 963 ms
5,156 KB
testcase_62 AC 979 ms
5,316 KB
testcase_63 AC 971 ms
5,232 KB
testcase_64 AC 973 ms
5,180 KB
testcase_65 AC 966 ms
5,168 KB
testcase_66 AC 956 ms
5,136 KB
testcase_67 AC 968 ms
5,104 KB
testcase_68 AC 973 ms
5,120 KB
testcase_69 AC 958 ms
5,136 KB
testcase_70 AC 964 ms
5,164 KB
testcase_71 AC 966 ms
5,140 KB
testcase_72 AC 976 ms
5,100 KB
testcase_73 AC 960 ms
5,140 KB
testcase_74 AC 988 ms
5,100 KB
testcase_75 AC 948 ms
5,092 KB
testcase_76 AC 960 ms
5,180 KB
testcase_77 AC 951 ms
5,160 KB
testcase_78 AC 2 ms
4,380 KB
testcase_79 AC 17 ms
5,124 KB
testcase_80 AC 27 ms
5,228 KB
testcase_81 AC 969 ms
5,100 KB
testcase_82 AC 961 ms
5,100 KB
testcase_83 AC 263 ms
4,376 KB
testcase_84 AC 423 ms
4,380 KB
testcase_85 AC 723 ms
4,824 KB
testcase_86 AC 199 ms
4,376 KB
testcase_87 AC 441 ms
4,380 KB
testcase_88 AC 299 ms
4,824 KB
testcase_89 AC 318 ms
4,376 KB
testcase_90 AC 870 ms
4,896 KB
testcase_91 AC 592 ms
4,596 KB
testcase_92 AC 151 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using namespace atcoder;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

unsigned int randxor(){
    static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned int t;
    t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}

using mint = modint1000000007;

// https://ei1333.github.io/library/library/math/matrix/matrix.cpp.html
template< class T >
struct Matrix {
  vector< vector< T > > A;

  Matrix() {}

  Matrix(int n, int m) : A(n, vector< T >(m, 0)) {}

  Matrix(int n) : A(n, vector< T >(n, 0)) {};

  int height() const {
    return (int)(A.size());
  }

  int width() const {
    return (int)(A[0].size());
  }

  inline const vector< T > &operator[](int k) const {
    return (A.at(k));
  }

  inline vector< T > &operator[](int k) {
    return (A.at(k));
  }

  static Matrix I(int n) {
    Matrix mat(n);
    for(int i = 0; i < n; i++) mat[i][i] = 1;
    return (mat);
  }

  Matrix &operator+=(const Matrix &B) {
    size_t n = height(), m = width();
    assert(n == B.height() && m == B.width());
    for(int i = 0; i < n; i++)
      for(int j = 0; j < m; j++)
        (*this)[i][j] += B[i][j];
    return (*this);
  }

  Matrix &operator-=(const Matrix &B) {
    size_t n = height(), m = width();
    assert(n == B.height() && m == B.width());
    for(int i = 0; i < n; i++)
      for(int j = 0; j < m; j++)
        (*this)[i][j] -= B[i][j];
    return (*this);
  }

  Matrix &operator*=(const Matrix &B) {
    int n = height(), m = B.width(), p = width();
    assert(p == B.height());
    vector< vector< T > > C(n, vector< T >(m, 0));
    for(int i = 0; i < n; i++)
      for(int j = 0; j < m; j++)
        for(int k = 0; k < p; k++)
          C[i][j] = (C[i][j] + (*this)[i][k] * B[k][j]);
    A.swap(C);
    return (*this);
  }

  Matrix &operator^=(long long k) {
    Matrix B = Matrix::I(height());
    while(k > 0) {
      if(k & 1) B *= *this;
      *this *= *this;
      k >>= 1LL;
    }
    A.swap(B.A);
    return (*this);
  }

  Matrix operator+(const Matrix &B) const {
    return (Matrix(*this) += B);
  }

  Matrix operator-(const Matrix &B) const {
    return (Matrix(*this) -= B);
  }

  Matrix operator*(const Matrix &B) const {
    return (Matrix(*this) *= B);
  }

  Matrix operator^(const long long k) const {
    return (Matrix(*this) ^= k);
  }

  friend ostream &operator<<(ostream &os, Matrix &p) {
    size_t n = p.height(), m = p.width();
    for(int i = 0; i < n; i++) {
      os << "[";
      for(int j = 0; j < m; j++) {
        os << p[i][j] << (j + 1 == m ? "]\n" : ",");
      }
    }
    return (os);
  }

  int rank(){
    Matrix B(*this);
    int res = 0;
    for(int k=0;k<width();k++){
      for(int i=res+1;i<height()&&(B[res][k]==0);i++){
        if(B[i][k]!=0)swap(B[i],B[res]);
      }
      if(B[res][k]==0)continue;
      for(int l=k+1;l<width();l++)B[res][l]/=B[res][k];
      for(int j=res+1;j<height();j++)
        for(int l=k+1;l<width();l++)
          B[j][l]-=B[j][k]*B[res][l];
      res++;
    }
    return res;
  }

  T determinant() {
    Matrix B(*this);
    assert(width() == height());
    T ret = 1;
    for(int i = 0; i < width(); i++) {
      int idx = -1;
      for(int j = i; j < width(); j++) {
        if(B[j][i] != 0) idx = j;
      }
      if(idx == -1) return (0);
      if(i != idx) {
        ret *= -1;
        swap(B[i], B[idx]);
      }
      ret *= B[i][i];
      T vv = B[i][i];
      for(int j = 0; j < width(); j++) {
        B[i][j] /= vv;
      }
      for(int j = i + 1; j < width(); j++) {
        T a = B[j][i];
        for(int k = 0; k < width(); k++) {
          B[j][k] -= B[i][k] * a;
        }
      }
    }
    return (ret);
  }
};

int main(){

    int N, M;
    cin >> N >> M;
    vector<int> u(M), v(M), w(M);
    REP(i, M) cin >> u[i] >> v[i] >> w[i], u[i]--, v[i]--, w[i]--;

    map<int, int> mp;
    REP(t, 10){
        Matrix<mint> X(N, N);
        REP(i, M){
            int r = randxor() % mod;
            X[u[i]][v[i]] += r;
            X[u[i]][w[i]] -= r;
            X[w[i]][v[i]] -= r;
            X[v[i]][u[i]] -= r;
            X[v[i]][w[i]] += r;
            X[w[i]][u[i]] += r;
        }

        int rank = X.rank();
        mp[rank/2] += 1;
    }

    int ma = 0, res = 0;
    for(auto x: mp){
        if(chmax(ma, x.second)) res = x.first;
    }

    cout << res << endl;

    return 0;
}
0