結果
問題 | No.807 umg tours |
ユーザー |
![]() |
提出日時 | 2019-03-16 14:59:13 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,619 bytes |
コンパイル時間 | 579 ms |
コンパイル使用メモリ | 67,212 KB |
実行使用メモリ | 17,100 KB |
最終ジャッジ日時 | 2024-07-01 22:30:41 |
合計ジャッジ時間 | 7,049 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 11 RE * 15 |
ソースコード
#include <iostream> using namespace std; typedef long long ll; int N,M,used[1010] = {}; int ok[1010][1010] = {}; ll cost[1010][1010] = {},ans[1010] = {},inf = 1e18; ll dist[10010][1010] = {};//辺iのコストを0にしたときの1からの距離の最小値 void dijkstra(int id,int a,int b){ for(int i=1;i<=N;i++){ dist[id][i] = inf; used[i] = 0; } dist[id][1] = 0; while(1){ int u = -1; for(int i=1;i<=N;i++){ if(used[i]==0 && (u==-1 || dist[id][u]>dist[id][i])){ u = i; } } used[u] = 1; if(u==-1) break; for(int i=1;i<=N;i++){ ll c = cost[u][i]; if(c==inf) continue; if((u==a && i==b) || (u==b && i==a)) c = 0; dist[id][i] = min(dist[id][i],dist[id][u]+c); } } // for(int i=1;i<=N;i++) cout << dist[id][i] << endl; } int main(){ cin >> N >> M; int a,b; ll c; for(int i=1;i<=N;i++){ ans[i] = inf; for(int j=1;j<=N;j++){ cost[i][j] = inf; } } for(int i=1;i<=M;i++){ cin >> a >> b >> c; cost[a][b] = c; cost[b][a] = c; } int cnt = 1; dijkstra(0,0,0); for(int i=1;i<=N;i++){ for(int j=1;j<=N;j++){ if(ok[j][i]==0 && cost[i][j]!=inf){ dijkstra(cnt,i,j); cnt++; ok[i][j] = 1; } } } for(int i=1;i<=N;i++){ for(int j=1;j<=M;j++){ ans[i] = min(ans[i],dist[0][i]+dist[j][i]); } cout << ans[i] << endl; } }