Cod sursa(job #3201631)

Utilizator robert2007oprea robert robert2007 Data 9 februarie 2024 11:39:04
Problema Sate Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.15 kb
#include <iostream>
#include <fstream>
#define L 100030
using namespace std;
ifstream f("sate.in");
ofstream g("sate.out");

int t[4][L], n, m, x, y, start[L], pp, pa, km, k, c[L], viz[L], pred[L];
void bfs_cu_liste(int plec, int ajung)
{
    int st, dr, k, om, sum = 0;
    st = dr = 1;
    c[dr] = plec;
    viz[plec] = 1;
    while(st <= dr && k != ajung)
    {
        k = c[st];
        om = start[k];
        while(om)
        {
            if(!viz[t[0][om]])
            {
                if(k < t[2][om])
                    sum = t[2][om] + sum;
                else
                    sum = sum - t[2][om];
                c[++dr] = t[0][om];
                viz[t[0][om]] = 1;
            }
            om = t[1][om];
        }
        st++;
    }

    g << sum;
}

int main()
{
    f >> n >> m >> pp >> pa;
    while(f >> x >> y >> km)
    {
        k++;
        t[0][k] = y;
        t[1][k] = start[x];
        t[2][k] = km;
        start[x] = k;
        k++;
        t[0][k] = x;
        t[1][k] = start[y];
        t[2][k] = km;
        start[y] = k;
    }
    bfs_cu_liste(pp, pa);

    return 0;
}