Cod sursa(job #583714)

Utilizator paul_gabryelPaul Buda paul_gabryel Data 22 aprilie 2011 02:34:40
Problema Distante Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb

#include <cstdio>
#include <fstream>
#include <vector>

using namespace std;

int main ()
{

    int m,n,t,s,x,y,c;
    ifstream in ("distante.in");
    freopen ("distante.out","w",stdout);
    for(in>>t;t;--t){
        in>>n>>m>>s;
        vector<int> v(n+1);
        for(int i=1;i<=n;++i)
            in>>v[i];
        bool vrf=true;
        if(v[s]){
            vrf=false;
            printf("NU\n");
        }
        for(;m&&vrf==true;--m){
            in>>x>>y>>c;
            if( v[y]>v[x]+c || v[x]>v[y]+c ){
                vrf=false;
                printf("NU\n");
            }
        }
        if(vrf==true)
            printf("DA\n");
    }

return 0;}