Cod sursa(job #2077241)

Utilizator flibiaVisanu Cristian flibia Data 27 noiembrie 2017 20:23:59
Problema PScNv Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.18 kb
#include <bits/stdc++.h>

using namespace std;

#define dim 100001
char buff[dim];
int pos = 0;

void read(int &nr){
	nr = 0;
	while(buff[pos] < '0' || buff[pos] > '9')
		if(++pos == dim) fread(buff, 1, dim, stdin), pos = 0;
	while(buff[pos] >= '0' && buff[pos] <= '9'){
		nr = 10*nr + buff[pos] - '0';
		if(++pos == dim) fread(buff, 1, dim, stdin), pos = 0;
	}
}

int n, m, x, y, from, to, c;
short st, dr, mid, mx, d[250100];
vector <pair <int, short> > v[250100];
set <pair <short, int> > h;
queue <int> q;

void ride_it(){
	for(int i = 1; i <= n; i++)
		d[i] = 1234;
	d[from] = 0;
	pair <short, int> dad;
	h.insert({0, from});
	while(!h.empty()){
		dad = *h.begin();
		h.erase(h.begin());
		for(auto son : v[dad.second])
			if(max(d[dad.second], son.second) < d[son.first]){
				d[son.first] = max(d[dad.second], son.second);
				h.insert({d[son.first], son.first});
			}
	}
}

int main(){
	freopen("pscnv.in", "r", stdin);
	freopen("pscnv.out", "w", stdout);
	cin >> n >> m >> from >> to;
	for(int i = 1; i <= m; i++){
		read(x); read(y); read(c);
		mx = max(mx, (short)c);
		v[x].push_back({y, (short)c});
	}
	ride_it();
	cout << d[to];
	return 0;
}