結果
問題 | No.1773 Love Triangle |
ユーザー | 👑 hitonanode |
提出日時 | 2021-10-08 00:47:54 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,330 bytes |
コンパイル時間 | 1,573 ms |
コンパイル使用メモリ | 120,320 KB |
実行使用メモリ | 4,504 KB |
最終ジャッジ日時 | 2023-09-16 22:09:12 |
合計ジャッジ時間 | 89,418 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 902 ms
4,384 KB |
testcase_01 | AC | 902 ms
4,384 KB |
testcase_02 | AC | 903 ms
4,380 KB |
testcase_03 | AC | 902 ms
4,380 KB |
testcase_04 | WA | - |
testcase_05 | AC | 902 ms
4,384 KB |
testcase_06 | AC | 903 ms
4,380 KB |
testcase_07 | AC | 903 ms
4,384 KB |
testcase_08 | AC | 903 ms
4,384 KB |
testcase_09 | AC | 903 ms
4,384 KB |
testcase_10 | AC | 903 ms
4,380 KB |
testcase_11 | AC | 903 ms
4,384 KB |
testcase_12 | AC | 902 ms
4,380 KB |
testcase_13 | AC | 903 ms
4,384 KB |
testcase_14 | AC | 903 ms
4,380 KB |
testcase_15 | AC | 903 ms
4,380 KB |
testcase_16 | AC | 902 ms
4,380 KB |
testcase_17 | AC | 903 ms
4,380 KB |
testcase_18 | WA | - |
testcase_19 | AC | 902 ms
4,384 KB |
testcase_20 | AC | 903 ms
4,380 KB |
testcase_21 | AC | 903 ms
4,380 KB |
testcase_22 | AC | 903 ms
4,384 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 903 ms
4,380 KB |
testcase_26 | AC | 903 ms
4,384 KB |
testcase_27 | AC | 903 ms
4,384 KB |
testcase_28 | AC | 903 ms
4,380 KB |
testcase_29 | AC | 902 ms
4,384 KB |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | AC | 903 ms
4,384 KB |
testcase_33 | AC | 902 ms
4,384 KB |
testcase_34 | AC | 903 ms
4,384 KB |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | AC | 902 ms
4,380 KB |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | WA | - |
testcase_54 | WA | - |
testcase_55 | WA | - |
testcase_56 | WA | - |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | WA | - |
testcase_60 | WA | - |
testcase_61 | WA | - |
testcase_62 | WA | - |
testcase_63 | WA | - |
testcase_64 | WA | - |
testcase_65 | WA | - |
testcase_66 | WA | - |
testcase_67 | WA | - |
testcase_68 | WA | - |
testcase_69 | WA | - |
testcase_70 | WA | - |
testcase_71 | WA | - |
testcase_72 | WA | - |
testcase_73 | WA | - |
testcase_74 | WA | - |
testcase_75 | WA | - |
testcase_76 | WA | - |
testcase_77 | WA | - |
testcase_78 | AC | 903 ms
4,380 KB |
testcase_79 | AC | 903 ms
4,380 KB |
testcase_80 | AC | 903 ms
4,380 KB |
testcase_81 | WA | - |
testcase_82 | WA | - |
testcase_83 | WA | - |
testcase_84 | WA | - |
testcase_85 | WA | - |
testcase_86 | WA | - |
testcase_87 | WA | - |
testcase_88 | AC | 903 ms
4,384 KB |
testcase_89 | WA | - |
testcase_90 | WA | - |
testcase_91 | WA | - |
testcase_92 | WA | - |
ソースコード
// 1つ消して2つ追加できるところをひたすら探す #include <algorithm> #include <chrono> #include <iostream> #include <random> #include <tuple> #include <vector> using namespace std; #include <atcoder/dsu> std::mt19937 rng(159376); using Tri = tuple<int, int, int>; int rnd(int n) { return uniform_int_distribution<int>(0, n - 1)(rng); } int main() { cin.tie(nullptr), ios::sync_with_stdio(false); auto START = std::chrono::system_clock::now(); int N, M; cin >> N >> M; vector<Tri> edges; for (int i = 0; i < M; i++) { int u, v, w; cin >> u >> v >> w; u--, v--, w--; edges.emplace_back(u, v, w); } std::shuffle(edges.begin(), edges.end(), rng); vector<int> best_solution; for (int h = 0; h < M; h++) { vector<int> tmp; atcoder::dsu uf(N); for (int t = 0; t < M; t++) { int i = (h + t) % M; auto [u, v, w] = edges[i]; if (!uf.same(u, v) and !uf.same(v, w) and !uf.same(u, w)) { uf.merge(u, v), uf.merge(v, w); tmp.emplace_back(i); } } if (best_solution.size() < tmp.size()) best_solution = tmp; } vector<int> is_in(M); for (auto i : best_solution) is_in[i] = 1; int ret = accumulate(is_in.begin(), is_in.end(), 0); while (true) { int64_t spent_ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - START).count(); if (spent_ms > 900) break; int i = rnd(M), j = rnd(M), k = rnd(M); if (i == j or j == k or k == i or is_in[i] + is_in[j] + is_in[k] != 1) continue; is_in[i] ^= 1; is_in[j] ^= 1; is_in[k] ^= 1; atcoder::dsu uf(N); bool good = true; for (int e = 0; e < M; e++) { if (!is_in[e]) continue; auto [u, v, w] = edges[e]; if (uf.same(u, v) or uf.same(v, w) or uf.same(w, u)) { good = false; break; } uf.merge(u, v), uf.merge(v, w); } if (good) { ret++; cerr << "Improved: " << ret << endl; } else { is_in[i] ^= 1; is_in[j] ^= 1; is_in[k] ^= 1; } } cout << ret << '\n'; }