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

/**
 *  author: MOOONI
 *  hackers are welcome!
 **/
#include <bits/stdc++.h>

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

const int N = (int)1e5 + 10;

vector<int> g[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  vector<int> que;
  que.push_back(0);
  vector<int> par(n, -1);
  for (int b = 0; b < (int)que.size(); b++) {
    int v = que[b];
    for (int u : g[v]) {
      if (par[u] == -1) {
        par[u] = v;
        que.push_back(u);
      }
    }
  }
  for (int i = 1; i < n; i++) {
    if (par[i] == -1) {
      cout << "No" << '\\n';
      return 0;
    }
  }
  cout << "Yes" << '\\n';
  for (int i = 1; i < n; i++) {
    cout << par[i] + 1 << '\\n';
  }
  return 0;
}

Error: TLE

Fixed submission:

/**
 *  author: MOOONI
 *  hackers are welcome!
 **/
#include <bits/stdc++.h>

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n, vector<int>(m));
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  vector<int> que;
  que.push_back(0);
  vector<int> par(n, -1);
  for (int b = 0; b < (int)que.size(); b++) {
    int v = que[b];
    for (int u : g[v]) {
      if (par[u] == -1) {
        par[u] = v;
        que.push_back(u);
      }
    }
  }
  for (int i = 1; i < n; i++) {
    if (par[i] == -1) {
      cout << "No" << '\\n';
      return 0;
    }
  }
  cout << "Yes" << '\\n';
  for (int i = 1; i < n; i++) {
    cout << par[i] + 1 << '\\n';
  }
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;
using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
ll const mod = 998244353;
const ll MAX = 300000;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
int main() {
  int n, m;
  cin >> n >> m;
  vvi ab(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    ab[a].push_back(b);
    ab[b].push_back(a);
  }
  vi ans(n);
  vi used(n);

  queue<int> q;
  q.push(0);
  while (q.size()) {
    int now = q.front();
    q.pop();
    used[now] = 1;
    for (int x : ab[now]) {
      if (used[x] == 1)
        continue;
      used[x] = 1;
      ans[x] = now + 1;
      q.push(x);
    }
    // cout<<"aaa";
  }
  cout << "Yes" << endl;
  arep(i, 1, n) { cout << ans[i] << endl; }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;
using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
ll const mod = 998244353;
const ll MAX = 300000;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
int main() {
  int n, m;
  cin >> n >> m;
  vvi ab(m);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    ab[a].push_back(b);
    ab[b].push_back(a);
  }
  vi ans(n);
  vi used(n);

  queue<int> q;
  q.push(0);
  while (q.size()) {
    int now = q.front();
    q.pop();
    used[now] = 1;
    for (int x : ab[now]) {
      if (used[x] == 1)
        continue;
      used[x] = 1;
      ans[x] = now + 1;
      q.push(x);
    }
    // cout<<"aaa";
  }
  cout << "Yes" << endl;
  arep(i, 1, n) { cout << ans[i] << endl; }
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

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

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define int long long

const int N = 2e5 + 5;

int n, m;
int vis[N], dist[N], ways[N], ans[N];
vector<int> g[N];

void bfs(int k) {
  queue<int> q;
  q.push(k);
  vis[k] = 1;
  while (!q.empty()) {
    int node = q.front();
    q.pop();
    for (auto it : g[node]) {
      if (!vis[it]) {
        dist[it] = dist[node] + 1;
        vis[it] = 1;
        ans[it] = node;
        q.push(it);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      cout << "No";
      exit(0);
    }
  }
}

int32_t main() {
  IOS;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  bfs(1);
  cout << "Yes" << endl;
  for (int i = 2; i <= n; i++)
    cout << ans[i] << endl;
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll, ll>
#define vpii vector<pair<ll, ll>>
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a, i) memset(a, i, sizeof(a))
#define all(x) x.begin(), x.end()
#define itit(it, a) for (auto it = (a).begin(); it != (a).end(); it++)
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define repr(i, a, b) for (ll i = a; i > b; i--)
#define reprr(i, a, b) for (ll i = a; i >= b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x, ll y, ll z) { return max(max(x, y), z); }
ll min3(ll x, ll y, ll z) { return min(min(x, y), z); }
const ll N = 1e5 + 10, M = 2e5 + 10, M2 = 1e6 + 10, mod = 1e9 + 7,
         inf = 1e17 + 10;
const int INF = 1e9 + 7;
void add(int &a, int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
}

int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
// assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z)
// is(65-90) and 32 for space
ll power(ll x, ll n) {
  ll result = 1;
  while (n > 0) {
    if (n % 2 == 1)
      result = (result * x) % mod;
    x = ((x % mod) * (x % mod)) % mod;
    n = n / 2;
  }
  return result;
}

int n, m;
vector<int> g[M];
int ans[N];

void dfs(int v, int par, int h) {
  ans[v] = h;
  for (int u : g[v]) {
    if (u != par) {
      dfs(u, v, h + 1);
    }
  }
}

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  rep(i, 1, m + 1) {
    int a, b;
    cin >> a >> b;
    g[a].pb(b);
    g[b].pb(a);
  }
  dfs(1, -1, 0);
  for (int i = 2; i <= n; i++) {
    if (!ans[i]) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes\\n";
  for (int i = 2; i <= n; i++)
    cout << ans[i] << "\\n";
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define ll long long

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  for (int i = 0; i < m; ++i) {
    int tmpa, tmpb;
    cin >> tmpa >> tmpb;
    a[i] = tmpa - 1;
    b[i] = tmpb - 1;
  }

  vector<int> dist(n, 1000000000);

  vector<vector<int>> coef(n);
  for (int i = 0; i < m; ++i) {
    coef[a[i]].push_back(b[i]);
    coef[b[i]].push_back(a[i]);
  }

  // for(int i = 0;i < n;++i){
  //     cout << coef[i].size() << endl;
  // }

  queue<int> next;
  next.push(0);
  dist[0] = 0;
  vector<int> ans(n);
  for (int i = next.front(); next.size() > 0; i = next.front()) {
    // cout << i << endl;
    for (int j = 0; j < coef[i].size(); ++j) {
      if (dist[coef[i][j]] > dist[i] + 1) {
        dist[coef[i][j]] = dist[i] + 1;
        // cout << "next push : " << coef[i][j] << endl;
        next.push(coef[i][j]);
        ans[coef[i][j]] = i;
      }
    }
    next.pop();
    // cout << "next is : " << next.front() << endl;
  }

  int flag = 1;
  for (int i = 1; i < n; ++i) {
    if (dist[i] == 1000000000) {
      flag = 0;
    }
  }

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

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define ll long long

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  for (int i = 0; i < m; ++i) {
    int tmpa, tmpb;
    cin >> tmpa >> tmpb;
    a[i] = tmpa - 1;
    b[i] = tmpb - 1;
  }

  vector<int> dist(n, 1000000000);

  vector<vector<int>> coef(n);
  for (int i = 0; i < m; ++i) {
    coef[a[i]].push_back(b[i]);
    coef[b[i]].push_back(a[i]);
  }

  // for(int i = 0;i < n;++i){
  //     cout << coef[i].size() << endl;
  // }

  queue<int> next;
  next.push(0);
  dist[0] = 0;
  vector<int> ans(n);
  for (int i = next.front(); next.size() > 0; i = next.front()) {
    // cout << i << endl;
    for (int j = 0; j < coef[i].size(); ++j) {
      if (dist[coef[i][j]] > dist[i] + 1) {
        dist[coef[i][j]] = dist[i] + 1;
        // cout << "next push : " << coef[i][j] << endl;
        next.push(coef[i][j]);
        ans[j] = i;
      }
    }
    next.pop();
    // cout << "next is : " << next.front() << endl;
  }

  int flag = 1;
  for (int i = 1; i < n; ++i) {
    if (dist[i] == 1000000000) {
      flag = 0;
    }
  }

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

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

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

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

  vector<int> nodes[100001];
  vector<int> signposts(n + 1, -1);

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    nodes[a].push_back(b);
    nodes[b].push_back(a);
  }

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

  while (!next_rooms.empty()) {
    int signpost = next_rooms.front();
    next_rooms.pop();

    for (int room : nodes[signpost]) {
      if (signposts[room] == -1) {
        signposts[room] = signpost;
        next_rooms.push(room);
      }
    }
  }

  cout << "Yes" << endl;

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

  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n, m;
  scanf("%d %d", &n, &m);

  vector<int> nodes[100000];
  vector<int> signposts(n, 0);

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

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

  while (!next_rooms.empty()) {
    int signpost = next_rooms.front();
    next_rooms.pop();

    for (int room : nodes[signpost]) {
      // printf("signpost: %d, room: %d\\n", signpost, room);

      if (signposts[room] == 0) {
        signposts[room] = signpost;
        // printf("ASSIGNED %d: %d\\n", room, signpost);
        next_rooms.push(room);
      }
    }
  }

  cout << "Yes" << endl;

  for (int i = 2; i <= n; i++) {
    cout << signposts[i] << endl;
  }
}
Problem p02678 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
vector<ll> adj[100010];
vector<bool> visited(100010);
vector<ll> p(100010);
ll n, m;
vector<ll> dist(100010);
void addEdge(ll v, ll w) {
  adj[v].push_back(w);
  adj[w].push_back(v);
}
void bfs(ll src) {
  for (int i = 1; i <= n; i++)
    visited[i] = false;
  queue<ll> q;
  visited[src] = true;
  q.push(src);
  p[src] = -1;
  while (!q.empty()) {
    ll z = q.front();
    q.pop();
    for (int i = 0; i < adj[z].size(); i++) {
      if (!visited[adj[z][i]]) {
        visited[adj[z][i]] = true;
        q.push(adj[z][i]);
        p[adj[z][i]] = z;
        dist[adj[z][i]] = dist[z] + 1;
      }
    }
  }
}
void solve() {
  cin >> n >> m;
  ll a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    addEdge(a, b);
  }
  vector<ll> ans;
  bfs(1);
  for (int i = 2; i <= n; i++) {
    if (!visited[i]) {
      cout << "No";
      return;
    }
    ans.push_back(p[i]);
  }
  cout << "Yes" << '\\n';
  for (auto x : ans)
    cout << x << '\\n';
}
int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  // cin>>t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
vector<ll> adj[100010];
vector<bool> visited(100010);
vector<ll> p(100010);
ll n, m;
void addEdge(ll v, ll w) {
  adj[v].push_back(w);
  adj[w].push_back(v);
}
void bfs(ll src) {
  for (int i = 1; i <= n; i++)
    visited[i] = false;
  queue<ll> q;
  visited[src] = true;
  q.push(src);
  p[src] = -1;
  while (!q.empty()) {
    ll z = q.front();
    q.pop();
    for (int i = 0; i < adj[z].size(); i++) {
      if (!visited[adj[z][i]]) {
        visited[adj[z][i]] = true;
        q.push(adj[z][i]);
        p[adj[z][i]] = z;
      }
    }
  }
}
void solve() {
  cin >> n >> m;
  ll a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    addEdge(a, b);
  }
  vector<ll> ans;
  for (int i = 2; i <= n; i++) {
    bfs(i);
    if (!visited[1]) {
      cout << "No";
      return;
    }
    ll v = 1;
    while (p[v] != i) {
      v = p[v];
    }
    ans.push_back(v);
  }
  cout << "Yes" << '\\n';
  for (auto x : ans)
    cout << x << '\\n';
}
int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  // cin>>t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define MAX 490000
#define max(a, b) ((a) < (b) ? (b) : (a))
using namespace std;
int to[MAX];
int head[MAX];
int nxt[MAX];
int v[MAX];
int sign[MAX];
int tot;
void Add(int fir, int sec) {
  nxt[++tot] = head[fir];
  to[tot] = sec;
  head[fir] = tot;
}

