結果

問題 No.845 最長の切符
コンテスト
ユーザー 梧桐
提出日時 2026-06-19 17:57:24
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,692 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 693 ms
コンパイル使用メモリ 90,296 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2026-06-19 17:57:28
合計ジャッジ時間 2,168 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 3 WA * 24
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:12:16: warning: integer constant is too large for its type
   12 | const LL INF = 0x3f3f3f3f3f3f3f3f3f3f3f3f3f3f3f3f;
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 26, M = 2010;
const LL INF = 0x3f3f3f3f3f3f3f3f3f3f3f3f3f3f3f3f;

bool st[N];
queue<PII> q;
LL g[N][N], ans;
int n, m, h[N], e[M], ne[M], w[M], idx;

void Add(int x, int y, int z) {
    e[idx] = y, w[idx] = z, ne[idx] = h[x], h[x] = idx++;
}

void Floyd() {
    for (int k = 0; k < N; ++k) {
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
}

int main() {
    // freopen("ticket.in", "r", stdin);
    // freopen("ticket.out", "w", stdout);

    scanf("%d%d", &n, &m);
    memset(h, -1, sizeof(h));
    memset(g, 0x3f, sizeof(g));
    for (int i = 1; i <= n; ++i) g[i][i] = 0;
    for (int i = 1, a, b, c; i <= m; ++i) {
        scanf("%d%d%d", &a, &b, &c);
        Add(a, b, c);
        Add(b, a, c);
        g[a][b] = g[b][a] = c;
    }

    Floyd();

    for (int i = 1; i <= n; ++i) {
        if (!st[i]) {
            st[i] = true;
            int p1 = 0, ma = 0;
            for (int j = 1; j <= n; ++j) {
                if (g[i][j] < INF) st[j] = true;
                if (ma < g[i][j]) {
                    ma = g[i][j];
                    p1 = j;
                }
            }
            int p2 = 0;
            ma = 0;
            for (int j = 1; j <= n; ++j) {
                if (ma < g[p1][j]) {
                    ma = g[p1][j];
                    p2 = j;
                }
            }
            ans = max(ans, g[p1][p2]);
        }
    }

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

    return 0;
}
0