#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Tools/heap_alias.hpp" #include template using MaxHeap = std::priority_queue; template using MinHeap = std::priority_queue, std::greater>; #line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Graph/graph.hpp" #include template 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& e) const { return cost < e.cost; } bool operator>(const Edge& e) const { return cost > e.cost; } }; template struct Graph : public std::vector>> { using std::vector>>::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 #include #line 6 "main.cpp" using namespace std; void solve() { int n, m, s, t; cin >> n >> m >> s >> t; --s; vector 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 vis(n, false); MaxHeap> 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; }