Pagini recente » Cod sursa (job #1801811) | Cod sursa (job #2841086) | Cod sursa (job #279876) | Cod sursa (job #1327348) | Cod sursa (job #2618659)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>
#define sz(x) (int)((x).size())
#define int long long
//#define in cin
//#define out cout
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const ll inf = 0x3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int N = 5e4 + 11;
const int NMAX = 1e4 + 11;
const ll INF64 = 3e18 + 1;
const double lil = 0.0000000000001;
ifstream in("distante.in");
ofstream out("distante.out");
int n, m, S;
vector<int>dist, r;
vector<vector<pi>>v;
priority_queue<pi, vector<pi>, greater<pi>>unmarked;
void Dijkstra(int nod){
unmarked.push({0,nod});
dist[nod] = 0;
while(!unmarked.empty()){
int cur = unmarked.top().ss;
int curDist = unmarked.top().ff;
unmarked.pop();
if(curDist != dist[cur])continue;
for(auto it : v[cur]){
int x = it.ff;
int weight = it.ss;
if(dist[cur] + weight < dist[x]){
dist[x] = dist[cur] + weight;
unmarked.push({dist[x],x});
}
}
}
}
int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
int t = 1;
cin >> t;
while(t--){
in >> n >> m >> S;
v.resize(N);
dist.resize(N, INF64);
r.resize(N);
for(int i = 1; i <= n; i++)cin >> r[i];
for(int i = 1, x, y, w; i <= m; i++){
in >> x >> y >> w;
v[x].push_back({y,w});
v[y].push_back({x,w});
}
Dijkstra(S);
string ans = "DA";
for(int i = 1; i <= n; i++){
if(r[i] != dist[i])ans = "NU";
}
out << ans << '\n';
for(int i = 1; i <= n; i++)v[i].clear();
}
}