#include #include #include #include #include #include #include using namespace std; #define int long long #define rep(i,n) for(int i = 0; i < (n); i++) #define INF ((long long)1e18) #define EPS (1e-5) #define MOD ((int)1e9+7) #define endl "\n" #define yn(f) ((f)?"Yes":"No") #define YN(f) ((f)?"YES":"NO") #define MAX 3000 typedef long long ll; typedef pair P; int N, M, L; int t[MAX]; struct edge{ll to, cost;}; vector G[MAX]; ll d[MAX], V, dl[MAX]; int temp, temp2; void dijkstra(ll s){ priority_queue,greater

> q; fill(d,d+V, INF); d[s] = 0; q.push(P(0,s)); while(!q.empty()){ P p = q.top();q.pop(); ll v = p.second; // cout< d[v] + e.cost){ d[e.to] = d[v] + e.cost; q.push(P(d[e.to],e.to)); } } } } void dijkstraL(){ priority_queue,greater

> q; fill(dl,dl+V, INF); ll s = L; dl[s] = 0; q.push(P(0,s)); while(!q.empty()){ P p = q.top();q.pop(); ll v = p.second; if(dl[v] < p.first) continue; for(edge e : G[v]){ if(dl[e.to] > dl[v] + e.cost){ dl[e.to] = dl[v] + e.cost; q.push(P(dl[e.to],e.to)); } } } } void bfs(int s){ queue Q; int used[MAX] = {}; Q.push(s); while(!Q.empty()){ int v = Q.front(); Q.pop(); for(edge e: G[v]){ if(used[e.to]) continue; temp += d[e.to]*t[e.to]*2; // cout<>N>>M>>L; L--; V = N; for(int i = 0; i < N; i++){ cin>>t[i]; if(t[i]) count++; } for(int i = 0; i < M; i++){ cin>>a>>b>>c; a--, b--; e.to = b, e.cost = c; G[a].push_back(e); e.to = a; G[b].push_back(e); } if(count <= 1){ cout<<0<<> "<