結果

問題 No.1773 Love Triangle
ユーザー 👑 hitonanodehitonanode
提出日時 2021-10-06 23:47:34
言語 C++23(draft)
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 249 ms / 2,000 ms
コード長 1,460 bytes
コンパイル時間 1,461 ms
コンパイル使用メモリ 133,128 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-16 21:59:54
合計ジャッジ時間 17,055 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 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,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 160 ms
4,380 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 9 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 9 ms
4,376 KB
testcase_23 AC 8 ms
4,376 KB
testcase_24 AC 65 ms
4,376 KB
testcase_25 AC 61 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 123 ms
4,376 KB
testcase_31 AC 87 ms
4,376 KB
testcase_32 AC 63 ms
4,376 KB
testcase_33 AC 19 ms
4,500 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 4 ms
4,376 KB
testcase_36 AC 22 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 219 ms
4,380 KB
testcase_39 AC 214 ms
4,376 KB
testcase_40 AC 220 ms
4,376 KB
testcase_41 AC 229 ms
4,376 KB
testcase_42 AC 233 ms
4,384 KB
testcase_43 AC 214 ms
4,384 KB
testcase_44 AC 223 ms
4,376 KB
testcase_45 AC 218 ms
4,384 KB
testcase_46 AC 226 ms
4,380 KB
testcase_47 AC 229 ms
4,380 KB
testcase_48 AC 236 ms
4,380 KB
testcase_49 AC 232 ms
4,376 KB
testcase_50 AC 225 ms
4,376 KB
testcase_51 AC 231 ms
4,380 KB
testcase_52 AC 229 ms
4,376 KB
testcase_53 AC 230 ms
4,376 KB
testcase_54 AC 229 ms
4,376 KB
testcase_55 AC 230 ms
4,376 KB
testcase_56 AC 227 ms
4,380 KB
testcase_57 AC 229 ms
4,376 KB
testcase_58 AC 233 ms
4,376 KB
testcase_59 AC 240 ms
4,380 KB
testcase_60 AC 247 ms
4,380 KB
testcase_61 AC 249 ms
4,380 KB
testcase_62 AC 241 ms
4,376 KB
testcase_63 AC 245 ms
4,376 KB
testcase_64 AC 247 ms
4,380 KB
testcase_65 AC 229 ms
4,376 KB
testcase_66 AC 229 ms
4,380 KB
testcase_67 AC 237 ms
4,428 KB
testcase_68 AC 238 ms
4,380 KB
testcase_69 AC 230 ms
4,380 KB
testcase_70 AC 232 ms
4,380 KB
testcase_71 AC 231 ms
4,380 KB
testcase_72 AC 232 ms
4,376 KB
testcase_73 AC 228 ms
4,380 KB
testcase_74 AC 233 ms
4,380 KB
testcase_75 AC 233 ms
4,500 KB
testcase_76 AC 233 ms
4,380 KB
testcase_77 AC 224 ms
4,376 KB
testcase_78 AC 2 ms
4,376 KB
testcase_79 AC 3 ms
4,376 KB
testcase_80 AC 4 ms
4,376 KB
testcase_81 AC 228 ms
4,380 KB
testcase_82 AC 236 ms
4,376 KB
testcase_83 AC 60 ms
4,376 KB
testcase_84 AC 95 ms
4,376 KB
testcase_85 AC 164 ms
4,376 KB
testcase_86 AC 39 ms
4,380 KB
testcase_87 AC 96 ms
4,380 KB
testcase_88 AC 55 ms
4,376 KB
testcase_89 AC 68 ms
4,380 KB
testcase_90 AC 207 ms
4,376 KB
testcase_91 AC 138 ms
4,380 KB
testcase_92 AC 29 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <chrono>
#include <iostream>
#include <random>
#include <tuple>
#include <vector>
using namespace std;

#include <atcoder/modint>
using mint = atcoder::modint1000000007;

mt19937 mt(530629);
uniform_int_distribution<int> rndgen(0, mint::mod() - 1);

template <class T> int rank_of_matrix(std::vector<std::vector<T>> &M) {
    const int N = M.size();
    int rank = 0;
    for (int i = 0; i < N; ++i) {
        int ti = i;
        while (ti < N and M[ti][i] == 0) ti++;
        if (ti == N) continue;
        ++rank;
        M[i].swap(M[ti]);
        T inv = T(1) / M[i][i];
        for (int j = i + 1; j < N; ++j) M[i][j] *= inv;
        for (int h = 0; h < N; ++h) {
            if (i == h) continue;
            const T c = -M[h][i];
            for (int j = i + 1; j < N; ++j) M[h][j] += M[i][j] * c;
        }
    }
    return rank;
}



int solve(int N, const vector<tuple<int, int, int>> &uvws) {
    vector M(N, vector<mint>(N));
    for (auto [u, v, w] : uvws) {
        mint x = rndgen(mt);
        M[u][v] += x;
        M[v][w] += x;
        M[w][u] += x;
        M[v][u] -= x;
        M[w][v] -= x;
        M[u][w] -= x;
    }
    return rank_of_matrix(M) / 2;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<tuple<int, int, int>> uvws;
    while (M--) {
        int u, v, w;
        cin >> u >> v >> w;
        u--, v--, w--;
        uvws.emplace_back(u, v, w);
    }
    cout << max(solve(N, uvws), solve(N, uvws)) << '\n';
}
0