Submission #1580431


Source Code Expand

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

int main(){
	int n, m, r;
	cin >> n >> m >> r;
	int t[r];
	for(int &i:t){
		cin >> i;
		i--;
	}
	sort(t, t + r);
	int cost[n][n];
	fill(cost[0], cost[n], 1 << 30);
	while(m--){
		int 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]);
	int ans = 1 << 30;
	do{
		int 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 0
Code Size 718 Byte
Status
Exec Time 28 ms
Memory 384 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt
All 0 / 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 384 KB
02.txt 10 ms 384 KB
03.txt 10 ms 384 KB
04.txt 12 ms 384 KB
05.txt 14 ms 384 KB
06.txt 27 ms 384 KB
07.txt 28 ms 384 KB
08.txt 10 ms 384 KB
sample_01.txt 1 ms 256 KB
sample_02.txt 1 ms 256 KB
sample_03.txt 1 ms 256 KB