結果

問題 No.17 2つの地点に泊まりたい
ユーザー TwizzTwizz
提出日時 2017-05-15 11:29:10
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 964 bytes
コンパイル時間 1,165 ms
コンパイル使用メモリ 145,112 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 13:10:57
合計ジャッジ時間 3,788 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 2 ms
4,356 KB
testcase_17 AC 1 ms
4,352 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 2 ms
4,348 KB
testcase_26 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"
//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
const ll mod = 2000000;

int d[52][52];
int n;

void warshall_floyd() {
	rep(k, 0, n) {
		rep(i, 0, n) {
			rep(j, 0, n) {
				if(d[i][j]>d[i][k]+d[k][j]){
					d[i][j] = d[i][k] + d[k][j];
					d[j][i] = d[i][j];
				}
			}
		}
	}
}

int main() {
	int m;
	int s[52],a[52],b[52],c[52];
	cin >> n;
	rep(i, 0, n)cin >> s[i];
	cin >> m;
	rep(i, 0, m)cin >> a[i] >> b[i] >> c[i];
	rep(i, 0, n) {
		rep(j, 0, n) {
			if (i == j) {
				d[i][j] = 0; d[j][i] = 0;
			}
			else {
				d[i][j] = mod; d[j][i] = mod;
			}
		}
	}
	rep(i, 0, m) { d[a[i]][b[i]] = c[i]; d[b[i]][a[i]] = c[i]; }
	warshall_floyd();
	int ans = INT_MAX;
	rep(i, 1, n-1) {
		rep(j, 1, n-1) {
			if (i == j)continue;
			int cost = 0;
			cost = d[0][i] + d[i][j] + d[j][n - 1] + s[i] + s[j];
			ans = min(ans, cost);
		}
	}
	print(ans);
}
0