結果
問題 |
No.1344 Typical Shortest Path Sum
|
ユーザー |
|
提出日時 | 2021-01-16 13:36:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,313 bytes |
コンパイル時間 | 4,055 ms |
コンパイル使用メモリ | 255,612 KB |
最終ジャッジ日時 | 2025-01-17 22:10:42 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 72 TLE * 5 |
ソースコード
#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; } int n,m; std::vector<edge> G[110]; std::vector<int> dijkstra(int s) { std::vector<int> dist(n); std::fill(all(dist),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}); } return dist; } signed main(void) { 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; for(auto p:dijkstra(i)) if(p!=inf) sum+=p; // rep(j, n) sum+=dijkstra(i,j); std::cout << sum << std::endl; } return 0; }