Cod sursa(job #2242230)

Utilizator SqueekDanielTodasca Daniel SqueekDaniel Data 18 septembrie 2018 09:36:36
Problema Distante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <bits/stdc++.h>

#define MaxN 50005
#define inf (int)(1e9)

std::ifstream InFile("distante.in");
std::ofstream OutFile("distante.out");

int N, M, T, S;
int Dist[MaxN], Dijk[MaxN];

bool Check() {
    for (int i=0; i<N; i++)
        if (Dist[i+1] != Dijk[i+1])
            return false;
    return true;
}

void Citire() {
    InFile >> N >> M >> S;

    for (int i=0; i<N; i++)
        Dist[i+1] = inf;
    for (int i=0; i<N; i++)
        InFile >> Dijk[i+1];
}
void Rezolvare() {
    Dist[S] = 0;
    for (int i=0, x, y, c; i<M; i++) {
        InFile >> x >> y >> c;
        Dist[x] = std::min(Dijk[y]+c, Dist[x]);
        Dist[y] = std::min(Dijk[x]+c, Dist[y]);
    }

    OutFile << (Check() ? "DA\n" : "NU\n");
}

int main()
{
    InFile >> T;
    while(T--) {
        Citire(),
        Rezolvare();
    }

    return 0;
}