Submission #1580640


Source Code Expand

Copy
#include <iostream>
#include <algorithm>
using namespace std;

int main(){
	int n, m, r;
	cin >> n >> m >> r;
	int64_t t[r];
	for(int64_t &i:t){
		cin >> i;
		i--;
	}
	sort(t, t + r);
	int64_t cost[n][n];
	fill(cost[0], cost[n], 1ll << 60);
	while(m--){
		int64_t a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		cost[a][b] = cost[b][a] = c;
	}
	for(int i = 0; i < n; i++) cost[i][i] = 0;
	for(int k = 0; k < n; k++) for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
	int64_t ans = 1ll << 60;
	do{
		int64_t tmp = 0;
		for(int i = 1; i < r; i++) tmp += cost[t[i - 1]][t[i]];
		ans = min(ans, tmp);
	}while(next_permutation(t, t + r));
	cout << ans << endl;
}

Submission Info

Submission Time
Task D - joisino's travel
User jbyxm
Language C++14 (GCC 5.4.1)
Score 400
Code Size 746 Byte
Status
Exec Time 28 ms
Memory 512 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt
All 400 / 400 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
Case Name Status Exec Time Memory
01.txt 27 ms 512 KB
02.txt 11 ms 512 KB
03.txt 11 ms 512 KB
04.txt 12 ms 512 KB
05.txt 15 ms 512 KB
06.txt 27 ms 512 KB
07.txt 28 ms 512 KB
08.txt 10 ms 512 KB
sample_01.txt 1 ms 256 KB
sample_02.txt 1 ms 256 KB
sample_03.txt 1 ms 256 KB