Pagini recente » Cod sursa (job #1537765) | Cod sursa (job #364692) | Cod sursa (job #231564) | Cod sursa (job #934584) | Cod sursa (job #2486466)
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cstring>
using namespace std;
//#include <iostream>
#include <fstream>
ifstream cin ("input.in");
ofstream cout ("output.out");
//ifstream cin ("distante.in");
//ofstream cout ("distante.out");
static const int INF = 1e9;
static const int NMAX = 5e4+5;
int best[NMAX];
int v[NMAX];
vector <pair<int, int>> graph[NMAX];
string solve(int n, int m, int s) {
for ( int i = 1; i <= n; ++i ) {
if ( i == s ) {
continue;
}
best[i] = INF;
}
for ( int i = 1; i <= n; ++i ) {
cin>>v[i];
}
for ( int i = 1; i <= m; ++i ) {
int a, b, c;
cin>>a>>b>>c;
graph[a].push_back({b, c});
graph[b].push_back({a, c});
}
for ( int i = 1; i <= n; ++i ) {
for ( auto x:graph[i] ) {
best[i] = min(best[i], v[x.first]+x.second);
}
}
for ( int i = 1; i <= n; ++i ) {
if ( i == s && v[i] != 0 ) {
return "NU";
}
if ( v[i] != best[i] ) {
return "NU";
}
}
return "DA";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t;
cin>>t;
while ( t-- ) {
int n, m, s;
cin>>n>>m>>s;
cout<<solve(n, m, s)<<'\n';
}
}