結果
| 問題 |
No.748 yuki国のお財布事情
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-10 15:19:32 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 56 ms / 2,000 ms |
| コード長 | 2,105 bytes |
| コンパイル時間 | 1,414 ms |
| コンパイル使用メモリ | 137,400 KB |
| 最終ジャッジ日時 | 2025-01-11 17:24:23 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:83:27: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
83 | int n, m, k; scanf("%d %d %d", &n, &m, &k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:89:35: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
89 | int u, v, w; scanf("%d %d %d", &u, &v, &w);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:95:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
95 | int c; scanf("%d", &c);
| ~~~~~^~~~~~~~~~
ソースコード
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
class UnionFind {
public:
vector<int> Parent;
UnionFind(int N) {
Parent = vector<int>(N, -1);
}
int root(int A) {
if (Parent[A] < 0) {
return A;
}
return Parent[A] = root(Parent[A]);
}
long long size(int A) {
return -(long long)Parent[root(A)];
}
bool connect(int A, int B) {
A = root(A);
B = root(B);
if (A == B) {
return false;
}
if (size(A) < size(B)) {
swap(A, B);
}
Parent[A] += Parent[B];
Parent[B] = A;
return true;
}
};
int main()
{
/*
cin.tie(nullptr);
ios::sync_with_stdio(false);
*/
int n, m, k; scanf("%d %d %d", &n, &m, &k);
vector<tuple<ll, int, int>> vt(m);
UnionFind uni(n);
ll res = 0;
ll sum = 0;
for (int i = 0; i < m; i++) {
int u, v, w; scanf("%d %d %d", &u, &v, &w);
u--; v--;
sum += w;
vt[i] = make_tuple(w, u, v);
}
for (int i = 0; i < k; i++) {
int c; scanf("%d", &c);
c--;
auto [w, u, v] = vt[c];
res += w;
uni.connect(u, v);
}
sort(vt.begin(), vt.end());
for (int i = 0; i < vt.size(); i++) {
auto [w, u, v] = vt[i];
if (uni.connect(u, v)) res += w;
}
res = sum - res;
cout << res << endl;
return 0;
}