Cod sursa(job #1434713)

Utilizator Darius15Darius Pop Darius15 Data 11 mai 2015 10:32:15
Problema PScNv Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
ifstream f("pscnv.in");
ofstream g("pscnv.out");
int e1,e2,j,n,m,i,y,c,st,dr,nr,best,x,viz[250001];
vector <pair <int,int> > v[250001];
queue <int> q;
bool drum(int m,int nr)
{
  int x;
   q.push(e1);
   while(!q.empty())
   {
     x=q.front();
     if (x==e2){
      while(!q.empty()) q.pop();return true;
     }
     q.pop();
     for (j=0;j<v[x].size();j++)
      if (viz[v[x][j].first]!=nr && v[x][j].second<=m)
      viz[v[x][j].first]=nr,q.push(v[x][j].first);
   }
   return false;
}

int main()
{
    f>>n>>m>>e1>>e2;
    for (i=1;i<=m;i++)
    {f>>x>>y>>c;
     v[x].push_back(make_pair(y,c));
    }
    st=1,dr=1000;
    while(st<=dr)
    {
      nr++;
     m=(st+dr)/2;
     if (drum(m,nr)==true)
      best=m,dr=m-1;
     else
      st=m+1;
    }
    g<<best;

    return 0;
}