Pagini recente » Cod sursa (job #3282551) | Cod sursa (job #744284) | Cod sursa (job #817284) | Cod sursa (job #1995681) | Cod sursa (job #1914860)
#include <fstream>
#include <bitset>
#include <list>
#include <cstring>
using namespace std;
list<pair<int,int> >G[250010];
int n,m,x,y,c,i,j,ls,ld,mij,a,b,ans,viz[250010];
ifstream fin("pscnv.in");
ofstream fout("pscnv.out");
void DF( int nod )
{
viz[ nod / 32 ] |= ( 1 << ( nod % 32 ) );
for( auto it : G[ nod ] )
{
if( ( viz[ it.first / 32 ] ^ ( 1 << ( it.first % 32 ) ) ) && it.second <= mij )
DF( it.first );
}
}
int main()
{
fin>>n>>m>>a>>b;
for( i = 1 ; i <= m ; i++ )
{
fin>>x>>y>>c;
G[ x ].push_back( { y , c } );
}
ls = 1;
ld = 1000;
while( ls <= ld )
{
mij = ( ls + ld ) / 2;
for( i = 0 ; i <= n / 32 + 2 ; i++ )
viz[ i ] = 0;
DF( a );
if( ls == ld )
{
if( viz[ b ] == 1 )
fout<<min(ans,mij);
else
fout<<ans;
return 0;
}
if( viz[ b / 32 ] ^ ( 1 << ( b % 32 ) ) )
ld = mij - 1,ans = mij;
else
ls = mij + 1;
}
fout<<ans;
return 0;
}