Cod sursa(job #1507896)

Utilizator justsomedudePalade Thomas-Emanuel justsomedude Data 21 octombrie 2015 23:23:57
Problema PScNv Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.31 kb
#include<iostream>
#include<fstream>
#include<queue>

using namespace std;

ifstream fin ("pscnv.in");
ofstream fout ("pscnv.out");

struct Nod
{
    int nod, cost;
    bool operator < (const Nod& e) const
    {
        return cost > e.cost;
    }
};

vector <Nod> L[250005];
int n,m,d[250005], X, Y;

priority_queue <Nod> q;

void Citire()
{
  int x,y,costt;
  Nod w;
  fin >> n >> m >> X >> Y;
  for (int i=1; i<=m; i++)
   {
      fin >> x >> y >> costt;
      w.nod=y;
      w.cost=costt;
      L[x].push_back(w);
   }
}

void Lee_Bellman_Ford_BFS_Dijkstra()
{
  int i,j,k,costt, c;
  Nod w,w1;
  w.nod=X;
  w.cost=0;
  q.push(w);
  for (i = 1;i <= n; i++)
	d[i] = 1000000000;
  d[X]=0;

  while (!q.empty())
 {
   w = q.top();
   q.pop();

   k = w.nod;
   c = w.cost;
   for (int j=0; j<L[k].size(); j++)
       {
            i = L[k][j].nod; costt = L[k][j].cost;

            c1 = max(d[k],costt);
if (d[i] > c1)
               {
                   d[i] = c1;
                   w1.nod=i;
                   w1.cost=c1;
                   q.push(w1);
               }
       }
 }
}

void Print_that()
{
 fout << d[Y] << "\n";
}

int main ()
{
 Citire();
 Lee_Bellman_Ford_BFS_Dijkstra();
 Print_that();
 fin.close();
 fout.close();
 return 0;
}