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

#include <bits/stdc++.h>
using namespace std;
int n, m, cnt = 1, head[200005], ans[200005];
struct edge {
  int to, next, w;
} e[500005];
void addedge(int u, int v) {
  e[cnt].to = v;
  e[cnt].w = 1;
  e[cnt].next = head[u];
  head[u] = cnt;
  ++cnt;
}
int dis[100005];
bool vis[100005];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>
    q;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    addedge(x, y);
    addedge(y, x);
  }
  for (int i = 1; i <= n; i++)
    dis[i] = 0x7fffffff;
  dis[1] = 0;
  q.push(make_pair(dis[1], 1));
  while (!q.empty()) {
    pair<int, int> fr = q.top();
    q.pop();
    int now = fr.second;
    if (vis[now])
      continue;
    vis[now] = true;
    int ndis = fr.first;
    for (int i = head[now]; i; i = e[i].next) {
      if (ndis + e[i].w < dis[e[i].to]) {
        dis[e[i].to] = ndis + e[i].w;
        ans[e[i].to] = now;
        if (!vis[e[i].to])
          q.push(make_pair(dis[e[i].to], e[i].to));
      }
    }
  }
  for (int i = 2; i <= n; i++) {
    if (ans[i] == 0) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes" << endl;
  for (int i = 2; i <= n; i++)
    cout << ans[i] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, m, cnt = 1, head[100005], ans[100005];
struct edge {
  int to, next, w;
} e[200005];
void addedge(int u, int v) {
  e[cnt].to = v;
  e[cnt].w = 1;
  e[cnt].next = head[u];
  head[u] = cnt;
  ++cnt;
}
int dis[100005];
bool vis[100005];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>
    q;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    addedge(x, y);
    addedge(y, x);
  }
  for (int i = 1; i <= n; i++)
    dis[i] = 0x7fffffff;
  dis[1] = 0;
  q.push(make_pair(dis[1], 1));
  while (!q.empty()) {
    pair<int, int> fr = q.top();
    q.pop();
    int now = fr.second;
    if (vis[now])
      continue;
    vis[now] = true;
    int ndis = fr.first;
    for (int i = head[now]; i; i = e[i].next) {
      if (ndis + e[i].w < dis[e[i].to]) {
        dis[e[i].to] = ndis + e[i].w;
        ans[e[i].to] = now;
        if (!vis[e[i].to])
          q.push(make_pair(dis[e[i].to], e[i].to));
      }
    }
  }
  for (int i = 2; i <= n; i++) {
    if (ans[i] == 0) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes" << endl;
  for (int i = 2; i <= n; i++)
    cout << ans[i] << endl;
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ll N, M;
  cin >> N >> M;
  vector<vector<ll>> G(N, vector<ll>(0));
  rep(i, M) {
    ll a, b;
    cin >> a >> b;
    --a;
    --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  queue<ll> q;
  q.push(0);
  vector<ll> ans(N, -1);
  vector<bool> gone(N, false);
  gone[0] = true;
  while (!q.empty()) {
    ll x = q.front();
    q.pop();
    if (!G[x].empty()) {
      for (auto g : G[x]) {
        if (gone[g])
          continue;
        gone[g] = true;
        ans[g] = x + 1;
        q.push(g);
      }
    }
  }
  bool can = true;
  for (ll i = 1; i < N; i++) {
    if (ans[i] == -1) {
      can = false;
      break;
    }
  }
  if (can) {
    cout << "Yes" << endl;
    for (ll i = 1; i < N; i++) {
      cout << ans[i] << endl;
    }
  } else
    cout << "No" << endl;
}

Error: 0

Fixed submission:

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

int main() {
  ll N, M;
  cin >> N >> M;
  vector<vector<ll>> G(M, vector<ll>(0));
  rep(i, M) {
    ll a, b;
    cin >> a >> b;
    --a;
    --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  queue<ll> q;
  q.push(0);
  vector<ll> ans(N, -1);
  vector<bool> gone(N, false);
  gone[0] = true;
  while (!q.empty()) {
    ll x = q.front();
    q.pop();
    if (!G[x].empty()) {
      for (auto g : G[x]) {
        if (gone[g])
          continue;
        gone[g] = true;
        ans[g] = x + 1;
        q.push(g);
      }
    }
  }
  bool can = true;
  for (ll i = 1; i < N; i++) {
    if (ans[i] == -1) {
      can = false;
      break;
    }
  }
  if (can) {
    cout << "Yes" << endl;
    for (ll i = 1; i < N; i++) {
      cout << ans[i] << endl;
    }
  } else
    cout << "No" << endl;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for (long long i = 0; i < n; i++)
#define reps(i, s, e) for (long long i = s; i < e; i++)
#define repr(i, n) for (long long i = n - 1; i >= 0; i--)
#define reprs(i, s, e) for (long long i = e - 1; i >= s; i--)

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n, m;
  cin >> n >> m;
  ll a[m], b[m];
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }

  vector<ll> g[n];
  rep(i, m) {
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }

  ll signal[n];
  memset(signal, -1, sizeof(signal));

  queue<ll> que;
  que.push(0);

  while (!que.empty()) {
    ll p_now = que.front();
    que.pop();

    for (ll p_nxt : g[p_now]) {
      if (signal[p_nxt] != -1)
        continue;

      signal[p_nxt] = p_now;
      que.push(p_nxt);
    }
  }

  cout << "Yes" << endl;
  reps(i, 1, n) { cout << signal[i] + 1 << endl; }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for (long long i = 0; i < n; i++)
#define reps(i, s, e) for (long long i = s; i < e; i++)
#define repr(i, n) for (long long i = n - 1; i >= 0; i--)
#define reprs(i, s, e) for (long long i = e - 1; i >= s; i--)

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n, m;
  cin >> n >> m;
  ll a[m], b[m];
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }

  vector<ll> g[n];
  rep(i, n) {
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }

  ll signal[n];
  memset(signal, -1, sizeof(signal));

  queue<ll> que;
  que.push(0);

  while (!que.empty()) {
    ll p_now = que.front();
    que.pop();

    for (ll p_nxt : g[p_now]) {
      if (signal[p_nxt] != -1)
        continue;

      signal[p_nxt] = p_now;
      que.push(p_nxt);
    }
  }

  cout << "Yes" << endl;
  reps(i, 1, n) { cout << signal[i] + 1 << endl; }

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = a; i < ll(b); i++)
#define repr(i, a, b) for (ll i = a; i >= ll(b); i--)
#define endl "\\n"
#define ALL(x) x.begin(), x.end()
#define ALLR(x) x.rbegin(), x.rend()
#define INF 1e9
#define DEBUG(x) cout << "debug: " << x << endl

