Cod sursa(job #2398926)

Utilizator blasterzMircea Dima blasterz Data 6 aprilie 2019 14:12:13
Problema PScNv Scor 70
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.48 kb
#include <fstream>
#include <vector>
#include <queue>
#include <climits>
using namespace std;
#define INF INT_MAX
//ifstream f("pscnv.in");
ofstream g("pscnv.out");

#define dim 8192
char ax[dim];
int pz = 0;

void readInt(int &x) {
    x = 0;
    while (ax[pz] < '0' || ax[pz] > '9')
        if (++pz == dim)
            fread(ax, 1, dim, stdin), pz = 0;
    while (ax[pz] >= '0' && ax[pz] <= '9') {
        x = x * 10 + ax[pz] - '0';
        if (++pz == dim)
            fread(ax, 1, dim, stdin), pz = 0;
    }
}


int n, m, x, y, dp[250001];
struct muchie{
    int nod, pond;
};
vector<muchie> a[250001];
queue<int> Q;
void parcurgere(int nod) {
    Q.pop();
    if (nod - y)
        for (int i = 0; i < a[nod].size(); ++i) {
            muchie v = a[nod][i];
            if (dp[v.nod] == INF) {
                dp[v.nod] = max(v.pond, dp[nod]);
                Q.push(v.nod);
            }
            else if (dp[nod] < dp[v.nod] && v.pond < dp[v.nod]) {
                dp[v.nod] = max(v.pond, dp[nod]);
                Q.push(v.nod);
            }
        }
}
int main()
{
    freopen("pscnv.in", "r", stdin);
    readInt(n); readInt(m); readInt(x); readInt(y);
    int d, b, c;
    for (int i = 1; i <= m; ++i) {
        readInt(d); readInt(b); readInt(c);
        muchie l;
        l.nod = b;
        l.pond = c;
        a[d].push_back(l);
    }
    for (int i = 1; i <= n; ++i) dp[i] = INF;
    dp[x] = 0;
    Q.push(x);
    while (!Q.empty()) parcurgere(Q.front());
    g << dp[y] << '\n';
    return 0;
}