Pagini recente » Cod sursa (job #2920165) | Cod sursa (job #750672) | Cod sursa (job #3154241) | Cod sursa (job #584884) | Cod sursa (job #2830307)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream in("distante.in");
ofstream out("distante.out");
vector <int> x(50000, 0), y(50000, 0), c(50000, 0), distanta(50000, 0);
int citire, noduri, muchii, start;
void verificare()
{
if (distanta[start - 1] != 0)
{
out << "NU\n";
return;
}
for (int i = 0; i < muchii; i++)
if (distanta[x[i] - 1] + c[i] < distanta[y[i] - 1])
{
out << "NU\n";
return;
}
out << "DA\n";
return;
}
int main()
{
in >> citire;
while(citire--)
{
in >> noduri >> muchii >> start;
for(int i = 0; i < noduri; i++)
in >> distanta[i];
for(int i = 0; i < muchii; i++)
in >> x[i] >> y[i] >> c[i];
verificare();
}
return 0;
}