結果
| 問題 |
No.17 2つの地点に泊まりたい
|
| コンテスト | |
| ユーザー |
mukadenodaiou
|
| 提出日時 | 2018-04-06 12:37:19 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 1,838 bytes |
| コンパイル時間 | 836 ms |
| コンパイル使用メモリ | 104,520 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-15 04:07:44 |
| 合計ジャッジ時間 | 1,640 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
ソースコード
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const int mod = 1000000007;
const int INF = 1 << 30;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define pb push_back
ll ppow(ll x, ll n) {
ll ans = 1;
while (n > 0) {
if ((n & 1) == 1)ans = ans * x;
x = x * x;
n >>= 1;
x %= mod;
ans %= mod;
}
return ans;
}
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
ll sz, fact[N], inv[N];
void setinv() {
fact[0] = 1; inv[0] = 1;
for (int i = 1; i <= sz; i++) {
fact[i] = (fact[i - 1] * i) % mod; //階乗を求める
inv[i] = ppow(fact[i], (ll)mod - 2) % mod; // フェルマーの小定理で逆元を求める
}
}
ll conv(ll r) {//nCr
return fact[sz] * inv[r] % mod * inv[sz - r] % mod;
}
const ll MAXV = 55;
ll V, E,d[MAXV][MAXV];
void reset() {
rep(i, MAXV)rep(j, MAXV)d[i][j] = (i == j ? 0 : INF);
}
void warshall_floyd() {
rep(k, V)rep(i, V)rep(j, V)d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
ll s[55],ans=INF;
int main() {
cin >> V;
rep(i, V)cin >> s[i];
cin >> E;
reset();
rep(i, E) {
int s, g, c;
cin >> s >> g >> c;
d[s][g] = c; d[g][s] = c;
}
warshall_floyd();
for (int i = 1; i < V-1; ++i) {
for (int j = 1; j < V-1; ++j) {
if (i == j)continue;
ans = min(ans,(ll)d[0][i] + s[i] + s[j] + d[i][j] + d[j][V-1]);
}
}
cout << ans << endl;
}
mukadenodaiou