結果
| 問題 |
No.748 yuki国のお財布事情
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-10-19 23:16:11 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,922 bytes |
| コンパイル時間 | 1,816 ms |
| コンパイル使用メモリ | 180,208 KB |
| 実行使用メモリ | 10,200 KB |
| 最終ジャッジ日時 | 2024-11-18 22:29:46 |
| 合計ジャッジ時間 | 3,666 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 WA * 11 |
ソースコード
#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
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]);
g.add_edge(A[i][1], A[i][0], A[i][2]);
}
debug(S);
cout << S - g.kruskal() << endl;
}
// for compilation: g++ -Ofast -march=native -o _ _.cpp -std=c++17