Cod sursa(job #1479580)

Utilizator tudormaximTudor Maxim tudormaxim Data 31 august 2015 17:08:20
Problema Distante Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <bits/stdc++.h>
using namespace std;
const int nmax = 50005;
int d[nmax];
int main()
{
    freopen("distante.in", "r", stdin);
    freopen("distante.out", "w", stdout);
    int t, n, m, s, x, y, c, i;
    bool ok;
    scanf("%d ", &t);
    while(t--)
    {
        scanf("%d %d %d", &n, &m, &s);
        for(i=1; i<=n; i++)
            scanf("%d", &d[i]);
        ok=true;
        if(d[s]) ok=false;
        for(i=1; i<=m && ok==true; i++)
        {
            scanf("%d %d %d", &x, &y, &c);
            if((d[x]+c < d[y]) || (d[y]+c < d[x])) ok=false;
        }
        if(ok==true) printf("DA\n");
        else printf("NU\n");
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}