Pagini recente » Cod sursa (job #1554502) | Cod sursa (job #39026) | Cod sursa (job #2228326) | Cod sursa (job #2144291) | Cod sursa (job #526096)
Cod sursa(job #526096)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const char iname[] = "distante.in";
const char oname[] = "distante.out";
ifstream fin(iname);
ofstream fout(oname);
int t, n, i, j, m, s, okey;
int D[50005];
int x, y, c, k;
vector<pair <int, int> >Gr[50005];
int main()
{
fin >> t;
for(i = 1; i <= t; i ++)
{
fin >> n >> m >> s;
for(j = 1; j <= n; j ++)
fin >> D[j];
for(j = 1; j <= m; j ++)
{
fin >> x >> y >> c;
Gr[x].push_back(make_pair(y, c));
Gr[y].push_back(make_pair(x, c));
}
okey = 1;
for(j = 1; j <= n; j ++)
{
if(j == s)
{
okey = 1;
continue;
}
if(okey == 0)
break;
okey = 0;
for(k = 0; k < Gr[j].size(); k ++)
if(D[Gr[j][k].first] + Gr[j][k].second == D[j])
okey = 1;
if(okey == 0)
break;
}
if(okey == 1)
fout << "DA\n";
else
fout << "NU\n";
}
return 0;
}