Pagini recente » Cod sursa (job #315677) | Cod sursa (job #958894) | Cod sursa (job #818806) | Cod sursa (job #171403) | Cod sursa (job #1338826)
#include <fstream>
using namespace std;
ifstream is("distante.in");
ofstream os("distante.out");
int t, n, s, m, a[50001];
bool d[50001];
int x, y, cost;
bool ok;
int main()
{
is >> t;
for( int i = 1; i <= t; i++ )
{
is >> n >> m >> s;
for ( int i = 1; i <= n; i++ )
is >> a[i];
ok = true;
for ( int i = 1; i <= m; i++ )
{
is >> x >> y >> cost;
if ( a[x] + cost < a[y] || a[y] + cost < a[x] )
ok = false;
if ( a[x] + cost == a[y] )
d[y] = true;
if ( a[y] + cost == a[x] )
d[x] = true;
}
if ( d[s] )
ok = false;
for ( int i = 1; i <= n; i++ )
if ( i != s && !d[i] )
ok = false;
if ( ok )
os << "DA\n";
else
os << "NU\n";
}
is.close();
os.close();
return 0;
}