結果

問題 No.748 yuki国のお財布事情
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2019-09-14 15:25:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,627 bytes
コンパイル時間 1,850 ms
コンパイル使用メモリ 178,940 KB
実行使用メモリ 13,496 KB
最終ジャッジ日時 2023-09-20 07:30:54
合計ジャッジ時間 4,900 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 101 ms
11,640 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 105 ms
10,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = MOD - 1;
const ll LLINF = 4e18;

// 最小全域木 O(ElogV)?
struct Edge {
    ll cost, to;
    bool operator>(const Edge e)const {
        return this->cost > e.cost;
    }
};

int Prim(const vector<vector<Edge>> &G) {
    ll res = 0;
    vector<bool> used(G.size(), false);
    priority_queue<Edge, vector<Edge>, greater<Edge>> pq;
    for (Edge e : G[0]) {
        pq.push(e);
    }
    used[0] = true;
    while (!pq.empty()) {
        Edge e = pq.top(); pq.pop();
        if (used[e.to]) continue;
        used[e.to] = true;
        res += e.cost;
        for (Edge u : G[e.to]) {
            if (used[u.to]) continue;
            pq.push(u);
        }
    }
    return res;
}

int main() {
    int n, m, k; cin >> n >> m >> k;
    vector<tuple<ll,ll,ll>> E(m);
    vector<vector<Edge>> G(n);
    ll sum = 0;
    REP(i, m) {
        ll a, b, c; cin >> a >> b >> c;
        a--; b--;
        E[i] = {a,b,c};
    }
    REP(i, k) {
        ll e; cin >> e;
        e--;
        E[e] = {get<0>(E[e]),get<1>(E[e]),0};
    }
    REP(i, m) {
        G[get<0>(E[i])].push_back({get<2>(E[i]),get<1>(E[i])});
        G[get<1>(E[i])].push_back({get<2>(E[i]),get<0>(E[i])});
        sum += get<2>(E[i]);
    }
    cout << sum - Prim(G) << endl;
    getchar(); getchar();
}
0