Cod sursa(job #1090117)

Utilizator MarghescuGabriel Marghescu Marghescu Data 22 ianuarie 2014 12:58:47
Problema Distante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <cstdio>
using namespace std;
 
int dist[50005];
int n,m,s,t;
 
int main() {
    freopen("distante.in","r",stdin);
    freopen("distante.out","w",stdout);
    scanf("%d",&t);
    while (t--)
    {
        bool gresit = false;
        scanf("%d %d %d",&n,&m,&s);
        for (int i=1;i<=n;i++)
		scanf("%d",&dist[i]);
        for (int i=1;i<=m;i++)
	{
            int a,b,d;
            scanf("%d %d %d",&a,&b,&d);
            if (dist[a] + d < dist[b]) gresit = true;
            if (dist[b] + d < dist[a]) gresit = true;
            if (dist[s] != 0) gresit = true;
        }
        if (gresit)
		printf("NU\n");
        else
		printf("DA\n");
    }
    return 0;
}