結果

問題 No.748 yuki国のお財布事情
ユーザー どららどらら
提出日時 2018-10-19 22:06:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,534 bytes
コンパイル時間 1,712 ms
コンパイル使用メモリ 176,748 KB
実行使用メモリ 11,824 KB
最終ジャッジ日時 2023-08-12 01:00:51
合計ジャッジ時間 4,386 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 WA -
testcase_26 AC 119 ms
11,788 KB
testcase_27 WA -
testcase_28 AC 86 ms
8,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

class UnionFind{
  int n;
  vector<int> data;
public:
  UnionFind(int _n):n(_n),data(_n,-1){}
  bool link(int a, int b){
    int ra=find_root(a);
    int rb=find_root(b);
    if(ra!=rb){
      if(data[rb]<data[ra]) swap(ra,rb);
      data[ra]+=data[rb];
      data[rb]=ra;
    }
    return (ra!=rb);
  }
  bool check(int a, int b){
    return (find_root(a)==find_root(b));
  }
  int find_root(int a){
    return ((data[a]<0)?a:(data[a]=find_root(data[a])));
  }
};

struct ST {
  int a, b, c;
};
bool operator<(const ST& a, const ST& b){
  return a.c > b.c;
}

int main(){
  int N, M, K;
  cin >> N >> M >> K;
  vector<vector<int>> edges;
  rep(i,M){
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    edges.push_back({a,b,c});
  }
  
  UnionFind uf(N);
  int ret = 0;
  rep(i,K){
    int e;
    cin >> e;
    e--;
    uf.link(edges[e][0], edges[e][1]);
    edges[e][0] = -1;
  }

  priority_queue<ST> que;
  rep(i,edges.size()){
    if(edges[i][0] == -1) continue;
    que.push((ST){edges[i][0], edges[i][1], edges[i][2]});
  }

  while(!que.empty()){
    ST st = que.top(); que.pop();
    if(uf.check(st.a, st.b)){
      ret += st.c;
    }else{
      uf.link(st.a, st.b);
    }
  }

  cout << ret << endl;
  
  return 0;
}
0