Cod sursa(job #1701170)

Utilizator tudorgalatanRoman Tudor tudorgalatan Data 12 mai 2016 12:31:19
Problema Distante Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.76 kb
#include <fstream>
#include <climits>
#define InFile  "distante.in"
#define OutFile "distante.out"
#define MAX 1001

using namespace std;

unsigned short int T;
unsigned short int N, S;
unsigned int M;
unsigned int a[MAX], b[MAX], c[MAX];
unsigned int D[MAX];

unsigned int matrix[MAX][MAX];
bool okay;
unsigned int path[MAX];
unsigned int i, j, cnt;

int main ()
{
    ifstream fin (InFile);
    ofstream fout (OutFile);

    fin >> T;
    for (i=1; i<=T; i++)
    {
        fin >> N >> M >> S;
        for (j=1; j<=N; j++)
            fin >> D[j];
        for (j=1; j<=M; j++)
            fin >> a[j] >> b[j] >> c[j];


        for (j=1; j<=N; j++)
            path[j] = 0;
        okay = 0;
        j = 0;
        cnt = 0;


        for (j=1; j<=M; j++)
            if (a[j] == 1)
                path[b[j]] = c[j];
        for (j=1; j<=N; j++)
            if (path[j] == 0)
                path[j] = INT_MAX;
        while (okay == 0)
        {
            okay = 1;
            for (j=1; j<=M; j++)
                if (path[b[j]] > path[a[j]] + c[j])
                {
                    path[b[j]] = path[a[j]] + c[j];
                    okay = 0;
                }
        }

        for (j=1; j<=N; j++)
            if (path[j] == INT_MAX)
                path[j] = 0;

        for (j=1; j<=N; j++)
            if (D[j] == path[j])
                cnt++;


        if (cnt == N)
            fout << "DA";
        else
            fout << "NU";

        /*
        for (j=1; j<=N; j++)
            if (path[j] != INT_MAX)
                fout << path[j] << ' ';
            else
                fout << 0 << ' ';
        */
        fout << '\n';
    }

    fin.close();
    fout.close();
    return 0;
}