Pagini recente » Cod sursa (job #973612) | Cod sursa (job #2657044) | Cod sursa (job #2802143) | Cod sursa (job #1202203) | Cod sursa (job #1222634)
#include<fstream>
#include<vector>
using namespace std;
ifstream cin("distante.in");
ofstream cout("distante.out");
const int nmax = 50010;
int t,n,m,s,i;
int d[nmax];
vector<pair<int, int > > g[nmax];
int main()
{
cin>>t;
while (t--)
{
cin>>n>>m>>s;
int ok=1;
for (i=1;i<=n;i++) cin>>d[i];
for (i=1;i<=m;i++) {
int x,y,z;
cin>>x>>y>>z;
g[x].push_back(make_pair(y,z));
g[y].push_back(make_pair(x,z));
}
if (d[s]!=0) ok=0;
for (i=1;i<=n && ok;i++) if (i!=s)
{
int gasit=0;
for (int j=0;j<g[i].size();++j) {
int to=g[i][j].first,len=g[i][j].second;
if (d[to]+len==d[i]) gasit=1;
if (d[to]+len<d[i]) ok=0;
}
if (gasit==0) ok=0;
}
if (ok==1) cout<<"DA\n"; else cout<<"NU\n";
}
return 0;
}