Cod sursa(job #2923468)

Utilizator bem.andreiIceman bem.andrei Data 14 septembrie 2022 15:10:47
Problema Distante Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <bits/stdc++.h>

using namespace std;
ifstream r("distante.in");
ofstream w("distante.out");

int dist[50003];
int n, m, s;
int main()
{
    int t;
    r>>t;
    while(t--)
    {
        int x, y, cost;
        bool ok=1;
        r>>n>>m>>s;
        for(int i=1; i<=n; i++){
            r>>dist[i];
        }
        if(dist[s]!=0){
            ok=0;
        }
        for(int i=1; i<=m; i++)
        {
            r>>x>>y>>cost;
            if(dist[x]+cost<dist[y] || dist[y]+cost<dist[x]){
                ok=0;
            }
        }
        if(ok==1){
            w<<"DA"<<"\n";
        }
        else{
            w<<"NU"<<"\n";
        }

    }
    return 0;
}