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

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

int main() {
  int N, Max;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N + 1);

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

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

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int N, i, j, count, kaisu, tmp;
  cin >> N;

  int A[N];

  for (i = 0; i < N - 1; i++) {
    cin >> A[i];
  }

  for (i = 0; i < N - 1; ++i) {
    for (j = i + 1; j < N - 1; ++j) {
      if (A[i] > A[j]) {
        tmp = A[i];
        A[i] = A[j];
        A[j] = tmp;
      }
    }
  }

  count = 1;
  kaisu = 0;

  for (i = 0; i < N - 2; i++) {
    if (A[i] == A[i + 1]) {
      count++;

    } else {
      cout << count << endl;
      count = 1;
      kaisu++;
    }
  }

  cout << count << endl;

  for (i = 0; i < N - kaisu - 1; i++) {
    cout << "0" << endl;
  }

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

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef vector<pi> vp;

#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define INF 1e9
#define modulo 1000000007
#define forn(i, n) for (int i = 0; i < (n); i++)
#define FAST                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL);
#define end1 "\\n"
#define print(x) cout << x << end1
#define debug(x) cout << #x << " :: " << x << end1;
#define debug2(x, y)                                                           \\
  cout << #x << " :: " << x << "\\t" << #y << " :: " << y << end1;

int main() {
  FAST;
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif

  ////////
  int n;
  cin >> n;
  map<int, int> m;

  for (int i = 1; i <= n; i++) {
    m.insert(mp(i, 0));
  }

  for (int i = 0, p; i < n - 1; i++) {
    cin >> p;
    m[p]++;
  }
  for (int i = 1; i <= n; i++)
    cout << (m[i]) << end1;

  return 0;
}

Error: TLE

Fixed submission:

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef vector<pi> vp;

#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define INF 1e9
#define modulo 1000000007
#define forn(i, n) for (int i = 0; i < (n); i++)
#define FAST                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL);
#define end1 "\\n"
#define print(x) cout << x << end1
#define debug(x) cout << #x << " :: " << x << end1;
#define debug2(x, y)                                                           \\
  cout << #x << " :: " << x << "\\t" << #y << " :: " << y << end1;

