結果
| 問題 |
No.748 yuki国のお財布事情
|
| コンテスト | |
| ユーザー |
xxxasdfghjk
|
| 提出日時 | 2018-10-22 15:13:23 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 67 ms / 2,000 ms |
| コード長 | 1,709 bytes |
| コンパイル時間 | 776 ms |
| コンパイル使用メモリ | 73,512 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-19 03:42:13 |
| 合計ジャッジ時間 | 2,269 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:49:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
49 | scanf("%lld %lld %lld",&N,&M,&K);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:54:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
54 | scanf("%lld %lld %lld",&f,&t,&r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define MAX_N 100001
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long ll;
struct edge{
ll from,to,cost;
};
typedef vector<vector<edge> > AdjList;
AdjList graph;
typedef pair<int , int> P;
bool comp(const edge& e1, const edge& e2){
return e1.cost < e2.cost;
}
int E,V;
edge es[100001];
ll kruskal(){
sort(es,es+E,comp);
ll res = 0;
for(int i=0;i<E;i++){
edge e = es[i];
if(!same(e.to,e.from)){
unite(e.to,e.from);
res += e.cost;
}
}
return res;
}
int main()
{
ll N,M,K,r,t,f,count,merge=0,sum=0;
scanf("%lld %lld %lld",&N,&M,&K);
E = M;
V = N;
init(V);
REP(i,M){
scanf("%lld %lld %lld",&f,&t,&r);
sum += r;
es[i] = (edge){--f,--t,r};
}
REP(i,K){
cin >> count;
merge += es[count-1].cost;
unite(es[count-1].from,es[count-1].to);
}
cout << (sum-(kruskal() + merge)) << endl;
return 0;
}
int par[MAX_N];
int ranks[MAX_N];
//n要素で初期化
void init(int n){
REP(i,n){
par[i] = i;
ranks[i] = 0;
}
}
//木の根を求める
int find(int x){
if(par[x] == x){
return x;
}else{
return par[x] = find(par[x]);
}
}
void unite(int x,int y){
x = find(x);
y = find(y);
if(x == y) return ;
if(ranks[x] < ranks[y]){
par[x] = y;
}else{
par[y] = x;
if(ranks[x] == ranks[y]) ranks[x]++;
}
}
bool same(int x, int y){
return find(x) == find(y);
}
xxxasdfghjk