結果

問題 No.845 最長の切符
ユーザー tomarint2tomarint2
提出日時 2019-06-28 22:30:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,615 bytes
コンパイル時間 991 ms
コンパイル使用メモリ 94,940 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-14 22:18:02
合計ジャッジ時間 2,225 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 2 ms
4,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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

void solve()
{
    ll N,M,i;

    cin >> N >> M;
    vector<vector<pll>> to(N);
    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) {
        vector<ll> score(N,-1);
        priority_queue<tuple<ll,ll,ll>> q;
        q.push(make_tuple(0,i,0));
        while (!q.empty()) {
            auto item = q.top();
            q.pop();
            ll sc = get<0>(item);
            ll loc = get<1>(item);
            ll arr = get<2>(item);
            if (score[loc] >= sc) {
                continue;
            }
            if ((arr & (1LL << loc)) != 0) {
                continue;
            }
            arr |= (1LL << loc);
            score[loc] = sc;
            for (auto t : to[loc]) {
                q.push(make_tuple(sc + t.second, t.first, arr));
            }
        }
        for1(j,N) {
            ans = max(ans, score[j]);
        }
    }
    cout << ans << endl;
}

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