Problem:
Omnes Viae Yokohamam Ducunt?
"
Omnes viae Romam ducunt
" is an old Latin proverb meaning "all roads lead to Rome." It is still
 desirable to have access to the capital from all the regions of a country.
The Kingdom of Kanagawa has a number of cities, including the capital city, Yokohama. The Ministry
 of Transport of the Kingdom is now planning to construct a highway network, connecting all those cities.
There are a number of candidate highway segments, each of which directly connects two cities. A
 highway network is a set of highway segments chosen from the candidates. The following are required
 for the highway network.
All the cities should be connected via highway segments in the network, directly or indirectly.
To save the budget, the minimum number of segments should be chosen. In other words, the highway network should not be redundant; the path connecting any pair of cities should be unique.
The highway network should be made resistant to natural disasters, with the limited budget. The emphasis is placed on accessibility to and from the capital city, Yokohama. As the network is planned to
 be non-redundant, when one segment becomes unavailable due to a natural disaster, some of the cities
become inaccessible from Yokohama.
We want to minimize the total
risk severity
, defined as follows.
The cities in the Kingdom have different populations and economic scales, based on which, the cities
 are assigned certain
significance values
. Given a highway network, the
damage
suffered from a natural disaster on a single segment in the network is estimated by the sum of the significance values of such cities made inaccessible from Yokohama.
Vulnerabilities
to natural disasters are assessed for all the candidate segments. The
risk severity
of a segment is calculated as the product of its estimated damage and vulnerability. The total risk severity of the network is estimated as the sum of the risk severities of all the segments in the network.
Your task is to determine the minimum total risk severity by appropriately designing the highway net
 work.
Input
The input consists of a single test case of the following format.
$n$ $m$
$p_1$ ... $p_n$
$u_1$ $v_1$ $q_1$
$\vdots$
$u_m$ $v_m$ $q_m$
The first two integers $n$ and $m$ ($2 \leq n \leq 10^5, 1 \leq m \leq 3 \times 10^5$) describe the numbers of cities and highway segment candidates, respectively. The cities are numbered from 1 to $n$, with Yokohama numbered 1. The second line contains $n$ integers $p_1,...,p_n$, where each $p_i$ ($1 \leq p_i \leq 1000$) represents the significance value assigned to the city numbered $i$.
The following $m$ lines describe the candidate highway segments. The $j$-th line of them contains three integers $u_j$, $v_j$, and $q_j$ ($1 \leq u_j < v_j \leq n,1 \leq q_j \leq 10^6$), meaning that the segment candidate connecting cities numbered $u_j$ and $v_j$ has the vulnerability $q_j$. Each pair ($u_j$,$v_j$) appears at most once in the input.
It is guaranteed that one or mor
...(truncated)

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
using ll=long long;
using P=pair<ll,ll>;

const ll INF=1001001001001001001;

