alexjercan/bugnet huggingface dataset:
Problem p00485 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define N 3002
using namespace std;
typedef pair<int, int> P;
vector<P> G[N];
bool num[N];
int n, m, K;

double dijkstra() {
  vector<int> D(N, 1e9);
  priority_queue<P, vector<P>, greater<P>> Q;
  for (int i = 0; i < n; i++)
    if (num[i])
      Q.push(P(0, i)), D[i] = 0;

  while (!Q.empty()) {
    P t = Q.top();
    Q.pop();
    int cost = t.first;
    int pos = t.second;
    if (D[pos] < cost)
      continue;

    for (int i = 0; i < G[pos].size(); i++) {
      int npos = G[pos][i].first;
      int ncost = cost + G[pos][i].second;
      if (D[npos] <= ncost)
        continue;
      Q.push(P(ncost, npos));
      D[npos] = ncost;
    }
  }

  double res = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < (int)G[i].size(); j++) {
      int npos = G[i][j].first;
      int ncost = G[i][j].second;
      res = max(res, (D[i] + D[npos] + ncost) / 2.0);
    }
  return res;
}

int main() {
  cin >> n >> m >> K;
  for (int i = 0, a, b, c; i < m; i++) {
    cin >> a >> b >> c;
    G[a - 1].push_back(P(b - 1, c));
    G[b - 1].push_back(P(a - 1, c));
  }

  for (int i = 0, a; i < K; i++)
    cin >> a, num[a - 1] = 1;
  printf("%d\\n", (int)(dijkstra() + 0.5));
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define N 3002
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
vector<P> G[N];
bool num[N];
int n, m, K;

double dijkstra() {
  int D[N];
  for (int i = 0; i < N; i++)
    D[i] = 1e9;

  vector<int> pre[N];
  priority_queue<PP, vector<PP>, greater<PP>> Q;

  for (int i = 0; i < N; i++)
    if (num[i]) {
      Q.push(PP(0, P(i, i)));
      D[i] = 0;
      pre[i].push_back(i);
    }

  while (!Q.empty()) {
    PP t = Q.top();
    Q.pop();
    int cost = t.first;
    int pos = t.second.first;
    int start = t.second.second;

    if (D[pos] < cost)
      continue;
    pre[pos].push_back(start);
    if (D[pos] <= cost)
      continue;

    for (int i = 0; i < G[pos].size(); i++) {
      int npos = G[pos][i].first;
      int ncost = cost + G[pos][i].second;
      if (D[npos] < ncost)
        continue;
      Q.push(PP(ncost, P(npos, start)));
      D[npos] = ncost;
    }
  }

  double res = 0;
  for (int i = 0; i < n; i++) {
    if (pre[i].size() >= 2)
      res = max(res, (double)D[i]);
    res = max(res, D[i] / 2.0);

    for (int j = 0; j < G[i].size(); j++) {
      int npos = G[i][j].first;
      int ncost = G[i][j].second;
      if (pre[npos][0] == pre[i][0] && abs(D[i] - D[npos]) == ncost)
        continue;

      res = max(res, (D[i] + D[npos] + ncost) / 2.0);
    }
  }
  return res;
}

int main() {

  cin >> n >> m >> K;
  for (int i = 0, a, b, c; i < m; i++) {
    cin >> a >> b >> c;
    G[a - 1].push_back(P(b - 1, c));
    G[b - 1].push_back(P(a - 1, c));
  }

  for (int i = 0, a; i < K; i++)
    cin >> a, num[a - 1] = 1;
  printf("%d\\n", (int)(dijkstra() + 0.5));
  return 0;
}
Problem p00485 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>

#pragma warning(disable : 4996)

using namespace std;

int N, M, K, A, B, L;

vector<vector<pair<int, int>>> G;

vector<int> P, D;

int main() {
  scanf("%d", &N);
  scanf("%d", &M);
  scanf("%d", &K);

  G = vector<vector<pair<int, int>>>(N);

  for (int i = 0; i < M; i++) {
    scanf("%d", &A);
    scanf("%d", &B);
    scanf("%d", &L);

    G[A - 1].push_back(make_pair(B - 1, L));
    G[B - 1].push_back(make_pair(A - 1, L));
  }

  P = vector<int>(K);

  for (int i = 0; i < K; i++) {
    scanf("%d", &P[i]);
    P[i]--; // 0 - indexed
  }

  D = vector<int>(N, 999999999);

  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      que;

  for (int i = 0; i < K; i++) {
    que.push(make_pair(0, P[i]));
    D[P[i]] = 0;
  }

  while (!que.empty()) {
    pair<int, int> state = que.top();
    que.pop();

    int dist = state.first;
    int node = state.second;

    for (int j = 0; j < G[node].size(); j++) {
      int node2 = G[node][j].first;
      int leng2 = G[node][j].second;

      if (D[node2] > D[node] + leng2) {
        D[node2] = D[node] + leng2;

        que.push(make_pair(D[node2], node2));
      }
    }
  }

  int ret = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < G[i].size(); j++) {
      ret = max(ret, D[i] + D[G[i][j].first] + G[i][j].second);
    }
  }

  printf("%d\\n", (ret + 1) / 2);

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>

