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

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

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

  int N, M;
  scanf("%d %d", &N, &M);

  vector<vector<pair<int, int>>> w(N + 1,
                                   vector<pair<int, int>>()); //(部屋,道番号)
  vector<pair<int, int>> result(N + 1, make_pair(N + 100, -1)); //(距離, 道)

  int a, b;
  for (int i = 1; i < M + 1; i++) {
    scanf("%d %d", &a, &b);
    w[a].insert(w[a].end(), make_pair(b, i));
    w[b].insert(w[b].end(), make_pair(a, i));
  }

  queue<int> que;

  que.push(1);
  result[1].first = 0;
  result[1].second = 0;
  while (!que.empty()) {
    int n = que.front();
    // std::cout << n << "\\n";
    que.pop(); // 先頭要素を削除
    for (int i = 0; i < w[n].size(); i++) {
      pair<int, int> now = w[n][i];
      // cout << "now is w[" << n << "][" << i << "]=" << now.first << " " <<
      // now.second << "\\n";
      if (result[now.first].first <= result[n].first + 1) {
        continue;
      }
      result[now.first].first = result[n].first + 1;
      result[now.first].second = n;
      que.push(now.first);
      // cout << "hoge";
    }
  }

  cout << "Yes\\n";

  for (int i = 2; i <= N; i++) {
    cout << result[i].second << "\\n";
  }
  return 0;
}

Error: TLE

Fixed submission:

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

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

  int N, M;
  scanf("%d %d", &N, &M);

  vector<vector<pair<int, int>>> w(N + 1,
                                   vector<pair<int, int>>()); //(部屋,道番号)
  vector<pair<int, int>> result(N + 1, make_pair(N + 100, -1)); //(距離, 道)

  int a, b;
  for (int i = 1; i < M + 1; i++) {
    scanf("%d %d", &a, &b);
    w[a].insert(w[a].end(), make_pair(b, i));
    w[b].insert(w[b].end(), make_pair(a, i));
  }

  queue<int> que;

  que.push(1);
  result[1].first = 0;
  result[1].second = 0;
  while (!que.empty()) {
    int n = que.front();
    // std::cout << n << "\\n";
    que.pop(); // 先頭要素を削除
    for (int i = 0; i < w[n].size(); i++) {
      pair<int, int> now = w[n][i];
      // cout << "now is w[" << n << "][" << i << "]=" << now.first << " " <<
      // now.second << "\\n";
      if (result[now.first].first <= result[n].first) {
        continue;
      }
      result[now.first].first = result[n].first + 1;
      result[now.first].second = n;
      que.push(now.first);
      // cout << "hoge";
    }
  }

  cout << "Yes\\n";

  for (int i = 2; i <= N; i++) {
    cout << result[i].second << "\\n";
  }
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f
#define pb push_back
#define debug1 cout << "&&";
#define debug2 cout << "**";
#define ms(a, x) memset(a, x, sizeof(a))
#define for0(i, n) for (int i = 0; i < n; ++i)
#define for1(i, n) for (int i = 1; i <= n; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
const int M = 1e6 + 10;
/*=================================================================================*/

int n, m, head[N], ver[M], nex[M], tot;
int vis[N], ans[N], sum;

void add(int a, int b) {
  ver[++tot] = b;
  nex[tot] = head[a];
  head[a] = tot;
}

int main() {
  cin >> n >> m;
  for1(i, m) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  queue<int> q;
  q.push(1);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = head[x]; i; i = nex[i]) {
      int y = ver[i];
      if (!vis[y]) {
        ans[y] = x;
        sum++, vis[y] = 1;
        q.push(y);
      }
    }
  }
  if (sum != n)
    puts("No");
  else {
    puts("Yes");
    for (int i = 2; i <= n; ++i)
      printf("%d\\n", ans[i]);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f
#define pb push_back
#define debug1 cout << "&&";
#define debug2 cout << "**";
#define ms(a, x) memset(a, x, sizeof(a))
#define for0(i, n) for (int i = 0; i < n; ++i)
#define for1(i, n) for (int i = 1; i <= n; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
const int M = 1e6 + 10;
/*=================================================================================*/

int n, m, head[N], ver[N << 1], nex[N << 1], tot;
int vis[N], ans[N], sum;

void add(int a, int b) {
  ver[++tot] = b;
  nex[tot] = head[a];
  head[a] = tot;
}

int main() {
  cin >> n >> m;
  for1(i, m) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  queue<int> q;
  q.push(1);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = head[x]; i; i = nex[i]) {
      int y = ver[i];
      if (!vis[y]) {
        ans[y] = x;
        sum++, vis[y] = 1;
        q.push(y);
      }
    }
  }
  if (sum != n)
    puts("No");
  else {
    puts("Yes");
    for (int i = 2; i <= n; ++i)
      printf("%d\\n", ans[i]);
  }
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

