Cod sursa(job #3298752)

Utilizator Carnu_EmilianCarnu Emilian Carnu_Emilian Data 1 iunie 2025 12:41:14
Problema PScNv Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fcin("pscnv.in");
ofstream fcout("pscnv.out");
typedef long long ll;

const int N = 25e4 + 5;
const int M = 1e3 + 5;
vector<vector<int>> L(M);
vector<vector<pair<int, int>>> h(N);
int n, m, x, y, d[N], a, b, c;
bool viz[N];

int main()
{
    fcin >> n >> m >> x >> y;
    while (m--)
    {
        fcin >> a >> b >> c;
        h[a].push_back({b, c});
    }
    for (int i = 1; i <= n; i++)
        d[i] = 1e9;
    d[x] = 0;
    L[0].push_back(x);
    for (int i = 0; i < M; i++)
        for (int e : L[i])
            if (!viz[e])
            {
                viz[e] = 1;
                for (pair<int, int> p : h[e])
                {
                    int nod, cost;
                    nod = p.first;
                    cost = p.second;
                    if (max(cost, d[e]) < d[nod])
                    {
                        d[nod] = max(cost, d[e]);
                        L[d[nod]].push_back(nod);
                    }
                }
            }
    fcout << d[y];
    fcin.close();
    fcout.close();
    return 0;
}