Cod sursa(job #2702779)

Utilizator AlexandruGabrielAliciuc Alexandru AlexandruGabriel Data 5 februarie 2021 20:31:18
Problema Distante Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin ("distante.in");
ofstream fout ("distante.out");

const int N = 50005;
int T, n, m, S, dist[N];
bool gasit;

int main()
{
    fin >> T;
    while (T--)
    {
        gasit = 1;
        fin >> n >> m >> S;
        for (int i = 1; i <= n; i++)
            fin >> dist[i];
        if (dist[S] != 0)
            fout << "NU" << "\n";
        else
        {
            while (m--)
            {
                int a, b, cost;
                fin >> a >> b >> cost;

                if (dist[a] <= dist[b] && dist[a] + cost < dist[b])
                    gasit = 0;
                if (dist[b] < dist[a] && dist[b] + cost < dist[a])
                    gasit = 0;

            }
            if (gasit)
                fout << "DA\n";
            else
                fout << "NU\n";
        }
    }
    return 0;
}