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

#include <iostream>

using namespace std;

int main() {
  int N, M;
  int H[100000] = {0};
  int NoGood[100000] = {0};
  cin >> N >> M;

  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }

  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    if (H[A - 1] > H[B - 1]) {
      NoGood[B - 1]++;
    } else if (H[A - 1] < H[B - 1]) {
      NoGood[A - 1]++;
    } else {
      NoGood[A - 1]++;
      NoGood[B - 1]++;
    }
  }

  int GoodCounter = 0;
  for (int i = 0; i < N; i++) {
    if (NoGood[i] == 0) {
      GoodCounter++;
    }
  }

  cout << GoodCounter << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int N, M;
  int H[10 ^ 5] = {0};
  int NoGood[10 ^ 5] = {0};
  cin >> N >> M;

  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }

  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    if (H[A - 1] > H[B - 1]) {
      NoGood[B - 1]++;
    } else if (H[A - 1] < H[B - 1]) {
      NoGood[A - 1]++;
    } else {
      NoGood[A - 1]++;
      NoGood[B - 1]++;
    }
  }

  int GoodCounter = 0;
  for (int i = 0; i < N; i++) {
    if (NoGood[i] == 0) {
      GoodCounter++;
    }
  }

  cout << GoodCounter << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, m;
  vector<int> h;
  cin >> n >> m;
  vector<bool> rr(n, false);
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    h.push_back(t);
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (h[a] == h[b]) {
      rr[a] = true;
      rr[b] = true;
    } else if (h[a] < h[b]) {
      rr[a] = true;
    } else {
      rr[b] = true;
    }
  }

  int r = 0;
  for (int i = 0; i < n; i++) {
    if (rr[i] == false) {
      r++;
    }
  }
  cout << r << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int n, m;
  vector<int> h, a, b;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    h.push_back(t);
  }
  for (int i = 0; i < m; i++) {
    int ta, tb;
    cin >> ta >> tb;
    ta--;
    tb--;
    a.push_back(min(ta, tb));
    b.push_back(max(ta, tb));
  }

  int r = 0;
  for (int i = 0; i < n; i++) {
    bool found = false;
    for (int j = 0; j < m; j++) {
      if ((a[j] == i && h[b[j]] >= h[i]) || (b[j] == i && h[a[j]] >= h[i])) {
        found = true;
      }
    }
    if (!found) {
      r++;
    }
  }
  cout << r << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int good[100100];
