Cod sursa(job #950972)

Utilizator antonioteoZait Teodor Antonio antonioteo Data 18 mai 2013 21:05:41
Problema PScNv Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.47 kb
#include <cstdio>
#include <vector>
#include <cstring>
#include <queue>
#define dim 8192
using namespace std;
const char iname[] = "pscnv.in";
const char oname[] = "pscnv.out";
int d[250004];
struct nod{
    int y, c; nod(){}; nod(int m, int n){ y = m; c = n;};
};
vector <nod> v[250004];
vector <nod> :: iterator it, fin;
/*
struct cmp{
	bool operator()(const int &a, const int &b)const{
		if (d[a] > d[b]) return 1;
		return 0;
	};
};
priority_queue <int, vector <int>, cmp> Q;
*/
queue <int> Q;
bool viz[250004];
int x;
char ax[dim];
int pz;
inline void cit(int &x){
    x = 0;
    while (ax[pz] < '0' || ax[pz] > '9')
        if (++pz == dim)
            fread (ax, 1, dim, stdin), pz = 0;
    while (ax[pz] >= '0' && ax[pz] <= '9'){
        x = x * 10 + ax[pz] - '0';
        if (++pz == dim)
            fread (ax, 1, dim, stdin), pz = 0;
    }
}
int N, M, A, B, i, j, g, h, ANS;
int main()
{
    freopen(iname,"r",stdin);
    freopen(oname,"w",stdout);
    cit(N); cit(M); cit(A); cit(B);
	for (i = 1; i <= N; ++i) d[i] = 0x3f3f3f3f;
    while (M--){
        cit(g); cit(h); cit(i);
        v[g].push_back(nod(h, i));
    }
	Q.push(A);
	d[A] = 0;
	while (!Q.empty()){
		x = Q.front();
		Q.pop();
		it = v[x].begin();
		fin = v[x].end();
		for (; it != fin; ++it){
			if (it -> c < d[it -> y] && d[x] < d[it -> y])
			{
				d[it -> y] = max(it -> c, d[x]);
				Q.push(it -> y);
			}
		}
	}
	printf("%d\n", d[B]);
    return 0;
}