Cod sursa(job #174051)

Utilizator crawlerPuni Andrei Paul crawler Data 8 aprilie 2008 13:59:46
Problema PScNv Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <cstdio>
#include <vector>
#include <bitset>
#include <algorithm>

using namespace std;

#define pb push_back
#define mk make_pair
#define fs first
#define sd second
#define Nmax 250006

vector< pair<int,int> > l[Nmax];
vector<int> best[Nmax];
bitset<Nmax> v;
int n,m,x,y;

int main()
{
    freopen("pscnv.in","r",stdin);
    freopen("pscnv.out","w",stdout);
    
    scanf("%d%d%d%d", &n,&m,&x,&y);
    
    int A,B,C;
    
    for (int i=1;i<=m;++i)
    {
        scanf("%d%d%d", &A,&B,&C);
        l[A].pb(mk(B,C));
        l[B].pb(mk(A,C));    
    }
    
    best[0].pb(x);
    
    for (int i=0;i<=10;++i)
    {
        v = 0;
        for (int j=0;j<best[i].size();++j)    
        {
            v[best[i][j]] = 1;
            if (best[i][j] == y)
            {
               printf("%d\n", i);
               return 0;               
            }
            for (int k=0;k<l[best[i][j]].size();++k) if (v[l[best[i][j]][k].fs]==0)
            best[max(i,l[best[i][j]][k].sd)].pb(l[best[i][j]][k].fs);    
        }
    }   
    
    return 0;    
}