Pagini recente » Cod sursa (job #995529) | Cod sursa (job #843638) | Cod sursa (job #2574087) | Cod sursa (job #1279086) | Cod sursa (job #3353852)
#include <bits/stdc++.h>
using namespace std;
const int nm=1e5+5;
int dist[nm], d[nm];
int main()
{
ifstream cin("distante.in");
ofstream cout("distante.out");
int t;
cin>>t;
for(int z=1; z<=t; z++)
{
int n, m, s, a, b, c, ok=0;
cin>>n>>m>>s;
vector<vector<pair<int, int>>> v;
v.resize(n+1);
for(int i=1; i<=n; i++)
{
cin>>d[i];
dist[i]=1e9;
}
for(int i=1; i<=m; i++)
{
cin>>a>>b>>c;
v[a].push_back({b, c});
v[b].push_back({a, c});
}
priority_queue<pair<int, int>> q;
q.push({0, s});
dist[s]=0;
map<pair<int, int>, bool> mp;
while(!q.empty())
{
int y=-q.top().first, x=q.top().second;
q.pop();
for(auto h:v[x])
{
if(mp[{x, h.first}]==0)
{
mp[{x, h.first}]=1;
dist[h.first]=min(dist[h.first], y+h.second);
q.push({-y-h.second, h.first});
}
}
}
for(int i=1; i<=n; i++)
{
if(d[i]!=dist[i])
{
ok=1;
break;
}
}
if(ok==0)
cout<<"DA"<<'\n';
else
cout<<"NU"<<'\n';
}
return 0;
}