Cod sursa(job #1222655)

Utilizator rangerChihai Mihai ranger Data 23 august 2014 22:52:09
Problema Distante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include<fstream>
using namespace std;

ifstream cin("distante.in");
ofstream cout("distante.out");
const int nmax = 50010;
int t,n,m,s,i;
int d[nmax],ex[nmax];

int main()
{
    cin>>t;
    while (t--)
    {
        cin>>n>>m>>s;
        int ok=1;
        for (i=1;i<=n;i++) cin>>d[i];
        if (d[s]!=0) ok=0;
        while (m--) {
            int x,y,z;
            cin>>x>>y>>z;
            if (d[x]+z<d[y] || d[y]+z<d[x]) ok=0;
            if (d[x]+z==d[y]) ex[y]=1;
            if (d[y]+z==d[x]) ex[x]=1;
        }
        for (i=1;i<=n;i++) if (ex[i]==0 && i!=s) ok=0;
        if (ok==1) cout<<"DA\n"; else cout<<"NU\n";
    }
    return 0;
}