結果

問題 No.748 yuki国のお財布事情
ユーザー ikdikd
提出日時 2018-07-18 00:50:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,189 bytes
コンパイル時間 774 ms
コンパイル使用メモリ 76,628 KB
実行使用メモリ 7,700 KB
最終ジャッジ日時 2023-09-18 02:22:28
合計ジャッジ時間 7,416 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)

struct UnionFind{
  vector<int> par;
  UnionFind(int n){
    par.resize(n);
    rep(i, n) par[i]=i;
  }
  int find(int i){
    return par[i]==i ? par[i] : (par[i]=find(par[i]));
  }
  void unite(int i, int j){
    par[find(i)]=find(j);
  }
  bool same(int i, int j){
    return find(i)==find(j);
  }
};

using i64=long long;
struct Edge{
  int u, v;
  i64 cost;
  Edge(int u, int v, i64 c):u(u), v(v), cost(c){};
};

int main(){

  int n, m, k; cin>> n>> m>> k;

  vector<Edge> edges;
  rep(_, m){
    int a, b; i64 c;
    cin>> a>> b>> c;
    edges.push_back(Edge{a-1, b-1, c});
  }

  int mask=0;
  rep(_, k){
    int i; cin>> i;
    i--;
    mask^=(1<<i);
  }

  i64 mx=0;
  for(i64 bit=0; bit<(1LL<<m); bit++){
    if((bit&mask)!=mask) continue;
    i64 sub=0;
    UnionFind uf(n);
    rep(i, m){
      if(bit&(1<<i)){
        uf.unite(edges[i].u, edges[i].v);
      }else{
        sub+=edges[i].cost;
      }
    }
    bool con=true;
    int root=uf.find(0);
    rep(i, n) con&=(root==uf.find(i));
    if(con) mx=max(mx, sub);
  }

  cout<< mx<< endl;
  return 0;
}
0