Cod sursa(job #2064816)

Utilizator vladcoroian2001Vlad Coroian vladcoroian2001 Data 12 noiembrie 2017 21:07:56
Problema Distante Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.2 kb
#include <stdio.h>
#include <vector>
#include <fstream>
using namespace std;
ifstream fi("distante.in");
ofstream fo("distante.out");
const int nmax=50000;
int t,n,m,s,x,y,c,ok,BEST[nmax];
vector <pair <int,int> > V[nmax];
int main()
{
    fi>>t;
    while(t--)
    {
        fi>>n>>m>>s;
        ok=1;
        for(int i=1;i<=n;i++)
            fi>>BEST[i];
        if(BEST[s]!=0)
        {
            fo<<"NU\n";
            continue;
        }
        for(int i=1;i<=m;i++)
        {
            fi>>x>>y>>c;
            V[x].push_back({y,c});
            V[y].push_back({x,c});
        }
        for(int i=1;i<=n;i++)
        {
            for(auto edge:V[i])
            {
                int y=edge.first;
                int cost=edge.second;
                if(BEST[y]>cost+BEST[i])
                {
                    ok=0;
                    break;
                }
            }
            if(ok==0)
                break;
        }
        if(ok==0)
            fo<<"NU\n";
        else
            fo<<"DA\n";
        for(int i=1;i<=n;i++)
            V[i].clear();
    }
    fi.close();
    fo.close();
    ///fclose(fi);
    ///fclose(fo);
    return 0;
}