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

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, K;
  int d, x;
  int count = 0;

  cin >> N >> K;
  vector<int> sunuke(N);
  for (int i = 0; i < K; i++) {
    cin >> d;
    for (int j = 0; j < d; j++) {
      cin >> x;
      sunuke.at(x - 1) = 1;
    }
  }

  for (int i = 0; i < N; i++) {
    if (sunuke.at(i) == 0)
      count++;
  }

  cout << count;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, K;
  int d, x;
  int count = 0;

  cin >> N >> K;
  vector<int> sunuke(N);
  for (int i = 0; i < K; i++) {
    cin >> d;
    for (int j = 0; j < d; j++) {
      cin >> x;
      sunuke.at(x - 1) = 1;
    }
  }

  for (int i = 0; i < K; i++) {
    if (sunuke.at(i) == 0)
      count++;
  }

  cout << count;
}
Problem p02688 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, K, ans = 0;
  cin >> N >> K;
  vector<bool> S(N, false);
  for (int i = 0; i < K; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int A;
      cin >> A;
      S[A - 1] = true;
    }
  }
  for (int i = 0; i < N; i++) {
    if (S[i])
      ans++;
  }
  cout << N - ans << endl;
}

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


Fixed submission:

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

int main() {
  int N, K, ans = 0;
  cin >> N >> K;
  vector<bool> S(K, false);
  for (int i = 0; i < K; i++) {
    int d;
    vector<int> A(d);
    cin >> d;
    for (int j = 0; j < d; j++) {
      cin >> A[j];
    }
    for (int j = 0; j < d; j++) {
      S[A[j] - 1] = true;
    }
  }
  for (int i = 0; i < K; i++) {
    if (S[i] == true)
      ans++;
  }
  cout << N - ans << endl;
}
Problem p02688 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int d[k];
  int ans[n];
  for (int i = 0; i < n; i++) {
    ans[i] = 0;
  }
  int sum = 0;
  int a[100][100];
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      a[i][j] = 0;
    }
  }
  for (int i = 0; i < k; i++) {
    cin >> d[i];
    for (int j = 0; j < d[i]; j++) {
      cin >> a[i][j];
      if (ans[a[i][j] - 1] == 0) {
        sum += 1;
        ans[a[i][j] - 1] += 1;
      }
    }
  }
  cout << n - sum << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int d[k];
  int ans[n];
  for (int i = 0; i < n; i++) {
    ans[i] = 0;
  }
  int sum = 0;
  int a[n][100];
  for (int i = 0; i < k; i++) {
    cin >> d[i];
    for (int l = 0; l < 100; l++) {
      a[i][l] = 0;
    }
    for (int j = 0; j < d[i]; j++) {
      cin >> a[i][j];
      if (ans[a[i][j] - 1] == 0) {
        sum += 1;
        ans[a[i][j] - 1] += 1;
      }
    }
  }
  cout << n - sum << endl;
}
Problem p02688 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N); // N人の子供を宣言
  // どの子供がどれだけお菓子をもらったかを入力
  for (int i = 0; i < K; i++) {
    int di; // i番目のお菓子をもってる人数
    cin >> di;
    int Ai; // i番目のお菓子を持ってる人の番号
    for (int j = 0; j < di; j++) {
      cin >> Ai;         // お菓子を持ってる人の番号を入力
      A.at(Ai - 1) += 1; // お菓子をもらった人のお菓子の数を＋１
    }
  }
  // A(N)の値を順に調べていって値が0の人数をカウントする
  int count = 0;
  for (int x : A) { // Aの値xをすべて調べる
    if (x == 0)
      count++;
  }
  cout << count << endl;
}


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


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N); // N人の子供を宣言
  // どの子供がどれだけお菓子をもらったかを入力
  for (int i = 0; i < K; i++) {
    int di; // i番目のお菓子をもってる人数
    cin >> di;
    int Ai; // i番目のお菓子を持ってる人の番号
    for (int j = 0; j < di; j++) {
      cin >> Ai;     // お菓子を持ってる人の番号を入力
      A.at(Ai) += 1; // お菓子をもらった人のお菓子の数を＋１
    }
  }
  // A(N)の値を順に調べていって値が0の人数をカウントする
  int count = 0;
  for (int x : A) { // Aの値xをすべて調べる
    if (x == 0)
      count++;
  }
  cout << count << endl;
}
Problem p02688 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)

