求调abc 362 D,玄3关,最后一个样例没过
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);
#define rep(i,x,y) for(int i=x;i<=y;i++)
const int N = 2e5 + 5;
int n, m;
int a[N];
bool vis[N];
typedef pair<long long, long long> PII;
vector <PII> v[N];
priority_queue <PII, vector<PII>, greater<PII> > q;
long long ans[N];
inline void fig() {
q.push({1, a[1]});
ans[1] = a[1];
while (!q.empty()) {
PII x = q.top();
q.pop();
if (!vis[x.first]) {
vis[x.first] = 1;
for (int j = 0; j < v[x.first].size(); j++) {
PII y = v[x.first][j];
if (!vis[y.first]) {
if (ans[y.first] > ans[x.first] + y.second + a[y.first]) {
ans[y.first] = ans[x.first] + y.second + a[y.first];
q.push({y.first, ans[y.first]});
}
}
}
}
}
}
inline void solve() {
cin >> n >> m;
rep(i, 1, n) {
cin >> a[i];
}
rep(i, 1, m) {
int x, y, z;
cin >> x >> y >> z;
v[x].push_back({y, z});
v[y].push_back({x, z});
}
for (int i = 1; i <= n; i++) {
ans[i] = LONG_LONG_MAX;
}
fig();
rep(i, 2, n) {
cout << ans[i] << " ";
}
}
signed main() {
IOS;
int T = 1;
//cin>>T;
rep(fain, 1, T) {
solve();
}
}