結果

問題 No.845 最長の切符
ユーザー toyamatoyama
提出日時 2019-06-28 21:58:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,517 bytes
コンパイル時間 739 ms
コンパイル使用メモリ 77,696 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-14 21:57:11
合計ジャッジ時間 1,996 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
using int64 = long long;
using pll = pair<int64, int64>;

struct edge { int64 cost, to; };

const int64 INF = 1ll << 60ll;
const int64 MINF = -1 * (1ll << 60ll);

int64 n, m;
vector<struct edge> graph[32];
priority_queue<pll> p_que;
int64 a, b, c;

int64 ans;

int64 max_cost[32];

int main()
{
    scanf("%lld %lld", &n, &m);

    for (int64 i = 0; i < m; i++) {
        scanf("%lld %lld %lld", &a, &b, &c);

        c = -c;

        graph[a].emplace_back((struct edge){.cost = c, .to = b});
        graph[b].emplace_back((struct edge){.cost = c, .to = a});
    }

    for (int64 i = 1; i <= n; i++) {
        for (int64 j = 1; j <= n; j++) max_cost[j] = MINF;

        max_cost[i] = INF;
        p_que.push(pll(0, i));

        while (!p_que.empty()) {
            pll state = p_que.top();
            p_que.pop();

            int64 cost = state.first;
            int64 pos = state.second;

            for (int64 j = 0; j < graph[pos].size(); j++) {
                int64 to = graph[pos][j].to;
                int64 nc = cost + graph[pos][j].cost;

                if (max_cost[to] < nc) {
                    max_cost[to] = nc;
                    p_que.push(pll(nc, to));
                }
            }
        }

        for (int i = 1; i <= n; i++) {
            if (max_cost[i] != MINF) {
                ans = max(ans, -max_cost[i]);
            }
        }
    }

    printf("%lld\n", ans);

    return 0;
}
0