Pagini recente » Cod sursa (job #3214452) | Borderou de evaluare (job #1777567) | oji20-20_dau_leak_la_probleme_smr | Borderou de evaluare (job #2902010) | Cod sursa (job #640290)
Cod sursa(job #640290)
#include <fstream>
#include <vector>
#include <queue>
#define PII pair<int,int>
#define st first
#define nd second
#define MP make_pair
using namespace std;
ifstream fin("distante.in");
ofstream fout("distante.out");
const int INF = int(2e9);
int N , M , S , D[50002] , dd[50002];
bool ans;
struct cmp{ bool operator() (const int &x,const int &y)
const { return D[x] < D[y]; }
};
priority_queue<int,vector<int>,cmp> h;
bool solve_test()
{
fin>>N>>M>>S;
vector< PII > G[50001];
int x , y , c;
for(int i=1;i<=N;++i)
fin>>dd[i] , D[i] = INF;
for(fin>>N>>M>>S;M;M--)
{
fin>>x>>y>>c;
G[x].push_back(MP(y,c));
G[y].push_back(MP(x,c));
}
D[S] = 0;
for(h.push(S);!h.empty();)
{
x = h.top() , h.pop();
for(vector< PII >::const_iterator w = G[x].begin();w!=G[x].end();++w)
if(D[w->st] > D[x] + w->nd)
D[w->st] = D[x] + w->nd , h.push(w->st);
}
for(int i = 1; i <= N;++i)
if(D[i]!=dd[i]) return 0;
return 1;
}
int main()
{
int T;
for(fin>>T;T;T--)
fout<< (solve_test()==1 ? "DA\n" : "NU\n");
return 0;
}