Pagini recente » Cod sursa (job #2314429) | Cod sursa (job #611273)
Cod sursa(job #611273)
#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,z,i,aux,sol=0;
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)
{
fgets(ch,sizeof(ch),stdin);
aux=strlen(ch)-1;
for (x=0,i=0;i<aux;++i)
if (ifnum(ch[i]))
x=x*10+ch[i]-'0';
else
break;
++i;
for (y=0;i<aux;++i)
if (ifnum(ch[i]))
y=y*10+ch[i]-'0';
else
break;
++i;
for (z=0;i<aux;++i)
if (ifnum(ch[i]))
z=z*10+ch[i]-'0';
else
break;
auxn.x=y;
auxn.d=z;
g[x].push_back(auxn);
}
auxn.d=0;
auxn.x=x;
b[x]=1;
h.push(auxn);
while (!h.empty())
{
auxn=h.top();
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;
}