Hi;) I have small problem with my code(Bellman-Ford algorithm). I don't have any idea why it's not working, maybe it can be a small mistake, but I'm just a beginner. Can you help me with it?
#include<cstdio>
#include<vector>
using namespace std;
int n, m, s;
vector<vector<int> >E;
vector<int>D;
const int INF = (1 << 30);
int main()
{
scanf("%d %d %d", &n, &m, &s);
E.resize(m);
for (int i = 0; i < m; i++)
{
int a , b, c;
scanf("%d %d %d", &a, &b, &c);
E[i].resize(3);
E[i][0] = a;
E[i][1] = b;
E[i][2] = c;
}
D.resize(n);
for (int i = 0; i < n; i++) D[i]=INF;
D[s] = 0;
for (int i = 1; i<=n; i++)
{
for (int j = 0; j < m; j++)
{
int a = E[j][0], b = E[j][1], c = E[j][2];
if (D[a]!=INF && D[a] < D[b]-c)
{
D[b] = D[a]+c;
if (i==n)
{
printf("NO");
return 0;
}
}
}
}
for (int i = 0; i < m; i++)
{
if (i!=s && D[i]<INF)
{
printf("%d %d\n", i, D[i]);
}
return 0;
}
}