結果

問題 No.1382 Travel in Mitaru city
ユーザー MisterMister
提出日時 2021-02-07 20:51:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 1,983 bytes
コンパイル時間 863 ms
コンパイル使用メモリ 90,180 KB
実行使用メモリ 11,496 KB
最終ジャッジ日時 2023-09-17 19:39:15
合計ジャッジ時間 6,478 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 28 ms
7,184 KB
testcase_07 AC 23 ms
6,264 KB
testcase_08 AC 13 ms
4,756 KB
testcase_09 AC 32 ms
7,372 KB
testcase_10 AC 29 ms
7,256 KB
testcase_11 AC 50 ms
7,856 KB
testcase_12 AC 49 ms
8,092 KB
testcase_13 AC 54 ms
8,336 KB
testcase_14 AC 43 ms
7,612 KB
testcase_15 AC 44 ms
7,700 KB
testcase_16 AC 81 ms
10,236 KB
testcase_17 AC 80 ms
10,108 KB
testcase_18 AC 78 ms
10,092 KB
testcase_19 AC 78 ms
10,128 KB
testcase_20 AC 82 ms
10,244 KB
testcase_21 AC 82 ms
10,140 KB
testcase_22 AC 86 ms
10,176 KB
testcase_23 AC 82 ms
10,120 KB
testcase_24 AC 80 ms
10,124 KB
testcase_25 AC 86 ms
10,236 KB
testcase_26 AC 80 ms
10,128 KB
testcase_27 AC 81 ms
10,072 KB
testcase_28 AC 84 ms
10,176 KB
testcase_29 AC 92 ms
10,108 KB
testcase_30 AC 89 ms
10,328 KB
testcase_31 AC 51 ms
8,196 KB
testcase_32 AC 64 ms
8,816 KB
testcase_33 AC 56 ms
8,552 KB
testcase_34 AC 37 ms
6,640 KB
testcase_35 AC 24 ms
5,596 KB
testcase_36 AC 36 ms
8,068 KB
testcase_37 AC 7 ms
4,376 KB
testcase_38 AC 39 ms
8,664 KB
testcase_39 AC 11 ms
4,384 KB
testcase_40 AC 30 ms
7,232 KB
testcase_41 AC 34 ms
7,500 KB
testcase_42 AC 40 ms
8,504 KB
testcase_43 AC 35 ms
7,700 KB
testcase_44 AC 15 ms
4,800 KB
testcase_45 AC 32 ms
7,436 KB
testcase_46 AC 19 ms
5,308 KB
testcase_47 AC 71 ms
11,088 KB
testcase_48 AC 50 ms
8,324 KB
testcase_49 AC 77 ms
11,496 KB
testcase_50 AC 31 ms
7,100 KB
testcase_51 AC 50 ms
7,972 KB
testcase_52 AC 59 ms
8,816 KB
testcase_53 AC 13 ms
4,376 KB
testcase_54 AC 25 ms
5,608 KB
testcase_55 AC 55 ms
8,560 KB
testcase_56 AC 17 ms
4,800 KB
testcase_57 AC 39 ms
6,708 KB
testcase_58 AC 7 ms
4,376 KB
testcase_59 AC 17 ms
4,852 KB
testcase_60 AC 58 ms
8,668 KB
testcase_61 AC 2 ms
4,380 KB
testcase_62 AC 1 ms
4,376 KB
testcase_63 AC 7 ms
4,384 KB
testcase_64 AC 3 ms
4,376 KB
testcase_65 AC 2 ms
4,380 KB
testcase_66 AC 2 ms
4,380 KB
testcase_67 AC 3 ms
4,376 KB
testcase_68 AC 4 ms
4,376 KB
testcase_69 AC 2 ms
4,376 KB
testcase_70 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Tools/heap_alias.hpp"

#include <queue>

template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Graph/graph.hpp"

#include <vector>

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;

    Edge() = default;
    Edge(int src, int dst, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return cost > e.cost; }
};

template <class Cost = int>
struct Graph : public std::vector<std::vector<Edge<Cost>>> {
    using std::vector<std::vector<Edge<Cost>>>::vector;

    void span(bool direct, int src, int dst, Cost cost = 1) {
        (*this)[src].emplace_back(src, dst, cost);
        if (!direct) (*this)[dst].emplace_back(dst, src, cost);
    }
};
#line 3 "main.cpp"
#include <iostream>
#include <algorithm>
#line 6 "main.cpp"

using namespace std;

void solve() {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    --s;

    vector<int> xs(n);
    for (auto& x : xs) cin >> x;

    Graph<> graph(n);
    while (m--) {
        int u, v;
        cin >> u >> v;
        graph.span(false, --u, --v);
    }

    vector<bool> vis(n, false);
    MaxHeap<pair<int, int>> heap;

    vis[s] = true;
    heap.emplace(xs[s], s);

    int xmin = xs[s], y = 0;
    while (!heap.empty()) {
        auto [x, v] = heap.top();
        heap.pop();
        if (x < xmin) {
            ++y;
            xmin = x;
        }

        for (auto e : graph[v]) {
            int u = e.dst;
            if (vis[u]) continue;

            vis[u] = true;
            heap.emplace(xs[u], u);
        }
    }

    cout << y << "\n";
}

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

    solve();

    return 0;
}
0