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

// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout << #x << "=" << x << '\\n'
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << '\\n'
#define db3(x, y, z)                                                           \\
  cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \\
       << '\\n'
#define rep(i, a, n) for (int i = a; i <= (n); ++i)
#define repD(i, a, n) for (int i = a; i >= (n); --i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0

using namespace std;
using ll = long long;

const int N = 2e5 + 1;
vector<int> adj[N];
bool vis[N];
int nxt[N];
int n, m;

void testcase() {
  cin >> n >> m;

  rep(i, 1, n) adj[i].clear();

  memset(vis, false, sizeof(vis));
  memset(nxt, 0, sizeof(nxt));

  while (m--) {
    int u, v;
    cin >> u >> v;
    adj[u].pb(v);
    adj[v].pb(u);
  }
  queue<int> q;
  q.push(1);
  vis[1] = true;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int v : adj[u]) {
      if (!vis[v]) {
        nxt[v] = u;
        vis[v] = true;
        q.push(v);
      }
    }
  }

  rep(i, 2, n) {
    if (nxt[i] == 0) {
      cout << "No\\n";
      return;
    }
  }
  cout << "Yes\\n";
  rep(i, 2, n) { cout << nxt[i] << "\\n"; }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  if (TC)
    cin >> t;
  while (t--) {
    testcase();
  }
  return 0;
}

Error: 0

Fixed submission:

// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout << #x << "=" << x << '\\n'
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << '\\n'
#define db3(x, y, z)                                                           \\
  cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \\
       << '\\n'
#define rep(i, a, n) for (int i = a; i <= (n); ++i)
#define repD(i, a, n) for (int i = a; i >= (n); --i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0

using namespace std;
using ll = long long;

const int N = 2e3 + 1;
vector<int> adj[N];
bool vis[N];
int nxt[N];
int n, m;