int main(){
    ll n,m;cin>>n>>m;
    vector<ll> p(n);
    rep(i,n)cin>>p[i];

    vector<vector<P>> g(n);
    rep(i,m){
        ll u,v,q;cin>>u>>v>>q;u--;v--;
        g[u].push_back({v,q});
        g[v].push_back({u,q});
    }

    vector<ll> dist(n,INF);
    dist[0]=0;

    priority_queue<P,vector<P>,greater<P>> q;
    q.push({0,0});
    while(!q.empty()){
        auto[c,v]=q.top();q.pop();
        if(c>dist[v])continue;
        for(auto[nex,d]:g[v]){
            if(dist[v]+d>=dist[nex])continue;
            dist[nex]=dist[v]+d;
            q.push({dist[nex],nex});
        }
    }

    ll ans=0;
    rep(i,n)ans+=dist[i]*p[i];
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 210
memory_kb: 24232
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
#define rep(i, a) for(ll i = 0; i < (a); i++)
#define all(a) begin(a), end(a)
#define sz(a) (a).size()
bool chmin(auto &a, auto b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto &a, auto b) { return a < b ? a = b, 1 : 0; }
template<class T> void out(T a) { cout << a << endl; }

using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using ull = unsigned long long;

int main()
{
    ll N, M; cin >> N >> M;
    vll P(N);
    for(auto &p : P) cin >> p;
    vvpll G(N);
    rep(i, M)
    {
        ll a, b, c; cin >> a >> b >> c;
        a--; b--;
        G[a].emplace_back(b, c);
        G[b].emplace_back(a, c);
    }
    priority_queue<pll, vpll, greater<pll>> pq;
    vll dist(N, INF);
    dist[0] = 0;
    ll ans = 0;
    pq.emplace(0, 0);
    while(!pq.empty())
    {
        auto [d, n] = pq.top(); pq.pop();
        if(dist[n] < d) continue;
        // cout << n << " " << d << endl;
        ans += d*P[n];
        for(auto [e, c] : G[n])
        {
            if(chmin(dist[e], dist[n] + c))
            {
                pq.emplace(dist[e], e);
            }
        }
    }
    out(ans);
}
accuracy: 1
time_ms: 150
memory_kb: 24632
final_rank: 6

code_snippet: //
// Created by cafe on 11/12/25.
//

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    vector<vector<P>> path(n);
    for (int i = 0; i < m; ++i) {
        ll a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        path[a].push_back({b, c});
        path[b].push_back({a, c});
    }
    priority_queue<P, vector<P>, greater<P>> pq;
    vector<ll> dist(n, 1e18);
    dist[0] = 0;
    pq.push({0, 0});
    while (!pq.empty()) {
        ll d = pq.top().first;
        ll u = pq.top().second;
        pq.pop();
        if (dist[u] < d) continue;
        for (auto [v, c] : path[u]) {
            if (dist[v] > d + c) {
                dist[v] = d + c;
                pq.push({d + c, v});
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += dist[i] * p[i];
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 210
memory_kb: 24144
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long;
using VLL = vector<ll>;
using PLL = pair<ll, ll>;

#define rep(i, b) for(ll i=0; i<(b); ++i)
#define all(x) begin(x),end(x)

int main() {
    int n, m;
    cin >> n >> m;
    VLL p(n);
    for (auto &e: p)cin >> e;

    vector<vector<PLL> > G(n);

    rep(i, m) {
        ll u, v, q;
        cin >> u >> v >> q;
        u--, v--;
        G[u].push_back({v, q});
        G[v].push_back({u, q});
    }

    priority_queue<PLL, vector<PLL>, greater<PLL> > q;

    vector<bool> visited(n);
    q.push({0, 0});

    ll ans = 0;
    while (!q.empty()) {
        auto [cost, pos] = q.top();
        q.pop();
        if (visited[pos]) continue;
        visited[pos] = true;
        ans += p[pos] * cost;

        for (auto [npos, ncost]: G[pos]) {
            if (!visited[npos]) {
                q.push({cost + ncost, npos});
            }
        }
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 230
memory_kb: 27660
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 lll;
using ull = unsigned long long;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
template<class T> using pqmin = priority_queue<T, vector<T>, greater<T>>;
template<class T> using pqmax = priority_queue<T>;
const ll inf=LLONG_MAX/3;
const ll dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const ll dy[] = {1, 0, -1, 0, 1, 1, -1, -1};
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define si(x) ll(x.size())
#define rept(n) for(ll _ovo_=0;_ovo_<n;_ovo_++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define rng(i,l,r) for(ll i=l;i<r;i++)
#define gnr(i,l,r) for(ll i=r-1;i>=l;i--)
#define fore(i, a) for(auto &&i : a)
#define fore2(a, b, v) for(auto &&[a, b] : v)
#define fore3(a, b, c, v) for(auto &&[a, b, c] : v)
template<class T> bool chmin(T& a, const T& b){ if(a <= b) return 0; a = b; return 1; }
template<class T> bool chmax(T& a, const T& b){ if(a >= b) return 0; a = b; return 1; }
template<class T, class U> bool chmin(T& a, const U& b){ return chmin(a, (T)b); }
template<class T, class U> bool chmax(T& a, const U& b){ return chmax(a, (T)b); }
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type>name(__VA_ARGS__)
#define VEC(type,name,size) vector<type>name(size);in(name)
#define VLL(name,size) vector<ll>name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>> name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>> name(h,vector<type>(w));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>> name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define SUM(...) accumulate(all(__VA_ARGS__),0LL)
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }
template<class T, class F = less<>> void sor(T& a, F b = F{}){ sort(all(a), b); }
template<class T> void uniq(T& a){ sor(a); a.erase(unique(all(a)), end(a)); }
template<class T, class F = less<>> map<T,vector<ll> > ivm(vector<T>& a, F b = F{}){ map<T,vector<ll> > ret; rep(i,si(a))ret[a[i]].push_back(i); return ret;}
template<class T, class F = less<>> map<T,ll> ivc(vector<T>& a, F b = F{}){ map<T,ll> ret; rep(i,si(a))ret[a[i]]++; return ret;}
template<class T, class F = less<>> vector<T> ivp(vector<T> a){ vector<ll> ret(si(a)); rep(i,si(a))ret[a[i]] = i; return ret;}
template<class T, class F = less<>> vector<ll> rev(vector<T> a){ reverse(all(a)); return a;}
template<class T, class F = less<>> vector<ll> sortby(vector<T> a, F b = F{}){vector<ll> w = a; sor(w,b); vector<pll> v; rep(i,si(a))v.eb(a[i],i); sor(v); if(w[0] != v[0].first)reverse(all(v)); vector<ll> ret; rep(i,si(v))ret.pb(v[i].second); return ret;}
template<class T, class P> vector<T> filter(vector<T> a,P f){vector<T> ret;rep(i,si(a)){if(f(a[i]))ret.pb(a[i]);}return ret;}
template<class T, class P> vector<ll> filter_id(vector<T> a,P f){vector<ll> ret;rep(i,si(a)){if(f(a[i]))ret.pb(i);}return ret;}
ll monotone_left(function<bool(ll)> f){ll l = -1,r = (ll)1e18 + 1; assert(f(l + 1) >= f(r - 1)); while(l + 1 < r){ll mid = (l + r)>> 1; (f(mid)?l:r) = mid;} return l;}
ll monotone_left(ll l,ll r,function<bool(ll)> f){l--; assert(f(l + 1) >= f(r - 1)); while(l + 1 < r){ll mid = (l + r)>> 1; (f(mid)?l:r) = mid;} return l;}
ll monotone_right(function<bool(ll)> f){ll l = -1,r = (ll)1e18 + 1; assert(f(l + 1) <= f(r - 1)); while(l + 1 < r){ll mid = (l + r)>> 1; (f(mid)?r:l) = mid;} return r;}
ll monotone_right(ll l,ll r,function<bool(ll)> f){l--; assert(f(l + 1) <= f(r - 1)); while(l + 1 < r){ll mid = (l + r)>> 1; (f(mid)?r:l) = mid;} return r;}
double monotone_double_left(double l,double r,function<bool(double)> f){assert(f(l) >= f(r)); rep(_,100){double mid = (l + r) / 2.0; (f(mid)?l:r) = mid;} return l;}
double monotone_double_right(double l,double r,function<bool(double)> f){assert(f(l) <= f(r)); rep(_,100){double mid = (l + r) / 2.0; (f(mid)?l:r) = mid;} return r;}
template<class S> S unimodal_max(ll l,ll r,function<S(ll)> f){while(l + 2 < r){ll m1 = l + (r - l) / 3,m2 = l + (r - l) / 3 * 2; if(f(m1) < f(m2))l = m1; else r = m2;} S ret = f(l); rng(k,l,r + 1)chmax(ret,f(k)); return ret;}
template<class S> S unimodal_min(ll l,ll r,function<S(ll)> f){while(l + 2 < r){ll m1 = l + (r - l) / 3,m2 = l + (r - l) / 3 * 2; if(f(m1) > f(m2))l = m1; else r = m2;} S ret = f(l); rng(k,l,r + 1)chmin(ret,f(k)); return ret;}
vector<pll> neighbor4(ll x,ll y,ll h,ll w){vector<pll> ret;rep(dr,4){ll xx = x + dx[dr],yy = y + dy[dr]; if(0 <= xx && xx < h && 0 <= yy && yy <w)ret.eb(xx,yy);} return ret;};
vector<pll> neighbor8(ll x,ll y,ll h,ll w){vector<pll> ret;rep(dr,8){ll xx = x + dx[dr],yy = y + dy[dr]; if(0 <= xx && xx < h && 0 <= yy && yy <w)ret.eb(xx,yy);} return ret;};

void outb(bool x){cout<<(x?"Yes":"No")<<"\n";}
ll max(int x, ll y) { return max((ll)x, y); }
ll max(ll x, int y) { return max(x, (ll)y); }
int min(int x, ll y) { return min((ll)x, y); }
int min(ll x, int y) { return min(x, (ll)y); }
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define lbg(c, x) distance((c).begin(), lower_bound(all(c), (x), greater{}))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define ubg(c, x) distance((c).begin(), upper_bound(all(c), (x), greater{}))
ll gcd(ll a,ll b){return (b?gcd(b,a%b):a);}
vector<pll> factor(ull x){ vector<pll> ans; for(ull i = 2; i * i <= x; i++) if(x % i == 0){ ans.push_back({i, 1}); while((x /= i) % i == 0) ans.back().second++; } if(x != 1) ans.push_back({x, 1}); return ans; }
vector<ll> divisor(ull x){ vector<ll> ans; for(ull i = 1; i * i <= x; i++) if(x % i == 0) ans.push_back(i); per(i,ans.size() - (ans.back() * ans.back() == x)) ans.push_back(x / ans[i]); return ans; }
vll prime_table(ll n){vec(ll,isp,n+1,1);vll res;rng(i,2,n+1)if(isp[i]){res.pb(i);for(ll j=i*i;j<=n;j+=i)isp[j]=0;}return res;}
ll powll(lll x,ll y){lll res = 1; while(y){ if(y & 1)res = res * x; x = x * x; y >>= 1;} return res;}
ll powmod(lll x,ll y,lll mod){lll res=1; while(y){ if(y&1)res=res*x%mod; x=x*x%mod; y>>=1;} return res; }
ll modinv(ll a,ll m){ll b=m,u=1,v=0;while(b){ll t=a/b;a-=t*b;swap(a,b);u-=t*v;swap(u,v);}u%=m;if(u<0)u+=m;return u;}

template <class T, class S> pair<T, S> operator-(const pair<T, S> &x) { return pair<T, S>(-x.first, -x.second); }
template <class T, class S> pair<T, S> operator-(const pair<T, S> &x, const pair<T, S> &y) { return pair<T, S>(x.fi - y.fi, x.se - y.se); }
template <class T, class S> pair<T, S> operator+(const pair<T, S> &x, const pair<T, S> &y) { return pair<T, S>(x.fi + y.fi, x.se + y.se); }
template <class T> pair<T, T> operator&(const pair<T, T> &l, const pair<T, T> &r) { return pair<T, T>(max(l.fi, r.fi), min(l.se, r.se)); }
template <class T, class S> pair<T, S> operator+=(pair<T, S> &l, const pair<T, S> &r) { return l = l + r; }
template <class T, class S> pair<T, S> operator-=(pair<T, S> &l, const pair<T, S> &r) { return l = l - r; }
template <class T> bool intersect(const pair<T, T> &l, const pair<T, T> &r) { return (l.se < r.se ? r.fi < l.se : l.fi < r.se); }

template <class T> vector<T> &operator++(vector<T> &v) {
		fore(e, v) e++;
		return v;
}
template <class T> vector<T> operator++(vector<T> &v, int) {
		auto res = v;
		fore(e, v) e++;
		return res;
}
template <class T> vector<T> &operator--(vector<T> &v) {
		fore(e, v) e--;
		return v;
}
template <class T> vector<T> operator--(vector<T> &v, int) {
		auto res = v;
		fore(e, v) e--;
		return res;
}
template <class T> vector<T> &operator+=(vector<T> &l, const vector<T> &r) {
		fore(e, r) l.eb(e);
		return l;
}

template<class... Ts> void in(Ts&... t);
[[maybe_unused]] void print(){}
template<class T, class... Ts> void print(const T& t, const Ts&... ts);
template<class... Ts> void out(const Ts&... ts){ print(ts...); cout << '\n'; }
namespace IO{
#define VOID(a) decltype(void(a))
struct S{ S(){ cin.tie(nullptr)->sync_with_stdio(0); fixed(cout).precision(12); } }S;
template<int I> struct P : P<I-1>{};
template<> struct P<0>{};
template<class T> void i(T& t){ i(t, P<3>{}); }
void i(vector<bool>::reference t, P<3>){ int a; i(a); t = a; }
template<class T> auto i(T& t, P<2>) -> VOID(cin >> t){ cin >> t; }
template<class T> auto i(T& t, P<1>) -> VOID(begin(t)){ for(auto&& x : t) i(x); }
template<class T, size_t... idx> void ituple(T& t, index_sequence<idx...>){ in(get<idx>(t)...); }
template<class T> auto i(T& t, P<0>) -> VOID(tuple_size<T>{}){ ituple(t, make_index_sequence<tuple_size<T>::value>{}); }
template<class T> void o(const T& t){ o(t, P<4>{}); }
template<size_t N> void o(const char (&t)[N], P<4>){ cout << t; }
template<class T, size_t N> void o(const T (&t)[N], P<3>){ o(t[0]); for(size_t i = 1; i < N; i++){ o(' '); o(t[i]); } }
template<class T> auto o(const T& t, P<2>) -> VOID(cout << t){ cout << t; }
template<class T> auto o(const T& t, P<1>) -> VOID(begin(t)){ bool first = 1; for(auto&& x : t) { if(first) first = 0; else o(' '); o(x); } }
template<class T, size_t... idx> void otuple(const T& t, index_sequence<idx...>){ print(get<idx>(t)...); }
template<class T> auto o(T& t, P<0>) -> VOID(tuple_size<T>{}){ otuple(t, make_index_sequence<tuple_size<T>::value>{}); }
#undef VOID
}
#define unpack(a) (void)initializer_list<int>{(a, 0)...}
template<class... Ts> void in(Ts&... t){ unpack(IO::i(t)); }
template<class T, class... Ts> void print(const T& t, const Ts&... ts){ IO::o(t); unpack(IO::o((cout << ' ', ts))); }
#undef unpack

int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	ll n,m;
	cin>>n>>m;
	vll p(n);
	rep(i,n)cin>>p[i];
	vector<vector<pll> >g(n);
	rep(i,m){
		ll u,v,q;
		cin>>u>>v>>q;
		u--,v--;
		g[u].eb(v,q);
		g[v].eb(u,q);
	}
	vll d(n,inf);
	priority_queue<pll,vector<pll>, greater<pll> > que;
	que.push({0,0});
	while(!que.empty()){
		auto [di,v] = que.top();
		que.pop();
		if(chmin(d[v],di)){
			for(auto &&[u,len]: g[v]){
				que.push({di + len, u});
			}
		}
	}
	ll ans = 0;
	rep(i,n)ans += p[i] * d[i];
	cout<<ans<<endl;
}
accuracy: 1
time_ms: 150
memory_kb: 32576
final_rank: 13

code_snippet: #include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pl = pair<ll, ll>;

int main(void){
    int n, m;
    cin >> n >> m;
    vl p(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    vector<vector<pl>> gr(n);
    for (int i = 0; i < m; i++)
    {
        ll u, v, q;
        cin >> u >> v >> q;
        u--;
        v--;
        gr[u].push_back({v, q});
        gr[v].push_back({u, q});
    }
    priority_queue<pl, vector<pl>, greater<pl>> que;
    que.push({0, 0});
    vl rt(n, -1);
    while(!que.empty()){
        auto [ps, t] = que.top();
        que.pop();
        if(rt[t] != -1) continue;
        rt[t] = ps;
        for(auto &z : gr[t]) {
            if(rt[z.first] != -1) continue;
            que.push({ps + z.second, z.first});
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans += p[i] * rt[i];
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 230
memory_kb: 28668
final_rank: 16

code_snippet: /*
 *   author : cellul4r
 */
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
#define all(x) x.begin(), x.end()
const char nl = '\n';
const int N =1e5+1;
const int INF = 1e9+7;
const ll LINF = 1e18+7;

void setIO(string);
int n,m;
vector<pl> adj[N];
ll a[N];
bool vis[N];
void solve(){

    cin>>n>>m;
    for(int i = 1; i <= n; i++) cin>>a[i];
    for(int i = 1; i <= m; i++) {
        int u,v,w; cin>>u>>v>>w;
        adj[u].push_back({v,w});
        adj[v].push_back({u,w});
    }
    
    vector<ll> dist(n+1,LINF);
    priority_queue<pi, vector<pi>, greater<pi>> pq;
    dist[1] = 0;
    pq.push({dist[1],1});
    memset(vis, false, sizeof vis);
    while(!pq.empty()) {
        int u = pq.top().second;
        pq.pop();
        if(vis[u]) continue;
        vis[u] = true;
        for(auto &vw : adj[u]) {
            int v = vw.first;
            ll w = vw.second;
            if(dist[v] > dist[u] + w) {
                dist[v] = dist[u] + w;
                pq.push({dist[v],v});
            }
        }
    }

    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        ans += 1ll * a[i] * dist[i];
    }
    cout << ans << nl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;

    //setIO("");
    //cin>>t;
    while(t--)solve();

    return 0;
}

void setIO(string s) {
    (void)!freopen((s + ".in").c_str(), "r", stdin);
    (void)!freopen((s + ".out").c_str(), "w", stdout);
}
accuracy: 1
time_ms: 90
memory_kb: 23520
final_rank: 5

code_snippet: /*
 *   author : cellul4r
 */
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
#define all(x) x.begin(), x.end()
const char nl = '\n';
const int N =1e5+1;
const int INF = 1e9+7;
const ll LINF = 1e18+7;

void setIO(string);
int n,m;
vector<pi> adj[N];
int a[N];
bool vis[N];
void solve(){

    cin>>n>>m;
    for(int i = 1; i <= n; i++) cin>>a[i];
    for(int i = 1; i <= m; i++) {
        int u,v,w; cin>>u>>v>>w;
        adj[u].push_back({v,w});
        adj[v].push_back({u,w});
    }
    
    vector<ll> dist(n+1,INF);
    priority_queue<pi, vector<pi>, greater<pi>> pq;
    dist[1] = 0;
    pq.push({dist[1],1});
    memset(vis, false, sizeof vis);
    while(!pq.empty()) {
        int u = pq.top().second;
        pq.pop();
        if(vis[u]) continue;
        vis[u] = true;
        for(auto &vw : adj[u]) {
            int v = vw.first, w = vw.second;
            if(dist[v] > dist[u] + w) {
                dist[v] = dist[u] + w;
                pq.push({dist[v],v});
            }
        }
    }

    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        ans += 1ll * a[i] * dist[i];
    }
    cout << ans << nl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;

    //setIO("");
    //cin>>t;
    while(t--)solve();

    return 0;
}

void setIO(string s) {
    (void)!freopen((s + ".in").c_str(), "r", stdin);
    (void)!freopen((s + ".out").c_str(), "w", stdout);
}
accuracy: 0.925
time_ms: 80
memory_kb: 16184
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
using ll=long long;
constexpr ll inf=1LL<<60;
int n,m,p[1<<17];
vector<pair<int,int>>g[1<<17];
signed main(){
  cin.tie(0)->sync_with_stdio(0);
  cin>>n>>m;
  rep(i,n)cin>>p[i];
  rep(i,m){
    int u,v,q;cin>>u>>v>>q,--u,--v;
    g[u].emplace_back(v,q);
    g[v].emplace_back(u,q);
  }
  priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<>>Q;
  Q.push({0,0});
  vector<ll>dist(n,inf);
  dist[0]=0;
  while(!Q.empty()){
    auto[d,from]=Q.top();
    Q.pop();
    if(d>dist[from])continue;
    for(auto[to,w]:g[from]){
      ll nd=d+w;
      if(dist[to]>nd){
        dist[to]=nd;
        Q.push({dist[to],to});
      }
    }
  }
  ll ans=0;
  rep(i,n){
    ans+=dist[i]*p[i];
  }
  cout<<ans<<endl;
}
accuracy: 1
time_ms: 70
memory_kb: 18456
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;

struct Edge{
    int to;
    ll cost;
};

int main(){
    int n,m;cin >> n >> m;
    vector<ll> p(n);
    for (int i = 0; i < n; i++)cin >> p[i];

    vector<vector<Edge>> g(n);
    for (int i = 0; i < m; i++){
        int u,v,w;cin >> u >> v >> w;
        u--,v--;
        g[u].push_back({v,w});
        g[v].push_back({u,w});
    }

    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll,int>>> q;


    
    vector<ll> d(n,1e18);
    d[0] = 0;
    q.push({0,0});
    while(!q.empty()){
        auto [w1,u] = q.top();
        q.pop();
        
        if (d[u] < w1)continue;
        
        for (auto [v,w2]: g[u]){
            if (d[v] > w1+w2){
                d[v] = w1+w2;
                q.push({w1+w2, v});
            }
        }
    }


    ll ans = 0;
    for (int i = 1; i < n; i++)ans += d[i]*p[i];
    cout << ans << endl;
}
accuracy: 1
time_ms: 210
memory_kb: 24008
final_rank: 8

code_snippet: // AOJ #1457 Omnes Viae Yokohamam Ducunt?
// 2025.2.26

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = numeric_limits<ll>::max();

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int Cin() {  // 整数の入力
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void Cout(ll n) { // 整数の表示（出力）
	char b[30];
	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		int i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

struct Edge { int to, q; };

int main(){
    int n = Cin(), m = Cin();
    vector<int> p(n+1);
    for (int i = 1; i <= n; i++) p[i] = Cin();

    vector<vector<Edge>> graph(n+1);
    for (int i = 0; i < m; i++){
        int u = Cin(), v = Cin(), q = Cin();
        graph[u].push_back({v, q});
        graph[v].push_back({u, q});
    }

    vector<ll> dist(n+1, INF);
    dist[1] = 0;
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
    pq.push({0, 1});

    while(!pq.empty()){
        auto [d, u] = pq.top();
        pq.pop();
        if(d != dist[u]) continue;
        for(auto &edge : graph[u]){
            int v = edge.to;
            ll nd = d + edge.q;
            if(nd < dist[v]){
                dist[v] = nd;
                pq.push({nd, v});
            }
        }
    }
    ll ans = 0;
    for (int i = 2; i <= n; i++) ans += (ll) p[i] * dist[i];
    Cout(ans);
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 17132
final_rank: 1

code_snippet: // AOJ #1457 Omnes Viae Yokohamam Ducunt?
// 2025.2.26

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = numeric_limits<ll>::max();

struct Edge { int to, q; };

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    vector<int> p(n+1);
    for (int i = 1; i <= n; i++) cin >> p[i];

    vector<vector<Edge>> graph(n+1);
    for (int i = 0; i < m; i++){
        int u, v, q;
        cin >> u >> v >> q;
        graph[u].push_back({v, q});
        graph[v].push_back({u, q});
    }

    vector<ll> dist(n+1, INF);
    dist[1] = 0;
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
    pq.push({0, 1});

    while(!pq.empty()){
        auto [d, u] = pq.top();
        pq.pop();
        if(d != dist[u]) continue;
        for(auto &edge : graph[u]){
            int v = edge.to;
            ll nd = d + edge.q;
            if(nd < dist[v]){
                dist[v] = nd;
                pq.push({nd, v});
            }
        }
    }
    ll ans = 0;
    for (int i = 2; i <= n; i++) ans += (ll) p[i] * dist[i];
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 17296
final_rank: 3

code_snippet: #include<iostream>
#include<queue>
using namespace std;
int N,M;
vector<pair<int,long> >G[1<<17],SPT[1<<17];
int p[1<<17];
long dist[1<<17];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N>>M;
	for(int i=0;i<N;i++)cin>>p[i];
	for(int i=0;i<M;i++)
	{
		int u,v,q;cin>>u>>v>>q;
		u--,v--;
		G[u].push_back(make_pair(v,q));
		G[v].push_back(make_pair(u,q));
	}
	priority_queue<pair<long,int>,vector<pair<long,int> >,greater<> >Q;
	Q.push(make_pair(0,0));
	for(int i=0;i<N;i++)dist[i]=1e18;
	dist[0]=0;
	while(!Q.empty())
	{
		int u=Q.top().second;
		long d=Q.top().first;
		Q.pop();
		if(dist[u]<d)continue;
		for(auto[v,c]:G[u])
		{
			long nd=d+c;
			if(dist[v]<nd)continue;
			SPT[u].push_back(make_pair(v,c));
			dist[v]=nd;
			Q.push(make_pair(nd,v));
		}
	}
	long ans=0;
	for(int i=0;i<N;i++)
	{
		ans+=p[i]*dist[i];
	}
	cout<<ans<<endl;
}
accuracy: 1
time_ms: 140
memory_kb: 35424
final_rank: 14

code_snippet: #include<iostream>
#include<queue>
using namespace std;
int N,M;
vector<pair<int,long> >G[1<<17],SPT[1<<17];
int p[1<<17];
long dist[1<<17];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N>>M;
	for(int i=0;i<N;i++)cin>>p[i];
	for(int i=0;i<M;i++)
	{
		int u,v,q;cin>>u>>v>>q;
		u--,v--;
		G[u].push_back(make_pair(v,q));
		G[v].push_back(make_pair(u,q));
	}
	priority_queue<pair<int,int>,vector<pair<int,int> >,greater<> >Q;
	Q.push(make_pair(0,0));
	for(int i=0;i<N;i++)dist[i]=1e18;
	dist[0]=0;
	while(!Q.empty())
	{
		int u=Q.top().second;
		int d=Q.top().first;
		Q.pop();
		if(dist[u]<d)continue;
		for(auto[v,c]:G[u])
		{
			int nd=d+c;
			if(dist[v]<nd)continue;
			SPT[u].push_back(make_pair(v,c));
			dist[v]=nd;
			Q.push(make_pair(nd,v));
		}
	}
	long ans=0;
	for(int i=0;i<N;i++)
	{
		ans+=p[i]*dist[i];
	}
	cout<<ans<<endl;
}
accuracy: 0.925
time_ms: 130
memory_kb: 33064
final_rank: 20

code_snippet: #include<iostream>
#include<queue>
using namespace std;
int N,M;
vector<pair<int,int> >G[1<<17],SPT[1<<17];
int p[1<<17];
long dist[1<<17];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N>>M;
	for(int i=0;i<N;i++)cin>>p[i];
	for(int i=0;i<M;i++)
	{
		int u,v,q;cin>>u>>v>>q;
		u--,v--;
		G[u].push_back(make_pair(v,q));
		G[v].push_back(make_pair(u,q));
	}
	priority_queue<pair<int,int>,vector<pair<int,int> >,greater<> >Q;
	Q.push(make_pair(0,0));
	for(int i=0;i<N;i++)dist[i]=1e18;
	dist[0]=0;
	while(!Q.empty())
	{
		int u=Q.top().second;
		int d=Q.top().first;
		Q.pop();
		if(dist[u]<d)continue;
		for(auto[v,c]:G[u])
		{
			int nd=d+c;
			if(dist[v]<nd)continue;
			SPT[u].push_back(make_pair(v,c));
			dist[v]=nd;
			Q.push(make_pair(nd,v));
		}
	}
	long ans=0;
	for(int i=0;i<N;i++)
	{
		ans+=p[i]*dist[i];
	}
	cout<<ans<<endl;
}
accuracy: 0.925
time_ms: 120
memory_kb: 23796
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll inf = 2e18;
int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> p(n);
  for (int i = 0; i < n; i++) cin >> p[i];

  vector<vector<pair<int, ll>>> E(n);
  for (int i = 0; i < m; i++) {
    ll u, v, q;
    cin >> u >> v >> q, u--, v--;
    E[u].emplace_back(v, q);
    E[v].emplace_back(u, q);
  }

  vector<ll> dist(n, inf);
  priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<>>
      pq;
  dist[0] = 0;
  pq.emplace(0, 0);
  while (!pq.empty()) {
    auto [w, u] = pq.top();
    pq.pop();
    if (w > dist[u]) continue;
    for (auto [v, c] : E[u]) {
      if (dist[v] > w + c) {
        dist[v] = w + c;
        pq.emplace(dist[v], v);
      }
    }
  }


  ll ans = 0;
  for (int i = 0;i < n;i++) {
    ans += dist[i]*p[i];
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 210
memory_kb: 24020
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL<<60;

int main() {
    using Edge = pair<int, long long>;
    using Graph = vector<vector<Edge>>;

    int N, M, u, v;
    long long q;
    cin >> N >> M;
    vector<long long> p(N);
    for (int i = 0; i < N; i++) cin >> p[i];
    Graph G(N);
    for (int i = 0; i < M; i++) {
        cin >> u >> v >> q, u--, v--;
        G[u].emplace_back(v, q);
        G[v].emplace_back(u, q);
    }

    vector<long long> dp(N, INF);
    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> que;
    dp[0] = 0;
    que.push({0, 0});
    while (!que.empty()) {
        auto [cur, v] = que.top();
        que.pop();
        if (cur > dp[v]) continue;
        for (auto e : G[v]) {
            if (dp[v] + e.second < dp[e.first]) {
                dp[e.first] = dp[v] + e.second;
                que.push({dp[e.first], e.first});
            }
        }
    }
    long long res = 0;
    for (int v = 0; v < N; v++) {
        res += dp[v] * p[v];
    }
    cout << res << endl;
}
accuracy: 1
time_ms: 210
memory_kb: 24136
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;

constexpr long long INF = 2e18;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> P(N);
    for(int i = 0; i < N; i++) {
        cin >> P[i];
    }

    vector<vector<pair<int, int>>> G(N);
    for(int i = 0; i < M; i++) {
        int u, v, q;
        cin >> u >> v >> q;
        u--; v--;
        G[u].push_back({v, q});
        G[v].push_back({u, q});
    }

    priority_queue<pair<long long, int>> q;
    q.push({0, 0});
    vector<long long> dist(N, INF);
    while(q.size()) {
        auto [d, v] = q.top(); q.pop();
        if(dist[v] != INF) continue;
        dist[v] = -d;
        for(auto [nv, c] : G[v]) {
            if(dist[nv] != INF) continue;
            q.push({d - c, nv});
        }
    }

    long long ans = 0;
    for(int i = 0; i < N; i++) {
        ans += dist[i] * P[i];
    }

    cout << ans << endl;

    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 21876
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
#define FOR(i,l,r) for(ll i=(l);i<(r);i++)
#define REP(i,n) FOR(i,0,n)
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
int main(){
  ll N,M;cin>>N>>M;
  vector<ll>A(N);
  REP(i,N)cin>>A[i];
  vector<vector<pi>>E(N);
  REP(i,M){
    ll u,v,d;cin>>u>>v>>d;u--;v--;
    E[u].emplace_back(pi(v,d));
    E[v].emplace_back(pi(u,d));
  }
  min_priority_queue<pi>Q;
  for(auto[u,d]:E[0])Q.emplace(pi(d,u));
  vector<bool>used(N);
  used[0]=1;
  vector<ll>D(N);
  ll ans=0;
  while(!Q.empty()){
    auto[cost,v]=Q.top();Q.pop();
    if(used[v])continue;
    used[v]=1;
    ans+=cost*A[v];
    D[v]=cost;
    for(auto[u,d]:E[v])if(!used[u]){
      Q.emplace(pi((d+D[v]),u));
    }
  }
  cout<<ans<<endl;
  return 0;
}
accuracy: 1
time_ms: 240
memory_kb: 28744
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
  int n, m;
  cin >> n >> m;
  vector<ll> p(n);
  for (int i = 0; i < n; i++)
    cin >> p[i];
  vector<vector<pair<int, ll>>> g(n);

  for (int i = 0; i < m; i++)
  {
    int u, v, c;
    cin >> u >> v >> c;
    u--;
    v--;
    g[u].push_back({v, c});
    g[v].push_back({u, c});
  }
  vector<ll> dis(n, (1ll << 60));
  dis[0] = 0;
  priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> q;
  q.push({0, 0});

  while (q.size())
  {
    auto [c, x] = q.top();
    q.pop();
    // cout<<x<<endl;
    if (dis[x] < c)
      continue;
    for (auto [y, cost] : g[x])
    {
      if (dis[y] > c + cost)
      {
        dis[y] = c + cost;
        q.push({c + cost, y});
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i < n; i++)
  {
    ans += p[i] * dis[i];
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 190
memory_kb: 24636
final_rank: 7