int main() {
  int n, k, d;
  cin >> n >> k;
  vector<int> A(n), B(n + 1);
  int cnt = 0;
  for (int i = 0; i <= n; i++) {
    B[i] = 0;
  }

  for (int i = 0; i < k; i++) {
    cin >> d;
    for (int j = 0; j < d; j++) {
      cin >> A[j];
      B[A[j]]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (B[i] != 0)
      cnt++;
  }
  cout << n - cnt << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)

int main() {
  int n, k, d;
  cin >> n >> k;
  vector<int> A(k), B(n + 1);
  int cnt = 0;
  for (int i = 0; i <= n; i++) {
    B[i] = 0;
  }

  for (int i = 0; i < k; i++) {
    cin >> d;
    for (int j = 0; j < d; j++) {
      cin >> A[j];
      B[A[j]]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (B[i] == 0)
      cnt++;
  }
  cout << cnt << endl;
}
Problem p02688 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> d(k);
  map<int, int> mp;

  rep(i, k) {
    cin >> d[i];
    int a[k][d[i]];
    rep(j, d[i]) {
      cin >> a[i][j];
      mp[a[i][j]]++;
    }
  }

  put(n - mp.size());
}

Error: 0

Fixed submission:

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> d(k);
  map<int, int> mp;

  rep(i, k) {
    cin >> d[i];
    int a[k][d[k]];
    rep(j, d[i]) {
      cin >> a[i][j];
      mp[a[i][j]]++;
    }
  }

  put(n - mp.size());
}
Problem p02688 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>

template <typename T> T lcm(T a, T b) { return a / __gcd(a, b) * b; }
void comb(vector<vector<ll>> &v) // v{n][k] == nCk
{
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int k = 1; k < v.size(); k++) {
    for (int j = 1; j < k; j++) {
      v[k][j] = v[k - 1][j - 1] + v[k - 1][j];
    }
  }
}
string RunLengthEncoding(string str) {
  int itr = 0;
  std::string res;
  while (itr < int(str.size())) {
    char tmp = str[itr++];
    int length = 1;
    while (itr < int(str.size()) && str[itr] == tmp) {
      ++itr;
      ++length;
    }
    res.push_back(tmp);
    res += to_string(length);
  }
  return res;
}

int a[101][101] = {0};

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n, 0);
  rep(i, k) {
    int d;
    cin >> d;
    rep(i, d) {
      int tmp;
      cin >> tmp;
      tmp--;
      v[tmp]++;
    }
  }
  int ans = 0;
  rep(i, n) {
    if (v[i] == 0) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>

template <typename T> T lcm(T a, T b) { return a / __gcd(a, b) * b; }
void comb(vector<vector<ll>> &v) // v{n][k] == nCk
{
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int k = 1; k < v.size(); k++) {
    for (int j = 1; j < k; j++) {
      v[k][j] = v[k - 1][j - 1] + v[k - 1][j];
    }
  }
}
string RunLengthEncoding(string str) {
  int itr = 0;
  std::string res;
  while (itr < int(str.size())) {
    char tmp = str[itr++];
    int length = 1;
    while (itr < int(str.size()) && str[itr] == tmp) {
      ++itr;
      ++length;
    }
    res.push_back(tmp);
    res += to_string(length);
  }
  return res;
}

int a[101][101] = {0};

