Problem p03722 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

struct edge {
  long long from, to, cost;
};
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
// static const int INF = 2147483647;
// static const long long INf = 9223372000000000000;
static const long long INF = 9223372000000000000 / 2;
// static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define itn int
#define scnaf scanf
#define reutnr return
#define scamf scanf
// int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
// int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
// int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
// int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define int ll

edge es[2018];
int d[1145];
int V, E;

bool Bellman_Ford(int s) {
  for (int i = 0; i < V; i++)
    d[i] = INF;
  d[s] = 0;
  int counter = 0, mindist;
  while (true) {
    if (counter > 2 * V) {
      if (-d[V - 1] > mindist)
        return true;
      else
        false;
    }
    bool update = false;
    for (int i = 0; i < E; i++) {
      edge e = es[i];
      if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;
        update = true;
      }
    }
    if (!update)
      break;
    counter++;
    if (counter == V - 1) {
      mindist = -d[V - 1];
    }
  }
  return false;
}

signed main() {
  scanf("%lld%lld", &V, &E);
  for (int i = 0; i < E; i++) {
    int tmp1, tmp2, tmp3;
    scanf("%lld%lld%lld", &tmp1, &tmp2, &tmp3);
    tmp1--;
    tmp2--;
    edge e;
    e.from = tmp1, e.to = tmp2, e.cost = -tmp3;
    es[i] = e;
  }
  if (Bellman_Ford(0))
    printf("inf\n");
  else
    printf("%lld\n", -d[V - 1]);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

struct edge {
  long long from, to, cost;
};
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
// static const int INF = 2147483647;
// static const long long INf = 9223372000000000000;
static const long long INF = 9223372000000000000 / 2;
// static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define itn int
#define scnaf scanf
#define reutnr return
#define scamf scanf
// int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
// int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
// int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
// int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define int ll

edge es[2018];
int d[1145];
int V, E;

bool Bellman_Ford(int s) {
  for (int i = 0; i < V; i++)
    d[i] = INF;
  d[s] = 0;
  int counter = 0, mindist;
  while (true) {
    if (counter > 2 * V) {
      if (-d[V - 1] > mindist)
        return true;
      else
        return false;
    }
    bool update = false;
    for (int i = 0; i < E; i++) {
      edge e = es[i];
      if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;
        update = true;
      }
    }
    if (!update)
      break;
    counter++;
    if (counter == V - 1) {
      mindist = -d[V - 1];
    }
  }
  return false;
}

signed main() {
  scanf("%lld%lld", &V, &E);
  for (int i = 0; i < E; i++) {
    int tmp1, tmp2, tmp3;
    scanf("%lld%lld%lld", &tmp1, &tmp2, &tmp3);
    tmp1--;
    tmp2--;
    edge e;
    e.from = tmp1, e.to = tmp2, e.cost = -tmp3;
    es[i] = e;
  }
  if (Bellman_Ford(0))
    printf("inf\n");
  else
    printf("%lld\n", -d[V - 1]);
  return 0;
}