Pagini recente » Cod sursa (job #2010498) | Cod sursa (job #3158546) | Cod sursa (job #2457376) | Cod sursa (job #2021282) | Cod sursa (job #2007182)
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
int n,m,s,t,D[50010],dist[50010];
vector <pair<int, int> > V[50010];
set <pair<int, int> > S;
void Dij(){
while (S.size()!=0){
int c = S.begin()->first, q = S.begin()->second;
S.erase(S.begin());
for (int w=0; w<V[q].size(); w++){
int weight = V[q][w].second;
if (c + weight < dist[V[q][w].first]){
if (dist[V[q][w].first] != (1<<30)){
S.erase(S.find({dist[V[q][w].first], V[q][w].first}));
}
dist[V[q][w].first] = c + weight;
S.insert({dist[V[q][w].first], V[q][w].first});
}
}
}
}
int main(){
ifstream cin ("distante.in");
ofstream cout ("distante.out");
cin >> t;
while (t--){
cin >> n >> m >> s;
S.insert({0,s});
for (int i=1; i<=n; i++){
cin >> D[i];
dist[i] = (1<<30);
V[i].erase(V[i].begin(),V[i].end());
}
dist[s]=0;
for (int i=1; i<=m; i++){
int a,b,c;
cin >> a >> b >> c;
V[a].pb({b,c});
V[b].pb({a,c});
}
Dij();
bool u=true;
for (int i=1; i<=n; i++){
if (D[i] != dist[i]) u=false;
}
if (u) cout << "DA\n";
else cout << "NU\n";
}
return 0;
}