#pragma warning(disable : 4996)

using namespace std;

int N, M, K, A, B, L;

vector<vector<pair<int, int>>> G;

vector<int> P, D;

int main() {
  scanf("%d", &N);
  scanf("%d", &M);
  scanf("%d", &K);

  G = vector<vector<pair<int, int>>>(N);

  for (int i = 0; i < M; i++) {
    scanf("%d", &A);
    scanf("%d", &B);
    scanf("%d", &L);

    G[A - 1].push_back(make_pair(B - 1, L));
    G[B - 1].push_back(make_pair(A - 1, L));
  }

  P = vector<int>(K);

  for (int i = 0; i < K; i++) {
    scanf("%d", &P[i]);
    P[i]--; // 0 - indexed
  }

  D = vector<int>(N, 999999999);

  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      que;

  for (int i = 0; i < K; i++) {
    que.push(make_pair(0, P[i]));
    D[P[i]] = 0;
  }

  while (!que.empty()) {
    pair<int, int> state = que.top();
    que.pop();

    int dist = state.first;
    int node = state.second;

    for (int j = 0; j < G[node].size(); j++) {
      int node2 = G[node][j].first;
      int leng2 = G[node][j].second;

      if (D[node2] < D[node] + leng2) {
        D[node2] = D[node] + leng2;

        que.push(make_pair(D[node2], node2));
      }
    }
  }

  int ret = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < G[i].size(); j++) {
      ret = max(ret, D[i] + D[G[i][j].first] + G[i][j].second);
    }
  }

  printf("%d\\n", (ret + 1) / 2);

  return 0;
}
Problem p00485 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#define INF 1e+9
using namespace std;

typedef pair<int, int> P;
struct edge {
  int to, cost;
};

int main() {
  int n, m, k, a, b, l, s;
  int d[3000];
  vector<edge> G[3000];
  queue<P> que;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    d[i] = INF;
  }
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> l;
    G[a - 1].push_back({b - 1, l});
    G[b - 1].push_back({a - 1, l});
  }
  for (int i = 0; i < k; i++) {
    cin >> s;
    que.push(P(s - 1, 0));
  }
  while (!que.empty()) {
    P p = que.front();
    que.pop();
    if (d[p.first] <= p.second)
      continue;
    d[p.first] = p.second;
    for (int i = 0; i < G[p.first].size(); i++) {
      if (d[p.first] + G[p.first][i].cost < d[G[p.first][i].to])
        que.push({G[p.first][i].to, d[p.first] + G[p.first][i].cost});
    }
  }
  double ma = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < G[i].size(); j++) {
      ma = max(ma, (double)(d[i] + d[G[i][j].to] + G[i][j].cost) / 2.0);
    }
  }
  cout << (int)round(ma) << endl;
  return 0;
}

