結果
問題 |
No.1344 Typical Shortest Path Sum
|
ユーザー |
![]() |
提出日時 | 2021-01-19 18:21:41 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,579 bytes |
コンパイル時間 | 863 ms |
コンパイル使用メモリ | 101,048 KB |
実行使用メモリ | 77,544 KB |
最終ジャッジ日時 | 2024-12-17 14:43:23 |
合計ジャッジ時間 | 18,749 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 WA * 41 TLE * 5 |
ソースコード
/* -*- coding: utf-8 -*- * * 1344.cc: No.1344 Typical Shortest Path Sum - yukicoder */ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility> #include<complex> #include<functional> using namespace std; /* constant */ const int MAX_N = 100; const long long LINF = 1LL << 62; /* typedef */ typedef long long ll; typedef pair<int,ll> pil; typedef pair<ll,int> pli; typedef vector<pil> vpil; /* global variables */ vpil nbrs[MAX_N]; ll ds[MAX_N]; /* subroutines */ void dijkstra(int n, int st) { fill(ds, ds + n, LINF); ds[st] = 0; priority_queue<pil> q; q.push(pli(0, st)); while (! q.empty()) { pli u = q.top(); q.pop(); ll ud = -u.first; int ui = u.second; if (ds[ui] != ud) continue; vpil &nbru = nbrs[ui]; for (vpil::iterator vit = nbru.begin(); vit != nbru.end(); vit++) { int vi = vit->first; ll vd = ud + vit->second; if (ds[vi] > vd) { ds[vi] = vd; q.push(pli(-vd, vi)); } } } } /* main */ int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { int u, v; ll d; scanf("%d%d%lld", &u, &v, &d); u--, v--; nbrs[u].push_back(pil(v, d)); } for (int st = 0; st < n; st++) { dijkstra(n, st); ll sum = 0; for (int i = 0; i < n; i++) if (ds[i] < LINF) sum += ds[i]; printf("%lld\n", sum); } return 0; }