結果

問題 No.1301 Strange Graph Shortest Path
ユーザー tarattata1tarattata1
提出日時 2020-11-27 22:41:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,495 bytes
コンパイル時間 973 ms
コンパイル使用メモリ 94,912 KB
実行使用メモリ 12,932 KB
最終ジャッジ日時 2023-10-09 21:39:15
合計ジャッジ時間 6,679 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 WA -
testcase_03 AC 81 ms
8,480 KB
testcase_04 AC 146 ms
12,528 KB
testcase_05 AC 78 ms
8,488 KB
testcase_06 AC 126 ms
11,200 KB
testcase_07 AC 110 ms
10,252 KB
testcase_08 AC 79 ms
8,464 KB
testcase_09 AC 116 ms
11,020 KB
testcase_10 WA -
testcase_11 AC 124 ms
11,120 KB
testcase_12 AC 128 ms
11,436 KB
testcase_13 AC 102 ms
9,836 KB
testcase_14 AC 110 ms
10,460 KB
testcase_15 AC 101 ms
10,300 KB
testcase_16 AC 141 ms
12,704 KB
testcase_17 AC 113 ms
10,308 KB
testcase_18 AC 100 ms
9,780 KB
testcase_19 AC 130 ms
11,404 KB
testcase_20 AC 133 ms
11,748 KB
testcase_21 AC 110 ms
10,264 KB
testcase_22 AC 131 ms
12,060 KB
testcase_23 AC 103 ms
9,960 KB
testcase_24 AC 130 ms
11,732 KB
testcase_25 AC 133 ms
11,936 KB
testcase_26 AC 110 ms
10,588 KB
testcase_27 AC 117 ms
10,972 KB
testcase_28 AC 82 ms
8,700 KB
testcase_29 WA -
testcase_30 AC 126 ms
11,384 KB
testcase_31 AC 134 ms
12,092 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 106 ms
11,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>
#pragma warning(disable:4996) 

//#define ATCODER
#ifdef ATCODER
#include <atcoder/all>
#endif

typedef long long ll;
typedef unsigned long long ull;
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;


using namespace std;
#ifdef ATCODER
using namespace atcoder;
#endif

vector<int> pre;
vector<int> preedge;
vector<int> c, d;

typedef pair<ll, int> P;
vector<ll> dijkstra(int s, const vector<vector<pair<int, int> > >& G) {
    priority_queue< P, vector<P>, greater<P> > que;
    vector<ll> d(G.size(), LINF);
    d[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        int curr = que.top().second;
        ll  dcurr = que.top().first;
        que.pop();
        if (d[curr] < dcurr) continue;
        int i;
        for (i = 0; i < (int)G[curr].size(); i++) {
            int next = G[curr][i].first;
            int edge = G[curr][i].second;;
            ll  dist = c[edge];
            if (d[next] > d[curr] + dist) {
                d[next] = d[curr] + dist;
                que.push(P(d[next], next));
                pre[next] = curr;
                preedge[next] = edge;
            }
        }
    }
    return d;
}

void solve()
{
    int n, m;
    scanf("%d%d", &n, &m);
    vector<int> u(m), v(m);
    c.resize(m); d.resize(m);
    vector<vector<pair<int, int> > > g(n);    // to, edge
    pre.resize(n); preedge.resize(n);
    int i;
    for (i = 0; i < m; i++) {
        scanf("%d%d%d%d", &u[i], &v[i], &c[i], &d[i]);
        u[i]--; v[i]--;
        g[u[i]].push_back(make_pair(v[i], i));
        g[v[i]].push_back(make_pair(u[i], i));
    }
    vector<ll> dist0 = dijkstra(0, g);

    int curr = n - 1;
    while (curr > 0) {
        c[preedge[curr]]=d[preedge[curr]];
        curr = pre[curr];
    }

    vector<ll> dist1= dijkstra(0, g);
    ll ans = dist0[n - 1] + dist1[n - 1];
    printf("%lld\n", ans);

    return;
}

int main()
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for (t = 0; t < T; t++) {
        //printf("Case #%d: ", t + 1);
        solve();
    }
#endif
    return 0;
}
0