Cod sursa(job #2349782)

Utilizator gabriel2506Dobre Gabriel gabriel2506 Data 20 februarie 2019 18:24:54
Problema Algoritmul Bellman-Ford Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.2 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>

#define nmax 100002


using namespace std;
ifstream fin("bellmanford.in");
ofstream fout("bellmanford.out");

int N=100001;

queue <int> q;
vector <int> v[nmax];
int dist[nmax],n,m,cost,x,y;

vector<pair<int,int> >a[N];

void read()
{
    fin>>n>>m;
    for(int i=0; i<m; i++)
    {
        a[x].push_back(make_pair(y,c));
    }
}

int bellmanford()
{
    queue <int>q;
    q.push(x);
    dist[x0]=0;
    inq[x0]=true;
    while(!q.empty())
    {
        x=p.front();
        q.pop();
        inq[x]=false;
        for(auto p:a[x])
        {
            y=p.first;
            c=p.second;
            if(d[x]+c<d[y])
            {
                y=p.first;
                c=p.second;
                if(d[x]+c<d[y])
                {
                    d[y]=d[x]+c;
                    if(!inq[y])
                    {
                        if(nr[q]==n)
                        {

                            return 0;
                        }

                    }
                }
            }
        }
    }
}


int main()
{
    read();
    bellmanford();
    for(int i=0;i<m;i++)
    {
        fout<<a[i]<<" ";
    }
    return 0;
}