#include <bits/stdc++.h>
// #define MULTI_TEST_CASE
// #define TEST_TEXT
using namespace std;
#define ll long long
#define MAX(a, b) (a) = max((a), (b))
#define MIN(a, b) (a) = min((a), (b))
#define all(a) (a).begin(), (a).end()
#define sortedpair(a, b) {min((a), (b)), max((a), (b))}
const ll MOD = 1e9+7;
struct edge {
int to, w;
};
int n, k, m;
vector<vector<edge>> v;
vector<int> w;
vector<ll> dijkstra(int start){
vector<ll> d1(n, 1e18);
d1[start] = 0;
priority_queue<pair<ll, int>> q;
q.push({0, start});
while(!q.empty()){
ll d = -q.top().first;
int c = q.top().second;
q.pop();
if(d > d1[c])continue;
for(auto&i : v[c]){
if(d + i.w < d1[i.to]){
d1[i.to] = d + i.w;
q.push({-d1[i.to], i.to});
}
}
}
return d1;
}
void solve(){
cin>>n>>k>>m;
w.assign(k, 0);
for(int&i:w){cin>>i; i--;}
v.assign(n, {});
for(int i = 0; i < m; i++){
int a, b, c; cin>>a>>b>>c; a--; b--;
v[a].push_back({b, c});
v[b].push_back({a, c});
}
vector<vector<ll>> d(n);
for(int i = 0; i < n; i++){
d[i] = dijkstra(i);
}
ll ans = 1e18;
for(int i = 0; i < n; i++){
for(int j = 0; j <= i; j++){
for(int k = 0; k < 15; k++){
ll c = d[i][j];
if((k>>0)&1)c += d[w[0]][i];
else c += d[w[0]][j];
if((k>>1)&1)c += d[w[1]][i];
else c += d[w[1]][j];
if((k>>2)&1)c += d[w[2]][i];
else c += d[w[2]][j];
if((k>>3)&1)c += d[w[3]][i];
else c += d[w[3]][j];
MIN(ans, c);
}
}
}
cout<<ans<<endl;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int _t = 1;
#ifdef MULTI_TEST_CASE
cin >> _t;
#endif
for(int _i = 0; _i < _t; _i++){
#ifdef TEST_TEXT
cout<<"Case #"<<_i+1<<": ";
#endif
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6054 ms |
142552 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
162 ms |
8216 KB |
Output is correct |
2 |
Correct |
163 ms |
8320 KB |
Output is correct |
3 |
Correct |
65 ms |
8132 KB |
Output is correct |
4 |
Correct |
57 ms |
2376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6040 ms |
143072 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6021 ms |
142300 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |