Cod sursa(job #2148855)

Utilizator dragosmihuDragos Mihu dragosmihu Data 2 martie 2018 08:34:47
Problema Distante Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include<bits/stdc++.h>

using namespace std;
ifstream fin("distante.in");
ofstream fout("distante.out");
int main()
{
    int i,x,y,t,n,m,s,j,c,sol[100000];
    fin>>t;
    for(i=1;i<=t;i++)
    {
        int e=0;
        fin>>n>>m>>s;
        for(j=1;j<=n;j++)
            fin>>sol[j];
        if(sol[s]==0)
        {for(j=1;j<=m;j++)
        {
            fin>>x>>y>>c;
            if(sol[x]>sol[y])
               {
                   if(sol[x]-sol[y]==c)
                    e++;
               }
               else
                if(sol[y]-sol[x]==c)
                e++;
        }
        if(e==m-1)
            fout<<"DA"<<"\n";
            else
                fout<<"NU"<<"\n";
        }
        else
            fout<<"NU"<<"\n";
    }
    return 0;
}