Pagini recente » Istoria paginii runda/adasd | Statistici Toncu Vlad (VladyTvm) | Istoria paginii runda/dorna_reloaded | Cod sursa (job #1108081) | Cod sursa (job #1028940)
#include <cstdio>
#include <vector>
using namespace std;
struct muchie {
int nod,dist;
};
vector <muchie> v[50005];
vector <muchie> :: iterator it;
int dist[50005];
bool gasit[50005];
bool maimic;
int n,m,s,t;
muchie mkmuc(int nod,int dist) {
muchie nou;
nou.dist = dist;
nou.nod = nod;
return nou;
}
int main() {
freopen("distante.in","r",stdin);
freopen("distante.out","w",stdout);
scanf("%d",&t);
while (t--) {
maimic = false;
bool rau = false;
scanf("%d %d %d",&n,&m,&s);
for (int i=1;i<=n;i++) {
while (!v[i].empty()) v[i].pop_back();
scanf("%d",&dist[i]);
gasit[i] = false;
}
for (int i=1;i<=m;i++) {
int a,b,d;
scanf("%d %d %d",&a,&b,&d);
v[a].push_back(mkmuc(b,d));
v[b].push_back(mkmuc(a,d));
}
for (int i=1;i<=n;i++) {
for (it = v[i].begin();it != v[i].end();it++) {
muchie muc = *it;
if (dist[muc.nod] == dist[i] + muc.dist) gasit[muc.nod] = true;
if (dist[muc.nod] > dist[i] + muc.dist) {maimic = true;break;}
}
}
if (dist[s] == 0) gasit[s] = true;
if (maimic) {
printf("NU\n");
rau = true;
}
if (!rau) for (int i=1;i<=n;i++) if (!gasit[i]) {
printf("NU\n");
rau = true;
break;
}
if (!rau) printf("DA\n");
}
return 0;
}