結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
sinsincoscos
|
| 提出日時 | 2019-03-16 14:57:00 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,686 bytes |
| コンパイル時間 | 537 ms |
| コンパイル使用メモリ | 65,964 KB |
| 実行使用メモリ | 16,976 KB |
| 最終ジャッジ日時 | 2024-07-01 22:30:33 |
| 合計ジャッジ時間 | 7,013 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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<=cnt-1;j++){
// cerr << dist[0][i] << " " << dist[j][i] << endl;
ans[i] = min(ans[i],dist[0][i]+dist[j][i]);
}
cout << ans[i] << endl;
}
}
sinsincoscos