結果
問題 |
No.1773 Love Triangle
|
ユーザー |
![]() |
提出日時 | 2021-11-28 11:58:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,401 bytes |
コンパイル時間 | 1,397 ms |
コンパイル使用メモリ | 110,924 KB |
最終ジャッジ日時 | 2025-01-26 02:26:16 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 3 WA * 82 RE * 5 |
ソースコード
// WA #include <chrono> #include <iostream> #include <random> #include <tuple> #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 H = M.size(), W = M[0].size(); int rank = 0; for (int i = 0; i < H; ++i) { int ti = i; while (ti < H and M[ti][i] == 0) ti++; if (ti == H) continue; ++rank; M[i].swap(M[ti]); T inv = T(1) / M[i][i]; for (int j = i + 1; j < W; ++j) M[i][j] *= inv; for (int h = 0; h < H; ++h) { if (i == h) continue; const T c = -M[h][i]; for (int j = i + 1; j < W; ++j) M[h][j] += M[i][j] * c; } } return rank; } int wrong_answer(int N, const vector<tuple<int, int, int>> &uvws) { vector<vector<mint>> M; for (auto [u, v, w] : uvws) { vector<mint> a(N), b(N); a[u]++; a[v]--; M.push_back(a); b[u]++; b[w]--; M.push_back(b); } 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(wrong_answer(N, uvws), wrong_answer(N, uvws)) << '\n'; }