I am trying to implement this algorithm what’s wrong with my implementation??
// Bellman Ford algorithm
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <math.h>
#include <algorithm>
#include <climits>
# include <string>
#define ll long long
#define N 10000001
#define MAX 1000001
using namespace std;
ll n,m,u,v,w;
vector<ll>adj[N];
ll cost[N]={0};
void bell()
{
//relax each edge v-1 times
for(ll i=0;i<n-1;i++)
{
for(ll j=0;j<m;j++)
{
cost[adj[j][1]]=min(cost[adj[j][0]]+adj[j][2],cost[adj[j][1]]);
}
}
for(ll i=1;i<=n;i++)
{
cout<<cost[i]<<endl;
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
for(ll i=2;i<=n;i++)
{
cost[i]=MAX;
}
for(ll i=0;i<m;i++)
{
cin>>u>>v>>w;
adj[i].push_back(u);
adj[i].push_back(v);
adj[i].push_back(w);
}
bell();
return 0;
}