alexjercan/bugnet huggingface dataset:
Problem p02678 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for (int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template <class T> T gcd(T a, T b) { return ((b == 0) ? a : gcd(b, a % b)); }

vi g[100005];
int vis[100005];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  // freopen("input.in", "r", stdin);
  // freopen("output.out", "w", stdout);
  int n, m;
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].pb(b);
    g[b].pb(a);
  }
  queue<int> q;
  q.push(0);
  vis[0] = 1;
  vi ans(n, 0);
  while (!q.empty()) {
    queue<int> q1;
    while (!q.empty()) {
      int cur = q.front();
      q.pop();
      for (int u : g[cur]) {
        if (!vis[u]) {
          q1.push(u);
          vis[u] = 1;
          if (!ans[u])
            ans[u] = cur + 1;
        }
      }
    }
    q = q1;
  }
  cout << "Yes" << endl;
  repn(i, 1, n) cout << ans[i] << endl;
  return 0;
}
/*
Things to look out for:
        - Integer overflows
        - Array bounds
        - Special cases
Be careful!
*/


Error: TLE

Fixed submission:

#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for (int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template <class T> T gcd(T a, T b) { return ((b == 0) ? a : gcd(b, a % b)); }

vi g[100005];
int vis[100005];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  // freopen("input.in", "r", stdin);
  // freopen("output.out", "w", stdout);
  int n, m;
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].pb(b);
    g[b].pb(a);
  }
  queue<int> q;
  q.push(0);
  vis[0] = 1;
  vi ans(n, 0);
  while (!q.empty()) {
    queue<int> q1;
    while (!q.empty()) {
      int cur = q.front();
      q.pop();
      for (int u : g[cur]) {
        if (!vis[u]) {
          q1.push(u);
          vis[cur] = 1;
          if (!ans[u])
            ans[u] = cur + 1;
        }
      }
    }
    q = q1;
  }
  cout << "Yes" << endl;
  repn(i, 1, n) cout << ans[i] << endl;
  return 0;
}
/*
Things to look out for:
        - Integer overflows
        - Array bounds
        - Special cases
Be careful!
*/
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

