結果

問題 No.748 yuki国のお財布事情
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2019-09-14 15:25:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 1,626 bytes
コンパイル時間 1,966 ms
コンパイル使用メモリ 177,996 KB
実行使用メモリ 13,368 KB
最終ジャッジ日時 2023-09-20 07:31:37
合計ジャッジ時間 4,928 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,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 17 ms
4,696 KB
testcase_14 AC 31 ms
5,536 KB
testcase_15 AC 20 ms
4,712 KB
testcase_16 AC 58 ms
7,548 KB
testcase_17 AC 124 ms
12,752 KB
testcase_18 AC 150 ms
13,300 KB
testcase_19 AC 165 ms
13,228 KB
testcase_20 AC 145 ms
12,100 KB
testcase_21 AC 145 ms
12,664 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 102 ms
11,508 KB
testcase_26 AC 146 ms
13,064 KB
testcase_27 AC 145 ms
13,368 KB
testcase_28 AC 106 ms
10,300 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;
    }
};

ll 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