結果
| 問題 |
No.1344 Typical Shortest Path Sum
|
| コンテスト | |
| ユーザー |
ぷら
|
| 提出日時 | 2021-01-16 13:17:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,274 bytes |
| コンパイル時間 | 1,796 ms |
| コンパイル使用メモリ | 182,740 KB |
| 実行使用メモリ | 57,588 KB |
| 最終ジャッジ日時 | 2024-11-27 13:31:59 |
| 合計ジャッジ時間 | 19,650 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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<map<int,int>>road(N);
for(int i = 0; i < M; i++) {
int s,t,d;
cin >> s >> t >> d;
s--;t--;
if(!road[s].count(t)) {
road[s][t] = d;
}
road[s][t] = min(road[s][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(P X:road[x.second]) {
if(dist[X.first] > x.first+X.second) {
dist[X.first] = x.first+X.second;
que.push({dist[X.first],X.first});
}
}
}
int ans = 0;
for(int j = 0; j < N; j++) {
if(dist[j] == INF) {
continue;
}
ans += dist[j];
}
cout << ans << endl;
}
}
ぷら