using namespace std;

struct Node {
  // ll num = 0;
  ll dist = 2000000000;

  ll path = -1;

  bool locked = false;

  vector<ll> near;
};

queue<ll> q;
vector<Node> gragh(100010); // 1 indexed
ll nd = 0;

void dfs(ll now);

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

  ll N, M;
  cin >> N >> M;

  REP(i, M) {
    ll a, b;
    cin >> a >> b;
    gragh[a].near.push_back(b);
    gragh[b].near.push_back(a);
  }

  gragh[0].near.push_back(1);
  gragh[1].near.push_back(0);
  gragh[0].dist = 0;
  gragh[1].path = 1;

  // dfs(0);

  q.push(0);

  while (1) {
    if (q.size() == 0)
      break;
    int q1 = q.front();
    q.pop();
    // if(gragh[q1].locked = true) continue;
    dfs(q1);
  }

  cout << "Yes" << endl;
  for (int i = 2; i <= N; i++) {
    // cout<<"Yes"<<endl;
    cout << gragh[i].path << endl;
  }

  return 0;
}

void dfs(ll now) {

  // cout<<now<<endl;
  vector<ll> next = gragh[now].near;
  ll D = gragh[now].dist;
  // cout<<now<<" "<<D<<endl;

  for (int i = 0; i < int(next.size()); i++) {
    ll ne = next[i];
    if (ne == gragh[now].path)
      continue;
    if (gragh[ne].dist > D + 1) {
      gragh[ne].path = now;
      gragh[ne].dist = D + 1;
      // dfs(ne);
      // gragh[ne].locked = true;
      q.push(ne);
      // cout<<ne<<" "<<gragh[ne].dist<<endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

using namespace std;

struct Node {
  // ll num = 0;
  ll dist = 2000000000;

  ll path = -1;

  vector<ll> near;
};

vector<Node> gragh(100010); // 1 indexed

void dfs(ll now);

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

  ll N, M;
  cin >> N >> M;

  REP(i, M) {
    ll a, b;
    cin >> a >> b;
    gragh[a].near.push_back(b);
    gragh[b].near.push_back(a);
  }

  gragh[0].near.push_back(1);
  gragh[1].near.push_back(0);
  gragh[0].dist = 0;
  gragh[1].path = 1;

  dfs(0);

  cout << "Yes" << endl;
  for (int i = 2; i <= N; i++) {
    // cout<<"Yes"<<endl;
    cout << gragh[i].path << endl;
  }

  return 0;
}

void dfs(ll now) {
  // cout<<now<<endl;
  vector<ll> next = gragh[now].near;
  ll D = gragh[now].dist;
  // cout<<now<<" "<<D<<endl;

  for (int i = 0; i < int(next.size()); i++) {
    ll ne = next[i];
    if (ne == gragh[now].path)
      continue;
    if (gragh[ne].dist > D + 1) {
      gragh[ne].path = now;
      gragh[ne].dist = D + 1;
      dfs(ne);
    }
  }
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error


#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stdio.h>
using namespace std;
#define N 200001
#define INFTY 100000000

int n, m;
vector<int> num[N];
bool color[N];
int d[N];

void bfs(int s) {
  queue<int> q; // 標準ライブラリのqueue 入るものは最後尾　出すものは先頭
  q.push(s);
  for (int i = 0; i < n; i++) {
    d[i] = INFTY;
  }
  d[s] = 0;
  int u;
  while (!q.empty()) { // qが空になるまで続ける
    u = q.front();     // uはqの先頭
    q.pop();           // qの先頭を取り出
    if (color[u] == false)
      continue;
    color[u] = false;
    for (int i = 0; i < num[u].size(); i++) {
      d[num[u][i]] = min(d[u] + 1, d[num[u][i]]);
      q.push(num[u][i]); // qの最後尾にvを追加
      // color[num[u][i]]=false;
    }
  }
}

int main() {
  cin >> n >> m;
  for (int i = 0; i <= n; i++) {
    color[i] = true;
    d[i] = 100000000;
  }

  for (int i = 0; i < m; i++) {
    int p, q;
    cin >> p >> q;
    num[p].push_back(q);
    num[q].push_back(p);
  }

  d[1] = 0;

  bfs(1);

  // cout<<d[num[6][1]]<<d[6]<<endl;

  // for (int i=1; i<=n; i++)cout<<d[i]<<endl;

  cout << "Yes" << endl;

  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < num[i].size(); j++) {
      if (d[num[i][j]] == d[i] - 1) {
        cout << num[i][j] << endl;
        break;
      }
    }
  }
}

Error: 0

Fixed submission:


#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stdio.h>
using namespace std;
#define N 10001
#define INFTY 100000000

int n, m;
vector<int> num[N];
bool color[N];
int d[N];

void bfs(int s) {
  queue<int> q; // 標準ライブラリのqueue 入るものは最後尾　出すものは先頭
  q.push(s);
  for (int i = 0; i < n; i++) {
    d[i] = INFTY;
  }
  d[s] = 0;
  int u;
  while (!q.empty()) { // qが空になるまで続ける
    u = q.front();     // uはqの先頭
    q.pop();           // qの先頭を取り出
    if (color[u] == false)
      continue;
    color[u] = false;
    for (int i = 0; i < num[u].size(); i++) {
      d[num[u][i]] = min(d[u] + 1, d[num[u][i]]);
      q.push(num[u][i]); // qの最後尾にvを追加
      // color[num[u][i]]=false;
    }
  }
}

int main() {
  cin >> n >> m;
  for (int i = 0; i <= n; i++) {
    color[i] = true;
    d[i] = 100000000;
  }

  for (int i = 0; i < m; i++) {
    int p, q;
    cin >> p >> q;
    num[p].push_back(q);
    num[q].push_back(p);
  }

  d[1] = 0;

  bfs(1);

  // cout<<d[num[6][1]]<<d[6]<<endl;

  // for (int i=1; i<=n; i++)cout<<d[i]<<endl;

  cout << "Yes" << endl;

  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < num[i].size(); j++) {
      if (d[num[i][j]] == d[i] - 1) {
        cout << num[i][j] << endl;
        break;
      }
    }
  }
}
Problem p02678 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define INF 1000000009

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> e(N);
  int d[100005];
  int back[100005];
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    e[a - 1].push_back(b - 1);
    e[b - 1].push_back(a - 1);
  }
  memset(d, INF, sizeof(d));
  memset(back, 0, sizeof(back));
  d[0] = 0;
  queue<pair<int, int>> que;
  pair<int, int> s(0, 0);
  que.push(s);
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    int i = p.second;
    for (int j = 0; j < e[i].size(); j++) {
      int to = e[i][j];
      if (d[to] > d[i] + 1) {
        d[to] = d[i] + 1;
        back[to] = i;
        pair<int, int> p2(d[to], to);
        que.push(p2);
      }
    }
  }

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

