結果

問題 No.17 2つの地点に泊まりたい
ユーザー hotpepsihotpepsi
提出日時 2015-03-15 00:55:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,575 bytes
コンパイル時間 584 ms
コンパイル使用メモリ 68,396 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 02:02:02
合計ジャッジ時間 1,395 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <sstream>
#include <vector>
#include <queue>

using namespace std;

typedef long long LL;
typedef pair<LL, LL> II;
typedef pair<LL, II> III;
typedef vector<II> IIVec;
typedef priority_queue<III> Queue;

static inline int popcount_ll(LL b) {
#ifdef __GNUC__
	return __builtin_popcountll(b);
#elif _MSC_VER >= 1400 && defined(_M_AMD64)
	return (int)__popcnt64(b);
#else
	b = (b & 0x5555555555555555LL) + (b >> 1 & 0x5555555555555555LL);
	b = (b & 0x3333333333333333LL) + (b >> 2 & 0x3333333333333333LL);
	b = (b & 0x0f0f0f0f0f0f0f0fLL) + (b >> 4 & 0x0f0f0f0f0f0f0f0fLL);
	b += b >> 8;
	b += b >> 16;
	return (int)((b + (b >> 32)) & 0x7F);
#endif
}

int main(int argc, char *argv[])
{
	LL i, j, k;
	string s;
	getline(cin, s);
	int N = atoi(s.c_str());
	int S[50];
	for (int i = 0; i < N; ++i) {
		getline(cin, s);
		stringstream ss(s);
		ss >> S[i];
	}

	getline(cin, s);
	LL dist[64][64];
	int M = atoi(s.c_str());
	for (i = 0; i < N; ++i) {
		for (j = 0; j < N; ++j) {
			dist[i][j] = 1LL << 60;
		}
	}
	for (int i = 0; i < M; ++i) {
		getline(cin, s);
		stringstream ss(s);
		int a, b, c;
		ss >> a >> b >> c;
		dist[a][b] = dist[b][a] = c;
	}
	for (k = 0; k < N; ++k) {
		for (i = 0; i < N; ++i) {
			for (j = 0; j < N; ++j) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}

	LL ans = 1LL << 60;
	for (i = 1; i < N - 1; ++i) {
		for (j = 1; j < N - 1; ++j) {
			if (i != j) {
				ans = min(ans, dist[0][i] + dist[i][j] + dist[j][N - 1] + S[i] + S[j]);
			}
		}
	}
	cout << ans << endl;
	return 0;
}
0