Pagini recente » Cod sursa (job #1849453) | Cod sursa (job #530984) | Cod sursa (job #1883954) | Cod sursa (job #1173760) | Cod sursa (job #1493339)
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAXN 250000
#define MAXM 500000
#define BUF_SIZE 4096
char buf[BUF_SIZE];
int pos=BUF_SIZE;
typedef struct{
int val, cost, next;
}mycreation;
mycreation e[MAXM+1];
int lista[MAXN+1], ok[MAXN+1], f, a, b, r;
FILE *fin;
inline char nextch(){
if(pos==BUF_SIZE){
fread(buf, BUF_SIZE, 1, fin);
pos=0;
}
return buf[pos++];
}
inline int read(){
int x=0;
char ch=nextch();
while(!isdigit(ch)){
ch=nextch();
}
while(isdigit(ch)){
x=10*x+ch-'0';
ch=nextch();
}
return x;
}
void dfs(int x){
int p=lista[x];
ok[x]=1;
if(x==b){
f=1;
return ;
}
while(p){
if((e[p].cost<=r)&&(ok[e[p].val]==0)){
dfs(e[p].val);
if(f==1){
return ;
}
}
p=e[p].next;
}
}
inline int check(int t){
f=0;
r=t;
memset(ok, 0, sizeof ok);
dfs(a);
return f;
}
int main(){
int n, m, rez, pas, x, i;
FILE *fout;
fin=fopen("pscnv.in", "r");
fout=fopen("pscnv.out", "w");
fscanf(fin, "%d%d%d%d", &n, &m, &a, &b);
for(i=1; i<=m; i++){
x=read();
e[i].val=read();
e[i].cost=read();
e[i].next=lista[x];
lista[x]=i;
}
rez=-1;
for(pas=1<<9; pas; pas>>=1){
if(!check(rez+pas)){
rez+=pas;
}
}
rez++;
fprintf(fout, "%d\n", rez);
fclose(fin);
fclose(fout);
return 0;
}