prithivMLmods/Coder-Stat huggingface dataset:
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
struct edge {
  int v, nxt;
} e[200010];
int head[200010], cnt, n, m, w[100010], x, y, ans;
inline void add(int u, int v) {
  e[++cnt].v = v;
  e[cnt].nxt = head[u];
  head[u] = cnt;
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; ++i)
    w[i] = read();
  for (int i = 1; i <= m; ++i)
    x = read(), y = read(), add(x, y), add(y, x);
  for (int u = 1; u <= n; ++u) {
    bool flag = 1;
    for (int i = head[u]; i; i = e[i].nxt) {
      int v = e[i].v;
      flag &= w[u] > w[v];
    }
    if (flag)
      ans++;
  }
  return printf("%d\n", ans);
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
struct edge {
  int v, nxt;
} e[200010];
int head[200010], cnt, n, m, w[100010], x, y, ans;
inline void add(int u, int v) {
  e[++cnt].v = v;
  e[cnt].nxt = head[u];
  head[u] = cnt;
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; ++i)
    w[i] = read();
  for (int i = 1; i <= m; ++i)
    x = read(), y = read(), add(x, y), add(y, x);
  for (int u = 1; u <= n; ++u) {
    bool flag = 1;
    for (int i = head[u]; i; i = e[i].nxt) {
      int v = e[i].v;
      flag &= w[u] > w[v];
    }
    if (flag)
      ans++;
  }
  return printf("%d\n", ans) & 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  long long n, m;
  bool check[10001];
  long long H[10001];
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> H[i];
    check[i] = true;
  }
  int A, B;
  for (int i = 0; i < m; i++) {
    cin >> A >> B;
    if (H[A] > H[B]) {
      check[B] = false;
    } else if (H[A] < H[B]) {
      check[A] = false;
    } else {
      check[A] = false;
      check[B] = false;
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (check[i]) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

int main() {
  long long n, m;
  bool check[100001];
  long long H[100001];
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> H[i];
    check[i] = true;
  }
  int A, B;
  for (int i = 0; i < m; i++) {
    cin >> A >> B;
    if (H[A] > H[B]) {
      check[B] = false;
    } else if (H[A] < H[B]) {
      check[A] = false;
    } else {
      check[A] = false;
      check[B] = false;
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (check[i]) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;

int main() {
  int N, M, a, b;
  vector<int> ma(M, 0), h(M, 0);
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    cin >> h[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    ma[a] = max(ma[a], h[b]);
    ma[b] = max(ma[b], h[a]);
  }
  int c = 0;
  for (int i = 1; i <= N; i++) {
    if (ma[i] < h[i])
      c += 1;
  }
  cout << c << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;

int main() {
  int N, M, a, b;
  vector<int> ma(1000000, 0), h(1000000, 0);
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    cin >> h[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    ma[a] = max(ma[a], h[b]);
    ma[b] = max(ma[b], h[a]);
  }
  int c = 0;
  for (int i = 1; i <= N; i++) {
    if (ma[i] < h[i])
      c += 1;
  }
  cout << c << endl;
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
//
//
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define is_in(i, s) (s.find(i) != s.end())
#define all(x) (x).begin(), (x).end()
#define outl(x) cout << x << endl
#define outsp(x) cout << x << " "
typedef long long ll;
typedef pair<int, int> P;

#define MAX_N 10005
int h[MAX_N];
vector<int> edge[MAX_N];

int main() {
  int n, m;
  cin >> n >> m;
  rep(i, n) cin >> h[i];
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  int ans = 0;
  rep(i, n) {
    bool good = true;
    rep(j, edge[i].size()) {
      if (h[i] <= h[edge[i][j]]) {
        good = false;
        break;
      }
    }
    ans += good;
  }
  outl(ans);

  return 0;
}


Fixed submission:
//
//
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define is_in(i, s) (s.find(i) != s.end())
#define all(x) (x).begin(), (x).end()
#define outl(x) cout << x << endl
#define outsp(x) cout << x << " "
typedef long long ll;
typedef pair<int, int> P;

#define MAX_N 100005
int h[MAX_N];
vector<int> edge[MAX_N];

int main() {
  int n, m;
  cin >> n >> m;
  rep(i, n) cin >> h[i];
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  int ans = 0;
  rep(i, n) {
    bool good = true;
    rep(j, edge[i].size()) {
      if (h[i] <= h[edge[i][j]]) {
        good = false;
        break;
      }
    }
    ans += good;
  }
  outl(ans);

  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include <bits/stdc++.h>
#define pi 2 * acos(0.0)
#define ll long long
#define FIO                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define Node struct node
#define spc " "
#define E 2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx, ny) nx >= 0 && nx < n &&ny >= 0 && ny < m
#define ee endl
#define pii pair<int, int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[] = {0, 0, +1, -1};
int fy[] = {+1, -1, 0, 0};

using namespace std;
/// check n=1;
/// check corner case;
const int maX = 1e3 + 1;
vector<ll> Graph[maX], cost[maX];
ll visit[maX];

int main() {
  ll n, k, i, j, cc = 0;
  cin >> n >> k;
  ll ara[n + 1];
  for (i = 1; i <= n; i++)
    cin >> ara[i];
  for (i = 1; i <= k; i++) {
    ll x, y;
    cin >> x >> y;
    Graph[x].pb(y);
    Graph[y].pb(x);
  }
  for (i = 1; i <= n; i++) {
    ll l = 0;
    for (j = 0; j < Graph[i].size(); j++) {
      ll u = Graph[i][j];
      if (ara[i] <= ara[u]) {
        l = 1;
        break;
      }
    }
    if (l == 0)
      cc++;
  }
  cout << cc << endl;
  return 0;
}


Fixed submission:
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include <bits/stdc++.h>
#define pi 2 * acos(0.0)
#define ll long long
#define FIO                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define Node struct node
#define spc " "
#define E 2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx, ny) nx >= 0 && nx < n &&ny >= 0 && ny < m
#define ee endl
#define pii pair<int, int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[] = {0, 0, +1, -1};
int fy[] = {+1, -1, 0, 0};

using namespace std;
/// check n=1;
/// check corner case;
const int maX = 1e5 + 1;
vector<ll> Graph[maX], cost[maX];
ll visit[maX];

int main() {
  ll n, k, i, j, cc = 0;
  cin >> n >> k;
  ll ara[n + 1];
  for (i = 1; i <= n; i++)
    cin >> ara[i];
  for (i = 1; i <= k; i++) {
    ll x, y;
    cin >> x >> y;
    Graph[x].pb(y);
    Graph[y].pb(x);
  }
  for (i = 1; i <= n; i++) {
    ll l = 0;
    for (j = 0; j < Graph[i].size(); j++) {
      ll u = Graph[i][j];
      if (ara[i] <= ara[u]) {
        l = 1;
        break;
      }
    }
    if (l == 0)
      cc++;
  }
  cout << cc << endl;
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1);
  for (int i = 1; i < n; i++) {
    cin >> a[i];
  }
  vector<bool> ans(n + 1, 1);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;

    ans[x] = ans[x] && (a[x] > a[y]);
    ans[y] = ans[y] && (a[y] > a[x]);
  }
  int count = 0;
  for (int i = 1; i <= n; i++) {
    if (ans[i]) {
      count++;
    }
  }

  cout << count;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vector<bool> ans(n + 1, 1);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;

    ans[x] = ans[x] && (a[x] > a[y]);
    ans[y] = ans[y] && (a[y] > a[x]);
  }
  int count = 0;
  for (int i = 1; i <= n; i++) {
    if (ans[i]) {
      count++;
    }
  }

  cout << count;

  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10005;
int H[MAXN];
bool Bad[MAXN];

int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 1; i <= N; ++i)
    cin >> H[i];

  for (int i = 1; i <= M; ++i) {
    int u, v;
    cin >> u >> v;

    if (H[u] <= H[v])
      Bad[u] = true;
    if (H[v] <= H[u])
      Bad[v] = true;
  }

  int ans = 0;
  for (int i = 1; i <= N; ++i)
    if (!Bad[i])
      ans++;

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int H[MAXN];
bool Bad[MAXN];

int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 1; i <= N; ++i)
    cin >> H[i];

  for (int i = 1; i <= M; ++i) {
    int u, v;
    cin >> u >> v;

    if (H[u] <= H[v])
      Bad[u] = true;
    if (H[v] <= H[u])
      Bad[v] = true;
  }

  int ans = 0;
  for (int i = 1; i <= N; ++i)
    if (!Bad[i])
      ans++;

  cout << ans << endl;

  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int, int>
#define vi vector<int>
#define vpi vector<pi>
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL)
const int N = 102, M = 11;
int a[N], h[N];
vi v[N];
int main() {
  int n, m, x, y;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  while (m--) {
    cin >> x >> y;
    if (h[x] <= h[y])
      a[x] = 1;
    if (h[y] <= h[x])
      a[y] = 1;
  }
  int r = 0;
  for (int i = 1; i <= n; i++)
    r += (a[i] == 0);
  cout << r;
  return 0;
}

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

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int, int>
#define vi vector<int>
#define vpi vector<pi>
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL)
const int N = 100002, M = 11;
int a[N], h[N];
vi v[N];
int main() {
  int n, m, x, y;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  while (m--) {
    cin >> x >> y;
    if (h[x] <= h[y])
      a[x] = 1;
    if (h[y] <= h[x])
      a[y] = 1;
  }
  int r = 0;
  for (int i = 1; i <= n; i++)
    r += (a[i] == 0);
  cout << r;
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

int main() {
  long long n, m;

  cin >> n >> m;
  vector<long long> h(n);
  vector<long long> ma(n);
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
    ma[i] = 0;
  }
  for (int i = 1; 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++) {
    if (ma[i] < h[i])
      ans++;
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

int main() {
  long long n, m;

  cin >> n >> m;
  vector<long long> h(n + 1);
  vector<long long> ma(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
    ma[i] = 0;
  }
  for (int i = 1; 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++) {
    if (ma[i] < h[i])
      ans++;
  }
  cout << ans << endl;

  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long a[10005];
  int t[10005];
  int n, m;
  int i, j, k, ans;
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    cin >> a[i];
  for (i = 1; i <= n; i++)
    t[i] = 1;
  for (i = 1; i <= m; i++) {
    cin >> j >> k;
    if (a[j] > a[k])
      t[k] = 0;
    else
      t[j] = 0;
    if (a[k] == a[j]) {
      t[j] = 0;
      t[k] = 0;
    }
  }
  ans = 0;
  for (i = 1; i <= n; i++) {
    if (t[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  long long a[100005];
  int t[100005];
  int n, m;
  int i, j, k, ans;
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    cin >> a[i];
  for (i = 1; i <= n; i++)
    t[i] = 1;
  for (i = 1; i <= m; i++) {
    cin >> j >> k;
    if (a[j] > a[k])
      t[k] = 0;
    else
      t[j] = 0;
    if (a[k] == a[j]) {
      t[j] = 0;
      t[k] = 0;
    }
  }
  ans = 0;
  for (i = 1; i <= n; i++) {
    if (t[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using ll = long long;
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<int> a(n), b(n);
  for (int i = 0; i < m; i++) {
    int ai, bi;
    cin >> ai >> bi;
    a[i] = ai - 1;
    b[i] = bi - 1;
  }

  vector<bool> g(n, true);
  for (int i = 0; i < m; i++) {
    if (h[a[i]] <= h[b[i]])
      g[a[i]] = false;
    if (h[a[i]] >= h[b[i]])
      g[b[i]] = false;
  }

  int ans = 0;
  for (int i = 0; i < n; i++)
    if (g[i])
      ans++;

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using ll = long long;
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<int> a(m), b(m);
  for (int i = 0; i < m; i++) {
    int ai, bi;
    cin >> ai >> bi;
    a[i] = ai - 1;
    b[i] = bi - 1;
  }

  vector<bool> g(n, true);
  for (int i = 0; i < m; i++) {
    if (h[a[i]] <= h[b[i]])
      g[a[i]] = false;
    if (h[a[i]] >= h[b[i]])
      g[b[i]] = false;
  }

  int ans = 0;
  for (int i = 0; i < n; i++)
    if (g[i])
      ans++;

  cout << ans << endl;

  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5, M = 1e5 * 2;
int n, m;
int hh[N];
int h[M], w[M], e[M], ne[M], idx;
bool st[N];
void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }
int main() {
  cin >> n >> m;
  memset(h, -1, sizeof h);
  for (int i = 1; i <= n; i++)
    cin >> hh[i];
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    add(a, b);
    add(b, a);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int flag = 1;
    for (int j = h[i]; j != -1; j = ne[j]) {
      int k = e[j];
      if (hh[i] <= hh[k]) {
        flag = 0;
        break;
      }
    }
    if (flag)
      ans++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7, M = 1e5 * 2 + 50;
int n, m;
int hh[N];
int h[M], w[M], e[M], ne[M], idx;
bool st[N];
void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }
int main() {
  cin >> n >> m;
  memset(h, -1, sizeof h);
  for (int i = 1; i <= n; i++)
    cin >> hh[i];
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    add(a, b);
    add(b, a);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int flag = 1;
    for (int j = h[i]; j != -1; j = ne[j]) {
      int k = e[j];
      if (hh[i] <= hh[k]) {
        flag = 0;
        break;
      }
    }
    if (flag)
      ans++;
  }
  cout << ans << endl;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m, h, a, b, ans = 0;
  cin >> n >> m;
  vector<int> height(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> h;
    height.at(i) = h;
  }
  vector<int> top(n + 1);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (height[a] > height[b]) {
      top[b]--;
    } else if (height[a] < height[b]) {
      top[a]--;
    } else {
      top[a]--;
      top[b]--;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (top[i] == 0) {
      ans++;
    }
  }
  cout << ans << endl;
  return ans;
}

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

int main() {
  int n, m, h, a, b, ans = 0;
  cin >> n >> m;
  vector<int> height(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> h;
    height.at(i) = h;
  }
  vector<int> top(n + 1);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (height[a] > height[b]) {
      top[b]--;
    } else if (height[a] < height[b]) {
      top[a]--;
    } else {
      top[a]--;
      top[b]--;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (top[i] == 0) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: 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[i];
  }
  vector<bool> ans(N, true);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    ans[min(H[a - 1] - 1, H[b - 1] - 1)] = false;
  }
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (ans[i]) {
      cnt++;
    }
  }
  cout << cnt << endl;
}

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[i];
  }
  vector<bool> ans(N, true);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    if (H[a - 1] == H[b - 1]) {
      ans[a - 1] = false;
      ans[b - 1] = false;
      continue;
    }
    int X = a - 1;
    if (H[a - 1] > H[b - 1]) {
      X = b - 1;
    }
    ans[X] = false;
  }
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (ans[i]) {
      cnt++;
    }
  }
  cout << cnt << endl;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {

  int n, m;
  cin >> n >> m;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  vector<vector<int>> g(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x -= 1;
    y -= 1;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int maxa = -1;
    for (int j = 0; j < g[i].size(); i++) {
      maxa = max(maxa, arr[g[i][j]]);
    }
    if (maxa < arr[i])
      ans += 1;
  }
  cout << ans << endl;

  return 0;
}

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

int main() {

  int n, m;
  cin >> n >> m;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  vector<vector<int>> g(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x -= 1;
    y -= 1;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int maxa = -1;
    for (int j = 0; j < g[i].size(); j++) {
      maxa = max(maxa, arr[g[i][j]]);
    }
    if (maxa < arr[i])
      ans += 1;
  }
  cout << ans << endl;

  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
// ABC166 C

#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
const lint mod = 1000000007;

lint ans = 0;
lint n, m;
lint h[200001];
lint a[200001], b[200001];
lint score[21];
lint res = 0;

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

  rep(i, n) { scanf("%lld", &h[i + 1]); }
  rep(i, m) { scanf("%lld %lld", &a[i], &b[i]); }

  rep(i, m) {
    score[a[i]] = max(score[a[i]], h[b[i]]);
    score[b[i]] = max(score[b[i]], h[a[i]]);
  }
  reps(i, 1, n + 1) {
    if (score[i] < h[i])
      ans++;
  }

  printf("%lld\n", ans);
}


Fixed submission:
// ABC166 C

#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
const lint mod = 1000000007;

lint ans = 0;
lint n, m;
lint h[200001];
lint a[200001], b[200001];
lint score[200001];
lint res = 0;

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

  rep(i, n) { scanf("%lld", &h[i + 1]); }
  rep(i, m) { scanf("%lld %lld", &a[i], &b[i]); }

  rep(i, m) {
    score[a[i]] = max(score[a[i]], h[b[i]]);
    score[b[i]] = max(score[b[i]], h[a[i]]);
  }
  reps(i, 1, n + 1) {
    if (score[i] < h[i])
      ans++;
  }

  printf("%lld\n", ans);
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> high(N);
  int ma[N];
  for (int i = 1; i <= N; i++) {
    cin >> high[i];
    ma[i] = 0;
  }

  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    ma[a] = max(ma[a], high[b]);
    ma[b] = max(ma[b], high[a]);
  }
  int res = 0;
  for (int i = 1; i <= N; i++) {
    if (high[i] > ma[i])
      res++;
  }

  cout << res << endl;
  return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  int high[N];
  int ma[N];
  for (int i = 1; i <= N; i++) {
    cin >> high[i];
    ma[i] = 0;
  }

  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    ma[a] = max(ma[a], high[b]);
    ma[b] = max(ma[b], high[a]);
  }
  int res = 0;
  for (int i = 1; i <= N; i++) {
    if (high[i] > ma[i])
      res++;
  }

  cout << res << endl;
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define st first
#define nd second

using ll = long long;
using namespace std;
using pii = pair<int, int>;
const int N = 1e5;
std::vector<int> gr[N];
int h[N];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &h[i]);
  }
  int x, y;
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &x, &y);
    gr[x].push_back(y);
    gr[y].push_back(x);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    bool io = true;
    for (auto it : gr[i]) {
      if (h[i] <= h[it]) {
        io = false;
        break;
      }
    }
    if (io)
      ans++;
  }
  printf("%d", ans);
}