int main() {
  FAST;
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif

  ////////
  int n;
  cin >> n;
  vi v(n - 1);
  for (auto &x : v)
    cin >> x;
  sort(v.begin(), v.end());
  print(count(v.begin(), v.end(), 1));
  for (int i = 0; i < n - 1; i++) {
    print(count(v.begin(), v.end(), i + 2));
  }

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

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

int main() {
  int n;
  cin >> n;
  vector<int> sub(n + 1);
  for (int i = 2; i <= n; i++) {
    int boss;
    cin >> boss;
    sub[boss]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << sub[i] << "\\n";
  }
}

Error: -11

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const ll INF = 1e18;
const int MAX = 1e6;

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

struct edge {
  int to, cost;
}; // 辺
// vector<edge> graph[MAX]; // 隣接リスト
// bool visit[MAX]; // 訪問状況

int n, m; // 変数

int main() {
  // input
  cin >> n;
  vector<int> sub(n + 1);
  rep(i, n + 1) {
    int boss;
    if (i > 1)
      cin >> boss;
    sub[boss]++;
  }
  // solve
  // output
  rep(i, n + 1) {
    if (i > 0)
      cout << sub[i] << "\\n";
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define ll long int
const int ARR = 2e5 + 5;
using namespace std;
int main() {
  ll n;
  cin >> n;
  ll a[ARR];
  a[0] = 1;
  for (int i = 1; i < n; i++) {
    cin >> a[i];
  }
  ll ans[ARR] = {0};
  for (int i = 1; i < n; i++) {
    ans[a[i] - 1]++;
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#define ll long int
const int ARR = 1e5 + 2;
using namespace std;
int main() {
  ll n;
  cin >> n;
  ll a[ARR];
  a[0] = 1;
  for (int i = 1; i < n; i++) {
    cin >> a[i];
  }
  ll ans[ARR] = {0};
  for (int i = 1; i < n; i++) {
    ans[a[i] - 1]++;
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  int A[N - 1];
  for (int i = 0; i < N - 1; i++) {
    cin >> A[i];
  }
  int count[N];
  for (int i = 0; i < N; i++) {
    count[i] = 0;
  }
  for (int i = 0; i < N - 1; i++) {
    count[A[i] - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << count[i] << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i = 1; i < N; i++) {
    cin >> A[i];
  }
  int count[N];
  for (int i = 0; i < N; i++) {
    count[i] = 0;
  }
  for (int i = 0; i < N; i++) {
    for (int j = 1; j < N; j++) {
      if (A[j] == (i + 1)) {
        count[i]++;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    cout << count[i] << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define ll long long
typedef long double ld;
#define all(v) ((v).begin()), ((v).end())
#define vec2(n, m) vector<vector<ll>> vv(n + 10, vector<ll>(m + 10, 0));
#define p_q1 priority_queue<int, vector<int>, greater<int>> pq1;
#define format(n) fixed << setprecision(n)
#define ll_min LLONG_MIN;
#define ll_max LLONG_MIN;
#define endl "\\n"
#define F first
#define S second
#define mkpr(x, y) make_pair(x, y)
using namespace std;
void weza() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  weza();
  int n, m, a, mx = 0;
  cin >> n;
  vector<int> fre(200100);
  for (int i = 1; i < n; i++) {
    cin >> a;
    fre[a]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << fre[i] << endl;
  }
}

Error: 0

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define ll long long
typedef long double ld;
#define all(v) ((v).begin()), ((v).end())
#define vec2(n, m) vector<vector<ll>> vv(n + 10, vector<ll>(m + 10, 0));
#define p_q1 priority_queue<int, vector<int>, greater<int>> pq1;
#define format(n) fixed << setprecision(n)
#define ll_min LLONG_MIN;
#define ll_max LLONG_MIN;
#define endl "\\n"
#define F first
#define S second
#define mkpr(x, y) make_pair(x, y)
using namespace std;
void weza() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  weza();
  int n, m, a, mx = 0;
  cin >> n;
  vector<int> fre(100100);
  for (int i = 1; i < n; i++) {
    cin >> a;
    fre[a]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << fre[i] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

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

using namespace std;
using ll = long long int;
using ull = unsigned long long;

float myPower(int a, int n) { // aのn乗の計算
  float x = 1;
  while (n > 0) { // 全てのbitが捨てられるまで
    if (n & 1) {  // 一番右のbitが１のとき
      x *= a;
    }
    a *= a;
    n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
  }
  return x;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> ans(n + 1);
  for (int i = 0; i <= n; i++) {
    ans[i] = 0;
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
    ans[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

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

using namespace std;
using ll = long long int;
using ull = unsigned long long;

float myPower(int a, int n) { // aのn乗の計算
  float x = 1;
  while (n > 0) { // 全てのbitが捨てられるまで
    if (n & 1) {  // 一番右のbitが１のとき
      x *= a;
    }
    a *= a;
    n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
  }
  return x;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < a.size(); j++) {
      if (a[j] == i) {
        ans++;
      }
    }
    cout << ans << endl;
    ans = 0;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  int x = 0;
  vector<int> a(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i];
  }
  vector<int> b(n, 0);
  for (int i = 0; i < n; i++) {
    b[a[i]]++;
  }
  for (int i = 1; i < n; i++) {
    cout << b[i] << endl;
  }
  cout << x << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> a.at(i);
  }
  int kaunto = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == a.at(j)) {
        kaunto++;
      }
      if (j == n - 2) {
        cout << kaunto << endl;
        kaunto = 0;
        break;
      }
    }
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 1; i < N; i++) {
    int n;
    cin >> n;
    vec.at(n - 1)++;
  }
  for (auto &v : vec)
    cout << v << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> v(N, 0), ans(N, 0);
  for (int i = 1; i < N; i++) {
    cin >> v.at(i);
  }
  for (int i = 0; i < N; i++) {
    for (int j = 1; j < N; j++) {
      if ((i + 1) == v.at(j)) {
        ans.at(i)++;
      }
    }
  }
  for (auto a : ans)
    cout << a << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int b[n];
  memset(b, 0, sizeof(b));
  int i;
  for (i = 1; i < n; i++) {
    cin >> a[i];
    b[a[i] - 1]++;
  }
  for (i = 0; i < n; i++)
    cout << b[i] << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int b[n];
  memset(b, 0, sizeof(b));
  int i;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] - 1 != i)
      b[a[i] - 1]++;
  }
  for (i = 0; i < n; i++)
    cout << b[i] << endl;
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  int cnt[200010] = {0};
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> x;
    cnt[x]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << cnt[i] << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  int cnt[100010] = {0};
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> x;
    cnt[x]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << cnt[i] << endl;
  }
  return 0;
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll N;
  cin >> N;
  vector<ll> count(N, 0);
  rep(j, N - 1) {
    ll x;
    cin >> x;
    count.at(x - 1)++;
  }

  rep(i, N) { cout << count.at(i) << endl; }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  ll N;
  cin >> N;
  vector<ll> count(N, 0);
  rep(j, N - 1) {
    ll x;
    cin >> x;
    for (ll i = 1; i <= N; i++) {
      if (i == x) {
        count.at(i - 1)++;
      }
    }
  }

  rep(i, N) { cout << count.at(i) << endl; }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(n) n.begin(), n.end()

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(6);
  int n;
  cin >> n;
  vi a(n);
  rep(i, n - 1) cin >> a[i];

  vi ans(n + 1, 0);
  rep(i, n - 1) { ans[a[i] - 1]++; }

  rep(i, n) { cout << ans[i] << endl; }
  return 0;
}

Error: -6
double free or corruption (out)


Fixed submission:

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(n) n.begin(), n.end()

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(6);
  int n;
  cin >> n;
  vi a(n);
  rep(i, n - 1) cin >> a[i];

  vi ans(n + 1, 0);
  rep(i, n) { ans[a[i] - 1]++; }

  rep(i, n) { cout << ans[i] << endl; }
  return 0;
}
Problem p02707 (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 all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), d(n);
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  for (int i = 1; i < n; i++) {
    d[a[i]]++;
  }
  rep(i, n) cout << d[i] << endl;
}

Error: -6
double free or corruption (out)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), d(n);
  rep(i, n) {
    cin >> a[i];
    a[i]--;
  }
  rep(i, n) { d[a[i]]++; }
  rep(i, n) cout << d[i] << endl;
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N - 1);
  vector<int> answer(N);
  for (int i = 0; i < N; i++) {
    answer.at(i) = 0;
  }
  for (int i = 0; i < N - 1; i++) {
    cin >> vec.at(i);
  }
  for (int i = 0; i < N - 1; i++) {
    int b = vec.at(i);
    answer.at(b - 1)++;
  }
  for (int i = 0; i < N; i++) {
    cout << answer.at(i) << endl;
  }
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 18446744073709551615) >= this->size() (which is 5)


Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
    a.at(i) = 0;
  }
  for (int i = 0; i < N; i++) {
    int j = vec.at(i);
    a.at(j - 1)++;
  }
  for (int i = 0; i < N; i++) {
    cout << a.at(i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {

  int n;
  cin >> n;

  vector<int> b(200000, 0);

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

  for (int i = 0; i < n; i++) {
    cout << b.at(i) << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {

  int n;
  cin >> n;

  vector<int> a(200000, 0);

  for (int i = 0; i < n - 1; i++) {
    cin >> a.at(i);
  }

  for (int i = 1; i <= n; i++) {
    int s = 0;
    for (int j = i - 1; j < n - 1; j++) {
      if (a.at(j) == i) {
        s++;
      }
    }
    cout << s << endl;
  }

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

#include <bits/stdc++.h>

using namespace std;

int arr[1000001];

int main() {
  int n, i, c;
  vector<int> v;

  cin >> n;

  for (i = 1; i < n; i++) {
    cin >> c;
    v.push_back(c);
  }

  for (i = 0; i < n - 1; i++) {
    arr[v[i]]++;
  }

  for (i = 1; i <= n; i++)
    cout << arr[i] << '\\n';

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, i, c;
  vector<int> v;

  cin >> n;

  for (i = 1; i < n; i++) {
    cin >> c;
    v.push_back(c);
  }

  for (i = 1; i <= n; i++) {
    cout << count(v.begin(), v.end(), i) << '\\n';
  }

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

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

  int n, x, i;
  cin >> n;
  for (i = 1; i < n; i++) {
    cin >> x;
    ara[x]++;
  }
  for (i = 1; i <= n; i++) {
    cout << ara[i] << endl;
  }
}


Error: 0

Fixed submission:

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

  int n, x, i;
  cin >> n;
  for (i = 1; i < n; i++) {
    cin >> x;
    ara[x]++;
  }
  for (i = 1; i <= n; i++) {
    cout << ara[i] << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> A.at(i);
  }

  vector<int> buka(N);
  for (int i = 0; i < N; i++) {
    buka.at(i) = 0;
  }

  for (int i = 0; i < N - 1; i++) {
    buka.at(A.at(i) - 1)++;
  }

  for (int i = 0; i < N; i++) {
    cout << buka.at(i) << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N - 1);
  for (int i = 0; i < N - 1; i++) {
    cin >> A.at(i);
  }

  vector<int> buka(N);
  for (int i = 0; i < N; i++) {
    buka.at(i) = 0;
  }

  for (int i = 0; i < N - 1; i++) {
    for (int j = 1; j < N + 1; j++) {
      if (j == A.at(i)) {
        buka.at(j - 1)++;
      }
    }
  }

  for (int i = 0; i < N; i++) {
    cout << buka.at(i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int M = 2 * 100000 + 5;
int s[M], n, x, i;

int main() {
  cin >> n;

  for (i = 2; i <= n; i++) {
    cin >> x;
    s[x]++;
  }

  for (i = 1; i <= n; i++)
    cout << s[i] << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int M = 2 * 10000 + 5;
int s[M], n, x, i;

int main() {
  cin >> n;

  for (i = 2; i <= n; i++) {
    cin >> x;
    s[x]++;
  }

  for (i = 1; i <= n; i++)
    cout << s[i] << endl;

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

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

int main() {
  int N;
  cin >> N;
  vector<int> S(N - 1, 0);
  vector<int> T(N, 0);
  for (int i = 0; i < N - 1; i++) {
    cin >> S.at(i);
    T.at(S.at(i) - 1)++;
  }

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


Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> S(N);
  vector<int> T(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (S.at(j) == i + 1) {
        T.at(i)++;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    cout << T.at(i) << endl;
  }
}
Problem p02707 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef vector<vector<ll>> VVL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main() {
  int N;
  cin >> N;
  VI A(N - 1);
  rep(i, N - 1) cin >> A[i];
  VI B(N);
  rep(i, N - 1) B[A[i] - 1]++;
  rep(i, N) cout << B[i] << endl;
}


Error: -6
double free or corruption (out)


Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef vector<vector<ll>> VVL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main() {
  int N;
  cin >> N;
  VI A(N - 1);
  rep(i, N - 1) cin >> A[i];
  VI B(N);
  rep(i, N) B[A[i] - 1]++;
  rep(i, N) cout << B[i] << endl;
}