結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー a9ua1i0n
提出日時 2022-10-14 23:26:15
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 2,394 bytes
コンパイル時間 3,102 ms
コンパイル使用メモリ 171,380 KB
実行使用メモリ 19,544 KB
最終ジャッジ日時 2024-06-26 17:20:42
合計ジャッジ時間 13,788 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35 WA * 4 TLE * 2 -- * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#if !__INCLUDE_LEVEL__
    #include __FILE__

ll dijkstra(int start, int end, vector<vector<edge<ll>>>& graph) {
    vector<ll> dist(graph.size(), 1e18);
    using node = pair<ll, pair<int, bool>>;
    priority_queue<node, vector<node>, greater<node>> pque;
    pque.push(node(0, pair<int, bool>(start, false)));
    dist[start] = 0;
    while (!pque.empty()) {
        auto cn = pque.top();
        ll cost = cn.first;
        ll index = cn.second.first;
        bool up = cn.second.second;
        pque.pop();
        if (dist[index] != cost) {
            continue;
        }
        for (auto nn: graph[index]) {
            if (up && nn.up) {
                continue;
            }
            if (dist[nn.to] <= cost + nn.cost) {
                continue;
            }
            dist[nn.to] = cost + nn.cost;
            pque.push(node(cost + nn.cost, pair<int, bool>(nn.to, nn.up)));
        }
    }
    cerr << dist[end] << "\n";
    return dist[end] <= 0 ? -dist[end] : -1;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N, M;
    cin >> N >> M;
    vector<ll> H(N);
    REP(i, N) cin >> H[i];
    vector<vector<edge<ll>>> cher(N), zelc(N);
    REP(i, M) {
        ll x, y;
        cin >> x >> y;
        x--;
        y--;
        if (H[x] > H[y]) {
            cher[x].push_back(edge<ll>(y, 0, false));
            zelc[y].push_back(edge<ll>(x, -(H[x] - H[y]), true));
        } else {
            cher[x].push_back(edge<ll>(y, -(H[y] - H[x]), true));
            zelc[y].push_back(edge<ll>(x, 0, false));
        }
    }

    cout << dijkstra(0, N - 1, cher) << "\n";
    cout << dijkstra(N - 1, 0, zelc) << "\n";

    return 0;
}

//====================temp====================
#else
    #include <bits/stdc++.h>
using namespace std;
    #define REP(i, n) for (int i = 0; i < (int)(n); i++)
    #define RREP(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
    #define REPITR(itr, ARRAY) \
        for (auto itr = (ARRAY).begin(); itr != (ARRAY).end(); ++itr)
    #define RREPITR(itr, ARRAY) \
        for (auto itr = (ARRAY).rbegin(); itr != (ARRAY).rend(); ++itr)
    #define ALL(n) (n).begin(), (n).end()
using ll = long long;
using ull = unsigned long long;
//#define int long long
template<typename T> struct edge {
    int to;
    T cost;
    bool up;
    edge() {}
    edge(int to, T cost, bool up): to(to), cost(cost), up(up) {}
};
#endif
0