Cod sursa(job #1388860)

Utilizator ManuNNazare Emanuel ManuN Data 15 martie 2015 19:36:30
Problema Sate Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <iostream>
#include <vector>
#include <queue>
#include <fstream>
using namespace std;
int viz[30000],tata[30000];
int main()
{
    int x,m,n,e,b,c,y,s=0,i,k=0,j;
    vector <int> v[30000];
    long int a[30000][30000];
    queue <int> q;
    ifstream f("sate.in");
    ofstream g("sate.out");
    f>>n>>m>>x>>y;
    for(i=1;i<=m;i++)
    {
        f>>e>>b>>c;
        v[e].push_back(b);
        v[b].push_back(e);
        a[e][b]=a[b][e]=c;
    }
    q.push(x);
    viz[x]=1;
    while(q.size()>0)
    {
        x=q.front();
        q.pop();
        for(i=0;i<v[x].size();i++)
            if(viz[v[x][i]]==0)
            {
                q.push(v[x][i]);
                viz[v[x][i]]=1;
                tata[v[x][i]]=x;
            }
    }
    while(tata[y])
    {
        if(y<tata[y])
            s-=a[y][tata[y]];
        else
            s+=a[y][tata[y]];
        y=tata[y];
    }
    g<<s;
    f.close();
    g.close();
    return 0;
}