Cod sursa(job #2596156)

Utilizator cyg_SerbanBFlorin Gheorghe cyg_SerbanB Data 9 aprilie 2020 12:50:07
Problema Distante Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <cstdio>
#include <vector>
using namespace std;
int cost[50005];
bool f[50005];
int main()
{
        freopen("distante.in","r",stdin);
        freopen("distante.out","w",stdout);
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m,st;
        bool ok=1;
        scanf("%d%d%d",&n,&m,&st);
        for(int i=1;i<=n;++i)
            scanf("%d",&cost[i]);
        if(cost[st])
            ok=0;
        else
            f[st]=1;
        for(int i=1;i<=m;++i)
        {
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            if(cost[a]+c<cost[b] || cost[b]+c<cost[a])
                ok=0;
            if(cost[a]+c==cost[b])
                f[b]=1;
            if(cost[b]+c==cost[a])
                f[a]=1;
        }
        for(int i=1;i<=n;++i)
        {
            if(!f[i])
                ok=0;
            f[i]=0;
        }
        if(ok)
            printf("DA\n");
        else
            printf("NU\n");
    }
    return 0;
}