Cod sursa(job #886203)

Utilizator radu_bucurRadu Bucur radu_bucur Data 22 februarie 2013 18:20:45
Problema Distante Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <fstream>
#include <vector>
using namespace std;
ifstream in("distante.in");
ofstream out("distante.out");
vector <int> a[50001],b[50001];
int n,i, x,y,z,e,l,k,m,c[50001],t,s;
bool ok;
bool verif1()
{
   int j;
    for(j=0;j<a[i].size();j++)
    {
        y=a[i][j];
        if(c[i]>c[y]+b[i][j]) return false;
    }
    return true;
}
bool verif2()
{
    int j;
    bool ok1;
    ok1=true;
    if(i==s) return true;
    for(j=0;j<a[i].size();j++)
    {
        y=a[i][j];
        if(c[i]==c[y]+b[i][j]) ok1=false;
    }
    if (ok1==false) return true;
    return false;
}
int main()
{
    in>>t;
    for(e=1;e<=t;e++)
    {
        in>>n>>m>>s;
        for(i=1;i<=n;i++)
        {
            a[i].clear();
            b[i].clear();
        }
        l=1; k=1; ok=true;
        for(i=1;i<=n;i++)
        {
            in>>c[i];
        }
        for(i=1;i<=m;i++)
        {
            in>>x>>y>>z;
            a[x].push_back(y);
            a[y].push_back(x);
            b[x].push_back(z);
            b[y].push_back(z);
        }
        for(i=1;i<=n;i++)
        {
                if(verif1()!=true&&verif2()!=true) ok=false;
        }
    }
    return 0;
}