void bfs(int node) {
  // v[node] = 1;
  queue<int> q;
  q.push(node);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    v[x] = 1;
    for (int i = head[x]; i != -1; i = nxt[i]) {
      int y = to[i];
      if (v[y] == 1) {
        continue;
      }
      if (sign[y] == 0) {
        sign[y] = x;
        q.push(y);
      }

      // printf("%d sign is %d\\n", y, x);
    }
  }
}

int main() {
  int N, M;
  while (cin >> N >> M) {
    tot = 0;
    memset(nxt, -1, sizeof(nxt));

    int fir, sec;
    for (int i = 1; i <= M; i++) {
      scanf("%d%d", &fir, &sec);
      Add(fir, sec);
      Add(sec, fir);
    }
    bfs(1);
    int flag = 0;
    for (int i = 2; i <= N; i++) {
      if (!sign[i]) {
        flag = 1;
        break;
      }
    }
    if (flag) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
      for (int i = 2; i <= N; i++)
        printf("%d\\n", sign[i]);
      // cout << sign[i] << endl;
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define MAX 210000
#define max(a, b) ((a) < (b) ? (b) : (a))
using namespace std;
int to[MAX];
int head[MAX];
int nxt[MAX];
int v[MAX];
int sign[MAX];
int tot;
void Add(int fir, int sec) {
  nxt[++tot] = head[fir];
  to[tot] = sec;
  head[fir] = tot;
}

void bfs(int node) {
  // v[node] = 1;
  queue<int> q;
  q.push(node);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    v[x] = 1;
    for (int i = head[x]; i != -1; i = nxt[i]) {
      int y = to[i];
      if (v[y] == 1) {
        continue;
      }
      if (sign[y] == 0)
        sign[y] = x;
      q.push(y);
      // printf("%d sign is %d\\n", y, x);
    }
  }
}

int main() {
  int N, M;
  while (cin >> N >> M) {
    tot = 0;
    memset(nxt, -1, sizeof(nxt));
    // memset(v, 0, sizeof(v));
    // memset(head, 0, sizeof(head));
    // // memset(to, 0, sizeof(to));
    // memset(sign, 0, sizeof(sign));
    int fir, sec;
    for (int i = 1; i <= M; i++) {
      scanf("%d%d", &fir, &sec);
      Add(fir, sec);
      Add(sec, fir);
    }
    bfs(1);
    int flag = 0;
    for (int i = 2; i <= N; i++) {
      if (!sign[i]) {
        flag = 1;
        break;
      }
    }
    if (flag) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
      for (int i = 2; i <= N; i++)
        printf("%d\\n", sign[i]);
      // cout << sign[i] << endl;
    }
  }
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

int main() {
  int N, M;
  std::cin >> N >> M;
  std::vector<std::vector<int>> edge(N);
  for (int i = 0; i < M; ++i) {
    int s, t;
    std::cin >> s >> t;
    edge[s - 1].push_back(t - 1);
    edge[t - 1].push_back(s - 1);
  }
  constexpr long long inf = 1e18;
  std::vector<long long> d(N, inf), prev(N, 0);
  d[0] = 0;
  std::priority_queue<std::pair<long long, long long>,
                      std::vector<std::pair<long long, long long>>,
                      std::greater<>>
      que;
  que.emplace(d[0], 0);
  while (not que.empty()) {
    auto tp = que.top();
    que.pop();
    int cv, cd;
    std::tie(cd, cv) = tp;
    if (cd > d[cv])
      continue;
    for (const auto nv : edge[cv]) {
      if (d[nv] > cd + 1) {
        d[nv] = cd + 1;
        prev[nv] = cv;
        que.emplace(d[nv], nv);
      }
    }
  }
  if (std::count_if(d.begin(), d.end(), [&](auto e) { return e == inf; })) {
    std::cout << "No" << std::endl;
  } else {
    std::cout << "Yes" << std::endl;
    prev.erase(prev.begin());
    for (const auto pv : prev) {
      std::cout << pv + 1 << std::endl;
    }
  }
}


Error: 0

Fixed submission:

#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
using namespace std;
struct Node {
  // ノード(親ノードと複数の子ノードを保存)
  int parent;
  vector<int> child;
};
void set_child(Node nodes[], int node_idx, int *Map_ptr, int N, int *list,
               queue<int> &que) {
  // 子ノードを全てセットする
  for (int i = 0; i < N; i++) {
    if (Map_ptr[i] == 1 && list[i] != 1) { // まだ書いてないノードだけ書く
      nodes[node_idx].child.push_back(i);
      nodes[i].parent = node_idx;
      list[i] = 1;
      que.push(i);
    }
  }
};
constexpr int myN = 100;
void out() { puts("hoge"); }
int main() {
  int N, M;
  scanf("%d %d", &N, &M);
  // 表現行列の初期化
  int Map[100][100];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      Map[i][j] = 0;
    }
  }
  // 2次元配列を関数に渡すために表現行列の各行のポインタを配列化
  int *Map_ptr[6];
  for (int i = 0; i < N; i++) {
    Map_ptr[i] = Map[i];
  }
  // 表現行列の作成
  for (int i = 0; i < M; i++) {
    int A, B;
    scanf("%d", &A);
    scanf("%d", &B);
    Map[A - 1][B - 1] = 1;
    Map[B - 1][A - 1] = 1;
  }
  Node node[100];
  int room_list[100] = {0}; // 行った部屋は1
  int idx = 0;
  queue<int> que;
  node[0].parent = 0;
  room_list[0] = 1;
  que.push(0);
  // node[0]から幅優先で全ノードの親と子をセットする
  while (!que.empty()) {
    idx = que.front();
    que.pop();
    set_child(node, idx, Map_ptr[idx], N, room_list, que);
    // Node nodes[], int node_idx, int* Map_ptr[], int N, int list[],
    // queue<int>& que)
  }
  int check = 0;
  for (int i = 0; i < N; i++) {
    if (room_list[i] == 0) {
      check = 1;
      break;
    }
  }
  if (check == 1) {
    printf("No\\n");
  } else {
    printf("Yes\\n");
    for (int i = 1; i < N; i++) {
      printf("%d\\n", node[i].parent + 1);
    }
  }
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<vector<int>> E(N, vector<int>());
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    E[a].push_back(b);
    E[b].push_back(a);
  }
  vector<int> ans(N, -1);
  vector<int> d(N, 1e9);
  vector<bool> f(N, false);
  queue<int> q;
  q.push(0);
  d[0] = 0;
  f[0] = true;
  while (!q.empty()) {
    auto cur = q.front();
    q.pop();
    for (auto i : E[cur]) {
      if (f[i])
        continue;
      d[i] = d[cur] + 1;
      ans[i] = cur;
      f[i] = true;
      q.push(i);
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < N; i++) {
    cout << ans[i] + 1 << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<vector<int>> E(N, vector<int>());
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    E[a].push_back(b);
    E[b].push_back(a);
  }
  vector<int> ans(N, -1);
  vector<int> d(N, 1e9);
  stack<int> st;
  st.push(0);
  d[0] = 0;
  while (!st.empty()) {
    auto cur = st.top();
    st.pop();
    for (auto i : E[cur]) {
      if (d[i] <= d[cur] + 1)
        continue; // 更新しないなら終わり
      d[i] = d[cur] + 1;
      ans[i] = cur;
      st.push(i);
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < N; i++) {
    cout << ans[i] + 1 << endl;
  }
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define m1(x) memset(x, -1, sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> e[110000];
  int ans[110000];
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  queue<int> q;
  q.push(1);
  while (!q.empty()) {
    int c = q.front();
    q.pop();
    for (int d : e[c]) {
      if (d == c)
        continue;
      if (ans[d] != 0)
        continue;
      ans[d] = c;
      q.push(d);
    }
  }
  cout << "Yes" << endl;
  for (int i = 2; i <= n; i++) {
    cout << ans[i] << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define m1(x) memset(x, -1, sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> e[11000];
  int ans[11000];
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  queue<int> q;
  q.push(1);
  while (!q.empty()) {
    int c = q.front();
    q.pop();
    for (int d : e[c]) {
      if (d == c)
        continue;
      if (ans[d] != 0)
        continue;
      ans[d] = c;
      q.push(d);
    }
  }
  cout << "Yes" << endl;
  for (int i = 2; i <= n; i++) {
    cout << ans[i] << endl;
  }
}