Pagini recente » Cod sursa (job #3236729) | Cod sursa (job #590606) | Cod sursa (job #1095382) | Cod sursa (job #3276292) | Cod sursa (job #2349782)
#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;
}