Cod sursa(job #1493338)

Utilizator alexpetrescuAlexandru Petrescu alexpetrescu Data 29 septembrie 2015 01:19:24
Problema PScNv Scor 80
Compilator c Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <stdio.h>
#include <string.h>
#define MAXN 250000
#define MAXM 500000
typedef struct{
    int val, cost, next;
}mycreation;
mycreation e[MAXM+1];
int lista[MAXN+1], ok[MAXN+1], f, a, b, r;
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 *fin, *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++){
        fscanf(fin, "%d%d%d", &x, &e[i].val, &e[i].cost);
        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;
}