vector<int> y[200005];
int z[200005];
int main() {
  int a, b, c, d, e, f, T;
  {
    memset(z, 0x3f, sizeof(z));
    scanf("%d%d", &a, &e);

    for (int i = 0; i < e; i++) {
      scanf("%d%d", &b, &c);
      y[b].push_back(c);
      y[c].push_back(b);
    }
    queue<int> q;
    q.push(1);
    int n = 1;
    z[1] = 0;
    while (q.size() && n != a) {
      b = q.front();
      q.pop();
      for (auto x : y[b]) {
        if (z[x] == 0x3f3f3f3f) {
          n++;
          z[x] = b;
          q.push(x);
        }
        if (n == a)
          break;
      }
    }
    d = 0;
    for (int i = 2; i <= a; i++) {
      if (z[i] == 0x3f3f3f3f) {
        d = 1;
        break;
      }
    }
    if (d)
      printf("No\\n");
    else {
      printf("Yes\\n");
      for (int i = 2; i <= a; i++)
        printf("%d\\n", z[i]);
    }
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int N = 200005;
int e[N], ne[N], h[N], idx;
int dist[N];
int n, m;

void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }

void djikstar() {
  memset(dist, 0x3f, sizeof dist);
  queue<int> q;
  q.push(1);
  dist[1] = 0;
  int cnt = 1;

  while (q.size() && cnt != n) {
    int t = q.front();
    q.pop();

    for (int i = h[t]; ~i; i = ne[i]) {
      int j = e[i];
      if (dist[j] == 0x3f3f3f3f) {
        cnt++;
        dist[j] = t;
        q.push(j);
      }
      if (cnt == n)
        break;
    }
  }
}

int main() {
  cin >> n >> m;
  memset(h, -1, sizeof h);
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    add(a, b);
    add(b, a);
  }
  djikstar();

  bool flag = true;
  for (int i = 2; i <= n; i++)
    if (dist[i] == 0x3f3f3f3f)
      flag = false;

  if (!flag)
    puts("No");
  else {
    puts("Yes");
    for (int i = 2; i <= n; i++)
      cout << dist[i] << endl;
  }

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

#include <iostream>
#include <queue>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  int a, b;
  vector<vector<int>> to(n, vector<int>());
  rep(i, m) {
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  // rep(i, n) cout<<to[i][0]<<endl;
  bool flg[200010] = {false};
  flg[0] = true;
  queue<int> root;
  root.push(0);
  int ans[200010];

  while (!root.empty()) {
    int v = root.front();
    // cout<<v<<endl;
    root.pop();
    for (int x : to[v]) {
      // cout<<x<<endl;
      if (flg[x])
        continue;
      root.push(x);
      ans[x] = v;
      flg[x] = true;
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < n; i++) {
    cout << ans[i] + 1 << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <queue>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  int a, b;
  vector<vector<int>> to(m, vector<int>());
  rep(i, m) {
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  // rep(i, n) cout<<to[i][0]<<endl;
  bool flg[200010] = {false};
  flg[0] = true;
  queue<int> root;
  root.push(0);
  int ans[200010];

  while (!root.empty()) {
    int v = root.front();
    // cout<<v<<endl;
    root.pop();
    for (int x : to[v]) {
      // cout<<x<<endl;
      if (flg[x])
        continue;
      root.push(x);
      ans[x] = v;
      flg[x] = true;
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < n; i++) {
    cout << ans[i] + 1 << endl;
  }
}
Problem p02678 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

// snippets:tmp,cl,cvl,cs,co,coy,con,cov
// export PATH=PATH:~/.local/bin

int main() {
  ll n;
  cin >> n;
  ll m;
  cin >> m;
  vvll d(n, vll(0));
  rep(i, m) {
    ll a;
    cin >> a;
    ll b;
    cin >> b;
    d[a - 1].push_back(b - 1);
    d[b - 1].push_back(a - 1);
  }
  vll c(n, 0);
  c[0] = 1;
  vll ans(n);
  ll ansn = 1;
  queue<ll> q;
  q.push(0);
  while (true) {
    if (ansn == n)
      break;
    queue<ll> que;
    while (!q.empty()) {
      rep(i, d[q.front()].size()) {
        if (c[d[q.front()][i]] == 0) {
          c[d[q.front()][i]] = 1;
          ans[d[q.front()][i]] = q.front();
          ansn++;
          que.push(d[q.front()][i]);
        }
      }
      q.pop();
    }
    q = que;
  }
  cout << "Yes" << endl;
  repi(i, 1, n) cout << ans[i] + 1 << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

// snippets:tmp,cl,cvl,cs,co,coy,con,cov
// export PATH=PATH:~/.local/bin

void check(vvll &d, vll &c, vll &ans, vll &co, ll i, ll moto, ll count) {
  count++;
  queue<ll> q;
  rep(j, d[i].size()) {
    if (c[d[i][j]] == 0 || co[d[i][j]] > count) {
      co[d[i][j]] = count;
      c[d[i][j]] = 1;
      q.push(d[i][j]);
    }
  }
  while (!q.empty()) {
    check(d, c, ans, co, q.front(), i, count);
    q.pop();
  }
  ans[i] = moto;
  return;
}

int main() {
  ll n;
  cin >> n;
  ll m;
  cin >> m;
  vvll d(n, vll(0));
  rep(i, m) {
    ll a;
    cin >> a;
    ll b;
    cin >> b;
    d[a - 1].push_back(b - 1);
    d[b - 1].push_back(a - 1);
  }
  vll c(n, 0);
  vll ans(n);
  vll co(n);
  check(d, c, ans, co, 0, 0, 0);
  cout << "Yes" << endl;
  repi(i, 1, n) cout << ans[i] + 1 << endl;
}
Problem p02678 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <queue>
#include <vector>

using namespace std;

int main() {
  int n, m;
  vector<vector<int>> nodes;

  vector<int> length;
  vector<int> parents;
  scanf("%d%d", &n, &m);

  nodes.resize(n);
  length.resize(n);
  parents.resize(n);

  for (int i = 0; i < n; ++i) {
    length[i] = ((i == 0) ? 0 : 100000000);
  }

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

    a -= 1;
    b -= 1;

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

  parents[0] = 0;

  queue<int> q;

  q.push(0);

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

    for (auto iter = nodes[p].begin(); iter != nodes[p].end(); iter++) {
      if (length[*iter] <= length[p] + 1)
        continue;
      length[*iter] = length[p] + 1;
      parents[*iter] = p;
      q.push(*iter);
    }
  }

  printf("Yes\\n");

  for (int i = 1; i < n; ++i) {
    printf("%d\\n", parents[i] + 1);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <queue>
#include <vector>

using namespace std;

int main() {
  int n, m;
  vector<vector<int>> nodes;

  vector<int> length;
  vector<int> parents;
  scanf("%d%d", &n, &m);

  nodes.resize(n);
  length.resize(n);
  parents.resize(n);

  for (int i = 0; i < n; ++i) {
    length[i] = ((i == 0) ? 0 : 100000000);
  }

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

    a -= 1;
    b -= 1;

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

  parents[0] = 0;

  queue<int> q;

  q.push(0);

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

    for (auto iter = nodes[p].begin(); iter != nodes[p].end(); iter++) {
      if (length[*iter] < length[p] + 1)
        continue;
      length[*iter] = length[p] + 1;
      parents[*iter] = p;
      q.push(*iter);
    }
  }

  printf("Yes\\n");

  for (int i = 1; i < n; ++i) {
    printf("%d\\n", parents[i] + 1);
  }

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

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

const string YES = "Yes";

template <typename T> bool chmin(T &x, T y) {
  if (x > y) {
    x = y;
    return true;
  }
  return false;
}

template <typename T> bool chmax(T &x, T y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}

void solve(long long n, long long m, std::vector<long long> a,
           std::vector<long long> b) {

  vector<vector<int>> edges(n);
  for (int i = 0; i < m; ++i) {
    edges[--a[i]].push_back(--b[i]);
    edges[b[i]].push_back(a[i]);
  }
  vector<int> dist(n, MOD);
  vector<int> v(n, -1);
  dist[0] = 0;
  queue<int> que;
  que.emplace(0);
  while (!que.empty()) {
    int x = que.front();
    que.pop();
    for (auto y : edges[x]) {
      if (v[y] == -1)
        v[y] = x;
      if (chmin(dist[y], dist[x] + 1)) {
        v[y] = x;
        que.push(y);
      }
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < n; ++i) {
    cout << v[i] + 1 << endl;
  }
}

signed main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> A(M);
  std::vector<long long> B(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
  }
  solve(N, M, std::move(A), std::move(B));
  return 0;
}


Error: TLE

Fixed submission:

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

const string YES = "Yes";

template <typename T> bool chmin(T &x, T y) {
  if (x > y) {
    x = y;
    return true;
  }
  return false;
}

template <typename T> bool chmax(T &x, T y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}

void solve(long long n, long long m, std::vector<long long> a,
           std::vector<long long> b) {

  vector<vector<int>> edges(n);
  for (int i = 0; i < m; ++i) {
    edges[--a[i]].push_back(--b[i]);
    edges[b[i]].push_back(a[i]);
  }
  vector<int> dist(n, MOD);
  vector<int> v(n, -1);
  dist[0] = 0;
  function<void(int)> f = [&](int x) {
    for (auto y : edges[x]) {
      if (v[y] == -1)
        v[y] = x;
      if (chmin(dist[y], dist[x] + 1)) {
        v[y] = x;
        f(y);
      }
    }
  };
  f(0);
  cout << "Yes" << endl;
  for (int i = 1; i < n; ++i) {
    cout << v[i] + 1 << endl;
  }
}

signed main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> A(M);
  std::vector<long long> B(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
  }
  solve(N, M, std::move(A), std::move(B));
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
struct Edge {
  int next, to;
} edge[N * 2];
int fi[N], se, pre[N], que[N], s, t;
inline void add_edge(int u, int v) { edge[++se] = {fi[u], v}, fi[u] = se; }
inline void add(int u, int v) { add_edge(u, v), add_edge(v, u); }
int main() {
  int n, m, u, v;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++)
    scanf("%d%d", &u, &v), add(u, v);
  que[t++] = 1;
  while (s < t) {
    int u = que[s++];
    for (int i = fi[u]; i; i = edge[i].next) {
      int v = edge[i].to;
      if (pre[v])
        continue;
      pre[v] = u, que[t++] = v;
    }
  }
  if (s < n)
    return puts("No"), 0;
  puts("Yes");
  for (int i = 2; i <= n; i++)
    printf("%d\\n", pre[i]);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
struct Edge {
  int next, to;
} edge[N];
int fi[N], se, pre[N], que[N], s, t;
inline void add_edge(int u, int v) { edge[++se] = {fi[u], v}, fi[u] = se; }
inline void add(int u, int v) { add_edge(u, v), add_edge(v, u); }
int main() {
  int n, m, u, v;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++)
    scanf("%d%d", &u, &v), add(u, v);
  que[t++] = 1;
  while (s < t) {
    int u = que[s++];
    for (int i = fi[u]; i; i = edge[i].next) {
      int v = edge[i].to;
      if (pre[v])
        continue;
      pre[v] = u, que[t++] = v;
    }
  }
  if (s < n)
    return puts("No"), 0;
  puts("Yes");
  for (int i = 2; i <= n; i++)
    printf("%d\\n", pre[i]);
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

constexpr long long mod = 1000000007;

#define rep(i, n) for (int i = 0; i < n; i++)

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

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

  vector<vector<int>> g(n + 1);

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vector<pair<int, int>> b(n + 1);
  for (int i = 0; i < n + 1; i++) {
    b[i] = make_pair(-1, INT_MAX);
  }

  b[1] = make_pair(0, 0);

  queue<pair<int, int>> q;
  q.push(make_pair(1, 0));

  while (!q.empty()) {
    pair<int, int> t = q.front();
    q.pop();

    for (int i = 0; i < g[t.first].size(); i++) {
      if (b[g[t.first][i]].first < 0) {
        b[g[t.first][i]] = make_pair(t.first, t.second + 1);
        q.push(make_pair(g[t.first][i], t.second + 1));
      }
    }
  }

  cout << "Yes" << endl;
  for (int i = 2; i <= n; i++) {
    cout << b[i].first << endl;
  }
}

Error: 0

Fixed submission:

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

constexpr long long mod = 1000000007;

#define rep(i, n) for (int i = 0; i < n; i++)

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

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

  vector<vector<int>> g(n + 1, vector<int>(n + 1, -1));

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    g[a][b] = g[b][a] = 1;
  }

  vector<pair<int, int>> b(n + 1);
  for (int i = 0; i < n + 1; i++) {
    b[i] = make_pair(-1, INT_MAX);
  }

  b[1] = make_pair(0, 0);

  queue<pair<int, int>> q;
  q.push(make_pair(1, 0));

  while (!q.empty()) {
    pair<int, int> t = q.front();
    q.pop();

    vector<int> v;
    for (int i = 1; i <= n; i++) {
      if (g[t.first][i] == 1) {
        v.push_back(i);
      }
    }

    for (int i = 0; i < v.size(); i++) {
      if (b[v[i]].first < 0) {
        b[v[i]] = make_pair(t.first, t.second + 1);
        q.push(make_pair(v[i], t.second + 1));
      }
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt, e) for (ll cnt = 0; cnt < e; cnt++)
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
const ll INF = INT64_MAX;
typedef tuple<ll, ll, ll, ll> T;

ll i, j, k;

int main() {
  ll N, M;
  cin >> N >> M;
  V A(M), B(M);
  rep(i, M) cin >> A[i] >> B[i];
  vector<V> rinsetu(N);
  rep(i, M) {
    rinsetu.at(A[i] - 1).push_back(B[i] - 1);
    rinsetu.at(B[i] - 1).push_back(A[i] - 1);
  }
  V tyokuzen(N, -1);
  queue<ll> path;
  path.push(0);
  tyokuzen[0] = 0;
  while (!path.empty()) {
    ll f = path.front();
    path.pop();
    for (ll x : rinsetu[f]) {
      if (tyokuzen[x] == -1) {
        path.push(x);
        tyokuzen[x] = f;
      }
    }
  }
  cout << "Yes" << endl;
  for (int c = 1; c < N; c++) {
    cout << tyokuzen[c] + 1 << endl;
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt, e) for (int cnt = 0; cnt < e; cnt++)
typedef pair<int, int> P;
const ll mod = 1e9 + 7;
const ll INF = INT64_MAX;
typedef tuple<ll, ll, ll, ll> T;

struct Dijkstra {
  vector<int> cost;
  vector<vector<P>> hen;
  queue<int> find;
  vector<int> tyokuzen;
  Dijkstra(int N, int K, int S) : cost(N), hen(K), tyokuzen(N, -1) {
    for (int i = 0; i < N; i++)
      cost.at(i) = INF;
    cost.at(S) = 0;
    find.push(S);
    tyokuzen[0] = 0;
  }

  void search() {
    while (!find.empty()) {
      int f = find.front();
      find.pop();
      for (int i = 0; i < hen.at(f).size(); i++) {
        if (cost.at(hen.at(f).at(i).first) >
            cost.at(f) + hen.at(f).at(i).second) {
          find.push(hen.at(f).at(i).first);
          cost.at(hen.at(f).at(i).first) = cost.at(f) + hen.at(f).at(i).second;
          tyokuzen[hen.at(f).at(i).first] = f;
        }
      }
    }
  }
};

int i, j, k;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(M), B(M);
  rep(i, M) cin >> A[i] >> B[i];
  Dijkstra doukutu(N, M, 0);
  rep(i, M) {
    doukutu.hen.at(A[i] - 1).push_back(P(B[i] - 1, 1));
    doukutu.hen.at(B[i] - 1).push_back(P(A[i] - 1, 1));
  }

  doukutu.search();
  bool jud = true;

  if (jud) {
    cout << "Yes" << endl;
    for (int i = 1; i < N; i++)
      cout << doukutu.tyokuzen[i] + 1 << endl;
  }
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\\n'
typedef pair<int, int> P;
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  queue<int> que;
  que.push(0);
  vector<int> ans(n);
  ans[0] = -1;
  while (!que.empty()) {
    auto it = que.front();
    que.pop();
    for (auto i : v[it]) {
      if (ans[i] == 0) {
        ans[i] = it + 1;
        que.push(i);
      }
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < n; i++) {
    cout << ans[i] << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\\n'
typedef pair<int, int> P;
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(n);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  queue<int> que;
  que.push(0);
  vector<int> ans(n);
  ans[0] = -1;
  while (!que.empty()) {
    auto it = que.front();
    que.pop();
    for (auto i : v[it]) {
      if (ans[i] == 0) {
        ans[i] = it + 1;
        que.push(i);
      }
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < n; i++) {
    cout << ans[i] << endl;
  }
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

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

lint gcd(lint x, lint y) {
  if (x == 0) {
    return y;
  } else {
    return gcd(y % x, x);
  }
}

lint lcm(lint x, lint y) { return abs(x - y) / gcd(x, y); }

int main() {
  lint n, m;
  cin >> n >> m;
  vector<lint> a(m, 0), b(m, 0);
  for (lint i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }

  vector<vector<lint>> mat(n);
  vector<int> check(n, -1);

  for (lint i = 0; i < m; i++) {
    mat[a[i] - 1].push_back(b[i] - 1);
    mat[b[i] - 1].push_back(a[i] - 1);
  }

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

  while (!q.empty()) {
    lint elem = q.front();
    q.pop();
    lint size = (int)mat[elem].size();

    for (lint i = 0; i < size; i++) {
      if (check[mat[elem][i]] == -1) {
        check[mat[elem][i]] = elem;
        q.push(mat[elem][i]);
      }
    }
  }

  for (lint i = 1; i < n; i++) {
    if (check[i] == -1) {
      cout << "No\\n";
      return 0;
    }
  }

  cout << "Yes\\n";
  for (lint i = 1; i < n; i++) {
    cout << check[i] + 1 << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

lint gcd(lint x, lint y) {
  if (x == 0) {
    return y;
  } else {
    return gcd(y % x, x);
  }
}

lint lcm(lint x, lint y) { return abs(x - y) / gcd(x, y); }

int main() {
  lint n, m;
  cin >> n >> m;
  vector<lint> a(m, 0), b(m, 0);
  for (lint i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }

  vector<vector<lint>> mat(m);
  vector<int> check(n, -1);

  for (lint i = 0; i < m; i++) {
    mat[a[i] - 1].push_back(b[i] - 1);
    mat[b[i] - 1].push_back(a[i] - 1);
  }

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

  while (!q.empty()) {
    lint elem = q.front();
    q.pop();
    lint size = (int)mat[elem].size();

    for (lint i = 0; i < size; i++) {
      if (check[mat[elem][i]] == -1) {
        check[mat[elem][i]] = elem;
        q.push(mat[elem][i]);
      }
    }
  }

  for (lint i = 1; i < n; i++) {
    if (check[i] == -1) {
      cout << "No\\n";
      return 0;
    }
  }

  cout << "Yes\\n";
  for (lint i = 1; i < n; i++) {
    cout << check[i] + 1 << endl;
  }
  return 0;
}