結果
問題 | No.1382 Travel in Mitaru city |
ユーザー |
|
提出日時 | 2021-03-07 20:43:16 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 187 ms / 2,000 ms |
コード長 | 1,315 bytes |
コンパイル時間 | 4,122 ms |
コンパイル使用メモリ | 233,876 KB |
実行使用メモリ | 13,076 KB |
最終ジャッジ日時 | 2024-10-09 04:29:59 |
合計ジャッジ時間 | 13,048 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 68 |
ソースコード
#include <bits/stdc++.h> #define pt(sth) cout << sth << "\n" #define itr(x,c) for(auto x=c.begin();x!=c.end();x++) #define all(a) (a.begin()),(a.end()) using namespace std; #include <atcoder/all> using namespace atcoder; typedef long long ll; typedef pair<ll, ll> pll; template<class T>bool chmax(T &a, const T &b) {if(a<b) {a=b; return 1;} return 0;} template<class T>bool chmin(T &a, const T &b) {if(b<a) {a=b; return 1;} return 0;} static const ll INF=1e18; static const ll MAX=101010; //static const ll MOD=1e9+7; //static const ll MOD=998244353; //for(i=0;i<N;i++) cin>>a[i]; typedef vector<ll> v1D; typedef vector<v1D> v2D; typedef vector<v2D> v3D; int main(void) { ll i,j,k; ll N,M,S,T;cin>>N>>M>>S>>T;S--;T--; vector<ll> a(N); for(i=0;i<N;i++)cin>>a[i]; vector<ll> g[MAX]; for(i=0;i<M;i++){ ll x,y;cin>>x>>y;x--;y--; g[x].push_back(y); g[y].push_back(x); } auto solve=[&](){ ll res=0; ll X=a[S]; priority_queue<pll> q; q.push({a[S],S}); vector<ll> clr(N,0); while(q.size()){ pll p=q.top();q.pop(); ll u=p.second; ll d=p.first; if(clr[u]) continue; clr[u]=1; res+=chmin(X,d); for(auto v:g[u]) q.push({a[v],v}); } return res; }; pt(solve()); }