Pagini recente » Cod sursa (job #438605) | Cod sursa (job #3278377) | Cod sursa (job #674070) | Cod sursa (job #530492) | Cod sursa (job #2447108)
/*
░░░░░░░░░░░░░░░░▄▄█▀▀██▄▄░░░░░░░
░░░░░░░░░░░░░▄█▀▀░░░░░░░▀█░░░░░░
░░░░░░░░░░░▄▀░░░░░░░░░░░░░█░░░░░
░░░░░░░░░▄█░░░░░░░░░░░░░░░█░░░░░
░░░░░░░██▀░░░░░░░▄▄▄░░▄░█▄█▄░░░░
░░░░░▄▀░░░░░░░░░░████░█▄██░▀▄░░░
░░░░█▀░░░░░░░░▄▄██▀░░█████░██░░░
░░░█▀░░░░░░░░░▀█░▀█▀█▀▀▄██▄█▀░░░
░░░██░░░░░░░░░░█░░█░█░░▀▀▄█▀░░░░
░░░░█░░░░░█░░░▀█░░░░▄░░░░░▄█░░░░
░░░░▀█░░░░███▄░█░░░░░░▄▄▄▄█▀█▄░░
░░░░░▀██░░█▄▀▀██░░░░░░░░▄▄█░░▀▄░
░░░░░░▀▀█▄░▀▄▄░▄░░░░░░░███▀░░▄██
░░░░░░░░░▀▀▀███▀█▄░░░░░█▀░▀░░░▀█
░░░░░░░░░░░░▄▀░░░▀█▄░░░░░▄▄░░▄█▀
░░░▄▄▄▀▀▀▀▀█▀░░░░░█▄▀▄▄▄▄▄▄█▀▀░░
░▄█░░░▄██▀░░░░░░░░░█▄░░░░░░░░░░░
█▀▀░▄█░░░░░░░░░░░░░░▀▀█▄░░░░░░░░
█░░░█░░░░░░░░░░░░░░░░░░█▄░░░░░░░
*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define pii pair<pair <int, int>, int>
#define vi vector <int>
const ll mod = 1000000007;
const ll nmax=1000003;
//#define int ll
int n, m, d[50001];
vector<pi> g[50001];
vector<pii> edg;
int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
ifstream cin("bellmanford.in");
ofstream cout("bellmanford.out");
cin>>n>>m;
for(int i=1, x, y, c; i<=m; i++){
cin>>x>>y>>c;
g[x].pb({y, c});
edg.pb({{x, y}, c});
}
for(int i=2; i<=n; i++) d[i]=1e9;
for(int i=1; i<=n-1; i++){
for(pii xd: edg){
int x=xd.x.x, y=xd.x.y, c=xd.y, lol=0;
if(i==n) lol=d[xd.y];
d[y]=min(d[y], d[x]+c);
if(lol && lol!=d[y]) return cout<<"Ciclu negativ", 0;
}
}
for(int i=2; i<=n; i++) cout<<d[i]<<" ";
}