Cod sursa(job #1383001)

Utilizator vladrochianVlad Rochian vladrochian Data 9 martie 2015 20:06:03
Problema PScNv Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <fstream>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;

const int kMaxN = 250005;

ifstream fin("pscnv.in");
ofstream fout("pscnv.out");

int N, M, x, y, sol;
vector<pair<int, int>> G[kMaxN];
bool vis[kMaxN];
char buffer[35], *p;

void Parse(int &x) {
	x = 0;
	while (!isdigit(*p))
		++p;
	while (isdigit(*p))
		x = x * 10 + *(p++) - '0';
}

void DFS(int node, int lim) {
	vis[node] = true;
	for (const auto &it : G[node])
		if (!vis[it.first] && it.second < lim)
			DFS(it.first, lim);
}

bool Check(int lim) {
	memset(vis, 0, sizeof vis);
	DFS(x, lim);
	return vis[y];
}

int main() {
	fin.getline(p = buffer, 35);
	Parse(N);
	Parse(M);
	Parse(x);
	Parse(y);
	while (M--) {
		int x, y, k;
		fin.getline(p = buffer, 35);
		Parse(x);
		Parse(y);
		Parse(k);
		G[x].emplace_back(y, k);
	}
	for (int step = 1 << 9; step; step >>= 1)
		if (!Check(sol | step))
			sol |= step;
	fout << sol << "\n";
	return 0;
}