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

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

int main() {
  int n, m;
  const int INF = 1001001001;
  cin >> n >> m;
  vector<int> to[100004];
  for (int i = 0; i < m; i++) {
    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, 0);
  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;
  for (int i = 0; i < n; i++) {
    if (i == 0)
      continue;
    int ans = pre[i];
    cout << ++ans << endl;
  }
}

Error: -6
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()


Fixed submission:

#include <bits/stdc++.h>
#define INF 40000000
using namespace std;

int main() {
  int n, m;
  vector<vector<int>> to(n, vector<int>(0));
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    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, 0);
  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;
  for (int i = 0; i < n; i++) {
    if (i == 0)
      continue;
    int ans = pre[i];
    cout << ++ans << endl;
  }
}
Problem p02678 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> parent(n, -1);
  vector<int> distance(n, INT_MAX);

  parent[0] = distance[0] = 0;

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

  int x, y;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    x--;
    y--;
    path[x].push_back(y);
    path[y].push_back(x);
  }

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

  while (!q.empty()) {
    int temp = q.front();
    q.pop();

    for (int i : path[temp]) {
      if (distance[i] > 1 + distance[temp]) {
        distance[i] = 1 + distance[temp];
        parent[i] = temp;
        q.push(i);
      }
    }
  }

  bool poss = true;
  for (int i = 0; i < n; i++) {
    if (distance[i] == INT_MAX) {
      poss = false;
      break;
    }
  }

  if (poss) {
    cout << "Yes"
         << "\\n";
    for (int i = 1; i < n; i++)
      cout << parent[i] + 1 << "\\n";
  } else
    cout << "No"
         << "\\n";

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> parent(n, -1);
  vector<int> distance(n, INT_MAX);

  parent[0] = distance[0] = 0;

  vector<vector<bool>> path(n, vector<bool>(n, false));

  int x, y;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    x--;
    y--;
    path[x][y] = path[y][x] = true;
  }

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

  while (!q.empty()) {
    int temp = q.front();
    q.pop();

    for (int i = 0; i < n; i++) {
      if (path[temp][i]) {
        if (distance[i] > 1 + distance[temp]) {
          distance[i] = 1 + distance[temp];
          parent[i] = temp;
          q.push(i);
        }
      }
    }
  }

  bool poss = true;
  for (int i = 0; i < n; i++) {
    if (distance[i] == INT_MAX) {
      poss = false;
      break;
    }
  }

  if (poss) {
    cout << "Yes"
         << "\\n";
    for (int i = 1; i < n; i++)
      cout << parent[i] + 1 << "\\n";
  } else
    cout << "No"
         << "\\n";

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define irep(i, a, b) for (typeof(i) i = (a); i < (b); ++i)
#define itrep(it, c) for (auto it = (c).begin(); it != (c).end(); ++it)

vector<vector<int>> X(100001);
vector<int> C(100001, 100001);
vector<int> T(100001, -1);

