alexjercan/bugnet huggingface dataset:
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (i = 1; i < n + 1; i++)
// 2D::rep(i,j)rep(j,j)cin>>bin[i][j];
// vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout << "No" << endl
#define A2 cout << "Yes" << endl
#define A3 cout << ans << endl
#define AA(i) cout << i << endl
#define PI 3.14159265359
const int U = 2e5 + 5;
const ll MOD = 998244353;
const int INF = 1001001001;

int main() {
  int N, M;
  cin >> N >> M;
  Graph G(N + 1);
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int> dist(N + 1, 0);
  queue<int> que;

  dist[1] = 1;
  que.push(1);

  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (int nv : G[v]) {
      if (dist[nv] != 0)
        continue;
      dist[nv] = v;
      que.push(nv);
    }
  }
  AA("Yes");
  for (int i = 2; i <= N; i++)
    AA(dist[i]);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (i = 1; i < n + 1; i++)
// 2D::rep(i,j)rep(j,j)cin>>bin[i][j];
// vector<int> a(n)
#define A1 cout << "No" << endl
#define A2 cout << "Yes" << endl
#define A3 cout << ans << endl
#define AA(i) cout << i << endl
#define PI 3.14159265359
const int U = 2e5 + 5;
const ll MOD = 998244353;
const int INF = 1001001001;

