結果

問題 No.1774 Love Triangle (Hard)
ユーザー 👑 hitonanodehitonanode
提出日時 2021-09-25 21:04:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,299 bytes
コンパイル時間 1,778 ms
コンパイル使用メモリ 153,656 KB
実行使用メモリ 7,464 KB
最終ジャッジ日時 2023-10-09 22:29:16
合計ジャッジ時間 209,839 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 4 ms
4,352 KB
testcase_18 WA -
testcase_19 AC 4 ms
4,352 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
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 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 WA -
testcase_83 WA -
testcase_84 WA -
testcase_85 WA -
testcase_86 WA -
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

// 嘘探索解
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <forward_list>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using pint = pair<int, int>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template <typename T> bool chmax(T &m, const T q) { return m < q ? (m = q, true) : false; }
template <typename T> bool chmin(T &m, const T q) { return m > q ? (m = q, true) : false; }


// UnionFind Tree (0-indexed), based on size of each disjoint set
struct UnionFind {
    std::vector<int> par, cou;
    UnionFind(int N = 0) : par(N), cou(N, 1) { iota(par.begin(), par.end(), 0); }
    int find(int x) { return (par[x] == x) ? x : (par[x] = find(par[x])); }
    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return false;
        if (cou[x] < cou[y]) std::swap(x, y);
        par[y] = x, cou[x] += cou[y];
        return true;
    }
    int count(int x) { return cou[find(x)]; }
    bool same(int x, int y) { return find(x) == find(y); }
};

struct rand_int_ {
    using lint = long long;
    mt19937 mt;
    rand_int_() : mt(1837654) {} // fixed
    lint operator()(lint x) { return this->operator()(0, x); } // [0, x)
    lint operator()(lint l, lint r) {
        uniform_int_distribution<lint> d(l, r - 1);
        return d(mt);
    }
} rnd;


int main() {
    auto START = std::chrono::system_clock::now();
    int64_t spent_ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - START).count();

    int N, M;
    cin >> N >> M;
    vector<tuple<int, int, int>> edges;
    REP(t, M) {
        int u, v, w;
        cin >> u >> v >> w;
        u--, v--, w--;
        edges.emplace_back(u, v, w);
    }

    vector<int> ret1(M, 0);

    REP(ntry, 100) {
        vector<int> ret(M);
        vector<UnionFind> ufs(M, UnionFind(N));
        REP(i, M) {
            auto [u, v, w] = edges[i];
            if (chmax(ret[i], 1)) {
                UnionFind uf(N);
                uf.unite(u, v);
                uf.unite(u, w);
                ufs[i] = uf;
            }
            REP(j, i) {
                if (ufs[j].same(u, v)) continue;
                if (ufs[j].same(v, w)) continue;
                if (ufs[j].same(u, w)) continue;
                if (ret[j] < ret[i] - 1) continue;
                if (ret[j] == ret[i] - 1 and rnd(2)) continue;
                chmax(ret[i], ret[j] + 1);
                ufs[i] = ufs[j];
                ufs[i].unite(u, v);
                ufs[i].unite(u, w);
            }
        }
        REP(i, M) chmax(ret1[i], ret[i]);
    }
    FOR(i, 1, ret1.size()) chmax(ret1[i], ret1[i - 1]);
    for (auto x : ret1) cout << x << '\n';
}
0