Pagini recente » Cod sursa (job #1972590) | Cod sursa (job #236089) | Cod sursa (job #1900587) | Cod sursa (job #1554720) | Cod sursa (job #1951269)
#include <fstream>
#include <vector>
#include <cstring>
#define nmax 250005
using namespace std;
class instream {
public:
instream() {}
instream(const char *file_name) {
input_file=fopen(file_name,"r");
cursor=0;
fread(buffer,SIZE,1,input_file);
}
inline instream &operator >>(int &n) {
while((buffer[cursor]<'0'||buffer[cursor]>'9')&&buffer[cursor]!='-') {
advance();
}
int semn=1;
if (buffer[cursor]=='-')
semn=-1,advance();
n=0;
while('0'<=buffer[cursor]&&buffer[cursor]<='9') {
n=n*10+buffer[cursor]-'0';
advance();
}
n*=semn;
return *this;
}
private:
FILE *input_file;
static const int SIZE=1<<15;
int cursor;
char buffer[SIZE];
inline void advance() {
++ cursor;
if(cursor==SIZE) {
cursor=0;
fread(buffer,SIZE,1,input_file);
}
}
};
instream f("pscnv.in");
ofstream g("pscnv.out");
vector <pair<int,int> > v[nmax];
int n,m,k,x,y,d[nmax];
void dfs(int x)
{
int i,z,t;
d[x]=1;
if (d[y])
return;
for (i=0;i<v[x].size();i++) {
z=v[x][i].first;
t=v[x][i].second;
if (t<=k&&d[z]==0)
dfs(z);
}
}
int possible(int p)
{
if (p<1)
return 0;
memset(d,0,sizeof(d));
k=p;
dfs(x);
return d[y];
}
int main()
{
int i,j,l,p;
f>>n>>m>>x>>y;
if (x==y) {
g<<1<<'\n';
return 0;
}
for (i=1;i<=m;i++) {
f>>j>>l>>p;
v[j].push_back(make_pair(l,p));
}
for (i=0,j=1<<9;j;j>>=1)
if (possible(1000-(i+j)))
i+=j;
g<<1000-i<<'\n';
return 0;
}