結果

問題 No.3827 MST on LCM Graph
コンテスト
ユーザー shiomusubi496
提出日時 2026-10-31 10:56:55
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
MLE  
実行時間 -
コード長 1,130 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,423 ms
コンパイル使用メモリ 230,912 KB
実行使用メモリ 1,300,572 KB
最終ジャッジ日時 2026-11-22 12:35:18
合計ジャッジ時間 8,040 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other MLE * 2 -- * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) begin(v), end(v)

using namespace std;
using ll = long long;

template<class T, class U> bool chmin(T& a, const U& b) { return a > b ? a = b, true : false; }
template<class T, class U> bool chmax(T& a, const U& b) { return a < b ? a = b, true : false; }

constexpr ll inf = 1e18;

class UnionFind {
    vector<int> par;

public:
    UnionFind(int n) : par(n, -1) {}
    int find(int x) {
        return par[x] < 0 ? x : par[x] = find(par[x]);
    }
    bool merge(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    int size(int x) { return -par[find(x)]; }
};

int main() {
    int N; cin >> N;
    vector<ll> A(N);
    rep (i, N) cin >> A[i];
    vector<tuple<ll, int, int>> B;
    rep (i, N) rep (j, i) B.emplace_back(lcm(A[i], A[j]), i, j);
    sort(all(B));
    UnionFind uf(N);
    ll ans = 0;
    for (auto [c, a, b] : B) if (uf.merge(a, b)) ans += c;
    cout << ans << endl;
}
0