結果
| 問題 |
No.17 2つの地点に泊まりたい
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-03-16 09:42:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,859 bytes |
| コンパイル時間 | 759 ms |
| コンパイル使用メモリ | 79,960 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-15 01:31:39 |
| 合計ジャッジ時間 | 1,846 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
ソースコード
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF 1<<29
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DDEBUG(x,y) cout<<#x<<": "<<x<<", "<<#y<<": "<<y<<endl
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
// refer:
// http://dai1741.github.io/maximum-algo-2012/docs/shortest-path/
typedef vector<vector<int> > Metrics;
Metrics d;
void warshall_floyd(int n) { // n:頂点数
REP(i, n) { // 経由する頂点
REP(j, n) { // 開始頂点
REP(k, n) { // 終端
d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}
}
}
}
void debugprint(int n) {
REP(i, n) {
REP(j, n) {
if (i != j && d[i][j] != INF) {
cout << i << "から" << j << "へのコスト: " << d[i][j] << endl;
}
}
}
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout.precision(16);
int n;
cin >> n;
vector<int> s(n);
REP(i, n) cin >> s[i];
d = Metrics(n, vector<int>(n, INF));
REP(i, n) d[i][i] = 0;
int m;
cin >> m;
REP(i, m) {
int from, to, cost;
cin >> from >> to >> cost;
d[from][to] = cost;
d[to][from] = cost; // if undirected graph
}
warshall_floyd(n);
int res = INF;
FOR(i, 1, n-1) {
FOR(j, 1, n-1) {
if(i == j) continue;
res = min(res, s[i] + s[j] + d[0][i] + d[i][j] + d[j][n-1]);
}
}
// cout << "**RESULT**" << endl;
cout << res << endl;
// DEBUG PRINT
// debugprint(n);
return 0;
}