結果
問題 | No.1382 Travel in Mitaru city |
ユーザー |
|
提出日時 | 2021-02-07 21:56:20 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 259 ms / 2,000 ms |
コード長 | 1,756 bytes |
コンパイル時間 | 1,284 ms |
コンパイル使用メモリ | 139,092 KB |
最終ジャッジ日時 | 2025-01-18 14:46:21 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 68 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>#include <cmath>#include <queue>#include <string>#include <map>#include <set>#include <stack>#include <tuple>#include <deque>#include <array>#include <numeric>#include <bitset>#include <iomanip>#include <cassert>#include <chrono>#include <random>#include <limits>#include <iterator>#include <functional>#include <sstream>#include <fstream>#include <complex>#include <cstring>#include <unordered_map>#include <unordered_set>using namespace std;using ll = long long;constexpr int INF = 1001001001;constexpr int mod = 1000000007;// constexpr int mod = 998244353;template<class T>inline bool chmax(T& x, T y){if(x < y){x = y;return true;}return false;}template<class T>inline bool chmin(T& x, T y){if(x > y){x = y;return true;}return false;}int main(){ios::sync_with_stdio(false);cin.tie(nullptr);int n, m, s, t;cin >> n >> m >> s >> t;--s, --t;vector<int> p(n);for(int i = 0; i < n; ++i) cin >> p[i];vector<vector<int>> g(n);for(int i = 0; i < m; ++i){int a, b;cin >> a >> b;--a, --b;g[a].emplace_back(b);g[b].emplace_back(a);}vector<int> dist(n, INF);dist[s] = 0;int X = p[s], Y = 0;using node = pair<int, int>;priority_queue<node> que;que.emplace(p[s], s);while(!que.empty()){auto [val, from] = que.top();que.pop();if(X > val) X = val, Y += 1;for(int to : g[from]){if(chmin(dist[to], dist[from] + 1)){que.emplace(p[to], to);}}}cout << Y << endl;return 0;}