結果
| 問題 |
No.1773 Love Triangle
|
| コンテスト | |
| ユーザー |
hitonanode
|
| 提出日時 | 2021-11-13 12:47:22 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,514 bytes |
| コンパイル時間 | 1,162 ms |
| コンパイル使用メモリ | 111,940 KB |
| 最終ジャッジ日時 | 2025-01-25 17:40:47 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 36 WA * 54 |
ソースコード
// This should be WA
#include <chrono>
#include <iostream>
#include <tuple>
#include <random>
#include <vector>
using namespace std;
#include <atcoder/modint>
using mint = atcoder::modint1000000007;
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;
}
mt19937 mt(1967176539);
uniform_int_distribution<int> rndgen(0, mint::mod());
int solve(int N, const vector<tuple<int, int, int>> &uvws) {
vector M(N, vector<mint>(N));
// Not bc - cb but bc + cb
for (auto [u, v, w] : uvws) {
int x = rndgen(mt);
M[u][v] += x;
M[v][u] += x;
M[v][w] += x;
M[w][v] += x;
M[v][v] -= x;
M[u][w] -= x;
M[w][u] -= 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 << solve(N, uvws) << '\n';
}
hitonanode