Cod sursa(job #712431)

Utilizator GavrilaVladGavrila Vlad GavrilaVlad Data 13 martie 2012 14:21:31
Problema PScNv Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.16 kb
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

#define maxn 250010
#define maxk 1010

int n, m, k, fiu, nod, a, b, c, x, y, sol[maxn];
vector<int> v[maxn], w[maxn], l[maxk];

int main()
{
    freopen("pscnv.in", "r", stdin);
    freopen("pscnv.out", "w", stdout);

    scanf("%d%d%d%d", &n, &m, &x, &y);
    for(int i=1; i<=m; ++i)
    {
        scanf("%d%d%d", &a, &b, &c);
        v[a].push_back(b);
        w[a].push_back(c);
    }

    for(int i=1; i<=n; ++i)
        sol[i]=maxk;
    sol[x]=0;

    l[0].push_back(x);
    for(int i=0; i<=1000; ++i)
    {
        for(int pz=0; pz<l[i].size(); ++pz)
        {
            nod=l[i][pz];
            if(nod==y)
            {
                printf("%d\n", i);
                return 0;
            }
            if(sol[nod]!=i)
                continue;
            for(int j=0; j<v[nod].size(); ++j)
            {
                fiu=v[nod][j];
                if(sol[fiu]>max(i, w[nod][j]))
                {
                    sol[fiu]=max(i, w[nod][j]);
                    l[max(i, w[nod][j])].push_back(fiu);
                }
            }
        }
    }
    return 0;
}