結果
問題 | No.748 yuki国のお財布事情 |
ユーザー | ok |
提出日時 | 2018-10-19 22:59:37 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 132 ms / 2,000 ms |
コード長 | 1,909 bytes |
コンパイル時間 | 1,074 ms |
コンパイル使用メモリ | 68,248 KB |
実行使用メモリ | 9,908 KB |
最終ジャッジ日時 | 2023-08-12 02:04:34 |
合計ジャッジ時間 | 3,845 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,364 KB |
testcase_01 | AC | 2 ms
5,448 KB |
testcase_02 | AC | 2 ms
5,464 KB |
testcase_03 | AC | 2 ms
5,516 KB |
testcase_04 | AC | 1 ms
5,424 KB |
testcase_05 | AC | 2 ms
5,364 KB |
testcase_06 | AC | 2 ms
5,532 KB |
testcase_07 | AC | 2 ms
5,628 KB |
testcase_08 | AC | 2 ms
5,472 KB |
testcase_09 | AC | 2 ms
5,448 KB |
testcase_10 | AC | 2 ms
5,484 KB |
testcase_11 | AC | 2 ms
5,352 KB |
testcase_12 | AC | 2 ms
5,468 KB |
testcase_13 | AC | 15 ms
7,836 KB |
testcase_14 | AC | 27 ms
8,012 KB |
testcase_15 | AC | 19 ms
8,072 KB |
testcase_16 | AC | 50 ms
8,368 KB |
testcase_17 | AC | 99 ms
9,464 KB |
testcase_18 | AC | 117 ms
9,504 KB |
testcase_19 | AC | 132 ms
9,908 KB |
testcase_20 | AC | 117 ms
9,372 KB |
testcase_21 | AC | 114 ms
9,364 KB |
testcase_22 | AC | 2 ms
5,588 KB |
testcase_23 | AC | 2 ms
5,448 KB |
testcase_24 | AC | 2 ms
5,424 KB |
testcase_25 | AC | 90 ms
9,608 KB |
testcase_26 | AC | 110 ms
9,660 KB |
testcase_27 | AC | 107 ms
9,668 KB |
testcase_28 | AC | 89 ms
8,924 KB |
ソースコード
#include<iostream> #include<string> #include<iomanip> #include<algorithm> using namespace std; #define int long long #define rep(i,n) for(int i = 0; i < n; i++) #define INF (long long)(1e17) #define MOD (int)(1e9+7) #define min(a,b) (a>b?b:a) #define max(a,b) (a>b?a:b) #define yn(f) (f?"Yes":"No") #define YN(f) (f?"YES":"NO") #define pro "はいプロ 世界一○○が上手 ○○界のtourist ○○時代の終焉を告げる者 実質○○ ○○するために生まれてきた男" #define Answer_to_the_Ultimate_Question_of_Life_the_Universe_and_Everything 42 #define MAX_E 100005 #define MAX_V 100005 #define MAX 100005 struct edge{int u, v, cost;}; bool comp(const edge& e1, const edge& e2){ return e1.cost < e2.cost; } int V, E, K; edge es[MAX_E]; int par[MAX_V]; int _rank[MAX_V]; int a[MAX], b[MAX], c[MAX]; void init(int x){ for(int i = 0; i < x; i++){ par[i] = i; _rank[i] = 0; } } int find(int x){ return par[x] == x ? x : par[x] = find(par[x]); } void unite(int x, int y){ x = find(x); y = find(y); if(_rank[x] < _rank[y]){ par[x] = y; } else{ par[y] = x; if(_rank[x] == _rank[y]) _rank[x]++; } } bool same(int x, int y){ return find(x) == find(y); } int kruskal(){ sort(es, es + E, comp); // init(V); int res = 0, count = 0; // for(int i = 0; i < E && count != V-1; i++){ for(int i = 0; i < E; i++){ edge e = es[i]; if(!same(e.u, e.v)){ unite(e.u,e.v); res += e.cost; count++; } } return res; } signed main(){ int s, t, w, e, ans = 0, sum = 0, kr; cin>>V>>E>>K; for(int i = 0; i < E; i++){ cin>>s>>t>>w; es[i].u = s; es[i].v = t; es[i].cost = w; a[i]=s;b[i]=t;c[i]=w; sum += w; } init(V); for(int i = 0; i < K; i++){ cin>>e; unite(a[e-1],b[e-1]); ans += c[e-1]; // es[e].cost = INF; } kr = kruskal(); // cout<<sum<<" "<<ans<<" "<<kr<<endl; cout<<sum-(ans+kr)<<endl; return 0; }