Cod sursa(job #2975485)

Utilizator and_Turcu Andrei and_ Data 6 februarie 2023 17:24:45
Problema PScNv Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <bits/stdc++.h>
#define N 250007
using namespace std;

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

int st,dr,n,m;
vector<int> muchie_minima(N,-1);
vector<pair<int,int>>g[N];
bitset<N>viz;

void Citire()
{
    fin >> n >> m >> st >> dr;
    for(int i=1;i<=n;i++)
    {
        int x,y,c;
        fin >> x >> y >> c;
        g[x].push_back({c,y});
    }
    fin.close();
}

void Rezolvare()
{
    Citire();

    priority_queue<pair<int,int>> pq;
    pq.push({0,st});
    muchie_minima[st]=0;
    while( !pq.empty() )
    {
        int cur=pq.top().second;
        int v=-pq.top().first;
        pq.pop();
        if( !viz[cur] )
        {
            for(auto w:g[cur])
            {
                int nod=w.second;
                int cost=w.first;
                if( muchie_minima[nod]==-1 or muchie_minima[nod]>max(v,cost) )
                {
                    muchie_minima[nod]=max(v,cost);
                    pq.push( {-muchie_minima[nod],nod} );
                }
            }
        }
        viz[cur]=1;
    }
    fout << muchie_minima[dr] << "\n";
    fout.close();
}


int main()
{
    Rezolvare();
    return 0;
}