Problem p00644 (C++) — buggy submission, verdict: Runtime Error

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

#define dump(...) cout << "# " << #__VA_ARGS__ << '=' << (__VA_ARGS__) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define peri(i, a, b) for (int i = int(b); i-- > int(a);)
#define rep(i, n) repi(i, 0, n)
#define per(i, n) peri(i, 0, n)
#define all(c) begin(c), end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  return os << '(' << p.first << ',' << p.second << ')';
}

template <typename Tuple> void print_tuple(ostream &, const Tuple &) {}
template <typename Car, typename... Cdr, typename Tuple>
void print_tuple(ostream &os, const Tuple &t) {
  print_tuple<Cdr...>(os, t);
  os << (sizeof...(Cdr) ? "," : "") << get<sizeof...(Cdr)>(t);
}
template <typename... Args>
ostream &operator<<(ostream &os, const tuple<Args...> &t) {
  print_tuple<Args...>(os << '(', t);
  return os << ')';
}

template <typename Ch, typename Tr, typename C, typename = decltype(begin(C()))>
basic_ostream<Ch, Tr> &operator<<(basic_ostream<Ch, Tr> &os, const C &c) {
  os << '[';
  for (auto i = begin(c); i != end(c); ++i)
    os << (i == begin(c) ? "" : " ") << *i;
  return os << ']';
}

constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr double EPS = 1e-9;

struct Edge {
  int src, dst, weight;
  Edge() {}
  Edge(int s, int d, int w) : src(s), dst(d), weight(w) {}
};
typedef vector<vector<Edge>> Graph;

void chmin(int &a, int b) { a = min(a, b); }

int main() {
  for (int n, m, s; cin >> n >> m >> s && n | m | s;) {
    Graph g(n);
    rep(i, m) {
      int u, v, w;
      cin >> u >> v >> w;
      g[u].emplace_back(u, v, w);
      g[v].emplace_back(v, u, w);
    }
    vi cs(s);
    rep(i, s) cin >> cs[i];

    vvi dp(n, vi(n, INF));
    rep(i, n) dp[i][i] = 0;
    rep(i, n) for (auto e : g[i]) chmin(dp[e.src][e.dst], e.weight);
    rep(k, n) rep(i, n) rep(j, n) chmin(dp[i][j], dp[i][k] + dp[k][j]);

    vd cnt1(n, 0);
    cnt1[0] = 1;
    {
      Graph gg(n);
      rep(i, n) for (auto e :
                     g[i]) if (dp[0][e.src] + e.weight + dp[e.dst][n - 1] ==
                               dp[0][n - 1]) gg[e.src]
          .push_back(e);
      vi is(n);
      iota(all(is), 0);
      sort(all(is), [&](int i, int j) { return dp[0][i] < dp[0][j]; });
      for (auto u : is)
        for (auto e : gg[u])
          cnt1[e.dst] += cnt1[u];
    }
    vd cnt2(n, 0);
    cnt2[n - 1] = 1;
    {
      Graph gg(n);
      rep(i, n) for (auto e :
                     g[i]) if (dp[0][e.src] + e.weight + dp[e.dst][n - 1] ==
                               dp[0][n - 1]) gg[e.dst]
          .emplace_back(e.dst, e.src, e.weight);
      vi is(n);
      iota(all(is), 0);
      sort(all(is), [&](int i, int j) { return dp[n - 1][i] < dp[n - 1][j]; });
      for (auto u : is)
        for (auto e : gg[u])
          cnt2[e.dst] += cnt2[u];
    }

    for (auto i : cs)
      printf("%.9f\\n", cnt1[i] * cnt2[i] / cnt1[n - 1]);
    puts("");
  }
}

Error: WA

Fixed submission:

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

#define dump(...) cout << "# " << #__VA_ARGS__ << '=' << (__VA_ARGS__) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define peri(i, a, b) for (int i = int(b); i-- > int(a);)
#define rep(i, n) repi(i, 0, n)
#define per(i, n) peri(i, 0, n)
#define all(c) begin(c), end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  return os << '(' << p.first << ',' << p.second << ')';
}

template <typename Tuple> void print_tuple(ostream &, const Tuple &) {}
template <typename Car, typename... Cdr, typename Tuple>
void print_tuple(ostream &os, const Tuple &t) {
  print_tuple<Cdr...>(os, t);
  os << (sizeof...(Cdr) ? "," : "") << get<sizeof...(Cdr)>(t);
}
template <typename... Args>
ostream &operator<<(ostream &os, const tuple<Args...> &t) {
  print_tuple<Args...>(os << '(', t);
  return os << ')';
}

template <typename Ch, typename Tr, typename C, typename = decltype(begin(C()))>
basic_ostream<Ch, Tr> &operator<<(basic_ostream<Ch, Tr> &os, const C &c) {
  os << '[';
  for (auto i = begin(c); i != end(c); ++i)
    os << (i == begin(c) ? "" : " ") << *i;
  return os << ']';
}

constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr double EPS = 1e-9;

struct Edge {
  int src, dst, weight;
  Edge() {}
  Edge(int s, int d, int w) : src(s), dst(d), weight(w) {}
};
bool operator<(const Edge &a, const Edge &b) { return a.weight < b.weight; }
bool operator>(const Edge &a, const Edge &b) { return a.weight > b.weight; }
typedef vector<vector<Edge>> Graph;

int main() {
  for (int n, m, k; cin >> n >> m >> k && n | m | k;) {
    Graph g(n);
    rep(i, m) {
      int u, v, w;
      cin >> u >> v >> w;
      g[u].emplace_back(u, v, w);
      g[v].emplace_back(v, u, w);
    }
    vi cs(k);
    rep(i, k) cin >> cs[i];

    priority_queue<Edge, vector<Edge>, greater<Edge>> pq;
    pq.emplace(-1, 0, 0);
    vi dist(n, INF);
    vvi prev(n);
    while (pq.size()) {
      Edge cur = pq.top();
      pq.pop();
      if (dist[cur.dst] < cur.weight)
        continue;
      dist[cur.dst] = cur.weight;
      prev[cur.dst].push_back(cur.src);
      for (auto e : g[cur.dst])
        pq.emplace(e.src, e.dst, cur.weight + e.weight);
    }

    vd ps(n, 0);
    ps[n - 1] = 1;
    // vi is(n); iota(all(is),0);
    // sort(all(is),[&](int i,int j){return dist[i]>dist[j];});
    // for(auto u:is) for(auto v:prev[u]) if(v!=-1)
    //	ps[v]+=ps[u]/prev[u].size();

    rep(i, k) printf("%.8f\\n", ps[cs[i]]);
    puts("");
  }
}