Cod sursa(job #996460)

Utilizator horatiu11Ilie Ovidiu Horatiu horatiu11 Data 11 septembrie 2013 23:02:08
Problema Distante Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
# include <cstdio>
using namespace std;
int t,q,a[50001],i,s,n,m,x,y,c;
bool ok;
int main()
{
    freopen("distante.in","r",stdin);
    freopen("distante.out","w",stdout);
    scanf("%d",&t);
    for(q=1;q<=t;++q)
    {
        scanf("%d%d%d",&n,&m,&s);
        for(i=1;i<=n;++i)
            scanf("%d",&a[i]);
        ok=true;
        if(a[s])ok=false;
        for(i=1;i<=m && ok;++i)
        {
            scanf("%d%d%d",&x,&y,&c);
            if(a[y]+c<a[x]||a[x]+c<a[y])ok=false;
        }
        if(ok)printf("DA\n");
        else printf("NU\n");
    }
    return 0;
}