Cod sursa(job #2831173)

Utilizator TDV24Tont Dragos-Valentin TDV24 Data 10 ianuarie 2022 21:47:58
Problema Distante Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("distante.in");
ofstream g("distante.out");

int sursa[50001], destinatie[50001], costuri[50001], distante[50001];

int test(int S, int M)
{
    if(distante[S]) // verific daca distanta de la nodul de inceput la el insusi este 0
        return -1;
    for(int i = 1; i <= M; i++)
        if(distante[sursa[i]] + costuri[i] < distante[destinatie[i]]) // verific daca exista un drum de o distanta mai mica fata de distanta data plimbandu-ma prin muchiile grafului
            return -1;
    return 1;
}

int main()
{
    int T, N, M, S, rez;
    f >> T;
    for(int i = 1; i <= T; i++)
    {
        f >> N >> M >> S;
        for(int j = 1; j <= N; j++)
            f >> distante[j];
        for(int j = 1; j <= N; j++)
            f >> sursa[j] >> destinatie[j] >> costuri[j]; //citire
        rez = test(S, M);
        if(rez == 1)
            g << "DA\n"; // distantele date sunt corecte
        else
            g << "NU\n"; // s-a gasit un drum de distanta mai mica fata de cea data
    }
    return 0;
}