Error: MLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <queue>
#define INF 1e+9
using namespace std;

typedef pair<int, int> P;
struct edge {
  int to, cost;
};

int main() {
  int n, m, k, a, b, l, s;
  static int d[3000], dtd[3000][3000];
  vector<edge> G[3000];
  queue<P> que;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    d[i] = INF;
    for (int j = 0; j < n; j++)
      dtd[i][j] = -1;
  }
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> l;
    G[a - 1].push_back({b - 1, l});
    G[b - 1].push_back({a - 1, l});
    dtd[a - 1][b - 1] = l;
    dtd[b - 1][a - 1] = l;
  }
  for (int i = 0; i < k; i++) {
    cin >> s;
    que.push(P(s - 1, 0));
  }
  while (!que.empty()) {
    P p = que.front();
    que.pop();
    if (d[p.first] <= p.second)
      continue;
    d[p.first] = p.second;
    for (int i = 0; i < G[p.first].size(); i++) {
      que.push({G[p.first][i].to, d[p.first] + G[p.first][i].cost});
    }
  }
  double ma = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (dtd[i][j] != -1)
        ma = max(ma, (double)(d[i] + d[j] + dtd[i][j]) / 2.0);
    }
  }
  cout << (int)round(ma) << endl;
  return 0;
}
Problem p00485 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int N, M, K;

struct edge {
  int to, cost;
  edge(int t, int c) {
    to = t;
    cost = c;
  }
};

typedef pair<int, int> P;
vector<edge> edges[10000];
int d[3000];

int dijkstra(vector<int> sts) {
  priority_queue<P, vector<P>, greater<P>> queue;
  for (auto st : sts) {
    d[st] = 0;
    queue.push(make_pair(0, st));
  }
  while (!queue.empty()) {
    auto p = queue.top();
    queue.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (auto e : edges[v]) {
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        queue.push(make_pair(d[e.to], e.to));
      }
    }
  }
}

