結果

問題 No.748 yuki国のお財布事情
コンテスト
ユーザー WutongDeath
提出日時 2025-12-21 23:59:10
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 32 ms / 2,000 ms
+ 626µs
コード長 1,216 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 558 ms
コンパイル使用メモリ 98,920 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-07-19 17:50:29
合計ジャッジ時間 3,754 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long LL;

const int N = 100010;

struct Edge {
    int u, v, w;
    bool is_del;
};

int n, m, k, fa[N];
vector<Edge> edges;
LL sum, v;

int Find(int x) { if (x != fa[x]) fa[x] = Find(fa[x]); return fa[x]; }

int main() {
    // freopen("cost.in", "r", stdin);
    // freopen("cost.out", "w", stdout);

    scanf("%d%d%d", &n, &m, &k);
    edges.resize(m);
    sum = 0LL;
    for (int i = 0; i < m; ++i) {
        scanf("%d%d%d", &edges[i].u, &edges[i].v, &edges[i].w);
        sum += edges[i].w;
    }
    for (int i = 1; i <= n; ++i) fa[i] = i;
    v = 0LL;
    for (int i = 0, x, fu, fv; i < k; ++i) {
        scanf("%d", &x); --x;
        v += edges[x].w;
        edges[x].is_del = true;
        fu = Find(edges[x].u), fv = Find(edges[x].v);
        if (fu != fv) fa[fu] = fv;
    }
    sort(edges.begin(), edges.end(), [](Edge e1, Edge e2) {
        return e1.w < e2.w;
    });
    for (Edge e : edges) {
        if (e.is_del) continue;
        int fu = Find(e.u), fv = Find(e.v);
        if (fu != fv) {
            fa[fu] = fv;
            v += e.w;
        }
    }
    printf("%lld\n", sum - v);

    return 0;
}
0