提出 #4635288


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	LL N, M, R; cin >> N >> M >> R;
	VL a(R);
	FOR(i, 0, R) {
		cin >> a[i];
		a[i]--;
	}
	VVL d(N, VL(N, LINF));
	FOR(i, 0, M) {
		LL a, b, c; cin >> a >> b >> c;
		a--, b--;
		d[a][b] = d[b][a] = min(d[a][b], c);
	}
	FOR(i, 0, N) {
		d[i][i] = 0;
	}
	FOR(k, 0, N)FOR(i, 0, N)FOR(j, 0, N)d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

	LL ans = LINF;
	SORT(a);
	do {
		LL ret = 0;
		FOR(i, 0, R - 1) {
			ret += d[a[i]][a[i+1]];
		}
		ans = min(ans, ret);
	} while (next_permutation(ALL(a)));
	cout << ans << endl;

	return 0;
}

提出情報

提出日時
問題 D - joisino's travel
ユーザ Yang33
言語 C++14 (GCC 5.4.1)
得点 400
コード長 1793 Byte
結果 AC
実行時間 17 ms
メモリ 640 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 11
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
01.txt AC 17 ms 640 KiB
02.txt AC 12 ms 640 KiB
03.txt AC 12 ms 640 KiB
04.txt AC 13 ms 640 KiB
05.txt AC 13 ms 640 KiB
06.txt AC 17 ms 640 KiB
07.txt AC 17 ms 640 KiB
08.txt AC 11 ms 512 KiB
sample_01.txt AC 1 ms 256 KiB
sample_02.txt AC 1 ms 256 KiB
sample_03.txt AC 1 ms 256 KiB