Cod sursa(job #1718594)

Utilizator LucianTLucian Trepteanu LucianT Data 18 iunie 2016 14:00:36
Problema Distante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <bits/stdc++.h>
#define maxN 50005
using namespace std;
int T,n,m,i,j,x,y,z,s;
int d[maxN];
void test()
{
    scanf("%d %d %d",&n,&m,&s);
    for(i=1;i<=n;i++)
        scanf("%d",&d[i]);
    bool ok=true;
    for(i=1;i<=m;i++)
    {
        scanf("%d %d %d",&x,&y,&z);
        if(d[x]+z<d[y] || d[y]+z<d[x])
            ok=false;
    }
    if(!d[s] && ok) printf("DA\n");
    else printf("NU\n");
}
int main()
{
    freopen("distante.in","r",stdin);
    freopen("distante.out","w",stdout);
    scanf("%d",&T);
    while(T--)
        test();
    return 0;
}