void testcase() {
  cin >> n >> m;

  rep(i, 1, n) adj[i].clear();

  memset(vis, false, sizeof(vis));
  memset(nxt, 0, sizeof(nxt));

  while (m--) {
    int u, v;
    cin >> u >> v;
    adj[u].pb(v);
    adj[v].pb(u);
  }
  queue<int> q;
  q.push(1);
  vis[1] = true;
  int ct = 10;
  while (!q.empty() && ct--) {
    int u = q.front();
    q.pop();
    for (int v : adj[u]) {
      if (!vis[v]) {
        nxt[v] = u;
        vis[v] = true;
        q.push(v);
      }
    }
  }

  rep(i, 2, n) {
    if (nxt[i] == '0') {
      cout << "No\\n";
      return;
    }
  }
  cout << "Yes\\n";
  rep(i, 2, n) { cout << nxt[i] << "\\n"; }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  if (TC)
    cin >> t;
  while (t--) {
    testcase();
  }
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; // 1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template <class T, class S> inline bool chmax(T &a, const S &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class S> inline bool chmin(T &a, const S &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N, M;
  std::cin >> N >> M;
  std::vector<std::vector<int>> G(N);
  {
    int A, B;
    for (int i(0); i < M; ++i) {
      std::cin >> A >> B;
      --A;
      --B;
      G[A].push_back(B);
      G[B].push_back(A);
    }
  }
  std::vector<int> prv(N, NIL);
  std::queue<int> que;
  que.push(0);
  while (!que.empty()) {
    int v(que.front());
    que.pop();
    for (int e : G[v]) {
      if (prv[e] != NIL)
        continue;
      prv[e] = v + 1;
      que.push(e);
    }
  }
  std::cout << "Yes\\n";
  for (int i(1); i < N; ++i) {
    std::cout << prv[i] << "\\n";
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rng 200015
queue<int> Q;
vector<int> edge[rng];
int vis[rng], lvl[rng];
int bfs(int n) {
  for (int x = 0; x < 200000; x++)
    vis[x] = 0;
  vis[n] = 1;
  Q.push(n);
  while (!Q.empty()) {
    n = Q.front();
    Q.pop();
    int len = edge[n].size();
    for (int i = 0; i < len; i++) {
      int num = edge[n][i];
      if (vis[num] == 0) {
        vis[num] = 1;
        lvl[num] = n;
        Q.push(num);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  memset(lvl, -1, sizeof(lvl));
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  bfs(1);
  for (int i = 2; i <= n; i++) {
    if (lvl[i] == -1) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  for (int i = 2; i <= n; i++) {
    cout << lvl[i] << endl;
  }
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define REP(i, n) for (decltype(n) i = 0; i < (n); ++i)
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  vector<vector<int>> adj(N);
  REP(i, N) { adj[i].reserve(M); }
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  deque<tuple<int, int, int>> q;
  q.emplace_back(0, 0, -1);
  int INF = N + 10;
  vector<int> dist(N, INF);
  vector<int> prev(N, -1);
  int cnt = 0;
  while (!q.empty()) {
    auto [l, node, pnode] = q.front();
    q.pop_front();
    if (dist[node] <= l)
      continue;
    dist[node] = l;
    prev[node] = pnode;
    ++l;
    for (auto &&nxt : adj[node]) {
      if (dist[nxt] > l) {
        q.emplace_back(l, nxt, node);
      }
    }
  }
  cout << "Yes\\n";
  for (int i = 1; i < N; ++i) {
    cout << (prev[i] + 1) << "\\n";
  }
}


Error: TLE

Fixed submission:

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define REP(i, n) for (decltype(n) i = 0; i < (n); ++i)
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  vector<vector<int>> adj(N);
  REP(i, N) { adj[i].reserve(M); }
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  deque<tuple<int, int, int>> q;
  q.emplace_back(0, 0, -1);
  int INF = N + 10;
  vector<int> dist(N, INF);
  vector<int> prev(N, -1);
  int cnt = 0;
  while (!q.empty()) {
    auto [l, node, pnode] = q.front();
    q.pop_front();
    if (dist[node] < l)
      continue;
    dist[node] = l;
    prev[node] = pnode;
    ++l;
    for (auto &&nxt : adj[node]) {
      if (dist[nxt] > l) {
        q.emplace_back(l, nxt, node);
      }
    }
  }
  cout << "Yes\\n";
  for (int i = 1; i < N; ++i) {
    cout << (prev[i] + 1) << "\\n";
  }
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength = 100100;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> way[alength];
  fori(m) {
    int a, b;
    cin >> a >> b;
    way[a - 1].push_back(b - 1);
    way[b - 1].push_back(a - 1);
  }

  queue<int> q;
  vector<int> dist(n, INF);
  vector<int> pre(n, -1);
  dist[0] = 0;
  q.push(0);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int u : way[v]) {
      if (dist[u] != INF) {
        continue;
      }
      dist[u] = dist[v] + 1;
      pre[u] = v;
      q.push(u);
    }
  }
  cout << "Yes\\n";
  fori(n - 1) {
    int ans = pre[i + 1];
    cout << ans + 1 << endl;
  }
}


Error: 0

Fixed submission:

#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int alength = 200000;

/*struct way{
        int a,b;
        void fix(){
                if(a>b){
                        swap(a,b);
                }
        }

        bool operator<(const way& w)const{
                return (a<w.a?true:b<w.b);
        }
};*/

// https://qiita.com/drken/items/996d80bcae64649a6580
using Graph = vector<vector<int>>;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n, m;
  cin >> n >> m;
  Graph w(m);
  fori(m) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    w[a].push_back(b);
    w[b].push_back(a);
  }
  vector<int> dist(n, -1); // 全頂点を「未訪問」に初期化
  vector<int> arr(n, -1);
  queue<int> que;

  dist[0] = 0;
  que.push(0);
  while (!que.empty()) {
    int v = que.front(); // キューから先頭頂点を取り出す
    que.pop();

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

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

  for (int v = 1; v < n; ++v) {
    if (arr[v] == -1) {
      cout << "No\\n";
      return 0;
    }
  }
  cout << "Yes\\n";

  for (int v = 1; v < n; ++v)
    cout << arr[v] + 1 << "\\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>;

int main() {
  int N, M;
  vector<vector<int>> root(200001);
  int cnt[100001] = {0};
  int mark[100001] = {0};
  cin >> N >> M;
  rep(i, M) {
    int A, B;
    cin >> A >> B;
    root[A].push_back(B);
    cnt[A]++;
    root[B].push_back(A);
    cnt[B]++;
  }

  queue<int> que;
  que.push(1);
  while (!que.empty()) {
    int room = que.front(); // 先頭要素を参照する
    que.pop();              // 先頭要素を削除
    rep(j, cnt[room]) {
      if (mark[root[room][j]] == 0) {
        mark[root[room][j]] = room;
        que.push(root[room][j]);
      }
    }
  }

  for (int i = 2; i < N + 1; i++) {
    if (mark[i] == 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  for (int i = 2; i < N + 1; i++) {
    cout << mark[i] << endl;
  }

  return 0;
}

Error: -11

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;
  vector<vector<int>> root(200001);
  int cnt[100001] = {0};
  int mark[100001] = {0};
  cin >> N >> M;
  rep(i, M) {
    int A, B;
    cin >> A >> B;
    root[A][cnt[A]++] = B;
    root[B][cnt[B]++] = A;
  }
  queue<int> que;
  que.push(1);
  while (!que.empty()) {
    int room = que.front(); // 先頭要素を参照する
    que.pop();              // 先頭要素を削除
    rep(j, cnt[room]) {
      if (mark[root[room][j]] == 0) {
        mark[root[room][j]] = room;
        que.push(root[room][j]);
      }
    }
  }

  for (int i = 2; i < N + 1; i++) {
    if (mark[i] == 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  for (int i = 2; i < N + 1; i++) {
    cout << mark[i] << endl;
  }

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

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout << (bool x ? "Yes" : "No") << endl;
#define out(s) cout << s << endl;
#define pb push_back;
#define sp " ";
void vout(vector<int> v) {
  for (unsigned int i = 1; i < v.size(); i++)
    cout << v.at(i) + 1 << endl;
}
int main() {
  int n, m;
  cin >> n >> m;
  vvi edge(n);
  vi ans(n, -1);
  rep(i, m) {
    int s, t;
    cin >> s >> t;
    s--;
    t--;
    edge.at(s).push_back(t);
    edge.at(t).push_back(s);
  }
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int k = q.front();
    q.pop();
    for (int j : edge.at(k)) {
      if (ans.at(j) == -1) {
        ans.at(j) = k;
        q.push(j);
      }
    }
  }
  cout << "Yes" << endl;
  vout(ans);
}

Error: TLE

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout << (bool x ? "Yes" : "No") << endl;
#define out(s) cout << s << endl;
#define pb push_back;
#define sp " ";
void vout(vector<int> v) {
  for (unsigned int i = 1; i < v.size(); i++)
    cout << v.at(i) + 1 << endl;
}
int main() {
  int n, m;
  cin >> n >> m;
  vvi edge(n, vi(n));
  vi ans(n, -1);
  rep(i, m) {
    int s, t;
    cin >> s >> t;
    s--;
    t--;
    edge.at(s).push_back(t);
    edge.at(t).push_back(s);
  }
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int k = q.front();
    q.pop();
    for (int j : edge.at(k)) {
      if (ans.at(j) == -1) {
        ans.at(j) = k;
        q.push(j);
      }
    }
  }
  cout << "Yes" << endl;
  vout(ans);
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;

int vis[maxn], pre[maxn];
int head[maxn], tot;

struct Edge {
  int to, next;
} e[maxn << 1];

void addedge(int from, int to) {
  e[tot].to = to;
  e[tot].next = head[from];
  head[from] = tot++;
}

void bfs(int u) {
  memset(vis, 0, sizeof(vis));
  vis[u] = 1;
  queue<int> q;
  q.push(u);
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (int i = head[u]; i != -1; i = e[i].next) {
      int v = e[i].to;
      if (!vis[v]) {
        vis[v] = 1;
        pre[v] = u;
        q.push(v);
      }
    }
  }
}

int main() {
  memset(head, -1, sizeof(head));
  tot = 0;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int from, to;
    cin >> from >> to;
    addedge(from, to);
    addedge(to, from);
  }
  bfs(1);
  bool judge = true;
  for (int i = 2; i <= n; i++)
    if (!vis[i]) {
      judge = false;
      break;
    }
  if (judge) {
    puts("Yes");
    for (int i = 2; i <= n; i++)
      cout << pre[i] << endl;
  } else
    puts("No");
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;

int vis[maxn], pre[maxn];
int head[maxn], tot;

struct Edge {
  int to, next;
} e[maxn << 1];

void addedge(int from, int to) {
  e[tot].to = to;
  e[tot].next = head[from];
  head[from] = tot++;
}

void bfs(int u) {
  memset(vis, 0, sizeof(vis));
  vis[u] = 1;
  queue<int> q;
  q.push(u);
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (int i = head[u]; i != -1; i = e[i].next) {
      int v = e[i].to;
      if (!vis[v]) {
        vis[v] = 1;
        pre[v] = u;
        q.push(v);
      }
    }
  }
}

int main() {
  memset(head, -1, sizeof(head));
  tot = 0;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int from, to;
    cin >> from >> to;
    addedge(from, to);
    addedge(to, from);
  }
  bfs(1);
  bool judge = true;
  for (int i = 2; i <= n; i++)
    if (!vis[i]) {
      judge = false;
      break;
    }
  if (judge) {
    puts("Yes");
    for (int i = 2; i <= n; i++)
      cout << pre[i] << endl;
  } else
    puts("No");
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
    BFS(bread-first search，幅優先探索)を用いる
    アリ本pp.87以降にグラフの解説がある
*/
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
using namespace std;

#define repeat(i, n) for (int i = 0; i < (n); i++)
#include <queue>

const int INF = 1001001001;
// vector<int>の配列
// なんでこんなことしてるの...？
vector<int> to[100005];

int main(void) {
  // 部屋数N、通路数M
  int N, M;
  cin >> N >> M;

  repeat(i, M) {
    // 互いに通行可能な部屋a-b
    int a, b;
    cin >> a >> b;
    // 配列格納用にデクリメント処理
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  queue<int> q;
  vector<int> dist(N, INF); // 無限大で初期化
  vector<int> pre(N, -1);   // -1で初期化
  dist[0] = 0;
  q.push(0);
  while (!q.empty()) {
    int v = q.front(); // 先頭要素の確認
    q.pop(); // 取り出し(上のと一緒くたにできないの...?)
    // 拡張for文(だっけ？)
    for (int u : to[v]) {
      // 既に距離が算出されていれば以降の処理を省く
      if (dist[u] != INF) {
        continue;
      }
      // 繋がっている部屋のゴールまでの距離+1がゴールまでの距離
      dist[u] = dist[v] + 1;
      // 道しるべの部屋番号を記録
      pre[u] = v;
      // キューに自身を格納(幅優先探索の処理、これに基づいて子を展開する)
      q.push(u);
    }
  }

  puts("Yes");
  repeat(i, N) {
    if (i == 0) {
      continue;
    }
    int ans = pre[i];
    printf("%d\\n", ans + 1);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
using namespace std;

class List {
private:
  List *next;
  int num;

public:
  List(int n) {
    next = NULL;
    num = n;
  }
  void connect(List &route) { next = &route; }
  int data(int count) {
    if (num == 1) {
      return ++count;
    } else {
      if (next == NULL) {
        return -1;
      } else {
        return data(count++);
      }
    }
  }
};

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<List> room;
  for (int i = 1; i <= N; i++) {
    room.push_back(i);
  }
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    room[A - 1].connect(room[B - 1]);
    room[B - 1].connect(room[A - 1]);
  }

  vector<int> cList(N - 1);
  bool flag = false;
  for (int i = 0; i < N - 1; i++) {
    int count = 0;
    cList[i] = room[i + 1].data(count);
  }
  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

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

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int m, n, a, b, temp, head, tail = 1, c[100010], q[100010];
vector<int> ac[100010];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a, &b);
    ac[a].push_back(b);
    ac[b].push_back(a);
  }
  q[++head] = 1;
  while (head <= tail) {
    for (int i = 0; i < ac[q[head]].size(); i++) {
      if (c[ac[q[head]][i]] == 0) {
        q[++tail] = ac[q[head]][i];
        c[ac[q[head]][i]] = q[head];
      }
    }
    head++;
  }
  for (int i = 2; i <= n; i++) {
    if (c[i] == 0) {
      printf("No\\n");
      return 0;
    }
  }
  printf("Yes\\n");
  for (int i = 2; i <= n; i++) {
    printf("%d\\n", c[i]);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int m, n, temp, head, tail = 1, c[100010], q[100010];
struct cave {
  int a, b;
} ca[200010];
int comp1(cave x, cave y) {
  if (x.a == y.a)
    return x.b < y.b;
  return x.a < y.a;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &ca[i].a, &ca[i].b);
    if (ca[i].a > ca[i].b) {
      temp = ca[i].a;
      ca[i].a = ca[i].b;
      ca[i].b = temp;
    }
  }
  q[++head] = 1;
  sort(ca + 1, ca + 1 + m, comp1);
  //	for(int i = 1; i <= m; i++)
  //	{
  //		cout<<ca[i].a<<' '<<ca[i].b<<endl;
  //	}
  while (head <= tail) {
    for (int i = 1; i <= m; i++) {
      if (ca[i].a > q[head] && ca[i].b > q[head])
        break;
      if (ca[i].a == q[head] && c[ca[i].b] == 0) {
        q[++tail] = ca[i].b;
        c[ca[i].b] = ca[i].a;
      }
      if (ca[i].b == q[head] && c[ca[i].a] == 0) {
        q[++tail] = ca[i].a;
        c[ca[i].a] = ca[i].b;
      }
    }
    head++;
  }
  for (int i = 2; i <= n; i++) {
    if (c[i] == 0) {
      printf("No");
      return 0;
    }
  }
  printf("Yes\\n");
  for (int i = 2; i <= n; i++) {
    printf("%d\\n", c[i]);
  }
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll N, M;

  cin >> N >> M;

  vector<vector<ll>> d(N);
  ll t[N];
  ll A, B;
  queue<ll> q;

  for (ll i = 0; i < N; i++) {
    t[i] = -1;
  }
  for (ll i = 0; i < M; i++) {
    cin >> A >> B;
    d[A - 1].push_back(B - 1);
    d[B - 1].push_back(A - 1);
  }

  t[0] = 0;
  ll p = 0;
  q.push(0);
  while (!q.empty()) {
    p = q.front();
    for (ll i = 0; i < d[p].size(); i++) {
      if (t[d[p][i]] == -1) {
        q.push(d[p][i]);
        t[d[p][i]] = p;
      }
    }
    q.pop();
  }

  cout << "Yes" << endl;
  for (ll i = 1; i < N; i++) {
    cout << t[i] + 1 << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll N, M;

  cin >> N >> M;

  ll d[N][N];
  ll t[N];
  ll A, B;
  queue<ll> q;

  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j < N; j++) {
      d[i][j] = -1;
    }
    t[i] = -1;
  }
  for (ll i = 0; i < M; i++) {
    cin >> A >> B;
    d[A - 1][B - 1] = 1;
    d[B - 1][A - 1] = 1;
  }

  t[0] = 0;
  ll p = 0;
  q.push(0);
  while (!q.empty()) {
    p = q.front();
    for (ll i = 0; i < N; i++) {
      if (d[p][i] != -1 && t[i] == -1) {
        q.push(i);
        t[i] = p;
      }
    }
    q.pop();
  }

  cout << "Yes" << endl;
  for (ll i = 1; i < N; i++) {
    cout << t[i] + 1 << endl;
  }

  return 0;
}