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

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#define rep(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
using namespace std;
int V, E, st, gl; // 頂点数、辺数、始点、終点
#define E_M 401
#define V_M 41
char INF[2000];
struct edge {
  int from, to;
  char label[2000];
};
edge es[E_M];
char d[V_M][2000];

// aにbをコピー
void cp(char *a, char *b) {
  int p = 0;
  while (b[p] != '\\0') {
    a[p] = b[p];
    p++;
    if (p >= 800)
      break;
  }
  a[p] = '\\0';
}
// aにx->y連結をコピー
void connect_str(char a[], char x[], char y[]) {
  int p = 0, q = 0;
  while (x[p] != '\\0') {
    a[p] = x[p], p++;
    if (p >= 1800)
      break;
  }
  while (y[q] != '\\0') {
    a[p] = y[q], q++, p++;
    if (p >= 1800)
      break;
  }
  a[p] = '\\0';
}

bool shortest(int s, int g) {
  rep(i, 0, V) cp(d[i], INF);
  d[g][0] = '\\0';
  rep(i, 0, 2 * V * 6 + 1) {
    rep(j, 0, E) {
      edge e = es[j];
      // cout << d[e.to] << endl;
      if (strcmp(d[e.to], INF) >= 0)
        continue;
      char target[2000] = {0};
      connect_str(target, e.label, d[e.to]);
      if ((strcmp(d[e.from], target) > 0)) {
        //	cout << d[e.to] << endl;
        cp(d[e.from], target);
        if (i == 2 * 6 * V + 1)
          return (true);
      }
    }
  }
  return (false);
}

int main(void) {

  rep(i, 0, 400) INF[i] = 'z';
  INF[400] = '\\0';
  while (true) {
    cin >> V >> E >> st >> gl;
    if (V == 0)
      return (0);
    rep(i, 0, E) cin >> es[i].from >> es[i].to >> es[i].label;

    if (shortest(st, gl) || strcmp(d[st], INF) >= 0 ||
        strlen(d[st]) > 6 * (V - 1))
      cout << "NO" << endl;
    else
      cout << d[st] << endl;
  }
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#define rep(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
using namespace std;
int V, E, st, gl; // 頂点数、辺数、始点、終点
#define E_M 401
#define V_M 41
char INF[1000];
struct edge {
  int from, to;
  char label[1000];
};
edge es[E_M];
char d[V_M][1000];

// aにbをコピー
void cp(char *a, char *b) {
  int p = 0;
  while (b[p] != '\\0') {
    a[p] = b[p];
    p++;
  }
  a[p] = '\\0';
}
// aにx->y連結をコピー
void connect_str(char a[], char x[], char y[]) {
  int p = 0, q = 0;
  while (x[p] != '\\0')
    a[p] = x[p], p++;
  while (y[q] != '\\0')
    a[p] = y[q], q++, p++;
  a[p] = '\\0';
}

bool shortest(int s, int g) {
  rep(i, 0, V) strcpy(d[i], INF);
  d[g][0] = '\\0';
  rep(i, 0, V + 1) {
    rep(j, 0, E) {
      edge e = es[j];
      // cout << d[e.to] << endl;
      if (strcmp(d[e.to], INF) >= 0)
        continue;
      char target[1000] = {0};
      connect_str(target, e.label, d[e.to]);
      if ((strcmp(d[e.from], target) > 0)) {
        //	cout << d[e.to] << endl;
        strcpy(d[e.from], target);
        if (i == V)
          return (true);
      }
    }
  }
  return (false);
}

int main(void) {

  rep(i, 0, 400) INF[i] = 'z';
  INF[400] = '\\0';
  while (true) {
    cin >> V >> E >> st >> gl;
    if (V == 0)
      return (0);
    rep(i, 0, E) cin >> es[i].from >> es[i].to >> es[i].label;

    if (shortest(st, gl) || strcmp(d[st], INF) >= 0)
      cout << "NO" << endl;
    else
      cout << d[st] << endl;
    //	rep(i, 0, V)cout << d[i] << endl;
  }
}