結果

問題 No.845 最長の切符
ユーザー treeonetreeone
提出日時 2019-06-28 22:04:37
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 3,000 ms
コード長 1,155 bytes
コンパイル時間 1,955 ms
コンパイル使用メモリ 199,688 KB
実行使用メモリ 13,776 KB
最終ジャッジ日時 2023-09-14 22:00:07
合計ジャッジ時間 3,401 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 12 ms
7,372 KB
testcase_16 AC 42 ms
13,776 KB
testcase_17 AC 11 ms
7,464 KB
testcase_18 AC 22 ms
9,672 KB
testcase_19 AC 6 ms
4,752 KB
testcase_20 AC 47 ms
13,600 KB
testcase_21 AC 49 ms
13,512 KB
testcase_22 AC 11 ms
7,668 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 42 ms
13,524 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 8 ms
13,540 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 8 ms
13,700 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int d[20][20];
int dp[1 << 16][20];

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    rep(i, 0, n) rep(j, 0, n) d[i][j] = -1;
    rep(i, 0, m){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        d[a][b] = max(d[a][b], c);
        d[b][a] = max(d[b][a], c);
    }
    rep(i, 0, 1 << n) rep(j, 0, n) dp[i][j] = -1;
    rep(i, 0, n) dp[1 << i][i] = 0;
    for(int mask = 0; mask < (1LL << n); mask++){
        for(int i = 0; i < n; i++){
            if(dp[mask][i] == -1) continue;
            for(int j = 0; j < n; j++){
                if(mask & (1LL << j)) continue;
                if(d[i][j] == -1) continue;
                dp[mask | (1LL << j)][j] = max(dp[mask | (1LL << j)][j], dp[mask][i] + d[i][j]);
            }
        }
    }
    int ans = 0;
    rep(i, 0, 1 << n){
        rep(j, 0, n){
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans << endl;
}
0