int main() {
  fill(d, d + 3000, 1000000000);
  cin >> N >> M >> K;
  for (int i = 0; i < M; i++) {
    int a, b, l;
    cin >> a >> b >> l;
    a--;
    b--;
    edges[a].push_back(edge(b, l));
    edges[b].push_back(edge(a, l));
  }

  vector<int> sts;
  for (int i = 0; i < K; i++) {
    int a;
    cin >> a;
    sts.push_back(--a);
  }
  dijkstra(sts);
  int ans = 0;
  for (int v = 0; v < N; v++) {
    for (auto e : edges[v]) {
      ans = max(ans, (int)((d[v] + d[e.to] + e.cost) / 2.0 + 0.5));
    }
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int N, M, K;

struct edge {
  int to, cost;
  edge(int t, int c) {
    to = t;
    cost = c;
  }
};

typedef pair<int, int> P;
vector<edge> edges[1000];
int d[1000];

int dijkstra(vector<int> sts) {
  priority_queue<P, vector<P>, greater<P>> queue;
  for (auto st : sts) {
    d[st] = 0;
    queue.push(make_pair(0, st));
  }
  while (!queue.empty()) {
    auto p = queue.top();
    queue.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (auto e : edges[v]) {
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        queue.push(make_pair(d[e.to], e.to));
      }
    }
  }
}

int main() {
  fill(d, d + 1000, 1000000000);
  cin >> N >> M >> K;
  for (int i = 0; i < M; i++) {
    int a, b, l;
    cin >> a >> b >> l;
    a--;
    b--;
    edges[a].push_back(edge(b, l));
    edges[b].push_back(edge(a, l));
  }

  vector<int> sts;
  for (int i = 0; i < K; i++) {
    int a;
    cin >> a;
    sts.push_back(--a);
  }
  dijkstra(sts);
  int ans = 0;
  for (int v = 0; v < N; v++) {
    for (auto e : edges[v]) {
      ans = max(ans, (int)((d[v] + d[e.to] + e.cost) / 2.0 + 0.5));
    }
  }
  cout << ans << endl;
}
Problem p00485 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

typedef pair<int, int> pii;

int n, m, k;
int amat[5000][5000];
int vtx[5000];
vector<vector<int>> adj(5000);
vector<int> mal;

int solve() {

  for (int i = 0; i < n; ++i) {
    vtx[i] = INT_MAX;
  }

  for (int s = 0; s < k; ++s) {

    int vtxt[5000];

    for (int i = 0; i < n; ++i) {
      vtxt[i] = INT_MAX;
    }

    priority_queue<pii, vector<pii>, greater<pii>> qu;
    qu.push(make_pair(0, mal[s]));
    vtxt[mal[s]] = 0;

    while (!qu.empty()) {

      int now = qu.top().second, nxt;
      qu.pop();

      for (int i = 0; i < adj[now].size(); ++i) {

        nxt = adj[now][i];

        if (vtxt[nxt] > vtxt[now] + amat[now][nxt]) {

          vtxt[nxt] = vtxt[now] + amat[now][nxt];
          qu.push(make_pair(vtxt[nxt], nxt));
        }
      }
    }

    for (int i = 0; i < n; ++i) {
      vtx[i] = min(vtx[i], vtxt[i]);
    }
  }

  int ma = -1;

  for (int p = 0; p < n; ++p) {
    for (int i = 0; i < adj[p].size(); ++i) {

      int q = adj[p][i];
      ma = max(ma, min(vtx[p], vtx[q]) +
                       (1 + amat[p][q] + abs(vtx[p] - vtx[q])) / 2);
    }
  }

  return ma;
}

int main() {

  cin >> n >> m >> k;

  for (int i = 0; i < m; ++i) {

    int a, b, l;
    cin >> a >> b >> l;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
    amat[a][b] = amat[b][a] = l;
  }

  for (int i = 0; i < k; ++i) {

    int s;
    cin >> s;
    mal.push_back(--s);
  }

  cout << solve() << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

typedef pair<int, int> pii;

int n, m, k;
int amat[5000][5000];
int vtx[5000];
vector<int> mal;

int solve() {

  for (int i = 0; i < n; ++i) {
    vtx[i] = INT_MAX;
  }

  for (int s = 0; s < k; ++s) {

    int vtx_tmp[5000];

    for (int i = 0; i < n; ++i) {
      vtx_tmp[i] = INT_MAX;
    }

    priority_queue<pii, vector<pii>, greater<pii>> qu;
    qu.push(make_pair(0, mal[s]));
    vtx_tmp[mal[s]] = 0;

    while (!qu.empty()) {

      int now = qu.top().second;
      qu.pop();

      for (int i = 0; i < n; ++i) {

        if (amat[now][i] && vtx_tmp[i] > vtx_tmp[now] + amat[now][i]) {

          vtx_tmp[i] = vtx_tmp[now] + amat[now][i];
          qu.push(make_pair(vtx_tmp[i], i));
        }
      }
    }

    for (int i = 0; i < n; ++i) {
      vtx[i] = min(vtx[i], vtx_tmp[i]);
    }
  }

  int ma = -1;

  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j) {

      if (amat[i][j]) {
        ma = max(ma, min(vtx[i], vtx[j]) +
                         (1 + amat[i][j] + abs(vtx[i] - vtx[j])) / 2);
      }
    }
  }

  return ma;
}

