結果
| 問題 |
No.748 yuki国のお財布事情
|
| コンテスト | |
| ユーザー |
🍮かんプリン
|
| 提出日時 | 2019-09-14 15:25:56 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 138 ms / 2,000 ms |
| コード長 | 1,626 bytes |
| コンパイル時間 | 1,653 ms |
| コンパイル使用メモリ | 182,176 KB |
| 実行使用メモリ | 13,508 KB |
| 最終ジャッジ日時 | 2024-07-06 03:27:04 |
| 合計ジャッジ時間 | 4,054 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#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();
}
🍮かんプリン