結果

問題 No.1773 Love Triangle
ユーザー theory_and_metheory_and_me
提出日時 2021-12-16 00:02:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,084 ms / 2,000 ms
コード長 6,471 bytes
コンパイル時間 2,608 ms
コンパイル使用メモリ 219,188 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-23 20:29:08
合計ジャッジ時間 54,877 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 4 ms
6,944 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 4 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 4 ms
6,944 KB
testcase_12 AC 4 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 3 ms
6,944 KB
testcase_15 AC 4 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 3 ms
6,944 KB
testcase_18 AC 705 ms
6,940 KB
testcase_19 AC 10 ms
6,940 KB
testcase_20 AC 39 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 37 ms
6,944 KB
testcase_23 AC 36 ms
6,940 KB
testcase_24 AC 337 ms
6,944 KB
testcase_25 AC 287 ms
6,940 KB
testcase_26 AC 11 ms
6,944 KB
testcase_27 AC 12 ms
6,940 KB
testcase_28 AC 6 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 548 ms
6,944 KB
testcase_31 AC 440 ms
6,940 KB
testcase_32 AC 354 ms
6,940 KB
testcase_33 AC 109 ms
6,944 KB
testcase_34 AC 5 ms
6,940 KB
testcase_35 AC 15 ms
6,940 KB
testcase_36 AC 109 ms
6,944 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 959 ms
6,940 KB
testcase_39 AC 957 ms
6,944 KB
testcase_40 AC 959 ms
6,940 KB
testcase_41 AC 996 ms
6,940 KB
testcase_42 AC 993 ms
6,940 KB
testcase_43 AC 967 ms
6,944 KB
testcase_44 AC 979 ms
6,940 KB
testcase_45 AC 953 ms
6,944 KB
testcase_46 AC 1,002 ms
6,944 KB
testcase_47 AC 972 ms
6,940 KB
testcase_48 AC 995 ms
6,940 KB
testcase_49 AC 1,009 ms
6,940 KB
testcase_50 AC 977 ms
6,940 KB
testcase_51 AC 973 ms
6,944 KB
testcase_52 AC 960 ms
6,940 KB
testcase_53 AC 969 ms
6,944 KB
testcase_54 AC 963 ms
6,940 KB
testcase_55 AC 980 ms
6,940 KB
testcase_56 AC 952 ms
6,940 KB
testcase_57 AC 968 ms
6,940 KB
testcase_58 AC 1,007 ms
6,944 KB
testcase_59 AC 1,007 ms
6,940 KB
testcase_60 AC 1,004 ms
6,940 KB
testcase_61 AC 1,004 ms
6,940 KB
testcase_62 AC 1,001 ms
6,940 KB
testcase_63 AC 1,001 ms
6,944 KB
testcase_64 AC 1,003 ms
6,940 KB
testcase_65 AC 1,002 ms
6,940 KB
testcase_66 AC 997 ms
6,940 KB
testcase_67 AC 1,006 ms
6,944 KB
testcase_68 AC 1,009 ms
6,940 KB
testcase_69 AC 1,084 ms
6,944 KB
testcase_70 AC 1,005 ms
6,940 KB
testcase_71 AC 1,008 ms
6,940 KB
testcase_72 AC 1,001 ms
6,944 KB
testcase_73 AC 1,004 ms
6,940 KB
testcase_74 AC 1,003 ms
6,940 KB
testcase_75 AC 1,007 ms
6,940 KB
testcase_76 AC 1,006 ms
6,940 KB
testcase_77 AC 1,000 ms
6,940 KB
testcase_78 AC 2 ms
6,940 KB
testcase_79 AC 18 ms
6,940 KB
testcase_80 AC 27 ms
6,940 KB
testcase_81 AC 1,004 ms
6,940 KB
testcase_82 AC 1,000 ms
6,940 KB
testcase_83 AC 270 ms
6,944 KB
testcase_84 AC 433 ms
6,940 KB
testcase_85 AC 757 ms
6,940 KB
testcase_86 AC 205 ms
6,944 KB
testcase_87 AC 461 ms
6,944 KB
testcase_88 AC 309 ms
6,944 KB
testcase_89 AC 332 ms
6,940 KB
testcase_90 AC 907 ms
6,944 KB
testcase_91 AC 617 ms
6,940 KB
testcase_92 AC 159 ms
6,940 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