結果
| 問題 |
No.1344 Typical Shortest Path Sum
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-16 13:16:21 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 849 bytes |
| コンパイル時間 | 1,690 ms |
| コンパイル使用メモリ | 176,860 KB |
| 実行使用メモリ | 55,936 KB |
| 最終ジャッジ日時 | 2024-11-27 13:28:46 |
| 合計ジャッジ時間 | 20,287 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 72 TLE * 5 |
ソースコード
#include<bits/stdc++.h>
#define int long long
using namespace std;
using P=pair<int,int>;
const int INF=1e18;
struct edge{int to,cost;};
bool chmin(int&a,int b){if(a>b)return a=b,true;return false;}
int N,M,dist[1<<20];
vector<edge>G[1<<20];
signed main(){
cin>>N>>M;
while(M--){
int a,b,c;cin>>a>>b>>c;
G[a-1].push_back({b-1,c});
}
for(int i=0;i<N;i++){
fill(dist,dist+N,INF);dist[i]=0;
priority_queue<P,vector<P>,greater<P>>Q;Q.push({0,i});
while(!Q.empty()){
P p=Q.top();Q.pop();
if(dist[p.second]<p.first)continue;
for(edge e:G[p.second])if(chmin(dist[e.to],p.first+e.cost)){
Q.push({dist[e.to],e.to});
}
}
int sum=0;
for(int i=0;i<N;i++)sum+=(dist[i]==INF?0:dist[i]);
cout<<sum<<endl;
}
}