Cod sursa(job #1345878)

Utilizator gerd13David Gergely gerd13 Data 17 februarie 2015 21:56:55
Problema Sate Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.25 kb
#include <fstream>
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>

#define x first
#define y second
#define mp make_pair
#define pb push_back


using namespace std ;

typedef unsigned long long ull ;
typedef pair <int, int> Pair ;

const int NMAX = 100024 ;
const int INF = 0x3f3f3f3f ;

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

int N, M, vis[NMAX] ;

vector <Pair> V[NMAX] ;
queue <int> Q ;
int X, Y ;
int sol ;


inline void BFS()
{
    vis[X] = 1 ;
    Q.push(X) ;

    while(!Q.empty())
    {
        int nod = Q.front() ;
        Q.pop() ;

        for(int i = 0 ; i < V[nod].size() ; ++ i)
        {
            if(!vis[V[nod][i].second])
            {
                sol = sol + V[nod][i].first ;
                vis[V[nod][i].second] = 1 ;
                Q.push(V[nod][i].second) ;

            }
        }

    }

}

int main()
{
    fin >> N >> M >> X >> Y ;


    for(int i = 1 ; i <= M ; ++ i)
    {
        int XX, YY ;
        int cos ;
        fin >> XX >> YY >> cos;

        V[XX].pb(mp(cos, YY)) ;
        V[YY].pb(mp(-cos, XX)) ;
    }

    BFS() ;

    fout << sol << '\n' ;

    fin.close() ;
    fout.close() ;
    return  0 ;
}