Submission #1578676


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/


int N, M, R;
int d[202][202];
int r[202];
#define INF INT_MAX/2
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M >> R;
    rep(i, 0, R) cin >> r[i];

    rep(i, 0, N) rep(j, 0, N) {
        if (i == j) d[i][j] = 0;
        else d[i][j] = INF;
    }
    rep(i, 0, M) {
        int a, b, c; cin >> a >> b >> c;
        a--; b--;
        d[a][b] = c;
        d[b][a] = c;
    }

    rep(k, 0, N) rep(i, 0, N) rep(j, 0, N)
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

    vector<int> v;
    rep(i, 0, R) v.push_back(r[i] - 1);
    sort(v.begin(), v.end());
    int ans = INF;
    do {
        int sm = 0;
        rep(i, 0, R - 1) sm += d[v[i]][v[i + 1]];
        ans = min(ans, sm);
    } while (next_permutation(v.begin(), v.end()));
    cout << ans << endl;
}

Submission Info

Submission Time
Task D - joisino's travel
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1830 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 16 ms 384 KB
02.txt AC 12 ms 384 KB
03.txt AC 12 ms 384 KB
04.txt AC 13 ms 384 KB
05.txt AC 13 ms 384 KB
06.txt AC 17 ms 384 KB
07.txt AC 17 ms 384 KB
08.txt AC 11 ms 384 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