Submission #1583207
Source Code Expand
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF 1<<29
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back
#define _DEBUG(x) cout<<#x<<": "<<x<<endl
#define _DDEBUG(x,y) cout<<#x<<": "<<x<<", "<<#y<<": "<<y<<endl
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
// refer:
// http://dai1741.github.io/maximum-algo-2012/docs/shortest-path/
typedef vector<vector<ll> > Metrics;
Metrics d;
void warshall_floyd(int n) { // n:頂点数
REP(i, n) { // 経由する頂点
REP(j, n) { // 開始頂点
REP(k, n) { // 終端
d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}
}
}
}
void debugprint(int n) {
REP(i, n) {
REP(j, n) {
if (i != j && d[i][j] != INF) {
cout << i << "から" << j << "へのコスト: " << d[i][j] << endl;
}
}
}
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout.precision(16);
int n, m, r;
cin >> n >> m >> r;
n++;
d = Metrics(n, vector<ll>(n, 100000000000000));
REP(i, n) d[i][i] = 0;
vector<int> goal(r);
REP(i, r) cin >> goal[i];
sort(goal.begin(), goal.end());
REP(i, m) {
int from, to;
ll cost;
cin >> from >> to >> cost;
d[from][to] = cost;
d[to][from] = cost; // if undirected graph
}
warshall_floyd(n);
ll ans = 1000000000000000;
do {
ll t = 0;
REP(i, r-1) {
t += d[ goal[i] ][ goal[i+1] ];
}
ans = min(ans, t);
} while(next_permutation(goal.begin(), goal.end()));
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
D - joisino's travel |
User |
yumechi |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
2040 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 |
11 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 |
512 KB |
sample_01.txt |
AC |
1 ms |
256 KB |
sample_02.txt |
AC |
1 ms |
256 KB |
sample_03.txt |
AC |
1 ms |
256 KB |