Pagini recente » Cod sursa (job #2959451) | Cod sursa (job #110527) | Cod sursa (job #1907049) | Cod sursa (job #1533325) | Cod sursa (job #2242230)
#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;
}