int main() {

  cin >> n >> m >> k;

  for (int i = 0; i < m; ++i) {

    int a, b, l;
    cin >> a >> b >> l;
    a--;
    b--;
    amat[a][b] = amat[b][a] = l;
  }

  for (int i = 0; i < k; ++i) {

    int s;
    cin >> s;
    mal.push_back(--s);
  }

  cout << solve() << endl;

  return 0;
}
Problem p00485 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
const int INF = 1e9;
struct data {
  int to, cost;
  data(int a, int b) : to(a), cost(b) {}
  bool operator>(const data &d) const { return cost > d.cost; }
};
vector<vector<data>> edge;
vector<int> D;
void dijkstra(int s) {
  priority_queue<data, vector<data>, greater<data>> Q;
  Q.push(data(s, 0));
  while (Q.size()) {
    data latte = Q.top();
    Q.pop();
    int At = latte.to, cost = latte.cost;
    if (D[At] < cost)
      continue;
    D[At] = cost;
    for (int i = 0; i < edge[At].size(); i++) {
      data e = edge[At][i];
      if (D[e.to] < D[At] + e.cost)
        continue;
      Q.push(data(e.to, D[At] + e.cost));
    }
  }
  return;
}
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  edge.resize(n);
  D.resize(n, INF);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    edge[a].push_back(data(b, c));
    edge[b].push_back(data(a, c));
  }
  for (int i = 0; i < k; i++) {
    int s;
    cin >> s;
    s--;
    dijkstra(s);
  }
  int Max = 0;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < edge[i].size(); j++) {
      data e = edge[i][j];
      int latte = (D[i] + D[e.to] + e.cost + 1) / 2;
      Max = max(max(D[i], D[e.to]), max(Max, latte));
    }
  }
  cout << Max << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
const int INF = 1e9;
struct data {
  int to, cost;
  data(int a, int b) : to(a), cost(b) {}
  bool operator<(const data &d) const { return cost < d.cost; }
};
vector<vector<data>> edge;
vector<int> D;
void dijkstra(int s) {
  priority_queue<data> Q;
  Q.push(data(s, 0));
  while (Q.size()) {
    data latte = Q.top();
    Q.pop();
    int At = latte.to, cost = latte.cost;
    if (D[At] < cost)
      continue;
    D[At] = cost;
    for (int i = 0; i < edge[At].size(); i++) {
      data e = edge[At][i];
      Q.push(data(e.to, D[At] + e.cost));
    }
  }
  return;
}
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  edge.resize(n);
  D.resize(n, INF);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    edge[a].push_back(data(b, c));
    edge[b].push_back(data(a, c));
  }
  for (int i = 0; i < k; i++) {
    int s;
    cin >> s;
    s--;
    dijkstra(s);
  }
  int Max = 0;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < edge[i].size(); j++) {
      data e = edge[i][j];
      int latte = (D[i] + D[e.to] + e.cost + 1) / 2;
      Max = max(max(D[i], D[e.to]), max(Max, latte));
    }
  }
  cout << Max << endl;
}
Problem p00485 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <queue>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

const int INF = 1 << 29;

struct edge {
  int v, cost;
};

int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  vector<edge> G[3000];
  rep(i, m) {
    int u, v, cost;
    scanf("%d%d%d", &u, &v, &cost);
    u--;
    v--;
    G[u].push_back((edge){v, cost});
    G[v].push_back((edge){u, cost});
  }

  int d[3000];
  rep(u, n) d[u] = INF;
  priority_queue<pair<int, int>> Q;
  rep(i, k) {
    int u;
    scanf("%d", &u);
    u--;
    d[u] = 0;
    Q.push(make_pair(0, u));
  }
  while (!Q.empty()) {
    int d_now = -Q.top().first, u = Q.top().second;
    Q.pop();
    if (d[u] < d_now)
      continue;
    rep(i, G[u].size()) {
      const edge &e = G[u][i];
      if (d[e.v] > d[u] + e.cost) {
        d[e.v] = d[u] + e.cost;
        Q.push(make_pair(-d[e.v], e.v));
      }
    }
  }

  int ans = 0;
  rep(u, n) rep(i, G[u].size()) {
    const edge &e = G[u][i];
    ans = max(ans, (d[u] + d[e.v] + e.cost + 1) / 2);
  }
  printf("%d\\n", ans);

  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <queue>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

