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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>

using namespace std;

#define dump(n) cout << "# " << #n << '=' << (n) << 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 iter(c) __typeof__((c).begin())
#define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define all(c) (c).begin(), (c).end()
#define mp make_pair

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

const int INFTY = 1 << 29;
const double EPS = 1e-9;

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  return os << '(' << p.first << ',' << p.second << ')';
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &a) {
  os << '[';
  rep(i, a.size()) os << (i ? " " : "") << a[i];
  return os << ']';
}

struct Edge {
  int src, dst;
  string label;
  Edge() {}
  Edge(int s, int d, string l) : src(s), dst(d), label(l) {}
  bool operator<(const Edge &e) const { return label < e.label; }
  bool operator>(const Edge &e) const { return label > e.label; }
};
typedef vector<vector<Edge>> Graph;

int main() {
  for (int n, m, s, t; cin >> n >> m >> s >> t, n | m | s | t;) {
    Graph g(n);
    rep(_, m) {
      int x, y;
      string l;
      cin >> x >> y >> l;
      g[y].emplace_back(y, x, l);
    }

    vs res(n, "~");
    res[t] = "";
    rep(_, 6 * n) rep(i, n) if (res[i] != "~") for (Edge e : g[i]) res[e.dst] =
        min(res[e.dst], e.label + res[e.src]);

    if (res[s] == "~" || res[s].size() >= 6 * n)
      cout << "NO" << endl;
    else
      cout << res[s] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>

using namespace std;

#define dump(n) cout << "# " << #n << '=' << (n) << 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 iter(c) __typeof__((c).begin())
#define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define all(c) (c).begin(), (c).end()
#define mp make_pair

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

const int INFTY = 1 << 29;
const double EPS = 1e-9;

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  return os << '(' << p.first << ',' << p.second << ')';
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &a) {
  os << '[';
  rep(i, a.size()) os << (i ? " " : "") << a[i];
  return os << ']';
}

struct Edge {
  int src, dst;
  string label;
  Edge() {}
  Edge(int s, int d, string l) : src(s), dst(d), label(l) {}
  bool operator<(const Edge &e) const { return label < e.label; }
  bool operator>(const Edge &e) const { return label > e.label; }
};
typedef vector<vector<Edge>> Graph;

int main() {
  for (int n, m, s, t; cin >> n >> m >> s >> t, n | m | s | t;) {
    Graph g(n);
    rep(_, m) {
      int x, y;
      string l;
      cin >> x >> y >> l;
      g[x].emplace_back(x, y, l);
    }

    vvs dp(n, vs(500, "~"));
    priority_queue<Edge, vector<Edge>, greater<Edge>> pq;
    dp[s][0] = "";
    pq.emplace(-1, s, "");
    while (!pq.empty()) {
      Edge cur = pq.top();
      pq.pop();
      if (dp[cur.dst][cur.label.size()] < cur.label)
        continue;
      for (Edge e : g[cur.dst]) {
        string nl = cur.label + e.label;
        if (nl.size() >= 500 || dp[e.dst][nl.size()] < nl)
          continue;
        dp[e.dst][nl.size()] = nl;
        pq.emplace(e.src, e.dst, nl);
      }
    }

    string res = *min_element(all(dp[t]) - 250);
    if (res == "~")
      cout << "NO" << endl;
    else if (res > *min_element(250 + all(dp[t])))
      cout << "NO" << endl;
    else
      cout << res << endl;
  }

  return 0;
}