int main() {
  int n, k;
  vector<int> v(n, 0);
  cin >> n >> k;
  rep(i, k) {
    int d;
    cin >> d;
    rep(i, d) {
      int tmp;
      cin >> tmp;
      tmp--;
      v[tmp]++;
    }
  }
  ll ans = 0;
  rep(i, n) {
    if (v[i] == 0) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02688 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, K, ans = 0;
  cin >> N >> K;
  vector<int> vec(N, 0);
  for (int i = 0; i < K; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int a;
      cin >> a;
      vec[a - 1] = 1;
    }
  }
  for (int i = 0; i < N; i++) {
    if (vec[i] == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int N, K, ans = 0;
  cin >> N >> K;
  vector<int> vec(K + 1, 0);
  for (int i = 0; i < K; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int a;
      cin >> a;
      vec[a - 1] = 1;
    }
  }
  for (int i = 0; i < N; i++) {
    if (vec[i] == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02688 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>

using namespace std;

int N, K;

int main() {
  cin >> N >> K;
  int d[K + 1], A[K + 1][N + 1];
  int su[N + 1];
  int sum = 0;
  for (int i = 1; i <= N; i++) {
    su[i] = 1;
  }

  for (int i = 1; i <= K; i++) {
    cin >> d[i];
    for (int j = 1; j <= d[i]; j++) {
      cin >> A[i][j];
    }
  }
  for (int i = 1; i <= K; i++) {
    for (int j = 1; j <= d[i]; j++) {
      su[A[i][j]] = 0;
    }
  }
  for (int i = 1; i <= N; i++) {
    sum += su[i];
  }
  cout << sum << endl;
}


Error: 0

Fixed submission:

#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>

using namespace std;

int N, K;

int main() {
  cin >> N >> K;
  int d[K], A[K][N];
  int su[N + 1];
  int sum = 0;
  for (int i = 1; i <= N; i++) {
    su[i] = 1;
  }

  for (int i = 1; i <= K; i++) {
    cin >> d[i];
    for (int j = 1; j <= d[i]; j++) {
      cin >> A[i][j];
    }
  }
  for (int i = 1; i <= K; i++) {
    for (int j = 1; j <= d[i]; j++) {
      su[A[i][j]] = 0;
    }
  }
  for (int i = 1; i <= N; i++) {
    sum += su[i];
  }
  cout << sum << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll a[200010], ans;
bool visited[200010];
vector<int> node[200010];
queue<int> qu;
map<pair<int, int>, bool> taken;
int main() {
  int i, j, v, u, edges, nodes;
  cin >> nodes >> edges;
  for (i = 1; i <= nodes; i++) {
    cin >> a[i];
    visited[i] = true;
  }
  for (i = 1; i <= edges; i++) {
    cin >> u >> v;
    if (a[u] == a[v]) {
      visited[u] = false;
      visited[v] = false;
    } else if (a[u] > a[v]) {
      visited[v] = false;
    } else {
      visited[u] = false;
    }
  }
  for (i = 1; i <= nodes; i++)
    ans += visited[i];
  cout << ans << endl;
  return 0;
}
/*8 9
1 2
1 3
2 5
2 4
4 5
5 6
6 8
6 7
3 7*/


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll a[200010], ans;
bool visited[200010];
vector<int> node[200010];
queue<int> qu;
map<pair<int, int>, bool> taken;
int main() {
  int i, j, v, u, edges, nodes;
  cin >> nodes >> edges;
  for (i = 1; i <= nodes; i++)
    cin >> a[i];
  for (i = 0; i < edges; i++) {
    cin >> u >> v;
    if (taken[{u, v}] != true) {
      node[u].push_back(v);
      node[v].push_back(u);
      taken[{u, v}] = true;
    }
  }
  //    for(i=1;i<=nodes;i++)
  //    {
  //        cout << i << " -> ";
  //        for(j=0;j<node[i].size();j++)
  //            cout << node[i][j] << " ";
  //        cout << endl;
  //    }
  for (i = 1; i <= nodes; i++) {
    if (!visited[i]) {
      qu.push(i);
      visited[i] = true;
      while (!qu.empty()) {
        v = qu.front();
        qu.pop();
        bool cond = true;
        for (i = 0; i < node[v].size(); i++) {
          u = node[v][i];
          if (a[v] <= a[u])
            cond = false;
          if (!visited[u]) {
            visited[u] = true;
            qu.push(u);
          }
        }
        ans += cond;
        //                if(cond)
        //                    cout << v << endl;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
/*8 9
1 2
1 3
2 5
2 4
4 5
5 6
6 8
6 7
3 7*/
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n), max_h(n);
  rep(i, n) {
    cin >> h[i];
    max_h[i] = 0;
  }
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    max_h[a] = max(max_h[a], h[b]);
    max_h[b] = max(max_h[b], h[a]);
  }

  int ans = 0;
  rep(i, n) {
    if (max_h[i] < h[i])
      ans++;
  }
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, m, ans;
  cin >> n >> m;
  ans = n;
  vector<int> h(n);
  rep(i, n) { cin >> h[i]; }
  vector<P> load(m);
  rep(i, m) {
    cin >> load[i].first;
    cin >> load[i].second;
  }

  rep(i, n) {
    rep(j, m) {
      if (i == load[j].first - 1) {
        if (h[load[j].second - 1] >= h[load[j].first - 1]) {
          ans--;
          break;
        }
      } else if (i == load[j].second - 1) {
        if (h[load[j].second - 1] <= h[load[j].first - 1]) {
          ans--;
          break;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
typedef long long ll;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define fr first
#define sc second
#define com(i, n) for (int i = 0; i < n; i++)
#define dom(i, n) for (int i = 1; i <= n; i++)
#define mom(i, n) for (int i = n; i >= 0; i--)
#define sortI(a, n) sort(a, a + n)
#define sortD(a, n) sort(a, a + n, greater<int>())
#define sortvi(a) sort(a.begin(), a.end())
#define sortvd(a) sort(a.begin(), a.end(), greater<int>())
#define sumall(a, x) accumulate(a.begin(), a.end(), x)
#define pi 3.14159265358979323846264338327950
using namespace std;
ll xp[100005] = {0};
int main() {
  ll n, m, cnt = 0, x, y;
  cin >> n >> m;
  ll a[100005];
  dom(i, n) { cin >> a[i]; }
  com(i, m) {
    cin >> x >> y;
    if (a[x] == a[y]) {
      xp[x] = 1;
      xp[y] = 1;
    } else if (a[x] < a[y]) {
      xp[x] = 1;
    } else {
      xp[y] = 1;
    }
  }
  dom(i, n) {
    if (xp[i] == 0) {
      // cout << a[i] << endl;
      cnt++;
    }
  }
  cout << cnt << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
typedef long long ll;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define fr first
#define sc second
#define com(i, n) for (int i = 0; i < n; i++)
#define dom(i, n) for (int i = 1; i <= n; i++)
#define mom(i, n) for (int i = n; i >= 0; i--)
#define sortI(a, n) sort(a, a + n)
#define sortD(a, n) sort(a, a + n, greater<int>())
#define sortvi(a) sort(a.begin(), a.end())
#define sortvd(a) sort(a.begin(), a.end(), greater<int>())
#define sumall(a, x) accumulate(a.begin(), a.end(), x)
#define pi 3.14159265358979323846264338327950
using namespace std;
ll xp[100005] = {0};
int main() {
  ll n, m, cnt = 0, x, y;
  cin >> n >> m;
  ll a[100005];
  dom(i, n) { cin >> a[i]; }
  com(i, m) {
    cin >> x >> y;
    if (a[x] == a[y]) {
      xp[a[x]] = 1;
      xp[a[x]] = 1;
    } else if (a[x] < a[y]) {
      xp[a[x]] = 1;
    } else {
      xp[a[y]] = 1;
    }
  }
  dom(i, n) {
    if (xp[a[i]] == 0) {
      // cout << a[i] << endl;
      cnt++;
    }
  }
  cout << cnt << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int ctoi(const char c) {
  switch (c) {
  case '0':
    return 0;
  case '1':
    return 1;
  case '2':
    return 2;
  case '3':
    return 3;
  case '4':
    return 4;
  case '5':
    return 5;
  case '6':
    return 6;
  case '7':
    return 7;
  case '8':
    return 8;
  case '9':
    return 9;
  default:
    return -1;
  }
}

// 5
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

long long int h[100002] = {};

long long int dat[100001] = {};

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int n, m;

  cin >> n >> m; // n展望台m道数

  long long int a;
  long long int b;

  long long int res = 0;

  for (long long int i = 0; i < n; i++)
    cin >> h[i];

  for (long long int i = 0; i < m; i++) {
    cin >> a >> b;
    dat[a - 1] = max(dat[a - 1], h[b - 1]);
    dat[b - 1] = max(dat[b - 1], h[a - 1]);
  }

  for (long long int i = 0; i < n; i++) {

    if (h[i] > dat[i])
      res++;
  }

  cout << res << endl;
}

// cout << fixed << setprecision(5) <<(n*2)*M_PI << endl;


Error: -11

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int ctoi(const char c) {
  switch (c) {
  case '0':
    return 0;
  case '1':
    return 1;
  case '2':
    return 2;
  case '3':
    return 3;
  case '4':
    return 4;
  case '5':
    return 5;
  case '6':
    return 6;
  case '7':
    return 7;
  case '8':
    return 8;
  case '9':
    return 9;
  default:
    return -1;
  }
}

// 5
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

long long int h[10002] = {};

long long int dat[10001][10001] = {}; // i-jへ道が透るかどうか

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int n, m;

  cin >> n >> m; // n展望台m道数

  long long int a;
  long long int b;

  long long int res = 0;

  for (long long int i = 0; i < n; i++)
    cin >> h[i];

  for (long long int i = 0; i < m; i++) {
    cin >> a >> b;
    dat[a - 1][b - 1] = 1;
    dat[b - 1][a - 1] = 1;
  }

  for (long long int i = 0; i < n; i++) {
    long long int maxi = -1;
    for (long long int j = 0; j < n; j++) {

      if (dat[i][j] == 1)
        maxi = max(maxi, h[j]);
    }

    if (h[i] > maxi)
      res++;
  }

  cout << res << endl;
}

// cout << fixed << setprecision(5) <<(n*2)*M_PI << endl;
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
#define N 100010
int main() {
  int n, m, h[N], ma[N];
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
    ma[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    ma[a] = max(ma[a], h[b]);
    ma[b] = max(ma[b], h[a]);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += h[i] > ma[i];
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

vector<int> arr;
vector<int> M;
int solve() {
  long long n, m, a, b;
  cin >> n >> m;
  arr.resize(n);
  M.resize(m);
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    M[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    M[a] = max(M[a], arr[b]);
    M[b] = max(M[b], arr[a]);
  }
  int ans = 0;
  for (int i = 1; i < arr.size(); i++) {
    ans += M[i] > arr[i];
  }
  return ans;
}

int main() {

  cout << solve() << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N), A(M), B(M);
  for (int i = 0; i < N; ++i) {
    cin >> H[i];
  }
  for (int i = 0; i < M; ++i) {
    cin >> A[i] >> B[i];
  }

  vector<vector<int>> g(N);
  for (int i = 0; i < M; ++i) {
    g[A[i] - 1].push_back(B[i] - 1), g[B[i] - 1].push_back(A[i] - 1);
  }

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    bool is_good = true;
    for (size_t j = 0; j < g[i].size(); ++j) {
      if (H[i] <= H[g[i][j]]) {
        is_good = false;
      }
    }

    if (is_good) {
      ++ans;
    }
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> /* H(N), */ A(M), B(M);
  int H[6];
  for (int i = 0; i < N; ++i) {
    cin >> H[i];
  }
  for (int i = 0; i < M; ++i) {
    cin >> A[i] >> B[i];
  }

  vector<vector<int>> g(N);
  for (int i = 0; i < M; ++i) {
    g[A[i] - 1].push_back(B[i] - 1), g[B[i] - 1].push_back(A[i] - 1);
  }

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    bool is_good = true;
    for (size_t j = 0; j < g[i].size(); ++j) {
      if (H[i] <= H[g[i][j]]) {
        is_good = false;
      }
    }

    if (is_good) {
      ++ans;
    }
  }

  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

signed main() {
  int N, M;
  cin >> N >> M;

  vector<ll> H(N + 1);
  rep(i, N) cin >> H[i + 1];

  vector<vector<ll>> A(2, vector<ll>(M));
  rep(i, M) cin >> A.at(0).at(i) >> A.at(1).at(i);

  //    cout << "aaa" << endl;
  vector<ll> R(N + 1);
  rep(i, M) {
    int f = A.at(0).at(i);
    int s = A.at(1).at(i);
    //       cout << H[f] << "vs" << H[s] << endl;
    if (H[f] > H[s]) {
      R[s] = -1;
    } else if (H[f] < H[s]) {
      R[f] = -1;
    } else {
      R[f] = -1;
      R[s] = -1;
    }
  }

  //    cout << "bbb" << endl;

  int ans = 0;
  rep(i, N) {
    //        cout << "R[" << i+1 << "]=" << R[i+1] << endl;
    if (R[i + 1] != -1)
      ans++;
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

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

signed main() {
  int N, M;
  cin >> N >> M;

  vector<ll> H(N + 1);
  rep(i, N) cin >> H[i + 1];

  vector<vector<ll>> A(2, vector<ll>(M));
  rep(i, M) cin >> A.at(0).at(i) >> A.at(1).at(i);

  //    cout << "aaa" << endl;
  vector<ll> R(N);
  rep(i, M) {
    int f = A.at(0).at(i);
    int s = A.at(1).at(i);
    //       cout << H[f] << "vs" << H[s] << endl;
    if (H[f] > H[s]) {
      R[s] = -1;
    } else if (H[f] < H[s]) {
      R[f] = -1;
    } else {
      R[f] = -1;
      R[s] = -1;
    }
  }

  //    cout << "bbb" << endl;

  int ans = 0;
  rep(i, N) {
    //        cout << "R[" << i+1 << "]=" << R[i+1] << endl;
    if (R[i + 1] != -1)
      ans++;
  }

  cout << ans << endl;
}