原题
我的10pts wa+tle die码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100002, M = 500002;
const ll INF = 0x3f3f3f3f3f3f3f3f;
ll h[N], e[M], ne[M], w[M], idx, state[N], dist[N], ene[N], n, m, ans;
void add(ll a, ll b, ll c) {
e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = ++ idx;
}
void dijkstra() {
memset(dist, 0x3f, sizeof(dist));
dist[n] = 0;
for (int i = h[n]; i != -1; i = ne[i]) dist[i] = w[i];
for (int i = 1; i <= n; i ++ ) {
int t = -1;
for (int j = 1; j <= n; j ++ ) if (!state[j] && (t == -1 || dist[j] < dist[t])) t = j;
state[t] = 1;
for (int j = h[t]; j != -1; j = ne[j]) {
int i = e[j];
if (dist[i] == INF) dist[i] = w[j];
else dist[i] = min(dist[i], dist[t] + w[j]);
}
}
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i ++ ) h[i] = -1, scanf("%lld", &ene[i]);
while (m -- ) {
ll a, b, w;
scanf("%lld%lld%lld", &a, &b, &w);
add(a, b, w);
add(b, a, w);
}
dijkstra();
for (int i = 1; i <= n; i ++ ) if (dist[i] <= dist[1]) ans += ene[i];
cout << ans;
}
提问于8天前
7860