結果

問題 No.845 最長の切符
ユーザー chocoruskchocorusk
提出日時 2019-06-28 21:57:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 50 ms / 3,000 ms
コード長 1,191 bytes
コンパイル時間 731 ms
コンパイル使用メモリ 97,368 KB
実行使用メモリ 7,576 KB
最終ジャッジ日時 2023-09-14 21:56:57
合計ジャッジ時間 2,204 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
5,440 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
5,688 KB
testcase_08 AC 2 ms
5,468 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
5,564 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
5,544 KB
testcase_13 AC 2 ms
5,428 KB
testcase_14 AC 2 ms
5,740 KB
testcase_15 AC 11 ms
5,804 KB
testcase_16 AC 44 ms
7,444 KB
testcase_17 AC 11 ms
5,976 KB
testcase_18 AC 22 ms
6,312 KB
testcase_19 AC 6 ms
5,668 KB
testcase_20 AC 48 ms
7,496 KB
testcase_21 AC 50 ms
7,496 KB
testcase_22 AC 11 ms
5,860 KB
testcase_23 AC 4 ms
5,532 KB
testcase_24 AC 45 ms
7,484 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 5 ms
7,576 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 5 ms
7,532 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, ll> P;

int main()
{
    int n, m;
    cin>>n>>m;
    int c[17][17]={};
    for(int i=0; i<m; i++){
        int a, b, ci; cin>>a>>b>>ci;
        a--; b--;
        c[a][b]=max(c[a][b], ci);
        c[b][a]=c[a][b];
    }
    int dp[16][1<<16];
    for(int i=0; i<n; i++) fill(dp[i], dp[i]+(1<<n), -1e9);
    for(int i=0; i<n; i++) dp[i][1<<i]=0;
    int ans=0;
    for(int i=0; i<(1<<n); i++){
        for(int j=0; j<n; j++){
            if(dp[j][i]<0) continue;
            for(int k=0; k<n; k++){
                if(i&(1<<k)) continue;
                if(c[j][k]==0) continue;
                dp[k][i^(1<<k)]=max(dp[k][i^(1<<k)], dp[j][i]+c[j][k]);
            }
            ans=max(ans, dp[j][i]);
        }
    }
    cout<<ans<<endl;
    return 0;
}
0