結果

問題 No.748 yuki国のお財布事情
ユーザー Shuz*Shuz*
提出日時 2018-10-19 23:37:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 2,890 bytes
コンパイル時間 1,845 ms
コンパイル使用メモリ 176,400 KB
実行使用メモリ 10,316 KB
最終ジャッジ日時 2023-08-12 02:32:14
合計ジャッジ時間 3,973 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 8 ms
4,376 KB
testcase_14 AC 13 ms
4,556 KB
testcase_15 AC 10 ms
4,560 KB
testcase_16 AC 22 ms
5,992 KB
testcase_17 AC 49 ms
8,716 KB
testcase_18 AC 53 ms
10,316 KB
testcase_19 AC 53 ms
9,412 KB
testcase_20 AC 50 ms
8,960 KB
testcase_21 AC 51 ms
9,976 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 45 ms
9,472 KB
testcase_26 AC 53 ms
9,640 KB
testcase_27 AC 51 ms
9,616 KB
testcase_28 AC 37 ms
8,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
// using namespace boost::multiprecision;

// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using int128 = __int128;
// using cint = cpp_int;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ull MAX = ULONG_MAX;
#define endl '\n'
#define space ' '
#define def inline auto
#define func inline constexpr ll
#define run __attribute__((constructor)) def _
#define all(v) begin(v), end(v)

// Debug
#define debug(...)                                                             \
    {                                                                          \
        cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ";                     \
        for (auto &&X : {__VA_ARGS__}) cerr << "[" << X << "] ";               \
        cerr << endl;                                                          \
    }

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define each(i, a) for (auto &&i : a)
#define rep(i, n) inc(i, 0, n - 1)

// Stream
#define input(a) scanf("%lld", &(a))
#define output(a) printf("%lld\n", (a))
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("O3")
#pragma GCC optimization_level 3
#pragma GCC target("avx")

// Math
func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
func lcm(ll a, ll b) { return a * b / gcd(a, b); }

#define fst first
#define snd second

#define int ll
struct edge {
    int src, dst;
    int weight;
};
struct graph {
    int n;
    vector<edge> edges;
    graph(int n = 0) : n(n) { p.assign(n, -1); }
    void add_edge(int src, int dst, int weight) {
        n = max(n, max(src, dst) + 1);
        edges.push_back({src, dst, weight});
    }
    vector<int> p;
    int root(int i) { return p[i] < 0 ? i : p[i] = root(p[i]); }
    bool unite(int i, int j) {
        if ((i = root(i)) == (j = root(j))) return false;
        if (p[i] > p[j]) swap(i, j);
        p[i] += p[j];
        p[j] = i;
        return true;
    }
    int kruskal() {
        sort(all(edges), [](edge x, edge y) { return x.weight < y.weight; });
        int result = 0;
        for (auto e : edges)
            if (unite(e.src, e.dst)) result += e.weight;
        return result;
    }
};

signed main() {
    ll N, M, K, A[100000][3], E, S = 0;
    cin >> N >> M >> K;
    graph g(N);
    rep(i, M) rep(j, 3) cin >> E, A[i][j] = E - bool(j - 2);
    rep(i, K) cin >> E, A[E - 1][2] = 0, g.unite(A[E - 1][0], A[E - 1][1]);
    rep(i, M) {
        S += A[i][2];
        g.add_edge(A[i][0], A[i][1], A[i][2]);
    }
    debug(S);
    cout << S - g.kruskal() << endl;
}

// for compilation: g++ -Ofast -march=native -o _ _.cpp -std=c++17
0