結果

問題 No.845 最長の切符
ユーザー beetbeet
提出日時 2019-06-28 21:33:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 3,000 ms
コード長 863 bytes
コンパイル時間 1,954 ms
コンパイル使用メモリ 199,356 KB
実行使用メモリ 11,852 KB
最終ジャッジ日時 2023-09-14 21:39:50
合計ジャッジ時間 3,582 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,556 KB
testcase_01 AC 5 ms
11,592 KB
testcase_02 AC 5 ms
11,548 KB
testcase_03 AC 5 ms
11,528 KB
testcase_04 AC 5 ms
11,676 KB
testcase_05 AC 5 ms
11,556 KB
testcase_06 AC 5 ms
11,716 KB
testcase_07 AC 5 ms
11,576 KB
testcase_08 AC 5 ms
11,556 KB
testcase_09 AC 5 ms
11,532 KB
testcase_10 AC 6 ms
11,560 KB
testcase_11 AC 5 ms
11,544 KB
testcase_12 AC 5 ms
11,548 KB
testcase_13 AC 5 ms
11,552 KB
testcase_14 AC 5 ms
11,540 KB
testcase_15 AC 16 ms
11,548 KB
testcase_16 AC 51 ms
11,560 KB
testcase_17 AC 15 ms
11,548 KB
testcase_18 AC 27 ms
11,556 KB
testcase_19 AC 9 ms
11,560 KB
testcase_20 AC 56 ms
11,616 KB
testcase_21 AC 59 ms
11,536 KB
testcase_22 AC 14 ms
11,556 KB
testcase_23 AC 7 ms
11,852 KB
testcase_24 AC 51 ms
11,820 KB
testcase_25 AC 4 ms
11,548 KB
testcase_26 AC 6 ms
11,556 KB
testcase_27 AC 5 ms
11,632 KB
testcase_28 AC 6 ms
11,724 KB
testcase_29 AC 5 ms
11,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
Int dp[16][1<<16];
signed main(){
  Int n,m;
  cin>>n>>m;
  Int es[20][20];
  memset(es,-1,sizeof(es));
  for(Int i=0;i<m;i++){
    Int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    chmax(es[a][b],c);
    chmax(es[b][a],c);
  }
  Int ans=0;
  Int s=1<<n;
  memset(dp,-1,sizeof(dp));
  for(Int i=0;i<n;i++) dp[i][1<<i]=0;
  for(Int b=0;b<s;b++){
    for(Int i=0;i<n;i++){
      if(dp[i][b]<0) continue;
      chmax(ans,dp[i][b]);
      for(Int j=0;j<n;j++){
        if((b>>j)&1) continue;
        if(es[i][j]<0) continue;
        chmax(dp[j][b|(1<<j)],dp[i][b]+es[i][j]);
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}
0