Pagini recente » Cod sursa (job #1882360) | Cod sursa (job #898441) | Cod sursa (job #1823555) | Cod sursa (job #2392872) | Cod sursa (job #982087)
Cod sursa(job #982087)
#include <fstream>
using namespace std;
int s,t,n,m,a,b,c,costm[50005],prob,probg,gasit[50005];
int main ()
{
ifstream in("distante.in");
ofstream out("distante.out");
in>>t;
for (int i=1;i<=t;++i)
{
in>>n>>m>>s;
for (int j=1;j<=n;++j) in>>costm[j];
probg=1; if (costm[s]==0) gasit[s]=1; else probg=0;
for (int j=1;j<=m;++j)
{
in>>a>>b>>c;
int folos=0;
if (gasit[a]==0) if ((costm[a]-c)>costm[b]) probg=0; else if ((costm[a]-c)==costm[b]) { gasit[a]=1; folos=1;}
if (folos==0) if ((costm[b]-c)>costm[a]) probg=0; else if ((costm[b]-c)==costm[a]) gasit[b]=1;
}
for (int j=1;j<=n;++j)
{
if (gasit[j]==0) probg=0;
gasit[j]=0;
}
if (probg==1) out<<"DA"<<"\n"; else out<<"NU"<<"\n";
}
in.close();
out.close();
}