Cod sursa(job #2918193)

Utilizator tomaionutIDorando tomaionut Data 10 august 2022 14:10:16
Problema PScNv Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

ifstream fin("pscnv.in");
ofstream fout("pscnv.out");
int n, m, k, dp[250005], X, Y;
bitset <250005> viz;
vector <pair <int, int> > a[250005];
priority_queue <pair <int, int> > q;
int main()
{
	int i, j, c, x, cost;
	fin >> n >> m >> X >> Y;
	while (m--)
	{
		fin >> i >> j >> c;
		a[i].push_back({ c, j });
	}

	for (i = 1; i <= n; i++)
		dp[i] = INF;

	dp[X] = 0;
	q.push({ 0, X });
	while (!q.empty())
	{
		x = q.top().second;
		q.pop();
		if (viz[x] == 0)
		{
			viz[x] = 1;
			for (auto w : a[x])
			{
				cost = max(w.first, dp[x]);
				if (dp[w.second] > cost)
				{
					dp[w.second] = cost;
					q.push({ -cost, w.second });
				}
			}
		}
	}

	fout << dp[Y] << "\n";

	return 0;
}