long long nums[100100];
int main() {
  for (int i = 0; i < 100100; ++i)
    good[i] = 1;
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> nums[i];
  }
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    if (nums[x] <= nums[y] && good[x] != 0)
      good[x] = 0;

    if (nums[y] <= nums[x] && good[y] != 0)
      good[y] = 0;
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (good[i] == 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int good[10010];
long long nums[10010];
int main() {
  memset(good, 1, sizeof(good));
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> nums[i];
  }
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    if (nums[x] <= nums[y] && good[x] != 0)
      good[x] = 0;

    if (nums[y] <= nums[x] && good[y] != 0)
      good[y] = 0;
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (good[i] == 0)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll << 60;

using Graph = vector<vector<ll>>;
Graph G;
vector<ll> dist;

int main(int argc, char **argv) {
  ll N, M;
  cin >> N >> M;
  vector<ll> H(N);
  for (ll i = 0; i < N; ++i)
    cin >> H[i];
  G.resize(N);

  for (ll i = 0; i < M; ++i) {
    ll a, b;
    cin >> a >> b;
    --a, --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  ll res{0};
  for (ll v = 0; v < N; ++v) {
    ll ok{true};
    ll th = H[v];
    for (auto &nv : G[v]) {
      if (th <= H[nv])
        ok = false;
    }
    if (ok)
      ++res;
  }
  std::cout << res << std::endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll << 60;

using Graph = vector<vector<ll>>;
Graph G;
vector<ll> dist;

int main(int argc, char **argv) {
  ll N, M;
  cin >> N >> M;
  vector<ll> H(N);
  for (ll i = 0; i < N; ++i)
    cin >> H[i];
  G.resize(N);

  for (ll i = 0; i < M; ++i) {
    ll a, b;
    cin >> a >> b;
    --a, --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  ll res{0};
  for (ll v = 0; v < N; ++v) {
    dist.assign(N, -1);
    dist[v] = 0;
    queue<ll> que;
    que.push(v);

    while (!que.empty()) {
      ll now = que.front();
      que.pop();

      for (auto &nv : G[now]) {
        if (dist[nv] != -1)
          continue;
        dist[nv] = dist[now] + 1;
        que.push(nv);
      }
    }

    ll ok{true};
    ll th = H[v];
    for (ll vv = 0; vv < N; ++vv) {
      if (v == vv)
        continue;
      if (dist[vv] == 1) {
        if (th <= H[vv])
          ok = false;
      }
    }
    if (ok)
      ++res;
  }
  std::cout << res << std::endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, p, q;
  cin >> n >> m;
  long long int h[n], a[n] = {0};
  for (long long int i = 0; i < n; i++) {
    cin >> h[i];
  }
  for (long long int i = 0; i < m; i++) {
    cin >> p >> q;
    if (h[p - 1] > h[q - 1]) {
      a[q - 1] = 1;
    } else if (h[p - 1] < h[q - 1])
      a[p - 1] = 1;
    else {
      a[p - 1] = 1;
      a[q - 1] = 1;
    }
  }
  long long int count = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == 0)
      count++;
  }
  cout << count;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, p, q;
  cin >> n >> m;
  long long int h[n], a[n][n];
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      a[i][j] = 0;
    }
  }
  for (long long int i = 0; i < n; i++) {
    cin >> h[i];
  }
  for (long long int i = 0; i < m; i++) {
    cin >> p >> q;
    a[p - 1][q - 1] = 1;
    a[q - 1][p - 1] = 1;
  }
  long long int count = 0, flag = 0;
  for (long long int i = 0; i < n; i++) {
    flag = 0;
    for (long long int j = 0; j < n; j++) {
      if (a[i][j] == 1) {
        if (h[j] >= h[i]) {
          flag = 1;
          break;
        }
      }
    }
    if (flag == 0)
      count++;
  }
  cout << count;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

#define ll long long
#define f(i, a, b) for (ll i = a; i < b; i++)
#define endl '\\n'
#define spc " "
#define pb push_back
#define mp make_pair
#define mod 1000000007

vector<vector<ll>> vii;

int main()

{
  ios::sync_with_stdio(0);
  cin.tie(0);
  // freopen("in.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  ll n, m, c = 0;
  cin >> n >> m;
  map<ll, ll> k;
  vii.resize(n + n);
  f(i, 1, n + 1) {
    ll x;
    cin >> x;
    k[i] = x;
  }
  while (m--) {
    ll x, y;
    cin >> x >> y;
    vii[x].pb(y);
    vii[y].pb(x);
  }
  f(i, 1, n + 1) {
    if (vii[i].size() > 0) {
      ll flag = 1;
      f(j, 0, vii[i].size()) {
        if (k[vii[i][j]] >= k[i]) {
          flag = 0;
          break;
        }
      }
      if (flag == 1)
        c++;
    } else
      c++;
  }
  cout << c << endl;
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

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

#define ll long long
#define f(i, a, b) for (ll i = a; i < b; i++)
#define endl '\\n'
#define spc " "
#define pb push_back
#define mp make_pair
#define mod 1000000007

vector<vector<ll>> vii;

int main()

{
  ios::sync_with_stdio(0);
  cin.tie(0);
  freopen("in.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  ll n, m, c = 0;
  cin >> n >> m;
  map<ll, ll> k;
  vii.resize(n + n);
  f(i, 1, n + 1) {
    ll x;
    cin >> x;
    k[i] = x;
  }
  while (m--) {
    ll x, y;
    cin >> x >> y;
    vii[x].pb(y);
    vii[y].pb(x);
  }
  f(i, 1, n + 1) {
    if (vii[i].size() > 0) {
      ll flag = 1;
      f(j, 0, vii[i].size()) {
        if (k[vii[i][j]] > k[i]) {
          flag = 0;
          break;
        }
      }
      if (flag == 1)
        c++;
    }
  }
  cout << c << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long ll;

int main() {
  int n, m, ans = 0;
  cin >> n >> m;
  vector<int> h(n), good(n, 1), a(m), b(m);
  rep(i, n) cin >> h[i];
  rep(i, m) cin >> a[i] >> b[i];

  rep(i, m) {
    if (h[a[i] - 1] < h[b[i] - 1]) {
      good[a[i] - 1] = 0;
    } else if (h[a[i] - 1] > h[b[i] - 1]) {
      good[b[i] - 1] = 0;
    } else {
      good[a[i] - 1] = 0;
      good[b[i] - 1] = 0;
    }
  }
  rep(i, n) {
    if (good[i])
      ans++;
  }
  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long ll;

int main() {
  int n, m, ans = 0;
  cin >> n >> m;
  vector<int> h(n), good(n, 1), a(n), b(n);
  rep(i, n) cin >> h[i];
  rep(i, m) cin >> a[i] >> b[i];

  rep(i, m) {
    if (h[a[i] - 1] < h[b[i] - 1]) {
      good[a[i] - 1] = 0;
      //    cout<<h[a[i]-1]<<endl;
    } else if (h[a[i] - 1] > h[b[i] - 1]) {
      good[b[i] - 1] = 0;
      //    cout<<h[b[i]-1]<<endl;
    } else {
      good[a[i] - 1] = 0;
      good[b[i] - 1] = 0;
    }
  }
  rep(i, n) {
    if (good[i])
      ans++;
  }
  cout << ans << endl;

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

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

using namespace std;

int main() {
  int n, m;

  cin >> n >> m;

  vector<int> h(n);

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

  vector<vector<int>> pathlist(n, vector<int>{});

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;

    pathlist[a - 1].push_back(b - 1);
    pathlist[b - 1].push_back(a - 1);
  }

  int sum = 0;

  for (int i = 0; i < n; i++) {
    bool flg = true;

    for (auto j : pathlist[i]) {
      if (h[i] <= h[j]) {
        flg = false;
        break;
      }
    }

    if (flg) {
      sum++;
    }
  }

  cout << sum << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

enum vertexColor {
  BLACK = 1,
  GRAY = 0,
  WHITE = -1,
};

void isConnected_sub(const vector<vector<int>> pathlist, int v,
                     vector<vertexColor> &colorState);

int main() {
  int n, m;

  cin >> n >> m;

  vector<int> h(n);

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

  vector<vector<int>> pathlist(n, vector<int>{});

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;

    pathlist[a - 1].push_back(b - 1);
    pathlist[b - 1].push_back(a - 1);
  }

  int sum = 0;

  for (int i = 0; i < n; i++) {
    vector<vertexColor> colorState(n, WHITE);
    bool flg = true;

    for (auto j : pathlist[i]) {
      if (h[i] <= h[j]) {
        flg = false;
        break;
      }
    }

    if (flg) {
      sum++;
    }
  }

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

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

int h[100001];
// int mx[100001];
vector<int> edges[100001];
int n, m;

int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> h[i];
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    edges[a - 1].push_back(b - 1);
    edges[b - 1].push_back(a - 1);
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    bool ok = true;
    for (int j = 0; j < edges[i].size(); j++) {
      if (h[edges[i][j]] >= h[i]) {
        ok = 0;
      }
    }
    if (ok)
      sum++;
  }
  cout << sum << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int h[100001], t[100001];
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    t[h[i] - 1] = i;
  }
  bool ok[100001];
  for (int i = 0; i < n; i++)
    ok[i] = true;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (a > b)
      ok[t[b - 1]] = false;
    if (b > a)
      ok[t[a - 1]] = false;
  }
  int sum = 0;
  for (int i = 0; i < n; i++)
    if (ok[i] == true)
      sum++;
  cout << sum << 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);

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

  vector<vector<int>> G(M, vector<int>(2));
  for (int j = 0; j < M; j++) {
    cin >> G.at(j).at(0) >> G.at(j).at(1);
  }

  set<int> MAX;
  set<int> MIN;
  set<int> ALL;

  for (int k = 0; k < M; k++) {
    if (H.at(G.at(k).at(0) - 1) > H.at(G.at(k).at(1) - 1)) {
      MAX.insert(G.at(k).at(0));
      MIN.insert(G.at(k).at(1));
    } else if (H.at(G.at(k).at(0) - 1) < H.at(G.at(k).at(1) - 1)) {
      MAX.insert(G.at(k).at(1));
      MIN.insert(G.at(k).at(0));
    } else if (H.at(G.at(k).at(0) - 1) == H.at(G.at(k).at(1) - 1)) {
      MIN.insert(G.at(k).at(0));
      MIN.insert(G.at(k).at(1));
    }
    ALL.insert(G.at(k).at(0));
    ALL.insert(G.at(k).at(1));
  }

  int EX = N - ALL.size();

  for (int l = 1; l < N + 1; l++) {
    if (MAX.count(l) && MIN.count(l)) {
      MAX.erase(l);
    }
  }

  cout << MAX.size() + EX << 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 3)


Fixed submission:

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

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

  vector<int> H(N);

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

  vector<vector<int>> G(M, vector<int>(2));
  for (int j = 0; j < M; j++) {
    cin >> G.at(j).at(0) >> G.at(j).at(1);
  }

  set<int> MAX;
  set<int> MIN;
  set<int> ALL;

  for (int k = 0; k < M; k++) {
    if (H.at(G.at(k).at(0) - 1) > H.at(G.at(k).at(1) - 1)) {
      MAX.insert(G.at(k).at(0));
      MIN.insert(G.at(k).at(1));
    } else if (H.at(G.at(k).at(0) - 1) < H.at(G.at(k - 1).at(1) - 1)) {
      MAX.insert(G.at(k).at(1));
      MIN.insert(G.at(k).at(0));
    } else if (H.at(G.at(k).at(0) - 1) == H.at(G.at(k - 1).at(1) - 1)) {
      MIN.insert(G.at(k).at(0));
      MIN.insert(G.at(k).at(1));
    }
    ALL.insert(G.at(k).at(0));
    ALL.insert(G.at(k).at(1));
  }

  int EX = N - ALL.size();

  for (int l = 1; l < N + 1; l++) {
    if (MAX.count(l) && MIN.count(l)) {
      MAX.erase(l);
    }
  }

  cout << MAX.size() + EX << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (i = 0; i < n; i++)
#define rep1(i, n) for (i = 1; i <= n; i++)
#define test(a) cout << "*" << a << endl
#define ll long long
int main() {
  int n, m;
  int i;
  ll H[100001];
  ll A[100001];
  ll B[100001];
  ll countGood = 0;
  bool existM[100001];

  cin >> n >> m;
  rep1(i, n) { cin >> H[i]; }
  rep1(i, m) { cin >> A[i] >> B[i]; }
  rep1(i, n) { existM[i] = true; }

  rep1(i, m) {
    if (H[A[i]] > H[B[i]]) {
      existM[B[i]] = false;
    } else if (H[A[i]] < H[B[i]]) {
      existM[A[i]] = false;
    } else {
      existM[A[i]] = false;
      existM[B[i]] = false;
    }
    // existM[ min(H[A[i]],H[B[i])]] = false;/*負けた展望台*/
  }

  rep1(i, n) {
    if (existM[i])
      countGood++;
  }
  cout << countGood << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (i = 0; i < n; i++)
#define rep1(i, n) for (i = 1; i <= n; i++)
#define test(a) cout << "*" << a << endl
#define ll long long
int main() {
  int n, m, k;
  int i, j;
  ll H[100001];
  ll A[100001];
  ll B[100001];
  ll countGood = 0;
  bool exist[100001];

  cin >> n >> m;
  rep1(i, n) { cin >> H[i]; }
  rep1(i, m) { cin >> A[i] >> B[i]; }

  rep1(i, n) { exist[i] = true; }

  rep1(i, n) {
    if (exist[i] == false) {
      continue;
    }
    rep1(j, m) {
      if (i == A[j]) {
        if (H[B[j]] >= H[i]) {
          exist[i] = false;
          break;
        } else {
          exist[B[j]] = false;
        }
      } else if (i == B[j]) {
        if (H[A[j]] >= H[i]) {
          exist[i] = false;
          break;
        } else {
          exist[A[j]] = false;
        }
      } else {
        continue;
      }
    }
  }

  /*test(i);
  test(j);
  test("*");*/

  for (i = 1; i <= n; i++) {
    if (exist[i] == true) {
      countGood++;
    }
  }
  /*if(exist==true){
    countGood++;
  }*/

  cout << countGood << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int *h = new int[n];
  int *h2 = new int[n]{};
  int *a = new int[m];
  int *b = new int[m];
  for (int i = 0; i < n; i++)
    cin >> h[i];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  for (int i = 0; i < m; i++) {
    if (h[a[i]] > h[b[i]]) {
      h2[b[i]] = -1;
    } else if (h[a[i]] < h[b[i]]) {
      h2[a[i]] = -1;
    } else if (h[a[i]] == h[b[i]]) {
      h2[a[i]] = h2[b[i]] = -1;
    }
  }
  int c = 0;
  for (int i = 0; i < n; i++) {
    if (h2[i] != -1)
      c++;
  }
  cout << c << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int *h = new int[n];
  int *a = new int[m];
  int *b = new int[m];
  for (int i = 0; i < n; i++)
    cin >> h[i];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  int c = 0;
  for (int i = 0; i < n; i++) {
    bool f = true;
    for (int j = 0; j < m; j++) {
      if (a[j] == i) {
        if (h[i] <= h[b[j]]) {
          f = false;
          break;
        }
      } else if (b[j] == i) {
        if (h[i] <= h[a[j]]) {
          f = false;
          break;
        }
      }
    }
    if (f)
      c++;
  }
  cout << c << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int i, j, n, m, a, b, c;
string s;
int main() {
  cin >> n >> m;
  vector<int> h(n);
  for (; i < n; i++)
    cin >> h[i];
  vector<bool> x(n);
  for (i = 0; i < n; i++)
    x[i] = true;
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;
    if (h[a] <= h[b])
      x[a] = false;
    if (h[b] <= h[a])
      x[b] = false;
  }
  for (i = 0; i < n; i++)
    if (x[i])
      c++;
  cout << c;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int i, j, n, m, k, a, b, c;
string s;
int main() {
  cin >> n >> m;
  vector<int> h(n);
  for (; i < n; i++)
    cin >> h[i];
  vector<vector<int>> g(n, vector<int>(n));
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++)
      g[i][j] = 0;
  for (i = 0; i < m; ++i) {
    cin >> a >> b;
    a--;
    b--;
    g[a][b] = 1;
    g[b][a] = 1;
  }

  for (i = 0; i < n; i++) {
    k = h[i];
    bool res = true;
    for (j = 0; j < n; j++) {
      if (g[i][j] == 1) {
        if (k <= h[j]) {
          res = false;
          break;
        }
      }
    }
    if (res)
      c++;
  }
  cout << c;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;

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

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

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

  int ans = 0;

  for (int i = 0; i < n; i++) {
    bool good = true;
    for (long unsigned int j = 0; j < graph[i].size(); j++) {
      int c = graph[i][j];
      if (h[i] <= h[c])
        good = false;
    }
    if (good)
      ans++;
  }

  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

vector<int> graph[10010];

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

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

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

  int ans = 0;

  for (int i = 0; i < n; i++) {
    bool good = true;
    for (long unsigned int j = 0; j < graph[i].size(); j++) {
      int c = graph[i][j];
      if (h[i] <= h[c])
        good = false;
    }
    if (good)
      ans++;
  }

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

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
string char_to_string(char val) { return string(1, val); }
int char_to_int(char val) { return val - '0'; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  } else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  ll N, M;
  cin >> N >> M;
  vector<int> H(100010);
  for (int i = 1; i <= N; ++i)
    cin >> H[i];
  vector<int> A(M), B(M);
  REP(i, M) cin >> A[i] >> B[i];

  vector<int> ans(100010);
  for (int i = 1; i <= N; ++i)
    ans[i] = 0;

  REP(i, M) {
    ans[A[i]] = max(ans[A[i]], H[B[i]]);
    ans[B[i]] = max(ans[B[i]], H[A[i]]);
  }

  int cnt = 0;
  for (int i = 1; i <= N; ++i) {
    if (H[i] > ans[i])
      cnt++;
  }

  cout << cnt << endl;
}

Error: 0

Fixed submission:

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
string char_to_string(char val) { return string(1, val); }
int char_to_int(char val) { return val - '0'; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  } else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  ll N, M;
  cin >> N >> M;
  vector<int> H(N);
  for (int i = 1; i < N + 1; ++i)
    cin >> H[i];
  vector<long long> A(M), B(M);
  REP(i, M) cin >> A[i] >> B[i];

  vector<int> ans(N + 1);
  REP(i, N + 1) ans[i] = 0;

  REP(i, M) {
    ans[A.at(i)] = max(ans[A[i]], H[B[i]]);
    ans[B.at(i)] = max(ans[B[i]], H[A[i]]);
  }

  int cnt = 0;
  for (int i = 1; i < N + 1; ++i) {
    if (H[i] > ans[i])
      cnt++;
  }

  cout << cnt << endl;
}