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

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

#define int long long
#define DEBUG 0
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
#define dump(o)                                                                \\
  if (DEBUG) {                                                                 \\
    cerr << #o << " " << o << endl;                                            \\
  }
#define dumpc(o)                                                               \\
  if (DEBUG) {                                                                 \\
    cerr << #o;                                                                \\
    for (auto &e : (o))                                                        \\
      cerr << " " << e;                                                        \\
    cerr << endl;                                                              \\
  }
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD = 1e9 + 7;

//??¶?´?????????£???????????? int:INF ll:INFL
#define INFG INFL
using Weight = ll; // int;

class Edge {
public:
  int s;    // source
  int d;    // destination
  Weight w; // weight
  Edge(int s = 0, int d = 0, Weight w = INFG) : s(s), d(d), w(w){};
  bool operator<(const Edge &e) const { return w > e.w; }
};
using Edges = vector<Edge>;
//???????????\\: g[u].push_back(Edge(u, v, c));
//????????¨???????????????????????°??????????????\\?????????????????????
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

//?????¢?´¢, ??¢?´¢???, ??¢?´¢???
enum { WHITE, GRAY, BLACK };

//?´?????????????????§????
// Union-Find??¨
struct UnionFind {
  vector<int> p; // parent
  int s;         // size ???????????°
  UnionFind(int n) : p(n, -1), s(n) {}
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (size(x) < size(y))
      swap(x, y);
    p[x] += p[y];
    p[y] = x;
    s--;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int root(int x) { return p[x] < 0 ? x : p[x] = root(p[x]); }
  //?????????????´???°
  int size(int x) { return -p[root(x)]; }
};

//????°???¨?????¨
// Kruskal O(|E|log|E|)
pair<Weight, Edges> kruskal(const Graph &g) {
  UnionFind UF(g.size());
  Edges es;
  for (int i = 0; i < g.size(); i++)
    for (auto &e : g[i])
      es.emplace_back(e);
  sort(es.begin(), es.end());
  Weight total = 0;
  Edges T;
  for (auto &e : es)
    if (!UF.same(e.s, e.d)) {
      T.push_back(e);
      total += e.w;
      UF.unite(e.s, e.d);
    }
  return make_pair(total, T);
}

//????°???¨?????¨
// Prim O(ElogV)
// r????????°?????????????????????????±?
// Edge??? bool operator<(const Edge &e)const { return w > e.w; }
// ????????????????????????
pair<Weight, Edges> prim(const Graph &g, int r = 0) {
  Edges T;
  Weight total = 0;
  vector<int> v(g.size());
  priority_queue<Edge> q;
  q.emplace(-1, r, 0);
  while (q.size()) {
    Edge e = q.top();
    q.pop();
    if (v[e.d])
      continue;
    v[e.d] = true;
    total += e.w;
    if (e.s != -1)
      T.emplace_back(e);
    for (auto &f : g[e.d])
      if (!v[f.d])
        q.emplace(f);
  }
  return make_pair(total, T);
}

signed main() {
  for (int n; cin >> n && n;) {
    int m;
    cin >> m;
    Graph g(n);
    rep(i, 0, m) {
      char c;
      int a, b, d;
      cin >> a >> c >> b >> c >> d;
      g[a].emplace_back(a, b, d);
      g[b].emplace_back(b, a, d);
    }
    pair<Weight, Edges> k = prim(g, 0);
    cout << k.first / 100 - k.second.size() << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

#define int long long
#define DEBUG 0
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
#define dump(o)                                                                \\
  if (DEBUG) {                                                                 \\
    cerr << #o << " " << o << endl;                                            \\
  }
#define dumpc(o)                                                               \\
  if (DEBUG) {                                                                 \\
    cerr << #o;                                                                \\
    for (auto &e : (o))                                                        \\
      cerr << " " << e;                                                        \\
    cerr << endl;                                                              \\
  }
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD = 1e9 + 7;

//??¶?´?????????£???????????? int:INF ll:INFL
#define INFG INFL
using Weight = ll; // int;

class Edge {
public:
  int s;    // source
  int d;    // destination
  Weight w; // weight
  Edge(int s = 0, int d = 0, Weight w = INFG) : s(s), d(d), w(w){};
  bool operator<(const Edge &e) const { return w > e.w; }
};
using Edges = vector<Edge>;
//???????????\\: g[u].push_back(Edge(u, v, c));
//????????¨???????????????????????°??????????????\\?????????????????????
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

//?????¢?´¢, ??¢?´¢???, ??¢?´¢???
enum { WHITE, GRAY, BLACK };

//?´?????????????????§????
// Union-Find??¨
struct UnionFind {
  vector<int> p; // parent
  int s;         // size ???????????°
  UnionFind(int n) : p(n, -1), s(n) {}
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (size(x) < size(y))
      swap(x, y);
    p[x] += p[y];
    p[y] = x;
    s--;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int root(int x) { return p[x] < 0 ? x : p[x] = root(p[x]); }
  //?????????????´???°
  int size(int x) { return -p[root(x)]; }
};

//????°???¨?????¨
// Kruskal O(|E|log|E|)
pair<Weight, Edges> kruskal(const Graph &g) {
  UnionFind UF(g.size());
  Edges es;
  for (int i = 0; i < g.size(); i++)
    for (auto &e : g[i])
      es.emplace_back(e);
  sort(es.begin(), es.end());
  Weight total = 0;
  Edges T;
  for (auto &e : es)
    if (!UF.same(e.s, e.d)) {
      T.push_back(e);
      total += e.w;
      UF.unite(e.s, e.d);
    }
  return make_pair(total, T);
}

//????°???¨?????¨
// Prim O(ElogV)
// r????????°?????????????????????????±?
// Edge??? bool operator<(const Edge &e)const { return w > e.w; }
// ????????????????????????
pair<Weight, Edges> prim(const Graph &g, int r = 0) {
  Edges T;
  Weight total = 0;
  vector<int> v(g.size());
  priority_queue<Edge> q;
  q.push(Edge(-1, r, 0));
  while (q.size()) {
    Edge e = q.top();
    q.pop();
    if (v[e.d])
      continue;
    v[e.d] = true;
    total += e.w;
    if (e.s != -1)
      T.push_back(e);
    for (auto &f : g[e.d])
      if (!v[f.d])
        q.push(f);
  }
  return make_pair(total, T);
}

signed main() {
  for (int n; cin >> n && n;) {
    int m;
    cin >> m;
    Graph g(n);
    rep(i, 0, n) {
      char c;
      int a, b, d;
      cin >> a >> c >> b >> c >> d;
      g[a].push_back(Edge(a, b, d));
      g[b].push_back(Edge(b, a, d));
    }
    pair<Weight, Edges> k = prim(g, 0);
    cout << k.first / 100 - k.second.size() << endl;
  }
  return 0;
}