Submission #3598850
Source Code Expand
/*input
4 6 3
2 3 4
1 2 4
2 3 3
4 3 1
1 4 1
4 2 2
3 1 6
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define YY cout<<"YES\n"
#define NN cout<<"NO\n"
#define yy cout<<"Yes\n"
#define nn cout<<"No\n"
#ifdef leowang
#define debug(...) do{\
fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
out<<'('<<P.F<<','<<P.S<<')';
return out;
}
//}}}
const ll maxn=205;
const ll maxlg=__lg(maxn)+2;
const ll INF64=1000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;
ll mypow(ll a,ll b){
ll res=1LL;
while(b){
if(b&1) res=res*a%MOD;
a=a*a%MOD;
b>>=1;
}
return res;
}
ll dis[maxn][maxn];
int a[maxn];
int main()
{
IOS;
REP(i,maxn) REP(j,maxn){
if(i==j) dis[i][j]=0;
else dis[i][j]=INF64;
}
int n,m,r;
cin>>n>>m>>r;
REP(i,r) cin>>a[i];
REP(i,r) a[i]--;
REP(i,m){
int A,B,C;
cin>>A>>B>>C;
A--;B--;
dis[A][B]=dis[B][A]=C;
}
REP(j,n) REP(i,n) REP(k,n){
dis[i][k]=min(dis[i][k],dis[i][j]+dis[j][k]);
}
sort(a,a+r);
ll ans=INF64;
do{
ll cur=0;
REP(i,r-1){
cur+=dis[a[i]][a[i+1]];
}
ans=min(ans,cur);
}while(next_permutation(a,a+r));
cout<<ans<<'\n';
return 0;
}
Submission Info
Submission Time |
|
Task |
D - joisino's travel |
User |
iloveUtaha |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
2273 Byte |
Status |
AC |
Exec Time |
15 ms |
Memory |
640 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
400 / 400 |
Status |
|
|
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 |
15 ms |
640 KB |
02.txt |
AC |
10 ms |
640 KB |
03.txt |
AC |
11 ms |
640 KB |
04.txt |
AC |
11 ms |
640 KB |
05.txt |
AC |
12 ms |
640 KB |
06.txt |
AC |
15 ms |
640 KB |
07.txt |
AC |
15 ms |
640 KB |
08.txt |
AC |
10 ms |
640 KB |
sample_01.txt |
AC |
1 ms |
640 KB |
sample_02.txt |
AC |
1 ms |
640 KB |
sample_03.txt |
AC |
1 ms |
640 KB |