結果
問題 |
No.1344 Typical Shortest Path Sum
|
ユーザー |
|
提出日時 | 2021-01-16 13:31:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,295 bytes |
コンパイル時間 | 4,154 ms |
コンパイル使用メモリ | 255,256 KB |
最終ジャッジ日時 | 2025-01-17 22:06:52 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 70 TLE * 7 |
ソースコード
#include<bits/stdc++.h> #if __has_include(<atcoder/all>) #include<atcoder/all> #endif // using namespace std; // using namespace atcoder; #define int long long #define rep(i, n) for(int i = 0;i<(int)(n);i++) #define all(v) (v).begin(),(v).end() using lint = long long; using ll = long long; using P = std::pair<int,int>; constexpr int inf = 2e18; struct edge{int to,cost;}; bool chmin(int &a,const int b) { if(a>b) { a=b; return true; } return false; } std::vector<edge> G[110]; int dijkstra(int s,int g) { int dist[110]; std::fill(dist,dist+110,inf); dist[s]=0; std::priority_queue<P,std::vector<P>,std::greater<P>> pri; pri.push({0,s}); while(!pri.empty()) { P p = pri.top();pri.pop(); int v = p.second; if(dist[v]<p.first) continue; for(auto &e:G[v]) if(chmin(dist[e.to],dist[v]+e.cost)) pri.push({dist[e.to],e.to}); } int ans = dist[g]; if(ans==inf) ans=0; return ans; } signed main(void) { int n,m; std::cin >> n >> m; rep(i, m) { int s,t,d; std::cin >> s >> t >> d; s--,t--; G[s].push_back({t,d}); } rep(i, n) { int sum = 0; rep(j, n) sum+=dijkstra(i,j); std::cout << sum << std::endl; } return 0; }