Problem p03608 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <fstream>
#include <iostream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define dum(x) cout << #x << '=' << x << endl
#define dum2(x, y)                                                             \
  cout << #x << '=' << x << ' ' << #y << '=' << y << '\n' << endl
#define dum3(x, y, z)                                                          \
  cout << #x << '=' << x << ' ' << #y << '=' << y << ' ' << #z << '=' << z     \
       << '\n'                                                                 \
       << endl
#define darr(arr, n)                                                           \
  rep(i, (n - arr)) { cout << *(arr + i) << ' '; }                             \
  cout << endl
#define ddd                                                                    \
  ifstream in("Text.txt");                                                     \
  cin.rdbuf(in.rdbuf());

int graph[200][200];
int V;

int main() {
  ddd int M, R;
  cin >> V >> M >> R;
  int r[8];
  rep(i, R) {
    cin >> r[i];
    r[i]--;
  }
  sort(r, r + R);

  rep(i, V) rep(j, V) graph[i][j] = INF - 1000000000;
  rep(i, M) {
    int A, B, C;
    cin >> A >> B >> C;
    A--, B--;
    graph[A][B] = graph[B][A] = C;
  }
  rep(k, V) rep(i, V) rep(j, V) graph[i][j] =
      min(graph[i][j], graph[i][k] + graph[k][j]);

  int ans = INF;
  do {
    int sum = 0;
    rep(i, R - 1) sum += graph[r[i]][r[i + 1]];

    ans = min(ans, sum);
  } while (next_permutation(r, r + R));

  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <fstream>
#include <iostream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define dum(x) cout << #x << '=' << x << endl
#define dum2(x, y)                                                             \
  cout << #x << '=' << x << ' ' << #y << '=' << y << '\n' << endl
#define dum3(x, y, z)                                                          \
  cout << #x << '=' << x << ' ' << #y << '=' << y << ' ' << #z << '=' << z     \
       << '\n'                                                                 \
       << endl
#define darr(arr, n)                                                           \
  rep(i, (n - arr)) { cout << *(arr + i) << ' '; }                             \
  cout << endl
#define ddd                                                                    \
  ifstream in("Text.txt");                                                     \
  cin.rdbuf(in.rdbuf());

int graph[200][200];
int V;

int main() {

  int M, R;
  cin >> V >> M >> R;
  int r[8];
  rep(i, R) {
    cin >> r[i];
    r[i]--;
  }
  sort(r, r + R);

  rep(i, V) rep(j, V) graph[i][j] = INF - 1000000000;
  rep(i, M) {
    int A, B, C;
    cin >> A >> B >> C;
    A--, B--;
    graph[A][B] = graph[B][A] = C;
  }
  rep(k, V) rep(i, V) rep(j, V) graph[i][j] =
      min(graph[i][j], graph[i][k] + graph[k][j]);

  int ans = INF;
  do {
    int sum = 0;
    rep(i, R - 1) sum += graph[r[i]][r[i + 1]];

    ans = min(ans, sum);
  } while (next_permutation(r, r + R));

  cout << ans << endl;
}