Submission #2530719


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
const ll INF=1e9+7;
const ll N = 100002;
int n,m,R;
vector<int> r,ju;
int d[201][201];
int ans=INF;

int nagasa(){
	int ans=0;
	FOR(i,1,R){
		ans+=d[r[ju[i]]][r[ju[i-1]]];
	}
	return ans;
}



int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m>>R;
	FOR(i,0,R)ju.pb(i);
	r.resize(R);
	FOR(i,0,R){
		cin>>r.at(i);
		r[i]--;
	}
	FOR(i,0,201){
		FOR(j,0,201){
			d[i][j]=INF;
		}
	}
	FOR(i,0,m){
		int a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		if(d[a][b]>c){
			d[a][b]=d[b][a]=c;
		}
	}
	FOR(i,0,n){
		FOR(j,0,n){
			FOR(k,0,n){
				if(d[j][k]>d[j][i]+d[i][k])d[j][k]=d[j][i]+d[i][k];
			}
		}
	}
	ans=nagasa();
	do{
		int k=nagasa();
		if(ans>k)ans=k;
	}while(NEXTP(ju));
	pri(ans);
	return 0;
}

Submission Info

Submission Time
Task D - joisino's travel
User kenta2997
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1646 Byte
Status AC
Exec Time 17 ms
Memory 384 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 11
Set Name Test Cases
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
Case Name Status Exec Time Memory
01.txt AC 17 ms 384 KB
02.txt AC 9 ms 384 KB
03.txt AC 9 ms 384 KB
04.txt AC 13 ms 384 KB
05.txt AC 14 ms 384 KB
06.txt AC 17 ms 384 KB
07.txt AC 13 ms 384 KB
08.txt AC 8 ms 384 KB
sample_01.txt AC 1 ms 384 KB
sample_02.txt AC 1 ms 384 KB
sample_03.txt AC 1 ms 384 KB