Fixed submission:
#include <bits/stdc++.h>
#define st first
#define nd second

using ll = long long;
using namespace std;
using pii = pair<int, int>;
const int N = 1e5 + 10;
std::vector<int> gr[N];
int h[N];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &h[i]);
  }
  int x, y;
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &x, &y);
    gr[x].push_back(y);
    gr[y].push_back(x);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    bool io = true;
    for (auto it : gr[i]) {
      if (h[i] <= h[it]) {
        io = false;
        break;
      }
    }
    if (io)
      ans++;
  }
  printf("%d", ans);
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
// #include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a), i##formax = (b); i < i##formax; i++)
typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<vector<pair<int, int>>> road(m);
  FOR(i, 0, n) { cin >> h[i]; }

  FOR(i, 0, m) {
    int a, b;
    cin >> a >> b;
    road[a - 1].push_back(make_pair(a - 1, b - 1));
    road[b - 1].push_back(make_pair(b - 1, a - 1));
  }

  int ans = 0;
  FOR(i, 0, n) {
    bool flag = true;
    FOR(j, 0, road[i].size()) {
      if (h[i] <= h[road[i][j].second]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
// #include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a), i##formax = (b); i < i##formax; i++)
typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<vector<pair<int, int>>> road(n);
  FOR(i, 0, n) { cin >> h[i]; }

  FOR(i, 0, m) {
    int a, b;
    cin >> a >> b;
    road[a - 1].push_back(make_pair(a - 1, b - 1));
    road[b - 1].push_back(make_pair(b - 1, a - 1));
  }

  int ans = 0;
  FOR(i, 0, n) {
    bool flag = true;
    FOR(j, 0, road[i].size()) {
      if (h[i] <= h[road[i][j].second]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n, m;
  cin >> n >> m;

  vector<int> hei(n);

  for (int i = 1; i <= n; i++)
    cin >> hei[i];

  vector<int> vec[200001];

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;

    vec[x].push_back(y);
    vec[y].push_back(x);
  }

  int cnt = 0;

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

    for (auto x : vec[i]) {
      if (hei[i] <= hei[x]) {
        flag = 1;
        break;
      }
    }

    if (flag == 0)
      cnt++;
  }

  cout << cnt << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n, m;
  cin >> n >> m;

  vector<int> hei(n + 1);

  for (int i = 1; i <= n; i++)
    cin >> hei[i];

  vector<int> vec[200001];

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;

    vec[x].push_back(y);
    vec[y].push_back(x);
  }

  int cnt = 0;

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

    for (auto x : vec[i]) {
      if (hei[i] <= hei[x]) {
        flag = 1;
        break;
      }
    }

    if (flag == 0)
      cnt++;
  }

  cout << cnt << endl;

  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> h(N);
  for (ll i = 0; i < N; i++) {
    cin >> h.at(i);
  }
  ll a, b;
  vector<ll> count(N, 0);
  for (ll j = 0; j < M; j++) {
    cin >> a >> b;
    ll c = min(h.at(a - 1), h.at(b - 1));
    count.at(c)++;
  }
  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    if (count.at(i) == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> h(N);
  for (ll i = 0; i < N; i++) {
    cin >> h.at(i);
  }
  ll a, b;
  vector<ll> count(N, 0);
  for (ll j = 0; j < M; j++) {
    cin >> a >> b;
    if (h.at(a - 1) < h.at(b - 1)) {
      count.at(a - 1)++;
    } else if (h.at(a - 1) == h.at(b - 1)) {
      count.at(a - 1)++;
      count.at(b - 1)++;
    } else {
      count.at(b - 1)++;
    }
  }
  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    if (count.at(i) == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m, count = 0;
  cin >> n >> m;
  vector<int> h(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];

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

  for (int i = 0; i < n; i++) {
    int r = 0;
    for (int x : G[i]) {
      if (h[i] <= h[x])
        r++;
    }
    if (r == 0)
      count++;
  }
  cout << count << endl;
}

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

int main() {
  int n, m, count = 0;
  cin >> n >> m;
  vector<int> h(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];

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

  for (int i = 0; i < n; i++) {
    int r = 0;
    for (int x : G[i]) {
      if (h[i] <= h[x])
        r++;
    }
    if (r == 0)
      count++;
  }
  cout << count << endl;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>
#include <limits>
#include <set>
#include <vector>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> ok(n, true);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    if (h[a] <= h[b])
      ok[a] = false;
    if (h[b] <= h[a])
      ok[b] = false;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (ok[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <cmath>
#include <iostream>
#include <limits>
#include <set>
#include <vector>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> ok(n, true);
  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;
    if (h[a] <= h[b])
      ok[a] = false;
    if (h[b] <= h[a])
      ok[b] = false;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (ok[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, N) for (ll(i) = 0; (i) < (N); (i)++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1000000007;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> to(10010);
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  int ans = 0;
  rep(i, n) {
    bool ok = true;
    for (int v : to[i]) {
      if (h[i] <= h[v]) {
        ok = false;
      }
    }
    if (ok)
      ans++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, N) for (ll(i) = 0; (i) < (N); (i)++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1000000007;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> to(100100);
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  int ans = 0;
  rep(i, n) {
    bool ok = true;
    for (int v : to[i]) {
      if (h[i] <= h[v]) {
        ok = false;
      }
    }
    if (ok)
      ans++;
  }
  cout << ans << endl;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <string.h>
#pragma warning(disable : 4996)
#define SIZE 100001
using namespace std;

int main() {
  /*    scanf("%lld", &N);
      for (int i = 1; i <= N; i++) {
          scanf("%lld", &A[i]);
          if (A[i] <= 100) cnt[A[i]]++;
      }

      long long Answer = 0;
      for (int i = 1; i <= 50; i++) Answer += cnt[i] * cnt[101 - i];
      cout << Answer << endl;
  */
  int N, M;
  scanf("%d %d", &N, &M);
  int *H;
  int *flag;
  int *A;
  int *B;
  H = (int *)malloc(sizeof(int));
  flag = (int *)malloc(sizeof(int));
  A = (int *)malloc(sizeof(int));
  B = (int *)malloc(sizeof(int));
  int count = 0;
  for (int i = 1; i <= N; i++) {
    scanf("%d", &H[i]);
    flag[i] = 0;
  }
  for (int i = 1; i <= M; i++) {
    scanf("%d %d", &A[i], &B[i]);
  }
  for (int i = 1; i <= M; i++) {
    if (H[A[i]] < H[B[i]]) {
      flag[A[i]] = 1;
    } else if (H[A[i]] == H[B[i]]) {
      flag[A[i]] = 1;
      flag[B[i]] = 1;
    } else
      flag[B[i]] = 1;
  }
  for (int i = 1; i <= N; i++) {
    if (flag[i] == 0)
      count++;
  }
  printf("%d\n", count);

  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <string.h>
#pragma warning(disable : 4996)
#define SIZE 100001
using namespace std;

int main() {
  /*    scanf("%lld", &N);
      for (int i = 1; i <= N; i++) {
          scanf("%lld", &A[i]);
          if (A[i] <= 100) cnt[A[i]]++;
      }

      long long Answer = 0;
      for (int i = 1; i <= 50; i++) Answer += cnt[i] * cnt[101 - i];
      cout << Answer << endl;
  */
  int N, M;
  scanf("%d %d", &N, &M);
  int H[SIZE];
  int flag[SIZE];
  int A[SIZE];
  int B[SIZE];
  // H = (int*)malloc(sizeof(int));
  // flag = (int*)malloc(sizeof(int));
  // A = (int*)malloc(sizeof(int));
  // B = (int*)malloc(sizeof(int));
  int count = 0;
  for (int i = 1; i <= N; i++) {
    scanf("%d", &H[i]);
    flag[i] = 0;
  }
  for (int i = 1; i <= M; i++) {
    scanf("%d %d", &A[i], &B[i]);
  }
  for (int i = 1; i <= M; i++) {
    if (H[A[i]] < H[B[i]]) {
      flag[A[i]] = 1;
    } else if (H[A[i]] == H[B[i]]) {
      flag[A[i]] = 1;
      flag[B[i]] = 1;
    } else
      flag[B[i]] = 1;
  }
  for (int i = 1; i <= N; i++) {
    if (flag[i] == 0)
      count++;
  }
  printf("%d\n", count);

  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

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

  int h[10010], ma[10010] = {0};

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

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

    if (h[a - 1] < h[b - 1])
      ma[a - 1] = 0;
    else if (h[a - 1] > h[b - 1])
      ma[b - 1] = 0;
    else {
      ma[a - 1] = 0;
      ma[b - 1] = 0;
    }
  }

  int ans = 0;

  for (int k = 0; k < n; k++) {
    if (ma[k] == 1)
      ans++;
  }

  cout << ans << endl;
}

Fixed submission:
#include <iostream>
using namespace std;

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

  int h[100010], ma[100010] = {0};

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

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

    if (h[a - 1] < h[b - 1])
      ma[a - 1] = 0;
    else if (h[a - 1] > h[b - 1])
      ma[b - 1] = 0;
    else {
      ma[a - 1] = 0;
      ma[b - 1] = 0;
    }
  }

  int ans = 0;

  for (int k = 0; k < n; k++) {
    if (ma[k] == 1)
      ans++;
  }

  cout << ans << endl;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define ll long long

using namespace std;

const int N = 1e5 + 5;
vector<int> gr[N];
ll d[N], used[N];
int cnt = 0;

int dfs(int v) {
  used[v] = 1;
  int fl = 1;
  for (auto e : gr[v]) {
    if (d[v] <= d[e])
      fl = 0;
  }
  if (fl)
    cnt++;
  for (auto e : gr[v]) {
    if (!used[e])
      dfs(e);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> d[i + 1];
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    gr[u].pb(v);
    gr[v].pb(u);
  }
  for (int i = 1; i <= n; i++) {
    if (!used[i])
      dfs(i);
  }
  cout << cnt;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define ll long long

using namespace std;

const int N = 1e5 + 5;
vector<int> gr[N];
ll d[N], used[N];
int cnt = 0;

void dfs(int v) {
  used[v] = 1;
  int fl = 1;
  for (auto e : gr[v]) {
    if (d[v] <= d[e])
      fl = 0;
  }
  if (fl)
    cnt++;
  for (auto e : gr[v]) {
    if (!used[e])
      dfs(e);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> d[i + 1];
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    gr[u].pb(v);
    gr[v].pb(u);
  }
  for (int i = 1; i <= n; i++) {
    if (!used[i])
      dfs(i);
  }
  cout << cnt;
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
// created by pyoxiao on 2020/05/03
#include <bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define CL(a, b) memset(a, b, sizeof(a))
using namespace std;
const int mod = 1e9 + 7;
LL fpow(LL a, LL b, LL p = mod) {
  LL ans = 1;
  a %= p;
  while (b) {
    if (b & 1)
      ans = ans * a % p;
    b >>= 1;
    a = a * a % p;
  }
  return ans;
}
LL gcd(LL a, LL b) { return b == 0 ? a : gcd(b, a % b); }
int n, m, h[10010];
vector<int> ver[10010];
void solve() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", h + i);
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    ver[a].pb(b);
    ver[b].pb(a);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    bool ok = 1;
    for (auto to : ver[i]) {
      if (h[to] >= h[i]) {
        ok = 0;
        break;
      }
    }
    if (ok)
      ans++;
  }
  printf("%d\n", ans);
}
int main() {
  int T = 1;
  // scanf("%d", &T);
  while (T--)
    solve();
  return 0;
}

Fixed submission:
// created by pyoxiao on 2020/05/03
#include <bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define CL(a, b) memset(a, b, sizeof(a))
using namespace std;
const int mod = 1e9 + 7;
LL fpow(LL a, LL b, LL p = mod) {
  LL ans = 1;
  a %= p;
  while (b) {
    if (b & 1)
      ans = ans * a % p;
    b >>= 1;
    a = a * a % p;
  }
  return ans;
}
LL gcd(LL a, LL b) { return b == 0 ? a : gcd(b, a % b); }
int n, m, h[100010];
vector<int> ver[100010];
void solve() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", h + i);
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    ver[a].pb(b);
    ver[b].pb(a);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    bool ok = 1;
    for (auto to : ver[i]) {
      if (h[to] >= h[i]) {
        ok = 0;
        break;
      }
    }
    if (ok)
      ans++;
  }
  printf("%d\n", ans);
}
int main() {
  int T = 1;
  // scanf("%d", &T);
  while (T--)
    solve();
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

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

  bool flag[N];
  for (int i = 0; i < N; i++)
    flag[i] = true;

  for (int i = 0; i < 1000; i++) {
    for (int j = 0; j < M; j++) {
      if (H[A[j]] > H[B[j]]) {
        H[B[j]] = H[A[j]];
        flag[B[j]] = false;
      }
      if (H[B[j]] > H[A[j]]) {
        H[A[j]] = H[B[j]];
        flag[A[j]] = false;
      }
    }
    for (int j = M - 1; j >= 0; j--) {
      if (H[A[j]] > H[B[j]]) {
        H[B[j]] = H[A[j]];
        flag[B[j]] = false;
      }
      if (H[B[j]] > H[A[j]]) {
        H[A[j]] = H[B[j]];
        flag[A[j]] = false;
      }
    }
  }

  int res = 0;
  for (int i = 0; i < N; i++) {
    if (flag[i] == true)
      res++;
  }

  cout << res << endl;
}

Fixed submission:
#include <iostream>
using namespace std;

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

  bool flag[N];
  for (int i = 0; i < N; i++)
    flag[i] = true;

  for (int i = 0; i < M; i++) {
    if (H[A[i] - 1] >= H[B[i] - 1])
      flag[B[i] - 1] = false;
    if (H[B[i] - 1] >= H[A[i] - 1])
      flag[A[i] - 1] = false;
  }

  int res = 0;
  for (int i = 0; i < N; i++) {
    if (flag[i] == true)
      res++;
  }

  cout << res << endl;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define REP3(i, x, n) for (int i = x; i > (n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n), end(n)
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
const long long INF = numeric_limits<long long>::max();
int main() {
  int n, m, h[114514810], ma[114514810];
  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;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define REP3(i, x, n) for (int i = x; i > (n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n), end(n)
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
const long long INF = numeric_limits<long long>::max();
int main() {
  int n, m, h[114514], ma[114514];
  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;
}
Problem p02689 (C++)

Buggy submission (status: Time Limit Exceeded):
#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[i];
  }
  vector<int> ab(2 * m);
  for (int i = 0; i < 2 * m; i++) {
    cin >> ab[i];
  }
  // ok
  // goodはよい展望台のこと
  vector<int> good(n);
  for (int i = 0; i < n; i++) {
    good[i] = 1;
  }
  // iはi番目の展望台の探索
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2 * m; j += 2) {
      if (i == ab[j] - 1) {
        if (h[ab[j] - 1] < h[ab[j + 1] - 1] ||
            h[ab[j] - 1] == h[ab[j + 1] - 1]) {
          good[i] = 0;
        }
        if (h[ab[j] - 1] > h[ab[j + 1] - 1] ||
            h[ab[j] - 1] == h[ab[j + 1] - 1]) {
          good[ab[j + 1] - 1] = 0;
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += good[i];
  }
  cout << ans << endl;
}

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[i];
  }
  vector<int> ab(2 * m);
  for (int i = 0; i < 2 * m; i++) {
    cin >> ab[i];
  }
  // ok
  // goodはよい展望台のこと
  vector<int> good(n);
  for (int i = 0; i < n; i++) {
    good[i] = 1;
  }
  // iはi番目の展望台の探索
  for (int i = 0; i < 2 * m; i += 2) {
    if (good[ab[i] - 1] == 0 && good[ab[i + 1] - 1] == 0) {
      continue;
    }
    if (h[ab[i] - 1] > h[ab[i + 1] - 1]) {
      good[ab[i + 1] - 1] = 0;
    } else if (h[ab[i] - 1] < h[ab[i + 1] - 1]) {
      good[ab[i] - 1] = 0;
    } else {
      good[ab[i] - 1] = 0;
      good[ab[i + 1] - 1] = 0;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += good[i];
  }
  cout << ans << endl;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define endl "\n"

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

  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  vector<set<int>> adj(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].insert(h[v]);
    adj[v].insert(h[u]);
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    auto it = adj[i].end();
    it--; // largest element
    ans += (h[i] > *it);
  }
  cout << ans;
  return 0;
}

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

typedef long long ll;
#define endl "\n"

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

  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  vector<set<int>> adj(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].insert(h[v]);
    adj[v].insert(h[u]);
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (adj[i].empty()) {
      ans++;
      continue;
    }
    auto it = adj[i].end();
    it--; // largest element
    ans += (h[i] > *it);
  }
  cout << ans;
  return 0;
}