Cod sursa(job #1075097)

Utilizator acomAndrei Comaneci acom Data 8 ianuarie 2014 16:54:57
Problema Distante Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include<fstream>
#include<vector>
using namespace std;
ifstream f("distante.in");
ofstream g("distante.out");
struct muchie {int x,y,c;} G[100005];
int t,k,m,n,s,d[50005];
void rez()
{
    int x,y,c,i;
    bool ok;
    f>>n>>m>>s;
    for (i=1;i<=n;++i) f>>d[i];
    k=0;
    for (i=1;i<=m;++i)
    {
        f>>x>>y>>c;
        G[++k].x=x, G[k].y=y, G[k].c=c;
        if (x!=y) G[++k].x=y, G[k].y=x, G[k].c=c;
    }
    for (i=1,ok=true;i<=k && ok;++i)
        if (d[G[i].x]+G[i].c<d[G[i].y])
            ok=false;
    if (ok) g<<"DA\n";
    else g<<"NU\n";
}
int main()
{
    int i;
    f>>t;
    for (i=0;i<t;++i)
        rez();
    return 0;
}