結果
問題 |
No.788 トラックの移動
|
ユーザー |
|
提出日時 | 2019-02-09 00:23:21 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 418 ms / 2,000 ms |
コード長 | 2,189 bytes |
コンパイル時間 | 1,088 ms |
コンパイル使用メモリ | 83,260 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-15 07:01:58 |
合計ジャッジ時間 | 3,610 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 |
ソースコード
#include<iostream> #include<string> #include<iomanip> #include<cmath> #include<vector> #include<algorithm> #include<queue> using namespace std; #define int long long #define rep(i,n) for(int i = 0; i < (n); i++) #define INF ((long long)1e18) #define EPS (1e-5) #define MOD ((int)1e9+7) #define endl "\n" #define yn(f) ((f)?"Yes":"No") #define YN(f) ((f)?"YES":"NO") #define MAX 3000 typedef long long ll; typedef pair<ll,ll> P; int N, M, L; int t[MAX]; struct edge{ll to, cost;}; vector<edge> G[MAX]; ll d[MAX], V, dl[MAX]; int temp, temp2; void dijkstra(ll s){ priority_queue<P,vector<P>,greater<P>> q; fill(d,d+V, INF); d[s] = 0; q.push(P(0,s)); while(!q.empty()){ P p = q.top();q.pop(); ll v = p.second; if(d[v] < p.first) continue; temp += d[v]*t[v]*2; if(t[v]){ temp2 = min(temp2,-dl[s]-d[v]+dl[v]); } // cout<<p.first<<" ()() "<<p.second<<endl; for(edge e : G[v]){ if(d[e.to] > d[v] + e.cost){ d[e.to] = d[v] + e.cost; // cout<<v<<" e.to "<<e.to<<" "<<d[e.to]<<endl; q.push(P(d[e.to],e.to)); } } } } void dijkstraL(){ priority_queue<P,vector<P>,greater<P>> q; fill(dl,dl+V, INF); ll s = L; dl[s] = 0; q.push(P(0,s)); while(!q.empty()){ P p = q.top();q.pop(); ll v = p.second; if(dl[v] < p.first) continue; for(edge e : G[v]){ if(dl[e.to] > dl[v] + e.cost){ dl[e.to] = dl[v] + e.cost; q.push(P(dl[e.to],e.to)); } } } } signed main(){ cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(10); int ans = INF; int a, b, c, count = 0; edge e; cin>>N>>M>>L; L--; V = N; for(int i = 0; i < N; i++){ cin>>t[i]; if(t[i]) count++; } for(int i = 0; i < M; i++){ cin>>a>>b>>c; a--, b--; e.to = b, e.cost = c; G[a].push_back(e); e.to = a; G[b].push_back(e); } if(count <= 1){ cout<<0<<endl; return 0; } dijkstraL(); for(int i = 0; i < N; i++){ // cout<<"<><> "<<i<<endl; temp = 0; temp2 = 0; dijkstra(i); // cout<<i<<" "<<temp<<" "<<temp2<<" "<<dl[i]<<endl; // cout<<temp+dl[i]+temp2<<" ans"<<endl; ans = min(temp+dl[i]+temp2,ans); } cout<<ans<<endl; return 0; }