結果
| 問題 |
No.1344 Typical Shortest Path Sum
|
| コンテスト | |
| ユーザー |
ぷら
|
| 提出日時 | 2021-01-16 13:12:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,314 bytes |
| コンパイル時間 | 1,591 ms |
| コンパイル使用メモリ | 177,380 KB |
| 実行使用メモリ | 74,336 KB |
| 最終ジャッジ日時 | 2024-11-27 13:22:58 |
| 合計ジャッジ時間 | 19,158 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 72 TLE * 5 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 3e18+7;
int mod = 1e9+7;
int dx[] = {1, 0,-1, 0, 1, 1,-1,-1};
int dy[] = {0, 1, 0,-1, 1,-1, 1,-1};
signed main() {
int N,M;
cin >> N >> M;
vector<vector<P>>road(N);
for(int i = 0; i < M; i++) {
int s,t,d;
cin >> s >> t >> d;
s--;t--;
road[s].push_back({t,d});
}
for(int i = 0; i < N; i++) {
vector<int>dist(N,INF);
dist[i] = 0;
priority_queue<P,vector<P>,greater<P>>que;
que.push({0,i});
while (!que.empty()) {
P x = que.top();
que.pop();
if(x.first > dist[x.second]) {
continue;
}
for(int j = 0; j < road[x.second].size(); j++) {
if(dist[road[x.second][j].first] > x.first+road[x.second][j].second) {
dist[road[x.second][j].first] = x.first+road[x.second][j].second;
que.push({dist[road[x.second][j].first],road[x.second][j].first});
}
}
}
int ans = 0;
for(int i = 0; i < N; i++) {
if(dist[i] == INF) {
continue;
}
ans += dist[i];
}
cout << ans << endl;
}
}
ぷら