結果

問題 No.845 最長の切符
ユーザー tomarint2tomarint2
提出日時 2019-06-28 23:19:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,246 bytes
コンパイル時間 720 ms
コンパイル使用メモリ 83,628 KB
実行使用メモリ 7,624 KB
最終ジャッジ日時 2023-09-14 22:41:46
合計ジャッジ時間 6,410 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 659 ms
4,376 KB
testcase_11 AC 107 ms
4,376 KB
testcase_12 AC 15 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 TLE -
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 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0
#define INF 1e18

ll N,M;
vector<vector<pll>> to(16);

ll dfs(ll sc, ll loc, ll arr)
{
    if ((arr & (1LL << loc)) != 0) {
        return -INF;
    }
    arr |= (1LL << loc);
    ll ret = sc;
    for (auto t : to[loc]) {
        if ((arr & (1LL << t.first)) == 0) {
            ret = max(ret, dfs(sc + t.second, t.first, arr));
        }
    }
    return ret;
}

void solve()
{
    cin >> N >> M;
    for1(i,M) {
        ll a,b,c;
        cin >> a >> b >> c;
        --a; --b;
        to[a].push_back(make_pair(b,c));
        to[b].push_back(make_pair(a,c));
    }
    ll ans = 0;

    // 駅iから出発する
    for1(i,N) {
        ans = max(ans,dfs(0,i,0));
    }
    cout << ans << endl;
}

int main()
{
    do {
        solve();
    } while (DEBUG);
}
0