提出 #55605212


ソースコード 拡げる

// {{{
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using vi = vector<int>;
using pii = pair<int, int>;
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
#define debug(x...)
#define debug_arr(x...)
#ifdef LOCAL
#include "prettyprint.hpp"
#endif
// }}}

const int N = 2e5 + 10;
int head[N], e;
struct E
{
    LL w;
    int v, next;
} edge[N << 2];

void addedge(int u, int v, LL w)
{
    edge[e].w = w;
    edge[e].v = v, edge[e].next = head[u];
    head[u] = e++;
}

LL a[N];

int pre[N];
LL dis[N];
using pli = pair<LL, int>;
priority_queue<pli, vector<pli>, greater<pli> > q;
void dijkstra(int st)
{
    clr(dis, 0x3f), clr(pre, -1);
    while (!q.empty()) q.pop();

    q.push({dis[st] = a[st], st});
    while (!q.empty())
    {
        auto [du, u] = q.top();
        q.pop();
        // if (u == ed) break;
        if (du != dis[u]) continue;

        for (int i = head[u]; ~i; i = edge[i].next)
        {
            int v = edge[i].v;
            LL val = edge[i].w;
            if (dis[u] + val + a[v] < dis[v])
            {
                dis[v] = dis[u] + val + a[v];
                pre[v] = u;
                q.push({dis[v], v});
            }
        }
    }
}

int n, m;
int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif
    cin.tie(0)->sync_with_stdio(0);

    while (cin >> n >> m)
    {
        clr(head, -1), e = 0;
        for (int i = 1; i <= n; ++i) cin >> a[i];

        for (int i = 1; i <= m; ++i)
        {
            int u, v;
            LL w;
            cin >> u >> v >> w;
            addedge(u, v, w);
            addedge(v, u, w);
        }
        dijkstra(1);
        for (int i = 2; i <= n; i++)
        {
            cout << dis[i] << " ";
        }
        cout << endl;
    }

    return 0;
}

提出情報

提出日時
問題 D - Shortest Path 3
ユーザ mickeyandkaka
言語 C++ 20 (gcc 12.2)
得点 425
コード長 1965 Byte
結果 AC
実行時間 105 ms
メモリ 18124 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 425 / 425
結果
AC × 3
AC × 41
セット名 テストケース
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random-small_01.txt, 01_random-small_02.txt, 01_random-small_03.txt, 01_random-small_04.txt, 01_random-small_05.txt, 01_random-small_06.txt, 01_random-small_07.txt, 01_random-small_08.txt, 01_random-small_09.txt, 01_random-small_10.txt, 01_random-small_11.txt, 01_random-small_12.txt, 01_random-small_13.txt, 01_random-small_14.txt, 01_random-small_15.txt, 02_random-large_01.txt, 02_random-large_02.txt, 02_random-large_03.txt, 02_random-large_04.txt, 02_random-large_05.txt, 02_random-large_06.txt, 02_random-large_07.txt, 02_random-large_08.txt, 02_random-large_09.txt, 02_random-large_10.txt, 02_random-large_11.txt, 02_random-large_12.txt, 02_random-large_13.txt, 02_random-large_14.txt, 02_random-large_15.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt, 03_handmade_05.txt, 03_handmade_06.txt, 03_handmade_07.txt, 03_handmade_08.txt
ケース名 結果 実行時間 メモリ
00_sample_01.txt AC 2 ms 6504 KiB
00_sample_02.txt AC 2 ms 6720 KiB
00_sample_03.txt AC 2 ms 6516 KiB
01_random-small_01.txt AC 3 ms 6652 KiB
01_random-small_02.txt AC 3 ms 6532 KiB
01_random-small_03.txt AC 2 ms 6508 KiB
01_random-small_04.txt AC 3 ms 6644 KiB
01_random-small_05.txt AC 40 ms 12084 KiB
01_random-small_06.txt AC 9 ms 7856 KiB
01_random-small_07.txt AC 6 ms 7356 KiB
01_random-small_08.txt AC 30 ms 10740 KiB
01_random-small_09.txt AC 2 ms 6620 KiB
01_random-small_10.txt AC 17 ms 8528 KiB
01_random-small_11.txt AC 4 ms 7048 KiB
01_random-small_12.txt AC 9 ms 7816 KiB
01_random-small_13.txt AC 42 ms 12156 KiB
01_random-small_14.txt AC 3 ms 6496 KiB
01_random-small_15.txt AC 12 ms 8304 KiB
02_random-large_01.txt AC 52 ms 11012 KiB
02_random-large_02.txt AC 101 ms 14660 KiB
02_random-large_03.txt AC 6 ms 7044 KiB
02_random-large_04.txt AC 100 ms 14560 KiB
02_random-large_05.txt AC 67 ms 13516 KiB
02_random-large_06.txt AC 99 ms 14652 KiB
02_random-large_07.txt AC 84 ms 13444 KiB
02_random-large_08.txt AC 104 ms 14564 KiB
02_random-large_09.txt AC 48 ms 11572 KiB
02_random-large_10.txt AC 102 ms 14668 KiB
02_random-large_11.txt AC 97 ms 14252 KiB
02_random-large_12.txt AC 105 ms 14600 KiB
02_random-large_13.txt AC 89 ms 13820 KiB
02_random-large_14.txt AC 100 ms 14588 KiB
02_random-large_15.txt AC 52 ms 12796 KiB
03_handmade_01.txt AC 84 ms 14496 KiB
03_handmade_02.txt AC 75 ms 14416 KiB
03_handmade_03.txt AC 90 ms 18124 KiB
03_handmade_04.txt AC 48 ms 12876 KiB
03_handmade_05.txt AC 72 ms 15332 KiB
03_handmade_06.txt AC 70 ms 15092 KiB
03_handmade_07.txt AC 3 ms 6548 KiB
03_handmade_08.txt AC 2 ms 6468 KiB