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

#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
typedef long long lli;
typedef lli Weight;
const lli INF = 1LL << 60;
const int MAX_V = 500;
int V;
int N;
lli W;

string name[7] = {"Sunday",   "Monday", "Tuesday", "Wednesday",
                  "Thursday", "Friday", "Saturday"};
#define REP(i, x) for (int i = 0; i < (int)x; i++)
struct Edge {
  int src, dst;
  Weight weight;
  int rev;
  Edge(int f, int t, Weight c, int rev = 0)
      : src(f), dst(t), weight(c), rev(rev) {}
};
struct Node : public vector<Edge> { // 頂点の情報を記録する場合
};
bool operator<(const Edge &a, const Edge &b) { return a.weight < b.weight; }
bool operator>(const Edge &a, const Edge &b) { return b < a; }

typedef vector<Node> Graph;

typedef vector<vector<Weight>> Matrix;

void add_edge(Graph &G, int s, int t, Weight cap) {
  G[s].push_back(Edge(s, t, cap, G[t].size()));
  G[t].push_back(Edge(t, s, 0, G[s].size() - 1));
}
void bfs(const Graph &G, vector<int> &level, int s) {
  level[s] = 0;
  queue<int> que;
  que.push(s);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    REP(i, G[v].size()) {
      const Edge &e = G[v][i];
      if (e.weight > 0 && level[e.dst] < 0) {
        level[e.dst] = level[v] + 1;
        que.push(e.dst);
      }
    }
  }
}
Weight dfs(Graph &G, vector<int> &level, vector<int> &iter, int v, int t,
           Weight flow) {
  if (v == t)
    return flow;
  for (int &i = iter[v]; i < (int)G[v].size(); i++) {
    Edge &e = G[v][i];
    if (e.weight > 0 && level[v] < level[e.dst]) {
      Weight d = dfs(G, level, iter, e.dst, t, min(flow, e.weight));
      if (d > 0) {
        e.weight -= d;
        G[e.dst][e.rev].weight += d;
        return d;
      }
    }
  }
  return 0;
}
//
Weight max_flow(Graph &G, int s, int t) {
  Weight flow = 0;
  while (true) {
    vector<int> level(G.size(), -1);
    vector<int> iter(G.size(), 0);
    bfs(G, level, s);
    if (level[t] < 0)
      break; // もう流せない
    Weight f = 0;
    while ((f = dfs(G, level, iter, s, t, INF)) > 0) {
      flow += f;
    }
  }
  return flow;
}

inline int string2int(const string &a) {
  return find(name, name + 7, a) - name;
}
int main() {
  while (cin >> N >> W) {
    Graph G(N + 9);
    if (N == 0)
      break;
    int s = N + 7;
    int e = N + 7 + 1;
    lli req = 0;
    V = N + 7 + 2;
    for (int i = 0; i < N; i++) {
      lli c, t;
      cin >> t >> c;
      add_edge(G, s, i, t);
      req += t;
      for (int j = 0; j < c; j++) {
        string k;
        cin >> k;
        add_edge(G, i, string2int(k) + N, t);
      }
    }
    for (int i = 0; i < 7; i++) {
      add_edge(G, N + i, e, W);
    }
    lli flow = max_flow(G, s, e);
    if (flow == req) {
      cout << "Yes" << endl;
      ;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
typedef long long lli;
typedef lli Weight;
const lli INF = 1LL << 60;
const int MAX_V = 500;
int V;
int N;
lli W;

string name[7] = {"Sunday",   "Monday", "Tuesday", "Wednesday",
                  "Thursday", "Friday", "Saturday"};
#define REP(i, x) for (int i = 0; i < (int)x; i++)
struct Edge {
  int src, dst;
  Weight weight;
  int rev;
  Edge(int f, int t, Weight c, int rev = 0)
      : src(f), dst(t), weight(c), rev(rev) {}
};
struct Node : public vector<Edge> { // 頂点の情報を記録する場合
};
bool operator<(const Edge &a, const Edge &b) { return a.weight < b.weight; }
bool operator>(const Edge &a, const Edge &b) { return b < a; }

typedef vector<Node> Graph;

typedef vector<vector<Weight>> Matrix;

void add_edge(Graph &G, int s, int t, int cap) {
  G[s].push_back(Edge(s, t, cap, G[t].size() - 1));
  G[t].push_back(Edge(t, s, 0, G[s].size()));
}
void bfs(const Graph &G, vector<int> &level, int s) {
  level[s] = 0;
  queue<int> que;
  que.push(s);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    REP(i, G[v].size()) {
      const Edge &e = G[v][i];
      if (e.weight > 0 && level[e.dst] < 0) {
        level[e.dst] = level[v] + 1;
        que.push(e.dst);
      }
    }
  }
}
Weight dfs(Graph &G, vector<int> &level, vector<int> &iter, int v, int t,
           Weight flow) {
  if (v == t)
    return flow;
  for (int &i = iter[v]; i < (int)G[v].size(); i++) {
    Edge &e = G[v][i];
    if (e.weight > 0 && level[v] < level[e.dst]) {
      Weight d = dfs(G, level, iter, e.dst, t, min(flow, e.weight));
      if (d > 0) {
        e.weight -= d;
        G[e.dst][e.rev].weight += d;
        return d;
      }
    }
  }
  return 0;
}
//
Weight max_flow(Graph &G, int s, int t) {
  Weight flow = 0;
  while (true) {
    vector<int> level(G.size(), -1);
    vector<int> iter(G.size(), 0);
    bfs(G, level, s);
    if (level[t] < 0)
      break; // もう流せない
    Weight f = 0;
    while ((f = dfs(G, level, iter, s, t, INF)) > 0) {
      flow += f;
    }
  }
  return flow;
}

inline int string2int(const string &a) {
  return find(name, name + 7, a) - name;
}
int main() {
  while (cin >> N >> W) {
    Graph G(N + 15);
    if (N == 0)
      break;
    int s = N + 7;
    int e = N + 7 + 1;
    lli req = 0;
    V = N + 7 + 2;
    for (int i = 0; i < N; i++) {
      lli c, t;
      cin >> t >> c;
      add_edge(G, s, i, t);
      req += t;
      for (int j = 0; j < c; j++) {
        string k;
        cin >> k;
        add_edge(G, i, string2int(k) + N, t);
      }
    }
    for (int i = 0; i < 7; i++) {
      // G[N+i][e]=W;
      add_edge(G, N + i, e, W);
    }
    lli flow = max_flow(G, s, e);
    if (flow == req) {
      cout << "Yes" << endl;
      ;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}