int n, m;
vector<int> graph[100010];
int main() {
  cin >> n >> m;
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  queue<int> que;
  vector<int> obj(n, -1);
  que.push(0);

  while (que.size()) {
    int now = que.front();
    que.pop();
    for (auto x : graph[now]) {
      if (obj[x] != -1)
        continue;
      obj[x] = now;
      que.push(x);
    }
  }

  cout << "Yes" << endl;
  rep(i, 1, n) { cout << obj[i] + 1 << endl; }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = a; i < ll(b); i++)
#define repr(i, a, b) for (ll i = a; i >= ll(b); i--)
#define endl "\\n"
#define ALL(x) x.begin(), x.end()
#define ALLR(x) x.rbegin(), x.rend()
#define INF 1e9
#define DEBUG(x) cout << "debug: " << x << endl

int n, m;
vector<int> graph[10010];
int main() {
  cin >> n >> m;
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  queue<int> que;
  vector<int> dist(n, INF);
  dist[0] = 0;
  que.push(0);

  while (que.size()) {
    int now = que.front();
    que.pop();
    for (auto x : graph[now]) {
      if (dist[x] != INF)
        continue;
      dist[x] = dist[now] + 1;
      que.push(x);
    }
  }

  cout << "Yes" << endl;
  rep(i, 1, n) { cout << dist[i] << endl; }
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

vector<ll> load[100005];

typedef pair<ll, ll> Pair;

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

  for (ll i = 0; i < M; ++i) {
    ll A, B;
    cin >> A >> B;
    A--;
    B--;
    load[A].push_back(B);
    load[B].push_back(A);
  }

  // BFS のためのデータ構造
  vector<ll> dist(N, -1); // 全頂点を「未訪問」に初期化
  vector<ll> pre(N, -1);
  queue<ll> que;

  // 初期条件 (頂点 0 を初期ノードとする)
  dist[0] = 0;
  que.push(0); // 0 を頂点にする

  // BFS 開始 (キューが空になるまで探索を行う)
  while (!que.empty()) {
    ll v = que.front(); // キューから先頭頂点を取り出す
    que.pop();

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

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

  bool flg = true;

  for (ll i = 0; i < N; ++i)
    if (dist[i] == -1)
      flg = false;

  if (flg) {

    cout << "Yes" << endl;

    // 結果出力 (各頂点の頂点 0 からの距離を見る)
    for (ll v = 0; v < N; ++v) {

      if (v == 0)
        continue;
      ll ans = pre[v];
      ans++;
      cout << ans << endl;
    }

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

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

typedef pair<ll, ll> Pair;

int main() {

  ll N, M;

  cin >> N >> M;

  ll A, B;
  vector<vector<ll>> load(M);

  for (ll i = 0; i < M; ++i) {

    cin >> A >> B;
    A--;
    B--;
    load[A].push_back(B);
    load[B].push_back(A);
  }

  // BFS のためのデータ構造
  vector<ll> dist(N, -1); // 全頂点を「未訪問」に初期化
  vector<ll> pre(N, -1);
  queue<ll> que;

  // 初期条件 (頂点 0 を初期ノードとする)
  dist[0] = 0;
  que.push(0); // 0 を頂点にする

  // BFS 開始 (キューが空になるまで探索を行う)
  while (!que.empty()) {
    ll v = que.front(); // キューから先頭頂点を取り出す
    que.pop();

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

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

  cout << "Yes" << endl;

  // 結果出力 (各頂点の頂点 0 からの距離を見る)
  for (ll v = 0; v < N; ++v) {

    if (v == 0)
      continue;
    ll ans = pre[v];
    ans++;
    cout << ans << endl;
  }

  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int main() {

  int n, m;
  cin >> n >> m;

  vector<vector<int>> matrix(n);

  for (int i = 0; i < m; i++) { // Lendo a matriz de adjacência
    int a, b;
    cin >> a >> b;

    matrix[a - 1].push_back(b - 1);
    matrix[b - 1].push_back(a - 1);
  }

  queue<int> q;
  q.push(0);

  int resp[n + 5];
  for (int i = 0; i < n; i++)
    resp[i] = -1;

  while (!q.empty()) {

    int atual = q.front();

    for (int i = 0; i < matrix[atual].size(); i++) {

      if (resp[matrix[atual][i]] == -1) { // Para ver se ja foi percorrida
        q.push(matrix[atual][i]);
        resp[matrix[atual][i]] = atual;
      }
    }
    q.pop();
  }

  bool ok = true;

  for (int i = 1; i < n; i++) {
    if (resp[i] == -1)
      ok = false;
  }

  if (ok) {
    cout << "Yes" << endl;
    for (int i = 1; i < n; i++) {
      cout << resp[i] + 1 << endl;
    }
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int main() {

  int n, m;
  cin >> n >> m;

  vector<vector<int>> matrix(n);
  /*    for(int i=0; i<n; i++){ //Definindo todos os valores
          for (int j=0; j<n; j++){
              matrix[i][j]=0;
          }
      }
  */
  for (int i = 0; i < n; i++)
    matrix[i].resize(n);

  for (int i = 0; i < m; i++) { // Lendo a matriz de adjacência
    int a, b;
    cin >> a >> b;

    matrix[a - 1][b - 1] = 1;
    matrix[b - 1][a - 1] = 1;
  }

  queue<int> q;
  q.push(0);

  int resp[n + 5];
  for (int i = 0; i < n; i++)
    resp[i] = -1;

  while (!q.empty()) {

    int atual = q.front();

    for (int i = 0; i < n; i++) {
      if (matrix[atual][i] == 1) { // Para verificar
        if (resp[i] == -1) {       // Para ver se ja foi percorrida
          q.push(i);
          resp[i] = atual;
        }
      }
    }
    q.pop();
  }

  bool ok = true;

  for (int i = 1; i < n; i++) {
    if (resp[i] == -1)
      ok = false;
  }

  if (ok) {
    cout << "Yes" << endl;
    for (int i = 1; i < n; i++) {
      cout << resp[i] + 1 << endl;
    }
  } else {
    cout << "No" << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

void bfs(vector<int> adj[], int v, int src) {
  bool *visited = new bool[v + 1]{0};
  int *dist = new int[v + 1]{0};
  int *parent = new int[v + 1];
  for (int i = 0; i < v; i++)
    parent[i] = -1;
  queue<int> q;
  q.push(src);
  visited[src] = true;
  int node;
  while (!q.empty()) {
    node = q.front();
    q.pop();
    for (auto neighbour : adj[node]) {
      if (!visited[neighbour]) {
        q.push(neighbour);
        visited[neighbour] = true;
        dist[neighbour] = dist[node] + 1;
        parent[neighbour] = node;
      }
    }
  }
  int temp;
  bool ok = true;
  for (int i = 1; i < v; i++) {
    if (!dist[i]) {
      ok = false;
      break;
    }
  }
  if (!ok)
    cout << "No" << endl;
  else {
    cout << "Yes" << endl;
    for (int i = 1; i < v; i++)
      cout << parent[i] + 1 << endl;
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int u, v;
  vector<int> adj[n];
  for (int i = 1; i <= m; i++) {
    cin >> u >> v;
    u--, v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  bfs(adj, n, 0);

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

void addEdge(vector<int> adj[], int u, int v, int bidir) {
  adj[u].push_back(v);
  if (bidir) {
    adj[v].push_back(u);
  }
}
void bfs(vector<int> adj[], int v, int src) {
  bool *visited = new bool[v + 1]{0};
  int *dist = new int[v + 1]{0};
  int *parent = new int[v + 1];
  for (int i = 0; i < v; i++)
    parent[i] = -1;
  queue<int> q;
  q.push(src);
  visited[src] = true;
  int node;
  while (!q.empty()) {
    node = q.front();
    q.pop();
    for (auto neighbour : adj[node]) {
      if (!visited[neighbour]) {
        q.push(neighbour);
        visited[neighbour] = true;
        dist[neighbour] = dist[node] + 1;
        parent[neighbour] = node;
      }
    }
  }
  int temp;
  bool ok = true;
  for (int i = 1; i < v; i++) {
    if (!dist[i]) {
      ok = false;
      break;
    }
  }
  if (!ok)
    cout << "No" << endl;
  else {
    cout << "Yes" << endl;
    for (int i = 1; i < v; i++)
      cout << dist[i] << endl;
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int u, v;
  vector<int> adj[n];
  for (int i = 1; i <= n; i++) {
    cin >> u >> v;
    u--, v--;
    addEdge(adj, u, v, 1);
  }
  bfs(adj, n, 0);

  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;

int n;
const int full = 200006;
vector<int> adj[full];
bool vis[full];
int par[full];
int depth[full];
int ans[full];

void dfs(int i) {
  queue<int> q;
  q.push(1);
  while (q.size() > 0) {
    int x = q.front();
    vis[x] = 1;
    q.pop();
    for (int j = 0; j < adj[x].size(); j++) {
      if (vis[adj[x][j]] == 0 && ans[adj[x][j]] == 0) {

        ans[adj[x][j]] = x;
        q.push(adj[x][j]);
      }
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int i, j, k;
  int n, m;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].pb(b);
    adj[b].push_back(a);
  }
  dfs(1);
  for (i = 2; i <= n; i++) {
    if (ans[i] == 0) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes\\n";
  for (i = 2; i <= n; i++) {
    cout << ans[i] << "\\n";
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;

int n;
const int full = 200006;
vector<int> adj[full];
bool vis[full];
int par[full];
int depth[full];
int ans[full];

void dfs(int i) {
  queue<int> q;
  q.push(1);
  while (q.size() > 0) {
    int x = q.front();
    vis[x] = 1;
    q.pop();
    for (int j = 0; j < adj[x].size(); j++) {
      if (vis[adj[x][j]] == 0) {
        if (ans[adj[x][j]] == 0)
          ans[adj[x][j]] = x;
        q.push(adj[x][j]);
      }
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int i, j, k;
  int n, m;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].pb(b);
    adj[b].push_back(a);
  }
  dfs(1);
  for (i = 2; i <= n; i++) {
    if (ans[i] == 0) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes\\n";
  for (i = 2; i <= n; i++) {
    cout << ans[i] << "\\n";
  }
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

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

const int INF = 1001001001;

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

  vector<int> dist(n, INF);
  vector<int> pre(n, -1);
  queue<int> q;
  dist[0] = 0;
  q.push(0);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int u : to[v]) {
      if (dist[u] != INF)
        continue;
      dist[u] = dist[v] + 1;
      pre[u] = v;
      q.push(u);
    }
  }

  cout << "Yes" << endl;
  rep(i, n) {
    if (i == 0)
      continue;
    cout << pre[i] + 1 << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  int road[m][2];
  rep(i, m) cin >> road[i][0] >> road[i][1];
  vector<int> ans(n + 1, -1);
  for (int i = 1; i < n; i++) {
    rep(j, n) {
      if (road[j][0] == i && ans[road[j][1]] == -1) {
        ans[road[j][1]] = i;
      } else if (road[j][1] == i && ans[road[j][0]] == -1) {
        ans[road[j][0]] = i;
      }
    }
  }

  cout << "Yes" << endl;
  for (int i = 2; i <= n; i++)
    cout << ans[i] << endl;
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;
#define PI 3.141592653589793
struct node {
  list<int> to;
};
int BPS(int i, node a[], bool b[]) {
  queue<int> q1;
  q1.push(1);
  if (b[i]) { // 巡回済み

  } else {
    b[i] = true;
    for (int aa : a[i].to) {
      if (b[aa])
        BPS(aa, a, b);
    }
  }
}
int main() {
  node a[100010];
  bool b[200000]{};
  int c[200000]{};
  a[0].to.push_back(0);
  int A, B, N, M;
  cin >> N >> M;

  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    a[A].to.push_back(B);
    a[B].to.push_back(A);
  }
  queue<int> q1;
  int count = 0;
  q1.push(1);
  b[1] = true;
  while (!q1.empty()) {
    for (int num : a[q1.front()].to) {
      if (!b[num]) {
        b[num] = true;
        q1.push(num);
        c[num] = q1.front();
        count++;
      }
    }
    q1.pop();
  }
  if (count >= N - 1) {
    cout << "Yes\\n";
  } else {
    cout << "No\\n";
  }
  for (int i = 2; i < N + 1; i++) {
    cout << c[i] << "\\n";
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;
#define PI 3.141592653589793
struct node {
  list<int> to;
};
int BPS(int i, node a[], bool b[]) {
  queue<int> q1;
  q1.push(1);
  if (b[i]) { // 巡回済み

  } else {
    b[i] = true;
    for (int aa : a[i].to) {
      if (b[aa])
        BPS(aa, a, b);
    }
  }
}
int main() {
  node a[100000];
  bool b[100000]{};
  int c[100000]{};
  a[0].to.push_back(0);
  int A, B, N, M;
  cin >> N >> M;

  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    a[A].to.push_back(B);
    a[B].to.push_back(A);
  }
  queue<int> q1;
  int count = 0;
  q1.push(1);
  b[1] = true;
  while (!q1.empty()) {
    for (int num : a[q1.front()].to) {
      if (b[num]) {

      } else {
        b[num] = true;
        q1.push(num);
        c[num] = q1.front();
        count++;
      }
    }
    q1.pop();
  }
  if (count >= N - 1) {
    cout << "Yes\\n";
  } else {
    cout << "No\\n";
  }
  for (int i = 2; i < N + 1; i++) {
    cout << c[i] << "\\n";
  }
  return 0;
}