結果
問題 | No.17 2つの地点に泊まりたい |
ユーザー |
![]() |
提出日時 | 2015-08-29 20:16:55 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,886 bytes |
コンパイル時間 | 637 ms |
コンパイル使用メモリ | 79,004 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-18 15:36:29 |
合計ジャッジ時間 | 2,240 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | WA * 27 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <cstring> #include <algorithm> #include <sstream> #include <map> #include <set> #include <queue> #define REP(i,k,n) for(int i=k;i<n;i++) #define rep(i,n) for(int i=0;i<n;i++) #define INF 1<<30 #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef pair<int,int> P; struct edge { int from,to; int cost; edge(int t,int c) : to(t),cost(c) {} edge(int f,int t,int c) : from(f),to(t),cost(c) {} bool operator<(const edge &e) const { return cost < e.cost; } }; vector<edge> G[55]; int d[55]; void dijkstra(int s,int n) { priority_queue<P,vector<P>,greater<P> > que; fill(d,d+n,INF); d[s] = 0; que.push(P(0,s)); while(que.size()) { P p = que.top(); que.pop(); int v = p.second; if(d[v] < p.first) continue; rep(i,G[v].size()) { edge e = G[v][i]; if(d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; que.push(P(d[e.to],e.to)); } } } } int main() { int n; cin >> n; vector<int> w(n); rep(i,n) cin >> w[i]; int m; cin >> m; rep(i,m) { int a,b,c; cin >> a >> b >> c; G[a].push_back(edge(b,c)); G[b].push_back(edge(a,c)); } int ans = INF; REP(i,1,n-1) { REP(j,1,n-1) { if(i == j) continue; int cost = 0; dijkstra(0,n); cost += d[i]; cout << d[i] << endl; dijkstra(i,n); cost += d[j]; cout << d[j] << endl; dijkstra(j,n); cost += d[n-1]; cout << d[n-1] << endl; cost += w[i] + w[j]; ans = min(ans,cost); } } cout << ans << endl; return 0; }