結果

問題 No.1382 Travel in Mitaru city
ユーザー norikamenorikame
提出日時 2021-02-11 21:49:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,211 bytes
コンパイル時間 2,329 ms
コンパイル使用メモリ 210,944 KB
実行使用メモリ 108,868 KB
最終ジャッジ日時 2023-09-25 11:27:00
合計ジャッジ時間 7,860 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
#define v(t) vector<t>
#define p(t) pair<t, t>
#define p2(t, s) pair<t, s>
#define vp(t) v(p(t))

#define rep(i, n) for (int i=0,i##_len=((int)(n)); i<i##_len; ++i)
#define rep2(i, a, n) for (int i=((int)(a)),i##_len=((int)(n)); i<=i##_len; ++i)
#define repr(i, n) for (int i=((int)(n)-1); i>=0; --i)
#define rep2r(i, a, n) for (int i=((int)(n)),i##_len=((int)(a)); i>=i##_len; --i)

#define repi(itr, c) for (__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); ++itr)
#define repir(itr, c) for (__typeof((c).rbegin()) itr=(c).rbegin(); itr!=(c).rend(); ++itr)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define eb emplace_back

#define INF (1e9)
#define LINF (1e18)
#define PI (acos(-1))
#define EPS (1e-7)
#define DEPS (1e-10)

int main(){
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    --s; --t;
    v(int) pi(n);
    rep(i, n) cin >> pi[i];
    v(v(int)) g(n);
    rep(i, m) {
        int ai, bi;
        cin >> ai >> bi;
        ai--; bi--;
        g[ai].pb(bi);
        g[bi].pb(ai);
    }
    vp(int) dist(n, {-1,-1});
    priority_queue<p2(p(int),int)> que;
    que.emplace(make_pair(pi[s],0), s);
    dist[s] = { pi[s], 0 };
    while (!que.empty()) {
        auto p1 = que.top(); que.pop();
        int vx = p1.first.first, vy = p1.first.second, vi = p1.second;
        if (dist[vi] != p(int){vx,vy}) continue;
        rep(i, sz(g[vi])) {
            int ni = g[vi][i], ny, nx;
            if (vx > pi[ni]) {
                ny = vy + 1;
                nx = pi[ni];
            }
            else {
                ny = vy;
                nx = vx;
            }
            if (dist[ni].second<ny||(dist[ni].second>=ny&&dist[ni].first<nx)) {
                que.emplace(make_pair(nx, ny), ni);
                dist[ni] = { nx, ny };
            }
        }
    }
    cout << dist[t].second << endl;
    return 0;
}
0