結果
問題 | No.1382 Travel in Mitaru city |
ユーザー |
|
提出日時 | 2021-02-07 20:51:24 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 88 ms / 2,000 ms |
コード長 | 1,983 bytes |
コンパイル時間 | 929 ms |
コンパイル使用メモリ | 88,168 KB |
最終ジャッジ日時 | 2025-01-18 13:58:58 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 68 |
ソースコード
#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; }