Pagini recente » Cod sursa (job #334086) | Cod sursa (job #2442463) | Cod sursa (job #1604337) | Cod sursa (job #2226454) | Cod sursa (job #1795134)
#include <iostream>
#include<cstdio>
#include<vector>
#include<queue>
#define Nmax 250001
#define inf 100005
using namespace std;
#define DIM 10000
priority_queue<pair <int,int> ,vector<pair<int,int> >, greater<pair <int,int> > >h;
char buff[DIM];
int poz=0;
void citeste(int &numar)
{
numar = 0;
//cat timp caracterul din buffer nu e cifra ignor
while (buff[poz] < '0' || buff[poz] > '9')
//daca am "golit" bufferul atunci il umplu
if (++poz == DIM)
fread(buff,1,DIM,stdin),poz=0;
//cat timp dau de o cifra recalculez numarul
while ('0'<=buff[poz] && buff[poz]<='9')
{
numar = numar*10 + buff[poz] - '0';
if (++poz == DIM)
fread(buff,1,DIM,stdin),poz=0;
}
}
int n,m,x,y,i,j,cost[Nmax],cst,sol,ans,s[Nmax];
vector<pair<int,int> >v[Nmax];
void Dijkstra(int p)
{
int k;
cost[p]=0;
h.push(make_pair(0,p));
while(h.size())
{
int nod=h.top().second;
int cst=h.top().first;
sol=max(sol,h.top().first);
s[nod]=min(s[nod],sol);
ans=max(ans,s[nod]);
h.pop();
for(k=0;k<v[nod].size();k++)
{
if(cost[v[nod][k].second] > v[nod][k].first)
{
cost[v[nod][k].second]=v[nod][k].first;
h.push(make_pair(max(sol,v[nod][k].first),v[nod][k].second));
}
}
}
/*int i,k;
for(i=1;i<=n;i++)
{
heap_node[i]=i;
h[i].cost=inf;
h[i].nod=i;
}
h[p].cost=0;
BuildHeap();
bool ok=1,ok1=1;
while(n>1 && ok)
{
j=extractMin();
if(j==y)
ok=0;
sol=max(sol,h[heap_node[j]].cost);
int sz=v[j].size();
for(k=0;k<sz&&ok;k++)
{
jh=heap_node[v[j][k].first];
if(v[j][k].second<h[jh].cost)
{
h[jh].cost=max(sol,v[j][k].second);
up(jh);
}
}
cut(heap_node[j]);
}*/
}
int main()
{
freopen("pscnv.in","r",stdin);
freopen("pscnv.out","w",stdout);
citeste(n);
citeste(m);
citeste(x);
citeste(y);
for(;m;m--)
{
citeste(i);
citeste(j);
citeste(cst);
v[i].push_back(make_pair(cst,j));
}
for(i=1;i<=n;i++)
cost[i]=s[i]=inf;
Dijkstra(x);
cout<<ans;
}