const int INF = 1 << 29;

struct edge {
  int v, cost;
};

int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  static vector<edge> G[3000];
  rep(i, m) {
    int u, v, cost;
    scanf("%d%d%d", &u, &v, &cost);
    u--;
    v--;
    G[u].push_back((edge){v, cost});
    G[v].push_back((edge){u, cost});
  }

  static int d[1000];
  rep(u, n) d[u] = INF;
  priority_queue<pair<int, int>> Q;
  rep(i, k) {
    int u;
    scanf("%d", &u);
    u--;
    d[u] = 0;
    Q.push(make_pair(0, u));
  }
  while (!Q.empty()) {
    int d_now = -Q.top().first, u = Q.top().second;
    Q.pop();
    if (d[u] < d_now)
      continue;
    rep(i, G[u].size()) {
      const edge &e = G[u][i];
      if (d[e.v] > d[u] + e.cost) {
        d[e.v] = d[u] + e.cost;
        Q.push(make_pair(-d[e.v], e.v));
      }
    }
  }

  int ans = 0;
  rep(u, n) rep(i, G[u].size()) {
    const edge &e = G[u][i];
    ans = max(ans, (d[u] + d[e.v] + e.cost + 1) / 2);
  }
  printf("%d\\n", ans);

  return 0;
}
Problem p00485 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int INF = 1e9;
struct dat {
  int a, b, c;
};
struct edge {
  int to, cost;
};
int d[3030], n, m, k;
vector<edge> G[3030];
void dijkstra(int s) {
  d[s] = 0;
  priority_queue<P, vector<P>, greater<P>> Q;
  Q.push(MP(0, s));
  while (!Q.empty()) {
    P p = Q.top();
    Q.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    REP(i, G[v].size()) {
      int to = G[v][i].to, cost = G[v][i].cost;
      if (d[to] > d[v] + cost) {
        d[to] = d[v] + cost;
        Q.push(MP(d[to], to));
      }
    }
  }
}
int main() {
  REP(i, 3030) d[i] = INF;
  cin >> n >> m >> k;
  vector<dat> road;
  REP(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    road.PB((dat){a, b, c});
    G[a].PB((edge){b, c});
    G[b].PB((edge){a, c});
  }
  REP(i, k) {
    int s;
    cin >> s;
    s--;
    dijkstra(s);
  }
  int ans = 0;
  REP(i, road.size()) {
    dat v = road[i];
    ans = max(ans, (d[v.a] + d[v.b] + v.c + 1) / 2);
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int INF = 1e9;
struct dat {
  int a, b, c;
};
struct edge {
  int to, cost;
};
int d[1010], n, m, k;
vector<edge> G[1010];
void dijkstra(int s) {
  d[s] = 0;
  priority_queue<P, vector<P>, greater<P>> Q;
  Q.push(MP(0, s));
  while (!Q.empty()) {
    P p = Q.top();
    Q.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    REP(i, G[v].size()) {
      int to = G[v][i].to, cost = G[v][i].cost;
      if (d[to] > d[v] + cost) {
        d[to] = d[v] + cost;
        Q.push(MP(d[to], to));
      }
    }
  }
}
int main() {
  REP(i, 1010) d[i] = INF;
  cin >> n >> m >> k;
  vector<dat> road;
  REP(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    road.PB((dat){a, b, c});
    G[a].PB((edge){b, c});
    G[b].PB((edge){a, c});
  }
  REP(i, k) {
    int s;
    cin >> s;
    s--;
    dijkstra(s);
  }
  int ans = 0;
  REP(i, road.size()) {
    dat v = road[i];
    ans = max(ans, (d[v.a] + d[v.b] + v.c + 1) / 2);
  }
  cout << ans << endl;
}