Pagini recente » Cod sursa (job #1277920) | 00001 | Cod sursa (job #1348867) | Cod sursa (job #265537) | Cod sursa (job #2635538)
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
ifstream fin ("distante.in");
ofstream fout("distante.out");
#define cin fin
#define cout fout
#define Nmax 50001
#define oo (int)INT_MAX / 2 - 1
int compare[Nmax];
int dist[Nmax];
bool viz[Nmax];
vector < pair < int, int > > g[Nmax];
struct compara
{
bool operator()(int x, int y) {
return dist[x] > dist[y];
}
};
priority_queue < int, vector < int >, compara > pq;
int n, m, k;
void d(int start) {
dist[start] = 0;
pq.push(start);
viz[start] = 1;
while(!pq.empty()) {
int nod = pq.top();
pq.pop();
viz[nod] = 0;
for(auto it : g[nod]) {
int v = it.first;
int c = it.second;
if(dist[nod] + c < dist[v]) {
dist[v] = dist[nod] + c;
if(viz[v] == false) {
pq.push(v);
viz[v] = 1;
}
}
}
}
}
void solve() {
cin >> n >> m >> k;
for(int i=1; i <= n; i++) {
cin >> compare[i];
dist[i] = oo;
}
while(m--) {
int x, y, c;
cin >> x >> y >> c;
g[x].push_back({y, c});
g[y].push_back({x, c});
}
d(k);
bool ok = true;
for(int i=1; i <= n; i++) {
if(compare[i] != dist[i]) {
ok = false;
}
viz[i] = 0;
g[i].clear();
}
if(ok) {
cout << "DA" << endl;
} else {
cout << "NU" << endl;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin .tie(0);
cout.tie(0);
int testCases = 1;
cin >> testCases;
while(testCases--) {
solve();
}
}