int main() {
  int N, M;
  cin >> N >> M;
  int i, k = N;
  vector<int> mapA(M + 1);
  vector<int> mapB(M + 1);
  vector<int> C(0);
  vector<int> ans(N + 1);
  rep(i, M) {
    cin >> mapA[i];
    cin >> mapB[i];
    if (mapA[i] == 1) {
      ans[mapB[i]] = 1;
      C.push_back(mapB[i]);
      k = k - 1;
    }
    if (mapB[i] == 1) {
      ans[mapA[i]] = 1;
      C.push_back(mapA[i]);
      k = k - 1;
    }
  }
  for (int i = 0;; i++) {
    for (int j = 1; j <= M; j++) {
      if (mapA[j] == C[i] && ans[mapB[j]] == 0) {
        ans[mapB[j]] = mapA[j];
        C.push_back(mapB[j]);
        k = k - 1;
      }
      if (mapB[j] == C[i] && ans[mapA[j]] == 0) {
        ans[mapA[j]] = mapB[j];
        C.push_back(mapA[j]);
        k = k - 1;
      }
    }
    if (k == 0)
      break;
  }
  AA("Yes");
  for (int i = 2; i < N + 1; i++)
    AA(ans[i]);
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int main() {
  int N, M, i, a, b;
  cin >> N >> M;
  vector<vector<int>> E(N + 1, vector<int>());
  for (i = 0; i < M; i++) {
    cin >> a >> b;
    E[a].push_back(b);
    E[b].push_back(a);
  }
  vector<int> ans(N + 1, -1);
  queue<int> R;
  ans[0] = ans[1] = 0;
  R.push(1);
  while (!R.empty()) {
    int room = R.front();
    R.pop();
    for (i = 0; i < E[room].size(); i++) {
      if (ans[E[room][i]] < 1) {
        ans[E[room][i]] = room;
        R.push(E[room][i]);
      }
    }
  }
  for (i = 2; i <= N; i++) {
    if (ans[i] < 1)
      break;
  }
  if (i <= N) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    for (i = 2; i <= N; i++) {
      cout << ans[i] << endl;
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int main() {
  int N, M, i, a, b;
  cin >> N >> M;
  vector<vector<int>> E(N + 1, vector<int>(N + 1));
  for (i = 0; i < M; i++) {
    cin >> a >> b;
    E[a].push_back(b);
    E[b].push_back(a);
  }
  vector<int> ans(N + 1, -1);
  queue<int> R;
  R.push(1);
  while (!R.empty()) {
    int room = R.front();
    R.pop();
    for (i = 0; i < E[room].size(); i++) {
      if (ans[E[room][i]] < 1) {
        ans[E[room][i]] = room;
        R.push(E[room][i]);
      }
    }
  }
  for (i = 2; i <= N; i++) {
    if (ans[i] < 1)
      break;
  }
  if (i < N) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    for (i = 2; i <= N; i++) {
      cout << ans[i] << endl;
    }
  }
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  int N, M;
  cin >> N >> M;
  int A, B;

  /* 各部屋が繋がっている部屋の番号を保持する */
  vector<vector<int>> room(N + 1);
  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    room.at(A).push_back(B);
    room.at(B).push_back(A);
  }

  vector<int> guide(N + 1, 0);
  queue<int> que;
  que.push(1);

  int cur_room;
  while (!que.empty()) {
    cur_room = que.front();
    que.pop();
    for (auto itr : room.at(cur_room)) {
      if (itr == 1 || guide.at(itr) != 0)
        continue;
      guide.at(itr) = cur_room;
      que.push(itr);
    }
  }

  for (int i = 2; i < N + 1; i++) {
    if (guide.at(i) == 0) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  for (int i = 2; i < N + 1; i++)
    cout << guide.at(i) << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

/* room_no に今の部屋番号が入っているので
 * 今の部屋に繋がっている部屋に今の部屋番号を入れる */
static void func(int room_no, int dist, vector<vector<int>> &room,
                 vector<pair<int, int>> &guide) {
  vector<int> new_room;
  for (auto itr : room.at(room_no)) {
    /* すでに他の部屋の番号が入っていたらそのまま */
    if (itr == 1 || guide.at(itr).second < dist)
      continue;
    guide.at(itr).first = room_no;
    guide.at(itr).second = dist;
    new_room.push_back(itr);
  }
  for (auto itr : new_room)
    func(itr, dist + 1, room, guide);
}

int main(void) {
  int N, M;
  cin >> N >> M;
  int A, B;

  /* 各部屋が繋がっている部屋の番号を保持する */
  vector<vector<int>> room(N + 1);
  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    room.at(A).push_back(B);
    room.at(B).push_back(A);
  }

  vector<pair<int, int>> guide(N + 1, make_pair(0, INT_MAX));
  func(1, 1, room, guide);

  for (int i = 2; i < N + 1; i++) {
    if (guide.at(i).first == 0) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  for (int i = 2; i < N + 1; i++)
    cout << guide.at(i).first << endl;
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vi = vector<int>;

int main() {
  int n, m;
  cin >> n >> m;
  vi an[n];
  int a, b;
  rep(i, m) {
    cin >> a >> b;
    a--;
    b--;
    an[a].push_back(b);
    an[b].push_back(a);
  }

  int bn[n];
  rep(i, n) bn[i] = -1;
  bn[0] = 0;
  queue<int> que;
  que.push(0);
  while (!que.empty()) {
    int v = que.front(); // キューから先頭頂点を取り出す
    que.pop();

    // v から辿れる頂点をすべて調べる
    for (int nv : an[v]) {
      if (bn[nv] != -1)
        continue; // すでに発見済みの頂点は探索しない

      // cout<<v<<" "<<nv<<endl;
      //  新たな白色頂点 nv について距離情報を更新してキューに追加する
      bn[nv] = v + 1;
      que.push(nv);
    }
  }

  cout << "Yes" << endl;
  rep(i, n - 1) cout << bn[i + 1] << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vi = vector<int>;

int main() {
  int n, m;
  cin >> n >> m;
  vi an[n];
  int a, b;
  rep(i, n) {
    cin >> a >> b;
    a--;
    b--;
    an[a].push_back(b);
    an[b].push_back(a);
  }

  int bn[n];
  rep(i, n) bn[i] = -1;
  queue<int> que;
  que.push(0);
  while (!que.empty()) {
    int v = que.front(); // キューから先頭頂点を取り出す
    que.pop();

    // v から辿れる頂点をすべて調べる
    for (int nv : an[v]) {
      if (bn[nv] != -1)
        continue; // すでに発見済みの頂点は探索しない

      // 新たな白色頂点 nv について距離情報を更新してキューに追加する
      bn[nv] = v + 1;
      que.push(nv);
    }
  }
  cout << "Yes" << endl;
  rep(i, n - 1) cout << bn[i + 1] << endl;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (ll i = 0; i < (n); ++i)
const int INF = 100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vint v[INF];
  /*
  v[1]: 1とつながっている番号リスト
  v[2]: 2とつながっている番号リスト
  ...
  */
  REP(i, m) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  queue<int> que;
  int went[INF]; // 選んだかどうか記録
  int ans[INF];  // 答え用
  que.push(1);
  FOR(i, 2, n + 1) went[i] = INF; // 初期化
  while (que.size()) {
    int p = que.front();
    que.pop();
    for (auto vv : v[p]) { // queの先頭と繋がる番号
      if (went[vv] == INF) {
        ans[vv] = p;  // ans
        que.push(vv); // あとで見るノード
        went[vv] = 1; // 済みのしるし
      }
    }
  }
  cout << "Yes\\n";
  FOR(i, 2, n + 1) cout << ans[i] << "\\n";

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (ll i = 0; i < (n); ++i)
const int INF = 10010;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vint v[INF];
  /*
  v[1]: 1とつながっている番号
  v[2]: 2とつながっている番号
  ...
  */
  REP(i, m) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  queue<int> que;
  int went[INF]; // 選んだかどうか記録
  int ans[INF];  // 答え用
  que.push(1);
  FOR(i, 2, n + 1) went[i] = INF; // 初期化
  while (que.size()) {
    int p = que.front();
    que.pop();
    for (auto vv : v[p]) { // queの先頭と繋がる番号
      if (went[vv] == INF) {
        ans[vv] = p;  // ans
        que.push(vv); // あとで見るノード
        went[vv] = 1; // 済みのしるし
      }
    }
  }
  cout << "Yes\\n";
  FOR(i, 2, n + 1) cout << ans[i] << "\\n";

  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

// 短縮
#define rep(i, n) for (int i = 0; i < (n); ++i)
// sort()用
#define all(v) v.begin(), v.end()

#define PB(N) push_back(N)

using namespace std;

using Graph = vector<vector<int>>;

int main() {
  int N, M;
  cin >> N >> M;

  Graph AB(M + 10, vector<int>());

  rep(i, M) {
    int buffer_a, buffer_b;
    cin >> buffer_a >> buffer_b;
    AB[buffer_a - 1].PB(buffer_b - 1);
    AB[buffer_b - 1].PB(buffer_a - 1);
  }

  vector<int> dist(N + 10, -1);
  queue<int> que;
  vector<int> pre(N + 10, -1); // 直前の頂点

  dist[0] = 0;
  que.push(0);

  // BFS開始
  while (!que.empty()) {
    int v = que.front();
    que.pop();

    // vから辿れる頂点を全て調べる
    for (int next_v : AB[v]) {
      if (dist[next_v] != -1)
        continue; // すでに探索済み

      // 新たな頂点next_vについて距離情報を取得してキューに追加
      dist[next_v] = dist[v] + 1;
      pre[next_v] = v;
      que.push(next_v);
    }
  }

  cout << "Yes" << endl;
  rep(i, N) {
    if (i == 0)
      continue;
    int ans = pre[i]; // 一個前の場所を表示しておけば良い
    ++ans;
    cout << ans << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

// 短縮
#define rep(i, n) for (int i = 0; i < (n); ++i)
// sort()用
#define all(v) v.begin(), v.end()

#define PB(N) push_back(N)

using namespace std;

using Graph = vector<vector<int>>;

int main() {
  int N, M;
  cin >> N >> M;

  Graph AB(M, vector<int>());

  rep(i, M) {
    int buffer_a, buffer_b;
    cin >> buffer_a >> buffer_b;
    AB[buffer_a - 1].PB(buffer_b - 1);
    AB[buffer_b - 1].PB(buffer_a - 1);
  }

  vector<int> dist(N + 1, -1);
  queue<int> que;
  vector<int> pre(N + 1, -1); // 直前の頂点

  dist[0] = 0;
  que.push(0);

  // BFS開始
  while (!que.empty()) {
    int v = que.front();
    que.pop();

    // vから辿れる頂点を全て調べる
    for (int next_v : AB[v]) {
      if (dist[next_v] != -1)
        continue; // すでに探索済み

      // 新たな頂点next_vについて距離情報を取得してキューに追加
      dist[next_v] = dist[v] + 1;
      pre[next_v] = v;
      que.push(next_v);
    }
  }

  cout << "Yes" << endl;
  rep(i, N) {
    if (i == 0)
      continue;
    int ans = pre[i]; // 一個前の場所を表示しておけば良い
    ++ans;
    cout << ans << endl;
  }
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
  ll N, M;

  cin >> N >> M;

  vector<int> A(M), B(M), ans(M - 1, 0);
  vector<vector<int>> C(N);

  rep(i, M) {
    cin >> A[i] >> B[i];
    C[A[i] - 1].push_back(B[i] - 1);
    C[B[i] - 1].push_back(A[i] - 1);
  }

  vector<int> dist(N, -1);
  queue<int> que;

  dist[0] = 0;
  que.push(0);

  while (!que.empty()) {
    int v = que.front();
    que.pop();

    for (int nv : C[v]) {
      if (dist[nv] != -1)
        continue;
      dist[nv] = v + 1;
      que.push(nv);
    }
  }
  vector<int> abc;
  abc = dist;
  sort(abc.begin(), abc.end());
  if (abc[0] == -1) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    for (int v = 1; v < N; v++) {
      cout << dist[v] << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
  ll N, M;
  bool ok = false;

  cin >> N >> M;

  vector<int> A(M), B(M), ans(M - 1, 0);
  vector<vector<int>> C(N, vector<int>(N));

  rep(i, M) {
    cin >> A[i] >> B[i];
    C[A[i] - 1].push_back(B[i] - 1);
    C[B[i] - 1].push_back(A[i] - 1);
  }

  vector<int> dist(N, -1);
  queue<int> que;

  dist[0] = 0;
  que.push(0);

  while (!que.empty()) {
    int v = que.front();
    que.pop();

    for (int nv : C[v]) {
      if (dist[nv] != -1)
        continue;
      dist[nv] = v + 1;
      que.push(nv);
    }
  }
  vector<int> abc;
  abc = dist;
  sort(abc.begin(), abc.end());
  if (abc[0] == -1) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    for (int v = 1; v < N; v++) {
      cout << dist[v] << endl;
    }
  }

  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

int t;
int n, m;
int par[N];
bool vis[N];

vector<vector<int>> v;

void fail() {
  cout << "No";
  exit(0);
}

void solve() {
  cin >> n >> m;
  v.resize(n + 5);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }

  queue<int> q;

  q.push(1);
  vis[1] = true;
  while (q.size()) {
    int node = q.front();
    q.pop();
    for (int to : v[node]) {
      if (vis[to])
        continue;
      else {
        q.push(to);
        vis[to] = true;
        par[to] = node;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i])
      fail();
  }
  cout << "Yes" << endl;

  for (int i = 2; i <= n; i++) {
    cout << par[i] << endl;
  }
}

int main() {
  t = 1;

  while (t--) {
    solve();
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int N = 5e3 + 5;

int t;
int n, m;
int par[N];
bool vis[N];

vector<vector<int>> v;

void fail() {
  cout << "No";
  exit(0);
}

void solve() {
  cin >> n >> m;
  v.resize(n + 5);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }

  queue<int> q;

  q.push(1);
  vis[1] = true;
  while (q.size()) {
    int node = q.front();
    q.pop();
    for (int to : v[node]) {
      if (vis[to])
        continue;
      else {
        q.push(to);
        vis[to] = true;
        par[to] = node;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i])
      fail();
  }
  cout << "Yes" << endl;

  for (int i = 2; i <= n; i++) {
    cout << par[i] << endl;
  }
}

int main() {
  t = 1;

  while (t--) {
    solve();
  }
}
Problem p02678 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
const uint ege = -1;

int main() {
  // 部屋数・通路数
  int N, M;
  cin >> N >> M;
  // vector<vector<bool>> pathway(N,vector<bool>(N,false));
  int A, B;
  vector<vector<uint>> pathway(N);
  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    pathway.at(A - 1).push_back(B - 1); //.at(B-1) = true;
    pathway.at(B - 1).push_back(A - 1); //.at(A-1) = true;
  }

  // vector<bool> fixed(N,true);
  // vector<bool> answer1(N,false);
  vector<uint> distan(N, -1);

  queue<uint> nextway;

  uint convert;
  for (uint i : pathway.at(0)) {

    // convert = pathway.at(0).a

    distan.at(i) = 1;
    nextway.push(i);
  }

  uint j;

  while (nextway.size()) {
    j = nextway.front();

    for (uint i : pathway.at(j)) {

      if (distan.at(i) == ege) {
        distan.at(i) = j + 1;
        nextway.push(i);
      }
    }

    nextway.pop();
  }

  bool aflg = true;
  // uint riri = -1;
  for (int i : distan) {
    if (i == ege) {
      aflg = false;
      break;
    }
  }

  if (aflg) {
    cout << "Yes" << endl;

    for (uint x = 1; x < N; x++) {
      cout << distan.at(x) << endl;
    }

  } else {
    cout << "No" << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;

int main() {
  // 部屋数・通路数
  int N, M;
  cin >> N >> M;
  vector<vector<bool>> pathway(N, vector<bool>(N, false));
  int A, B;
  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    pathway.at(A - 1).at(B - 1) = true;
    pathway.at(B - 1).at(A - 1) = true;
  }

  vector<bool> fixed(N, true);
  vector<bool> answer1(N, false);
  vector<uint> distan(N, 0);

  queue<uint> nextway;

  for (uint i = 0; i < N; i++) {
    if (pathway.at(0).at(i)) {

      distan.at(i) = 1;
      nextway.push(i);
      fixed.at(i) = false;
    }
  }

  uint j;

  uint skip = 0;
  bool sflg = true;
  uint eskip = 0;

  uint eed = N;
  while (nextway.size()) {
    j = nextway.front();
    eed = N - eskip;
    sflg = true;
    for (uint i = skip; i < eed; i++) {

      if (pathway.at(j).at(i) && fixed.at(i)) {

        distan.at(i) = j + 1;
        nextway.push(i);
        fixed.at(i) = false;
      }

      if (fixed.at(i)) {
        sflg = false;
        eskip = 0;
      } else {
        if (sflg)
          skip++;
        eskip++;
      }
    }

    nextway.pop();
  }

  if (fixed == answer1) {
    cout << "Yes" << endl;

    for (uint x = 1; x < N; x++) {
      cout << distan.at(x) << endl;
    }

  } else {
    cout << "No" << endl;
  }
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

struct edge {
  int src, dest, cost;
};
using P = pair<int, int>; // 距離、ノード番号

const int INF = INT_MAX;
int V;                    // Node数
map<int, vector<edge>> G; // edge集合、G[src][index]
map<int, int> DIST;       // 現状のコスト　DIST[Node][Cost]
map<int, int> preNode;    // 最短経路上の1ホップ前のノード

void init() {
  for (int i = 0; i < V; i++) {
    DIST[i] = INF;
  }
}

void setEdge(int src, int dest, int cost) {
  edge e = {src, dest, cost};
  G[src].push_back(e);
}

void dijkstra(int s) {
  // 要素の型,内部コンテナの型、並べ替え方法
  // P->first＝距離で昇順にソート
  priority_queue<P, vector<P>, greater<P>> que;

  DIST[s] = 0;
  preNode[s] = s;
  que.push(P(0, s));

  while (!que.empty()) {

    P p = que.top();
    que.pop();

    int tmp_node = p.second;
    if (DIST[tmp_node] < p.first) {
      continue;
    }
    for (auto g : G[tmp_node]) {
      edge e = g;
      if (DIST[e.dest] > DIST[tmp_node] + e.cost) {
        DIST[e.dest] = DIST[tmp_node] + e.cost;
        que.push(P(DIST[e.dest], e.dest));
        preNode[e.dest] = tmp_node;
      }
    }
  }
}

int main(void) {

  int N, M, A, B;
  cin >> N >> M;

  V = N; // 頂点数を登録

  // 初期化
  init();

  // エッジの作成
  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    setEdge(A - 1, B - 1, 1);
    setEdge(B - 1, A - 1, 1);
  }

  // ダイクストラ法実行
  dijkstra(0);

  for (int i = 0; i < N; i++) {
    if (DIST[i] == INF) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  for (int i = 1; i < N; i++) {
    cout << preNode[i] + 1 << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define INF 1e+9
#define MAX_V 10

struct edge {
  int to;
  int cost;
};

// <最短距離, 頂点の番号>
using P = pair<int, int>;

long long V;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + V, INF);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;

    for (int i = 0; i < G[v].size(); ++i) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main(void) {
  long long N, M;
  bool ansflg = true;

  cin >> N >> M;
  ;
  V = N;
  // int E;
  // cin >> E;
  for (int i = 1; i <= M; ++i) {
    int a, b;
    cin >> a >> b;
    edge e = {b - 1, 1};
    G[a - 1].push_back(e);
    e = {a - 1, 1};
    G[b - 1].push_back(e);
  }
  dijkstra(0);
  for (int i = 0; i < V; ++i) {
    if (d[i] == INF) {
      ansflg = false;
      break;
    }
  }

  if (ansflg = -false) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    for (int i = 1; i < V; i++) {

      cout << d[i] << endl;
    }
  }

  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define pi 3.1415
#define ll long long
#define pii pair<ll, ll>
#define debug(a) cout << a << '\\n'
#define maxn 200009
#define MOD 1000000007
#define rep(i, a, b) for (ll i = a; i < (b); ++i)
using namespace std;
const ll INF = 1e15 + 9;
ll n, m;
vector<pii> adj[maxn];
ll dis[maxn];
ll pai[maxn];
void addedge(ll a, ll b, ll c) {
  adj[a].push_back({b, c});
  adj[b].push_back({a, c});
}
void INFINITAR() {
  for (ll i = 0; i <= n; i++) {
    dis[i] = INF;
  }
}
void dijkstra(int x) {
  INFINITAR();
  dis[x] = 0;
  priority_queue<pii, vector<pii>, greater<pii>> pq;
  pq.push({0, x});
  while (!pq.empty()) {
    auto f = pq.top();
    pq.pop();
    if (dis[f.second] < f.first)
      continue;
    for (auto e : adj[f.second]) {
      if (f.first + e.second < dis[e.first]) {
        pai[e.first] = f.second;
        dis[e.first] = f.first + e.second;
        pq.push({dis[e.first], e.first});
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  memset(pai, -1, sizeof pai);
  while (m--) {
    ll a, b;
    cin >> a >> b;
    addedge(a, b, 1);
  }
  dijkstra(1);
  bool can = true;
  rep(i, 2, n + 1) {
    if (pai[i] == -1)
      can = false;
  }
  if (!can) {
    cout << "No\\n";
  } else {
    cout << "Yes\\n";
    rep(i, 2, n + 1) cout << pai[i] << '\\n';
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define pi 3.1415
#define ll long long
#define pii pair<ll, ll>
#define debug(a) cout << a << '\\n'
#define maxn 50009
#define MOD 1000000007
#define rep(i, a, b) for (ll i = a; i < (b); ++i)
using namespace std;
const ll INF = 1e15 + 9;
ll n, m;
vector<pii> adj[maxn];
ll dis[maxn];
ll pai[maxn];
void addedge(ll a, ll b, ll c) {
  adj[a].push_back({b, c});
  adj[b].push_back({a, c});
}
void INFINITAR() {
  for (ll i = 0; i <= n; i++) {
    dis[i] = INF;
  }
}
void dijkstra(int x) {
  INFINITAR();
  dis[x] = 0;
  priority_queue<pii, vector<pii>, greater<pii>> pq;
  pq.push({0, x});
  while (!pq.empty()) {
    auto f = pq.top();
    pq.pop();
    if (dis[f.second] < f.first)
      continue;
    for (auto e : adj[f.second]) {
      if (f.first + e.second < dis[e.first]) {
        pai[e.first] = f.second;
        dis[e.first] = f.first + e.second;
        pq.push({dis[e.first], e.first});
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  memset(pai, -1, sizeof pai);
  while (m--) {
    ll a, b;
    cin >> a >> b;
    addedge(a, b, 1);
  }
  dijkstra(1);
  bool can = true;
  rep(i, 2, n + 1) {
    if (pai[i] == -1)
      can = false;
  }
  if (!can) {
    cout << "No\\n";
  } else {
    cout << "Yes\\n";
    rep(i, 2, n + 1) cout << pai[i] << '\\n';
  }
  return 0;
}