結果
問題 | No.1344 Typical Shortest Path Sum |
ユーザー |
|
提出日時 | 2021-12-01 04:43:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,167 bytes |
コンパイル時間 | 1,825 ms |
コンパイル使用メモリ | 195,804 KB |
最終ジャッジ日時 | 2025-01-26 02:37:34 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 77 |
ソースコード
#include <bits/stdc++.h> using namespace std; long long int dist[101]; vector <pair<int,long long int>> adj[101]; const long long int INF = 1e18; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int n,m; long long int a,b,c; cin >> n >> m; for(int i=0;i<m;i++) { cin >> a >> b >> c; a-=1; b-=1; adj[a].push_back(make_pair(b,c)); } for(int i=0;i<n;i++) { long long int res = 0; fill(dist,dist+101,INF); dist[i] = 0; for(int j=0;j<n;j++) { for(int k=0;k<n;k++) { for(auto it : adj[k]) { int next = it.first; long long int cost = it.second; if(dist[k]!=INF && dist[next] > dist[k] + cost) { dist[next] = dist[k] + cost; } } } } for(int j=0;j<n;j++) { if(dist[j]!=INF) { res += dist[j]; } } cout << res << '\n'; } return 0; }