/*ㅤ∧_∧
( ・∀・)
( つ┳⊃
ε (_)へ⌒ヽフ
( ( ・ω・)
◎―◎ ⊃ ⊃
BePhuongSuperSuwi
From TK4 - CHT
ㅤㅤ/ ⌒\____
/・ ) \
/ノへ ノ /|
ノ \\ |/_/_/*/
#include<bits/stdc++.h>
#define task "main"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define int long long
#define pb push_back
#define fi first
#define se second
#define ii pair<int,int>
#define iii pair<int,ii>
#define iv pair<ii, ii>
#define base 341
#define MASK(i) (1ll << i)
#define oo 1e18
#define isOn(x,i) ((x) & MASK(i))
#define bitOn(x,i) ((x) | MASK(i))
#define bitOff(x,i) ((x) & ~MASK(i))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define __lcm(a,b) (1ll * ((a) / __gcd((a), (b))) * (b))
using namespace std;
//using namespace __gnu_pbds;
const int maxn = 2e5 + 5;
int n, k, m, c[maxn];
vector <ii> g[maxn];
namespace giai1{
int dist[5][maxn];
void djk(int st) {
priority_queue <ii, vector <ii>, greater <ii>> q;
for (int i = 1; i <= n; i++) dist[st][i] = oo;
dist[st][c[st]] = 0;
q.push({0, c[st]});
while(!q.empty()) {
int cost = q.top().fi, z = q.top().se;
q.pop();
if (cost > dist[st][z]) continue;
for (auto e : g[z]) {
int x = e.fi, y = e.se;
if (dist[st][x] > dist[st][z] + y) {
dist[st][x] = dist[st][z] + y;
q.push({dist[st][x], x});
}
}
}
}
void solve() {
for (int i = 1; i <= k; i++)
djk(i);
int mini = oo;
for (int x = 1; x <= n; x++) {
int sum = 0;
for (int i = 1; i <= k; i++) {
if (dist[i][x] == oo) {
sum = oo;
break;
}
sum += dist[i][x];
}
mini = min(mini, sum);
}
cout << mini;
}
}
main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
if(fopen(task".inp","r")) {
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
cin >> n >> k >> m;
for (int i = 1; i <= k; i++) cin >> c[i];
for (int i = 1; i <= m; i++) {
int l, r, z;
cin >> l >> r >> z;
g[l].pb({r, z});
g[r].pb({l, z});
}
// if (k <= 3) giai1::solve();
giai1::solve();
}
컴파일 시 표준 에러 (stderr) 메시지
cities.cpp:86:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
86 | main() {
| ^~~~
cities.cpp: In function 'int main()':
cities.cpp:89:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
89 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
cities.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
90 | freopen(task".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |