Cod sursa(job #1366229)

Utilizator morandy14Andreea morandy14 Data 28 februarie 2015 21:10:02
Problema Distante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include<fstream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
ifstream in("distante.in");
ofstream out("distante.out");
 
#define Nmax 50001
#define INF ((1<<31)-1)
 
int d[Nmax];
int n, m, start;
 
int main ()
{
    int t;
    in>>t;
    for(int i=1; i<=t; i++)
    {
        int ok=1, x, y, cost;
 
        in >> n >> m >> start;
 
        for(int i=1; i<=n; i++)     in>>d[i];
 
        if(d[start]!=0)
            ok=0;
 
        while(m--)
        {
            in>> x >> y >>cost;
            if(d[x] + cost < d[y] || d[y] + cost < d[x])
                ok=0;
        }
 
        if(ok == 0) out<<"NU\n";
        else        out<<"DA\n";
    }
    return 0;
}