Submission #1789983
Source Code Expand
#include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; #define INF (1<<29) int main() { int n, m, r; cin >> n >> m >> r; vector<int> R(r); for (int i = 0; i < r; i++) { int a; cin >> a; R[i] = a - 1; } int M[209][209]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { /* if (i == j) { M[i][j] = 0; } else { */ if (i != j) { M[i][j] = INF; } } } for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; a--; b--; if (M[a][b] > c) { M[a][b] = M[b][a] = c; } } for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { M[i][j] = min(M[i][j], M[i][k] + M[k][j]); } } } sort(R.begin(), R.end()); long long ans = 1e9; do { long long sum = 0; for (int i = 0; i < (r-1); i++) { sum += M[ R[i] ][ R[i+1] ]; } ans = min(sum ,ans); } while ( next_permutation(R.begin(), R.end()) ); printf("%lld\n", ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | A - September 9 |
User | nomi |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1350 Byte |
Status | WA |
Exec Time | 2 ms |
Memory | 384 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 100 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample01.txt, sample02.txt, sample03.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, sample01.txt, sample02.txt, sample03.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | WA | 2 ms | 384 KB |
02.txt | WA | 1 ms | 256 KB |
03.txt | WA | 1 ms | 256 KB |
04.txt | WA | 1 ms | 256 KB |
05.txt | WA | 1 ms | 256 KB |
06.txt | WA | 1 ms | 256 KB |
sample01.txt | WA | 1 ms | 256 KB |
sample02.txt | WA | 2 ms | 256 KB |
sample03.txt | WA | 2 ms | 384 KB |