void loop(int prv, int me, int cost) {
  if (cost + 1 >= C.at(me))
    return;
  C.at(me) = cost + 1;
  T.at(me) = prv;
  vector<int> *s = &X.at(me);
  for (auto it = s->begin(); it != s->end(); it++) {
    if (*it != prv) {
      if (C.at(*it) > cost + 2) {
        loop(me, *it, cost + 1);
      }
    }
  }
  return;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    X.at(A - 1).push_back(B - 1);
    X.at(B - 1).push_back(A - 1);
  }

  C.at(0) = 0;
  T.at(0) = -1;
  int count = 1;
  int cost = 0;
  set<int> bag;
  set<int> nb;
  bag.insert(0);
  while (bag.size() > 0) {
    nb.clear();
    cost++;
    for (auto it = bag.begin(); it != bag.end(); it++) {
      for (auto jt = X[*it].begin(); jt != X[*it].end(); jt++) {
        if (C.at(*jt) > cost) {
          C.at(*jt) = cost;
          T.at(*jt) = *it;
          nb.insert(*jt);
        }
      }
    }
    bag.clear();
    bag = nb;
  }

  cout << "Yes" << endl;
  for (int i = 1; i < N; i++) {
    cout << T.at(i) + 1 << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define irep(i, a, b) for (typeof(i) i = (a); i < (b); ++i)
#define itrep(it, c) for (auto it = (c).begin(); it != (c).end(); ++it)

vector<vector<ll>> X(100001);
vector<ll> C(100001, 100001);
vector<ll> T(100001, -1);

void loop(ll prv, ll me, ll cost) {
  if (cost + 1 >= C.at(me))
    return;
  C.at(me) = cost + 1;
  T.at(me) = prv;
  vector<ll> *s = &X.at(me);
  for (auto it = s->begin(); it != s->end(); it++) {
    if (*it != prv) {
      if (C.at(*it) > cost + 2) {
        loop(me, *it, cost + 1);
      }
    }
  }
  return;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  ll N, M;
  cin >> N >> M;
  for (ll i = 0; i < M; i++) {
    ll A, B;
    cin >> A >> B;
    X.at(A - 1).push_back(B - 1);
    X.at(B - 1).push_back(A - 1);
  }

  loop(-1, 0, -1);

  cout << "Yes" << endl;
  for (ll i = 1; i < N; i++) {
    cout << T.at(i) + 1 << endl;
  }
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <cstdint>
#include <iostream>
#include <queue>
#include <vector>

using std::cin;
using std::cout;
using std::vector;

using ll = long long;
using ull = unsigned long long;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  ull n, m, a, b;
  std::cin >> n >> m;

  vector<ull> from(n);
  vector<vector<ull>> edge(n);
  for (ull i = 0; i < m; i++) {
    cin >> a >> b;
    edge[a - 1].push_back(b - 1);
    edge[b - 1].push_back(a - 1);
  }

  // bfs
  std::queue<ull> q;
  vector<bool> done(n, false);
  q.push(0);
  done[0] = true;
  while (!q.empty()) {
    ull node = q.front();
    q.pop();
    for (ull next_node : edge[node]) {
      if (!done[next_node]) {
        q.push(next_node);
        from[next_node] = node;
        done[next_node] = true;
      }
    }
  }

  cout << "Yes\\n";
  for (ull i = 1; i < n; i++) {
    cout << from[i] + 1 << "\\n";
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cstdint>
#include <iostream>
#include <queue>
#include <vector>

using std::cin;
using std::cout;
using std::vector;

using ll = long long;
using ull = unsigned long long;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  ull n, m, a, b;
  std::cin >> n >> m;

  vector<ull> from(n);
  vector<vector<ull>> edge(m);
  for (ull i = 0; i < m; i++) {
    cin >> a >> b;
    edge[a - 1].push_back(b - 1);
    edge[b - 1].push_back(a - 1);
  }

  // bfs
  std::queue<ull> q;
  vector<bool> done(n, false);
  q.push(0);
  done[0] = true;
  while (!q.empty()) {
    ull node = q.front();
    q.pop();
    for (ull next_node : edge[node]) {
      if (!done[next_node]) {
        q.push(next_node);
        from[next_node] = node;
        done[next_node] = true;
      }
    }
  }

  cout << "Yes\\n";
  for (ull i = 1; i < n; i++) {
    cout << from[i] + 1 << "\\n";
  }

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

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define MAX_V 100001
#define INF 1000000000
typedef vector<vector<int>> Graph;

typedef pair<int, int> P;
int V = MAX_V;
Graph G[MAX_V];
vector<int> ans(MAX_V);
int d[MAX_V];
void dijkstra(int s, const Graph &G) {
  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++) {
      int to = G[v][i];
      if (d[to] > d[v] + 1) {
        d[to] = d[v] + 1;
        ans[to] = v + 1;
        que.push(P(d[to], to));
      }
    }
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  Graph G(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dijkstra(0, G);
  int flag = 1;
  for (int i = 1; i < n; i++) {
    if (ans[i] == INF)
      flag = 0;
  }
  if (flag) {
    cout << "Yes" << endl;
    for (int i = 1; i < n; i++)
      cout << ans[i] << endl;
  } else
    cout << "No" << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define MAX_V 100001
#define INF 1000000000
typedef vector<vector<int>> Graph;

vector<int> ans(MAX_V);
vector<int> d(MAX_V);
void dfs(const Graph &G, int v) {
  for (auto next_v : G[v]) {
    if (d[next_v] <= d[v] + 1)
      continue;
    ans[next_v] = v + 1;
    d[next_v] = d[v] + 1;
    dfs(G, next_v);
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  Graph G(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  d.assign(n, INF);
  d[0] = 0;
  dfs(G, 0);
  int flag = 1;
  for (int i = 1; i < n; i++) {
    if (ans[i] == INF)
      flag = 0;
  }
  if (flag) {
    cout << "Yes" << endl;
    for (int i = 1; i < n; i++)
      cout << ans[i] << endl;
  } else
    cout << "No" << endl;
}
Problem p02678 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define lla(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; i++)
#define Rep(i, n) for (int i = 1; i <= n; i++)

const int INF = 1001001001;

vvi a(100100);

int n, m, d[100100][2];

int main() {
  cin >> n >> m;
  int b, c;
  rep(i, m) {
    cin >> b >> c;
    b--;
    c--;
    a[b].push_back(c);
    a[c].push_back(b);
  }
  rep(i, n) d[i][0] = INF;
  queue<int> que;
  que.push(0);
  d[0][0] = 0;
  while (!que.empty()) {
    int x = que.front();
    que.pop();
    for (int i : a[x]) {
      if (d[i][0] == INF) {
        que.push(i);
        d[i][0] = d[x][0] + 1;
        d[i][1] = x;
      }
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < n; i++) {
    cout << d[i][1] + 1 << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define lla(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; i++)
#define Rep(i, n) for (int i = 1; i <= n; i++)

int n, m;
vvi x(100100, vi(2, -1)), a(100100);

void hoge(int b, int c, int d) {
  if (0 <= x[b][0] && x[b][0] <= c)
    return;
  x[b][0] = c;
  x[b][1] = d;
  for (int i : a[b]) {
    if (!(0 <= x[i][0] && x[i][0] <= c + 1))
      hoge(i, c + 1, b);
  }
  return;
}

int main() {
  scanf("%d%d", &n, &m);
  {
    int b, c;
    rep(i, m) {
      // int b, c;
      // cin >> b >> c;
      scanf("%d%d", &b, &c);
      b--;
      c--;
      a[b].push_back(c);
      a[c].push_back(b);
    }
  }
  for (int i : a[0]) {
    hoge(i, 1, 0);
  }
  puts("Yes");
  for (int i = 1; i < n; i++) {
    // cout << x[i][1] + 1 << endl;
    printf("%d\\n", x[i][1] + 1);
  }
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"

const double pi = 3.141592653589793;
#define YESNO(x) x ? printf("YES") : printf("NO")
#define YesNo(x) x ? printf("Yes") : printf("No")
#define rep(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define scani(x) scanf("%d", &x)
#define scanll(x) scanf("%lld", &x)
#define printi(x) printf("%d", x)
#define printll(x) printf("%lld", x)
typedef long long ll;
using namespace std;

long long GCD(long long x, long long y) { return y ? GCD(y, x % y) : x; }

long long LCM(long long x, long long y) { return x * y / GCD(x, y); }

// give up(TLE)
int ABC168D() {
  int n, m;
  scani(n);
  scani(m);

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

  vector<bool> visit(n, false);
  visit[0] = true;
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int cur = q.front();
    q.pop();

    for (auto &itr : graph[cur]) {
      if (!visit[itr]) {
        ans[itr] = cur;
        visit[itr] = true;
        q.push(itr);
      }
    }
  }

  bool isOk = true;
  for (auto itr : visit) {
    if (!itr) {
      YesNo(0);
      return 0;
    }
  }

  YesNo(1);
  printf("\\n");
  rep(i, 1, n) { printf("%d\\n", ans[i] + 1); }

  return 0;
}

int main() {
  ABC168D();
  return 0;
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"

const double pi = 3.141592653589793;
#define YESNO(x) x ? printf("YES") : printf("NO")
#define YesNo(x) x ? printf("Yes") : printf("No")
#define rep(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define scani(x) scanf("%d", &x)
#define scanll(x) scanf("%lld", &x)
#define printi(x) printf("%d", x)
#define printll(x) printf("%lld", x)
typedef long long ll;
using namespace std;

long long GCD(long long x, long long y) { return y ? GCD(y, x % y) : x; }

long long LCM(long long x, long long y) { return x * y / GCD(x, y); }

// give up(TLE)
int ABC168D() {
  int n, m;
  scani(n);
  scani(m);

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

  vector<bool> visit(n, false);
  visit[0] = true;
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int cur = q.front();
    q.pop();

    for (auto &itr : graph[cur]) {
      if (!visit[itr]) {
        ans[itr] = cur;
        visit[itr] = true;
        q.push(itr);
      }
    }
  }

  bool isOk = true;
  for (auto itr : visit) {
    if (!itr) {
      YesNo(0);
      return 0;
    }
  }

  YesNo(1);
  printf("\\n");
  rep(i, 1, n) { printf("%d\\n", ans[i] + 1); }

  return 0;
}

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k, i, n) for (ll i = k; i < n; ++i)
#define pb push_back
ll n, m;
queue<pair<ll, ll>> q;
vector<ll> edge[(ll)1e5 + 10];
ll c[(ll)1e5 + 10];
void bfs(ll x) {
  for (ll i : edge[x]) {
    if (c[i] == -1)
      q.push({x, i});
  }
  while (!q.empty()) {
    ll nx = q.front().first, ni = q.front().second;
    q.pop();
    // cout<<nx<<" "<<ni<<endl;
    if (c[ni] == -1) {
      c[ni] = nx;
      for (ll i : edge[ni]) {
        if (c[i] == -1)
          q.push({ni, i});
      }
    }
  }
}
int main(void) {
  cin >> n >> m;
  rep(0, i, n) c[i] = -1;
  rep(0, i, m) {
    ll a, b;
    cin >> a >> b;
    --a, --b;
    edge[a].pb(b);
    edge[b].pb(a);
  }
  bfs(0);
  bool t = true;
  rep(1, i, n) if (c[i] == -1) t = false;
  if (t) {
    cout << "Yes" << endl;
    rep(1, i, n) cout << c[i] + 1 << endl;
  } else {
    cout << "No" << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k, i, n) for (ll i = k; i < n; ++i)
#define pb push_back
ll n, m;
queue<pair<ll, ll>> q;
vector<ll> edge[(ll)2e5];
ll c[(ll)2e5];
void bfs(ll x) {
  for (ll i : edge[x]) {
    if (c[i] == -1)
      q.push({x, i});
  }
  while (!q.empty()) {
    ll nx = q.front().first, ni = q.front().second;
    q.pop();
    // cout<<nx<<" "<<ni<<endl;
    if (c[ni] == -1)
      c[ni] = nx;
    for (ll i : edge[ni]) {
      if (c[i] == -1)
        q.push({ni, i});
    }
  }
}
int main(void) {
  cin >> n >> m;
  rep(0, i, n) c[i] = -1;
  rep(0, i, m) {
    ll a, b;
    cin >> a >> b;
    --a, --b;
    edge[a].pb(b);
    edge[b].pb(a);
  }
  bfs(0);
  bool t = true;
  rep(1, i, n) if (c[i] == -1) t = false;
  if (t) {
    cout << "Yes" << endl;
    rep(1, i, n) cout << c[i] + 1 << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> r(n, vector<int>(0));
  vector<int> sig(n, 200005);

  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d", &a);
    scanf("%d", &b);
    r[a - 1].push_back(b);
    r[b - 1].push_back(a);
  }

  queue<int> p;
  p.push(1);

  while (p.size()) {
    int s = p.front();
    p.pop();
    for (int i = 0; i < r[s - 1].size(); i++) {
      if (sig[r[s - 1][i] - 1] == 200005) {
        sig[r[s - 1][i] - 1] = s;
        p.push(r[s - 1][i]);
      }
    }
  }

  cout << "Yes" << endl;

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

Error: -11

Fixed submission:

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

int n, m;
vector<vector<int>> r(100000, vector<int>(0));
vector<int> sig(100000, 200005);

void dfs(int s, int p) { // sは一個前の場所、pは今の場所
  if (sig[p] == 200005) {
    sig[p - 1] = s;
    int si = r[p - 1].size();
    for (int i = 0; i < si; i++) {
      dfs(p + 1, r[p][i]);
    }
  }
}

int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    r.at(a - 1).push_back(b);
    r.at(b - 1).push_back(a);
  }

  int si = r[0].size();
  for (int i = 0; i < si; i++) {
    dfs(1, r[0][i]);
  }

  cout << "Yes" << endl;

  for (int i = 1; i < n; i++) {
    cout << sig[i] << endl;
  }
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {

  int N, M;
  cin >> N >> M;
  int A[M], B[M];
  vector<vector<int>> Ren(N, vector<int>());
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
    Ren.at(A[i]).push_back(B[i]);
    Ren.at(B[i]).push_back(A[i]);
  }
  queue<int> seen;
  int Pr[N];
  bool TA[N];
  for (int i = 0; i < N; i++)
    TA[i] = false;
  for (int i = 0; i < N; i++)
    Pr[i] = -1;
  TA[0] = true;
  seen.push(0);
  int ct = 0;

  while (!(seen.empty() || ct == N)) {
    int S = seen.front();
    for (int i = 0; i < Ren.at(S).size(); i++) {
      int NextV = Ren.at(S).at(i);
      if (TA[NextV])
        continue;
      Pr[NextV] = S;
      seen.push(NextV);
      TA[NextV] = true;
    }
    seen.pop();
    ct++;
  }

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


Error: -11

Fixed submission:

#include <iostream>
#include <queue>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
  // 頂点数と辺数
  int N, M;
  cin >> N >> M;

  // グラフ入力受取 (ここでは無向グラフを想定)
  Graph G(N);
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

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

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

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

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

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

  // 結果出力 (各頂点の頂点 0 からの距離を見る)
  cout << "Yes" << endl;
  for (int v = 1; v < N; v++) {
    cout << dist[v] << endl;
  }
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(n);
  int tmp1, tmp2;
  for (int i = 0; i < m; i++) {
    cin >> tmp1 >> tmp2;
    tmp1--;
    tmp2--;
    a.at(tmp1).push_back(tmp2);
    a.at(tmp2).push_back(tmp1);
  }
  int v;
  queue<int> tmp;
  tmp.push(0);
  vector<int> pre(n, -1);
  pre.at(0) = 0;
  while (!tmp.empty()) {
    v = tmp.front();
    tmp.pop();
    for (auto k : a.at(v)) {
      if (pre.at(k) != -1)
        continue;
      pre.at(k) = v;
      tmp.push(k);
    }
  }
  cout << "Yes" << endl;
  ;
  for (int i = 1; i < n; i++) {
    cout << pre.at(i) + 1 << endl;
  }
  cout << endl;
}

Error: WA

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(n);
  int tmp1, tmp2;
  for (int i = 0; i < n; i++) {
    cin >> tmp1 >> tmp2;
    tmp1--;
    tmp2--;
    a.at(tmp1).push_back(tmp2);
    a.at(tmp2).push_back(tmp1);
  }
  int v;
  queue<int> tmp;
  tmp.push(0);
  vector<int> pre(n, -1);
  while (!tmp.empty()) {
    v = tmp.front();
    tmp.pop();
    for (auto k : a.at(v)) {
      if (pre.at(k) != -1)
        continue;
      pre.at(k) = v;
      tmp.push(k);
    }
  }
  cout << "Yes" << endl;
  ;
  for (int i = 1; i < n; i++) {
    cout << pre.at(i) + 1 << endl;
  }
  cout << endl;
}
Problem p02678 (C++) — buggy submission, verdict: Time Limit Exceeded

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

vector<int> G[100006];
int d[100006];
int v[100006];
int ans[100006];
vector<int> q;

int main() {

  int n;
  int m;
  int i, j;
  int a, b;

  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++) {
    d[i] = 100100100;
    v[i] = 0;
  }

  for (i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);

    G[a].push_back(b);
    G[b].push_back(a);
  }

  d[1] = 0;
  v[1] = 1;

  q.push_back(1);
  int u, x;
  int head = 0;
  int tail = 1;

  while (head != tail) {
    u = q[head++];
    for (i = 0; i < G[u].size(); i++) {
      x = G[u][i];
      if (v[x] == 0) {
        q.push_back(x);
        tail++;
        d[x] = d[u] + 1;
        ans[x] = u;
        v[x] = 1;
      }
    }
  }

  int f = 0;
  for (i = 1; i <= n; i++) {
    if (v[i] == 0)
      f = 1;
  }

  if (f == 1)
    printf("No\\n");

  else {
    printf("Yes\\n");
    for (i = 2; i <= n; i++)
      printf("%d\\n", ans[i]);
  }

  return 0;
}


Error: TLE

Fixed submission:

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

vector<int> G[100006];
int d[100006];
int v[100006];
int ans[100006];
vector<int> q;

int main() {

  int n;
  int m;
  int i, j;
  int a, b;

  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++) {
    d[i] = 100100100;
    v[i] = 0;
  }

  for (i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);

    G[a].push_back(b);
    G[b].push_back(a);
  }

  d[1] = 0;
  v[1] = 1;

  q.push_back(1);
  int u, x;
  int head = 0;
  int tail = 1;

  while (head != tail) {
    u = q[head++];
    for (i = 0; i < G[u].size(); i++) {
      x = G[u][i];
      if (v[x] == 0) {
        q.push_back(x);
        tail++;
      }

      if (d[x] > d[u] + 1) {
        d[x] = d[u] + 1;
        ans[x] = u;
      }
    }

    v[u] = 1;
  }

  int f = 0;
  for (i = 1; i <= n; i++) {
    if (v[i] == 0)
      f = 1;
  }

  if (f == 1)
    printf("No\\n");

  else {
    printf("Yes\\n");
    for (i = 2; i <= n; i++)
      printf("%d\\n", ans[i]);
  }

  return 0;
}