Pagini recente » Cod sursa (job #766679) | Cod sursa (job #614967) | Cod sursa (job #291657) | Cod sursa (job #1490198) | Cod sursa (job #611291)
Cod sursa(job #611291)
#include <bitset>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
using namespace std;
inline bool ifnum(char x){return (x>='0'&&x<='9');}
bitset <250001> b(0);
char ch[30];
struct node{int x,d;};
struct cmp_n{bool operator()(node x,node y){return x.d>y.d;};};
priority_queue <node,vector <node>,cmp_n> h;
vector <node> g[250001];
int main()
{
int n,m,x,y,sol=0,a1,a2,a3;
vector <node>::iterator it;
node auxn,auxn2;
freopen("pscnv.in","r",stdin);
freopen("pscnv.out","w",stdout);
scanf("%d %d %d %d\n",&n,&m,&x,&y);
for (;m;--m)
{
scanf("%d %d %d\n",&a1,&a2,&a3);
auxn.x=a2;
auxn.d=a3;
g[a1].push_back(auxn);
}
auxn.d=0;
auxn.x=x;
h.push(auxn);
while (!h.empty())
{
auxn=h.top();
b[auxn.x]=1;
h.pop();
if (auxn.d>sol)
sol=auxn.d;
if (auxn.x==y)
break;
for (it=g[auxn.x].begin();it!=g[auxn.x].end();++it)
if (!b[it->x])
{
auxn2.x=it->x;
auxn2.d=it->d;
h.push(auxn2);
}
}
printf("%d\n",sol);
return 0;
}