結果

問題 No.845 最長の切符
ユーザー tko919tko919
提出日時 2019-09-04 16:27:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 341 ms / 3,000 ms
コード長 1,222 bytes
コンパイル時間 1,584 ms
コンパイル使用メモリ 170,556 KB
実行使用メモリ 7,780 KB
最終ジャッジ日時 2023-08-27 16:18:36
合計ジャッジ時間 4,342 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,596 KB
testcase_01 AC 4 ms
7,540 KB
testcase_02 AC 4 ms
7,652 KB
testcase_03 AC 3 ms
7,652 KB
testcase_04 AC 3 ms
7,624 KB
testcase_05 AC 4 ms
7,684 KB
testcase_06 AC 3 ms
7,596 KB
testcase_07 AC 3 ms
7,740 KB
testcase_08 AC 4 ms
7,596 KB
testcase_09 AC 3 ms
7,564 KB
testcase_10 AC 4 ms
7,628 KB
testcase_11 AC 4 ms
7,636 KB
testcase_12 AC 4 ms
7,600 KB
testcase_13 AC 3 ms
7,668 KB
testcase_14 AC 4 ms
7,740 KB
testcase_15 AC 18 ms
7,556 KB
testcase_16 AC 341 ms
7,664 KB
testcase_17 AC 83 ms
7,732 KB
testcase_18 AC 58 ms
7,576 KB
testcase_19 AC 17 ms
7,620 KB
testcase_20 AC 86 ms
7,680 KB
testcase_21 AC 49 ms
7,568 KB
testcase_22 AC 74 ms
7,728 KB
testcase_23 AC 18 ms
7,780 KB
testcase_24 AC 286 ms
7,568 KB
testcase_25 AC 4 ms
7,556 KB
testcase_26 AC 9 ms
7,600 KB
testcase_27 AC 3 ms
7,536 KB
testcase_28 AC 11 ms
7,596 KB
testcase_29 AC 3 ms
7,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end



int main(){
    int n,m; scanf("%d%d",&n,&m);
    vector<vector<P>> g(n);
    rep(i,0,m){
        int u,v,w; scanf("%d%d%d",&u,&v,&w);
        g[u-1].push_back({v-1,w});
        g[v-1].push_back({u-1,w});
    }
    int dp[1<<16][16]; Fill(dp,0);
    rep(mask,0,1<<n)rep(i,0,n){
        if(!(mask>>i&1))continue;
        for(P p:g[i]){
            int v=p.first,w=p.second;
            if(mask>>v&1)continue;
            chmax(dp[mask|1<<v][v],dp[mask][i]+w);
        }
    }
    int ans=0;
    rep(mask,0,1<<n)rep(i,0,n)chmax(ans,dp[mask][i]);
    printf("%d\n",ans);
    return 0;
}
0