結果
| 問題 | No.17 2つの地点に泊まりたい |
| コンテスト | |
| ユーザー |
小指が強い人
|
| 提出日時 | 2016-01-05 00:27:56 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 378 ms / 5,000 ms |
| コード長 | 1,797 bytes |
| 記録 | |
| コンパイル時間 | 838 ms |
| コンパイル使用メモリ | 88,068 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-12-01 16:07:45 |
| 合計ジャッジ時間 | 3,731 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 |
ソースコード
#include <iostream>
#include <queue>
#include <unordered_map>
#include <climits>
using namespace std;
typedef long long int64;
const long long MAX_COST = (LLONG_MAX >> 6);
struct Map1
{
int id;
int64 cost;
bool operator<(const Map1& m) const {
return cost > m.cost;
}
};
struct Map2
{
int64 cost = MAX_COST;
int prev = -1;
};
int s[50] = {0};
unordered_map<int, unordered_map<int, int64>> cost;
int n, m;
int64 min_cost(int start, int end) {
Map2 root[50];
for(int i = 0; i < n; i++) {
root[i].cost = MAX_COST;
root[i].prev = -1;
}
priority_queue<Map1> q;
root[start].cost = 0;
for(auto c : cost[start]) {
Map1 m = {c.first, c.second};
root[c.first].prev = start;
root[c.first].cost = c.second;
q.push(m);
}
while(!q.empty()) {
int cur = q.top().id;
q.pop();
for(auto c : cost[cur]) {
int64 d = root[cur].cost + c.second;
if(d < root[c.first].cost) {
Map1 m = {c.first, d};
q.push(m);
root[c.first].prev = cur;
root[c.first].cost = d;
}
}
}
return root[end].cost;
}
int main(void)
{
cin >> n;
for(int i = 0; i < n; i++)
cin >> s[i];
cin >> m;
for(int i = 0; i < m; i++) {
int a, b, c;
cin >> a >> b >> c;
cost[b][a] = cost[a][b] = c;
}
int64 res = MAX_COST;
for(int i = 1; i < n - 1; i++)
for(int j = 1; j < n - 1; j++) {
if(i == j) continue;
int64 t = s[i] + s[j];
t += min_cost(0, i);
t += min_cost(i, j);
t += min_cost(j, n - 1);
if(t < res)
res = t;
}
cout << res << endl;
return 0;
}
小指が強い人