#define INF 1000000009

using namespace std;

int main() {
  int N, M;
  vector<pair<int, int>> edge;
  cin >> N >> M;
  int d[100005];
  int back[100005];
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    pair<int, int> p(a - 1, b - 1);
    pair<int, int> p2(b - 1, a - 1);
    edge.push_back(p);
    edge.push_back(p2);
  }
  memset(d, INF, sizeof(d));
  memset(back, 0, sizeof(back));
  d[0] = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 2 * M; j++) {
      pair<int, int> p = edge[j];
      if (d[p.second] > d[p.first] + 1) {
        d[p.second] = d[p.first] + 1;
        back[p.second] = p.first;
        if (i == N - 1) {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < N; i++) {
    cout << back[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 < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vi> path(n);
  vector<bool> seen(n, false);
  vi mark(n, -1);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    path[a].push_back(b);
    path[b].push_back(a);
  }
  queue<int> q;
  q.push(0);
  mark[0] = 0;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    seen[v] = true;
    for (auto nv : path[v]) {
      if (mark[nv] == -1) {
        q.push(nv);
        mark[nv] = v;
      }
    }
  }
  rep(i, n) if (mark[i] == -1) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  rep(i, n - 1) cout << mark[i + 1] + 1 << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

void dfs(int now, int from, vector<vi> &path, vector<bool> &seen, vi &mark) {
  if (seen[now])
    return;
  seen[now] = true;
  for (auto next : path[now]) {
    if (seen[next])
      continue;
    dfs(next, now, path, seen, mark);
    mark[next] = now;
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<vi> path(n, vi(n));
  vector<bool> seen(n);
  vi mark(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    path[a].push_back(b);
    path[b].push_back(a);
  }
  rep(i, n) seen[i] = false;
  for (auto next : path[0])
    dfs(next, 0, path, seen, mark);
  rep(i, n) if (!seen[i]) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  rep(i, n - 1) cout << mark[i + 1] + 1 << 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<vector<int>> r(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    r[a - 1].push_back(b - 1);
    r[b - 1].push_back(a - 1);
  }
  vector<int> d(n, -1);
  queue<int> que;
  d[0] = 0;
  que.push(0);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (int nv : r[v]) {
      if (d[nv] != -1)
        continue;
      d[nv] = v;
      que.push(nv);
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < n; i++) {
    cout << d[i] + 1 << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> r(m);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    r[a - 1].push_back(b - 1);
    r[b - 1].push_back(a - 1);
  }
  vector<int> d(n, -1);
  queue<int> que;
  d[0] = 0;
  que.push(0);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (int nv : r[v]) {
      if (d[nv] != -1)
        continue;
      d[nv] = v;
      que.push(nv);
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < n; i++) {
    cout << d[i] + 1 << endl;
  }
  return 0;
}
Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define int long long
int mod = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  int n, m;
  cin >> n >> m;
  vector<vector<int>> 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);
  }
  queue<int> q;
  vector<int> used(n, -1);
  q.push(0);
  used[0] = 0;
  while (!q.empty()) {
    int a = q.front();
    q.pop();
    for (int i = 0; i < g[a].size(); i++) {
      int to = g[a][i];
      if (used[to] == -1) {
        used[to] = a;
        q.push(to);
      }
    }
  }
  for (int i = 1; i < n; i++) {
    if (used[i] == -1) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < n; i++) {
    cout << used[i] + 1 << endl;
  }
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define int long long
int mod = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  queue<int> q;
  vector<int> used(n, -1);
  q.push(0);
  used[0] = 0;
  while (!q.empty()) {
    int a = q.front();
    q.pop();
    for (int i = 0; i < g[a].size(); i++) {
      int to = g[a][i];
      if (used[to] == -1) {
        used[to] = a;
        q.push(to);
      }
    }
  }
  for (int i = 1; i < n; i++) {
    if (used[i] == -1) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < n; i++) {
    cout << used[i] + 1 << 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>> path(N + 1);
  for (int i = 1; i <= M; i++) {
    int a, b;
    cin >> a >> b;
    path[a].push_back(b);
    path[b].push_back(a);
  }

  vector<int> dist(N + 1, INT_MAX);
  vector<int> prev(N + 1, INT_MAX);
  dist[1] = 0;

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

  while (!que.empty()) {
    int n = que.front();
    que.pop();
    for (size_t i = 0; i < path[n].size(); i++) {
      if (dist[path[n][i]] != INT_MAX) {
        continue;
      }
      dist[path[n][i]] = dist[n] + 1;
      prev[path[n][i]] = n;
      que.push(path[n][i]);
    }
  }

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

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> path(M + 1);
  for (int i = 1; i <= M; i++) {
    int a, b;
    cin >> a >> b;
    path[a].push_back(b);
    path[b].push_back(a);
  }

  vector<int> dist(N + 1, INT_MAX);
  vector<int> prev(N + 1, INT_MAX);
  dist[1] = 0;

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

  while (!que.empty()) {
    int n = que.front();
    que.pop();
    for (size_t i = 0; i < path[n].size(); i++) {
      if (dist[path[n][i]] != INT_MAX) {
        continue;
      }
      dist[path[n][i]] = dist[n] + 1;
      prev[path[n][i]] = n;
      que.push(path[n][i]);
    }
  }

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

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

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a) * (a)
#define nl "\\n"
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<ll> vll;

const double pi = 3.14159265359;
const int MAXN = 100005;
ll mod = 1000000007;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  map<pair<ll, ll>, pair<ll, ll>> slope;
  int n;
  ll pw[2 * MAXN] = {1};
  pw[0] = 1;
  for (int i = 1; i <= 2 * MAXN - 1; i++)
    pw[i] = (pw[i - 1] * 2) % mod;
  cin >> n;

  ll z = -1;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    if (x == 0 and y == 0) {
      z++;
      continue;
    }
    if (make_pair(x, y) < make_pair(0ll, 0ll))
      x = -x, y = -y;
    ll g = gcd(abs(x), abs(y));
    x /= g, y /= g;
    if (y <= 0)
      slope[{-y, x}].second++;
    else
      slope[{x, y}].first++;
  }
  ll r = 1;
  for (auto &p : slope) {
    r = (r * (pw[p.second.first] + pw[p.second.second] - 1) % mod) % mod;
  }
  cout << (r + z + mod) % mod << nl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a) * (a)
#define nl "\\n"
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<ll> vll;

const double pi = 3.14159265359;
const int MAXN = 100005;
ll mod = 1000000007;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  map<pair<ll, ll>, pair<ll, ll>> slope;
  int n;
  ll pw[2 * MAXN] = {1};
  pw[0] = 1;
  for (int i = 1; i <= 2 * MAXN - 1; i++)
    pw[i] = (pw[i - 1] * 2) % mod;
  cin >> n;

  ll z = mod - 1;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    if (x == 0 and y == 0) {
      z++;
      continue;
    }
    if (make_pair(x, y) < make_pair(0ll, 0ll))
      x = -x, y = -y;
    ll g = gcd(abs(x), abs(y));
    x /= g, y /= g;
    if (y <= 0)
      slope[{-y, x}].second++;
    else
      slope[{x, y}].first++;
  }
  ll r = 1;
  for (auto &p : slope) {
    r = (r * (pw[p.second.first] + pw[p.second.second] - 1) % mod) % mod;
  }
  assert(r != 0);
  cout << (r + z) % mod << nl;

  return 0;
}