Pagini recente » Cod sursa (job #562362) | Cod sursa (job #1522185) | Cod sursa (job #2141104) | Cod sursa (job #545860) | Cod sursa (job #3284082)
#include <bits/stdc++.h>
using namespace std;
ifstream f("distante.in");
ofstream g("distante.out");
#define cout g
const int INF=1e9, NMAX=100001;
int main()
{
int t;
f >> t;
for(int T=1; T<=t; T++)
{
int n, m, s;
f >> n >> m >> s;
bitset<NMAX> viz=0;
vector<vector<pair<int,int>>> v(n+1, vector<pair<int,int>>());
vector<int> pred(n+1);
priority_queue<pair<int, int>>pq;
vector<int> d(n+1,INF);
for(int i=1; i<=n; i++)
{
f >> pred[i];
}
for(int i=1; i<=m; i++)
{
int x, y, c;
f >> x >> y >> c;
v[x].push_back({y,c});
v[y].push_back({x,c});
}
d[s]=0;
pq.push({0,s});
while(!pq.empty())
{
int curent, dist;
tie(dist,curent)=pq.top();
dist=-dist;
pq.pop();
if(!viz[curent])
{
for(auto& vecin:v[curent])
{
if(d[vecin.first]>d[curent]+vecin.second)
{
d[vecin.first]=d[curent]+vecin.second;
pq.push({-d[vecin.first], vecin.first});
}
}
viz[curent]=1;
}
}
int ok=0;
for(int i=1; i<=n; i++)
{
if(d[i]!=pred[i])
{
ok=1;
}
}
if(ok==1)
cout << "NU" <<'\n';
else cout << "DA" << '\n';
}
}