Cod sursa(job #1016152)
Utilizator | Data | 25 octombrie 2013 20:45:04 | |
---|---|---|---|
Problema | Distante | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.64 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ("distante.in");
ofstream g ("distante.out");
int n, m, nodSursa;
int cost[50002];
int main ()
{
int ok, a, b, c, nrTeste;
f>>nrTeste;
for (int i=1; i<=nrTeste; i++)
{
f>>n>>m>>nodSursa;
for (int i=1; i<=n; i++) f>>cost[i];
ok=1;
for (int i=1; i<=m; i++)
{
f>>a>>b>>c;
if (cost[a]+c<cost[b]) ok=0;
if (cost[b]+c<cost[a]) ok=0;
}
if (cost[nodSursa]) ok=0;
if (ok) g<<"DA";
else g<<"NU";
g<<'\n';
}
return 0;
}