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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, d, sum, temp, c;
  cin >> n >> m;
  vector<long long int> a(n);
  vector<vector<int>> p(n, vector<int>(n, 0));
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vector<int> b(n, 1);
  while (m--) {
    cin >> c >> d;
    if (a[c - 1] <= a[d - 1])
      b[c - 1] = 0;
    if (a[d - 1] <= a[c - 1])
      b[d - 1] = 0;
  }
  sum = 0;
  for (int i = 0; i < n; i++) {
    if (b[i]) {
      // cout<<i+1<<endl;
      sum++;
    }
  }
  cout << sum << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, d, sum, temp, c;
  cin >> n >> m;
  vector<long long int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vector<int> b(n, 1);
  while (m--) {
    cin >> c >> d;
    if (a[c - 1] <= a[d - 1])
      b[c - 1] = 0;
    if (a[d - 1] <= a[c - 1])
      b[d - 1] = 0;
  }
  sum = 0;
  for (int i = 0; i < n; i++) {
    if (b[i]) {
      // cout<<i+1<<endl;
      sum++;
    }
  }
  cout << sum << endl;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  long N, M, cnt = 0;
  cin >> N >> M;
  vector<long> H(N), A(M), B(M), check(N, 1);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
  }
  for (int i = 0; i < N; i++) {
    if (H[A[i] - 1] > H[B[i] - 1]) {
      check[B[i] - 1] = 0;
    } else if (H[A[i] - 1] < H[B[i] - 1]) {
      check[A[i] - 1] = 0;
    } else {
      check[A[i] - 1] = 0;
      check[B[i] - 1] = 0;
    }
  }
  for (int i = 0; i < N; i++) {
    if (check[i] == 1) {
      cnt++;
    }
  }
  cout << cnt;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  long N, M, cnt = 0;
  cin >> N >> M;
  vector<long> H(N), A(M), B(M), check(N, 1);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
  }
  for (int i = 0; i < M; i++) {
    if (H[A[i] - 1] > H[B[i] - 1]) {
      check[B[i] - 1] = 0;
    } else if (H[A[i] - 1] < H[B[i] - 1]) {
      check[A[i] - 1] = 0;
    } else {
      check[A[i] - 1] = 0;
      check[B[i] - 1] = 0;
    }
  }
  for (int i = 0; i < N; i++) {
    if (check[i] == 1) {
      cnt++;
    }
  }
  cout << cnt;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <string>
#include <unordered_map>
#define ll long long
using namespace std;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const int N = 1e5 + 10;
inline void fastio() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int h[10010];
int good[10010];
int main() {
  int n, m, a, b, ans = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    if (h[a] > h[b])
      good[b] = 1;
    else if (h[a] == h[b])
      good[a] = good[b] = 1;
    else
      good[a] = 1;
  }
  for (int i = 1; i <= n; i++)
    ans += (good[i] == 1) ? 0 : 1;
  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <string>
#include <unordered_map>
#define ll long long
using namespace std;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const int N = 1e5 + 10;
inline void fastio() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int h[100010];
int good[100010];
int main() {
  int n, m, a, b, ans = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    if (h[a] > h[b])
      good[b] = 1;
    else if (h[a] == h[b])
      good[a] = good[b] = 1;
    else
      good[a] = 1;
  }
  for (int i = 1; i <= n; i++)
    ans += (good[i] == 1) ? 0 : 1;
  cout << ans;
  return 0;
}
Problem p02689 (C++)

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

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

Buggy submission (status: Runtime Error):
#include <cstdio>
const int MAXN = 105;
bool good[MAXN];
int H[MAXN];
int a, b, M, N;

int main() {
  scanf(" %d%d", &N, &M);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &H[i]);
    good[i] = true;
  }
  for (int i = 0; i < M; ++i) {
    scanf(" %d%d", &a, &b);
    good[a] &= (H[a] > H[b]);
    good[b] &= (H[b] > H[a]);
  }
  int ret = 0;
  for (int i = 1; i <= N; ++i) {
    if (good[i])
      ++ret;
  }
  printf("%d\n", ret);
  return 0;
}

Fixed submission:
#include <cstdio>
const int MAXN = 1e5 + 5;
bool good[MAXN];
int H[MAXN];
int a, b, M, N;

int main() {
  scanf(" %d%d", &N, &M);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &H[i]);
    good[i] = true;
  }
  for (int i = 0; i < M; ++i) {
    scanf(" %d%d", &a, &b);
    good[a] &= (H[a] > H[b]);
    good[b] &= (H[b] > H[a]);
  }
  int ret = 0;
  for (int i = 1; i <= N; ++i) {
    if (good[i])
      ++ret;
  }
  printf("%d\n", ret);
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  bool vis[100010];
  int tot = 0;
  int h[10010], a, b;
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  for (int j = 1; j <= m; j++) {
    cin >> a >> b;
    if (h[a] < h[b])
      vis[a] = true;
    else if (h[a] == h[b])
      vis[a] = vis[b] = true;
    else
      vis[b] = true;
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i] == false) {
      tot++;
    }
  }
  cout << tot;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  bool vis[100010];
  int tot = 0;
  int h[100010], a, b;
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  for (int j = 1; j <= m; j++) {
    cin >> a >> b;
    if (h[a] < h[b])
      vis[a] = true;
    else if (h[a] == h[b])
      vis[a] = vis[b] = true;
    else
      vis[b] = true;
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i] == false) {
      tot++;
    }
  }
  cout << tot;
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;
typedef long long ll;

int N, M, H[10010];
vector<int> G[10010];

int main() {
  cin >> N >> M;
  rep(i, N) cin >> H[i];
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    // aとbは0インデックスに揃える
    a--;
    b--;
    G[a].push_back(b);
    // 無向グラフなのでbにもaを追加する
    G[b].push_back(a);
  }
  int ans = 0;
  rep(i, N) {
    bool check = true;
    for (auto g : G[i]) {
      if (H[i] <= H[g])
        check = false;
    }
    if (check)
      ans++;
  }
  cout << ans << endl;
}


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

int N, M, H[100010];
vector<int> G[100010];

int main() {
  cin >> N >> M;
  rep(i, N) cin >> H[i];
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    // aとbは0インデックスに揃える
    a--;
    b--;
    G[a].push_back(b);
    // 無向グラフなのでbにもaを追加する
    G[b].push_back(a);
  }
  int ans = 0;
  rep(i, N) {
    bool check = true;
    for (auto g : G[i]) {
      if (H[i] <= H[g])
        check = false;
    }
    if (check)
      ans++;
  }
  cout << ans << endl;
}
Problem p02689 (C++)

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

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

  vector<ll> h;
  vector<int> to[1000005];

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

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

  bool goo;
  int cnt = 0;

  for (int i = 0; i < n; i++) {
    goo = true;
    int hig = h.at(i);

    for (auto x : to[i]) {
      if (hig <= h.at(x)) {
        goo = false;
      }
    }

    if (goo)
      cnt++;
  }

  cout << cnt << endl;

  return 0;
}


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

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

  vector<ll> h(n);
  vector<int> to[1000005];

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

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

  bool goo;
  int cnt = 0;

  for (int i = 0; i < n; i++) {
    goo = true;
    int hig = h.at(i);

    for (auto x : to[i]) {
      if (hig <= h.at(x)) {
        goo = false;
      }
    }

    if (goo)
      cnt++;
  }

  cout << cnt << 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++)
int main() {
  int N, M, A, B;
  int ans = 0;
  cin >> N >> M;
  long long H[10010];
  int Ten[10010] = {0};
  rep(i, N) { cin >> H[i]; }
  rep(i, M) {
    cin >> A >> B;
    if (H[A - 1] > H[B - 1]) {
      Ten[B - 1] = 1;
    } else if (H[A - 1] < H[B - 1]) {
      Ten[A - 1] = 1;
    } else {
      Ten[A - 1] = 1;
      Ten[B - 1] = 1;
    }
  }

  rep(i, N) {
    if (Ten[i] == 0)
      ans++;
  }

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int N, M, A, B;
  int ans = 0;
  cin >> N >> M;
  long long H[100100];
  int Ten[100100] = {0};
  rep(i, N) { cin >> H[i]; }
  rep(i, M) {
    cin >> A >> B;
    if (H[A - 1] > H[B - 1]) {
      Ten[B - 1] = 1;
    } else if (H[A - 1] < H[B - 1]) {
      Ten[A - 1] = 1;
    } else {
      Ten[A - 1] = 1;
      Ten[B - 1] = 1;
    }
  }

  rep(i, N) {
    if (Ten[i] == 0)
      ans++;
  }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100005
int hill[MAXN];
int fir[MAXN];
int n, m, ecnt, ans;
struct edge {
  int v, nxt;
} eds[MAXN];
void adde(int a, int b) {
  eds[++ecnt].v = b, eds[ecnt].nxt = fir[a], fir[a] = ecnt;
  eds[++ecnt].v = a, eds[ecnt].nxt = fir[b], fir[b] = ecnt;
}
int main() {
  int a, b;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d", &hill[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a, &b);
    adde(a, b);
  }
  for (int i = 1; i <= n; i++) {
    bool flg = 0;
    for (int j = fir[i]; j; j = eds[j].nxt) {
      int v = eds[j].v;
      if (hill[v] >= hill[i])
        flg = 1;
    }
    if (flg == 0)
      ans++;
  }
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100005
int hill[MAXN];
int fir[MAXN];
int n, m, ecnt, ans;
struct edge {
  int v, nxt;
} eds[MAXN << 1];
void adde(int a, int b) {
  eds[++ecnt].v = b, eds[ecnt].nxt = fir[a], fir[a] = ecnt;
  eds[++ecnt].v = a, eds[ecnt].nxt = fir[b], fir[b] = ecnt;
}
int main() {
  int a, b;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d", &hill[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a, &b);
    adde(a, b);
  }
  for (int i = 1; i <= n; i++) {
    bool flg = 0;
    for (int j = fir[i]; j; j = eds[j].nxt) {
      int v = eds[j].v;
      if (hill[v] >= hill[i])
        flg = 1;
    }
    if (flg == 0)
      ans++;
  }
  printf("%d\n", ans);
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

static const int NMAX = 10010;

int main() {
  int n, m;
  int h[NMAX], ma[NMAX]; // ma[i]: 展望台 i から一本で行ける山の標高の最大値
  cin >> n >> m;
  REP(i, n) cin >> h[i];
  REP(i, n) ma[i] = 0; // 初期化
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    ma[a] = max(ma[a], h[b]);
    ma[b] = max(ma[b], h[a]);
  }

  int cnt = 0;

  REP(i, n) {
    if (h[i] > ma[i])
      ++cnt;
  }

  cout << cnt << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

static const int NMAX = 100100;

int main() {
  int n, m;
  int h[NMAX], ma[NMAX]; // ma[i]: 展望台 i から一本で行ける山の標高の最大値
  cin >> n >> m;
  REP(i, n) cin >> h[i];
  REP(i, n) ma[i] = 0; // 初期化
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    ma[a] = max(ma[a], h[b]);
    ma[b] = max(ma[b], h[a]);
  }

  int cnt = 0;

  REP(i, n) {
    if (h[i] > ma[i])
      ++cnt;
  }

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <sstream>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;

int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> H(N);
  rep(i, N) cin >> H.at(i);
  vector<ll> J(N);
  rep(i, M) J.at(i) = 0;
  ll A, B;

  ll count = 0;
  rep(i, M) {
    cin >> A >> B;
    A--;
    B--;
    if (H.at(A) > H.at(B))
      J.at(B)++;
    else if (H.at(A) < H.at(B))
      J.at(A)++;
    else {
      J.at(A)++;
      J.at(B)++;
    }
  }

  rep(i, N) if (J.at(i) == 0) count++;
  cout << count << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <sstream>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;

int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> H(N);
  rep(i, N) cin >> H.at(i);
  vector<ll> J(N);
  rep(i, N) J.at(i) = 0;
  ll A, B;

  ll count = 0;
  rep(i, M) {
    cin >> A >> B;
    A--;
    B--;
    if (H.at(A) > H.at(B))
      J.at(B)++;
    else if (H.at(A) < H.at(B))
      J.at(A)++;
    else {
      J.at(A)++;
      J.at(B)++;
    }
  }

  rep(i, N) if (J.at(i) == 0) count++;
  cout << count << endl;
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: 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 h[10010];
int main() {
  int n, m, a, b;
  cin >> n >> m;
  vector<vector<int>> G(n);
  rep(i, n) cin >> h[i];
  rep(i, m) {
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int cnt = 0;
  rep(i, n) {
    rep(j, G[i].size()) {
      if (h[i] <= h[G[i][j]]) {
        cnt++;
        break;
      }
    }
  }
  cout << n - cnt;
}

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 h[100010];
int main() {
  int n, m, a, b;
  cin >> n >> m;
  vector<vector<int>> G(n);
  rep(i, n) cin >> h[i];
  rep(i, m) {
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int cnt = 0;
  rep(i, n) {
    rep(j, G[i].size()) {
      if (h[i] <= h[G[i][j]]) {
        cnt++;
        break;
      }
    }
  }
  cout << n - cnt;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  long long int n, m;
  cin >> n >> m;
  long long int h[100001];
  for (long long int i = 1; i <= n; i++) {
    cin >> h[i];
  }

  long long int g[100001];
  for (long long int i = 1; i <= n; i++) {
    g[i] = 1;
  }
  long long int c[100001];
  for (long long int i = 1; i <= n; i++) {
    c[i] = 1;
  }

  long long int a[100001], b[100001];
  for (long long int j = 1; j <= n; j++) {
    cin >> a[j] >> b[j];
    if (h[a[j]] > h[b[j]]) {
      g[a[j]] = 1;
    } else {
      c[a[j]] = 0;
    }
    if (h[a[j]] < h[b[j]]) {
      g[b[j]] = 1;
    } else {
      c[b[j]] = 0;
    }
  }
  int l = 0;
  for (long long int i = 1; i <= n; i++) {
    if (c[i] && g[i]) {
      l++;
    }
  }
  cout << l;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  long long int n, m;
  cin >> n >> m;
  long long int h[100001];
  for (long long int i = 1; i <= n; i++) {
    cin >> h[i];
  }

  long long int g[100001];
  for (long long int i = 1; i <= n; i++) {
    g[i] = 1;
  }
  long long int c[100001];
  for (long long int i = 1; i <= n; i++) {
    c[i] = 1;
  }

  long long int a[100001], b[100001];
  for (long long int j = 1; j <= m; j++) {
    cin >> a[j] >> b[j];
    if (h[a[j]] > h[b[j]]) {
      g[a[j]] = 1;
    } else {
      c[a[j]] = 0;
    }
    if (h[a[j]] < h[b[j]]) {
      g[b[j]] = 1;
    } else {
      c[b[j]] = 0;
    }
  }
  int l = 0;
  for (long long int i = 1; i <= n; i++) {
    if (c[i] && g[i]) {
      l++;
    }
  }
  cout << l;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#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);
  vector<bool> ok(n, true);

  rep(i, n) cin >> h[i];

  rep(i, n) {
    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;
  rep(i, n) {
    if (ok[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}

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;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> ok(n, true);

  rep(i, n) cin >> h[i];

  rep(i, m) {
    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;
  rep(i, n) {
    if (ok[i])
      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), ma(n);
  for (int i = 1; i < n + 1; i++) {
    cin >> h[i];
    ma[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    ma[a] = max(h[b], ma[a]);
    ma[b] = max(h[a], ma[b]);
  }
  int ans = 0;
  for (int i = 1; i < n + 1; i++) {
    if (h[i] > ma[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}

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

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

Buggy submission (status: Runtime Error):
//                        DushtuBunny
//                        Rahul Halder
//    Indian Institute of Engineering Science & Technology,Shibpur

#include <bits/stdc++.h>

#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long
#define f first
#define se second
#define LB lower_bound
#define UB upper_bound
#define pb push_back
#define mp make_pair
#define vll vector<ll>
#define vi vector<int>
#define vc vector<char>
#define vpll vector<pair<ll, ll>>
const unsigned int MOD = 1000000007;

using namespace std;

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  IOS;
  int T;
  // cin>>T;
  T = 1;

  while (T--) {
    ll n, m;
    cin >> n >> m;

    ll h[n + 1];

    for (ll i = 1; i <= n; i++)
      cin >> h[i];

    vector<vector<ll>> v(m + 2);
    // cout<<m;

    for (ll i = 0; i < m; i++) {
      ll x, y;
      cin >> x >> y;
      v[x].pb(y);
      v[y].pb(x);
    }

    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
      if (v[i].size() == 0) {
        ans++;
        continue;
      }

      ll flag = 1;
      for (ll j = 0; j < v[i].size(); j++) {
        if (h[i] <= h[v[i][j]]) {
          flag = 0;
          break;
        }
      }

      if (flag)
        ans++;
    }

    cout << ans;
  }

  return 0;
}

Fixed submission:
//                        DushtuBunny
//                        Rahul Halder
//    Indian Institute of Engineering Science & Technology,Shibpur

#include <bits/stdc++.h>

#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long
#define f first
#define se second
#define LB lower_bound
#define UB upper_bound
#define pb push_back
#define mp make_pair
#define vll vector<ll>
#define vi vector<int>
#define vc vector<char>
#define vpll vector<pair<ll, ll>>
const unsigned int MOD = 1000000007;

using namespace std;

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  IOS;
  int T;
  // cin>>T;
  T = 1;

  while (T--) {
    ll n, m;
    cin >> n >> m;

    ll h[n + 1];

    for (ll i = 1; i <= n; i++)
      cin >> h[i];

    vector<vector<ll>> v(n + 1);
    // cout<<m;

    for (ll i = 0; i < m; i++) {
      ll x, y;
      cin >> x >> y;
      v[x].pb(y);
      v[y].pb(x);
    }

    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
      if (v[i].size() == 0) {
        ans++;
        continue;
      }

      ll flag = 1;
      for (ll j = 0; j < v[i].size(); j++) {
        if (h[i] <= h[v[i][j]]) {
          flag = 0;
          break;
        }
      }

      if (flag)
        ans++;
    }

    cout << ans;
  }

  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("Ofast", "-funroll-loops", "-fdelete-null-pointer-checks")
#pragma GCC target("ssse3", "sse3", "sse2", "sse", "avx2", "avx", "popcnt")
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define endl '\n'

const ll MOD = 1e9 + 7;

void solve() {
  int n, m;
  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 x, y;
    cin >> x >> y;
    g[--x].push_back(--y);
    g[--y].push_back(--x);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    bool ok = 1;
    for (int j : g[i]) {
      if (h[i] <= h[j]) {
        ok = 0;
        break;
      }
    }
    ans += ok;
  }
  cout << ans << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ll t = 1;
  for (ll tt = 1; tt <= t; tt++) {
    // cout << "case #" << tt << ":\n";
    solve();
  }

  return 0;
}


Fixed submission:
#pragma GCC optimize("Ofast", "-funroll-loops", "-fdelete-null-pointer-checks")
#pragma GCC target("ssse3", "sse3", "sse2", "sse", "avx2", "avx", "popcnt")
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define endl '\n'

const ll MOD = 1e9 + 7;

void solve() {
  int n, m;
  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 x, y;
    cin >> x >> y;
    g[x - 1].push_back(y - 1);
    g[y - 1].push_back(x - 1);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    bool ok = 1;
    for (int j : g[i]) {
      if (h[i] <= h[j]) {
        ok = 0;
        break;
      }
    }
    ans += ok;
  }
  cout << ans << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ll t = 1;
  for (ll tt = 1; tt <= t; tt++) {
    // cout << "case #" << tt << ":\n";
    solve();
  }

  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define ll long long
#define pb push_back
#define F first
#define S second
#define ld long double
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define vi vector<ll>
#define all(v) (v).begin(), (v).end()
const int inf = 1e9 + 10;

void solve() {
  ll n, m;
  cin >> n >> m;
  vi a(n, 0), h(n, 0);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  for (int i = 0; i < m; i++) {
    ll x, y;
    cin >> x >> y;
    a[x] = max(a[x], h[y]);
    a[y] = max(a[y], h[x]);
  }
  ll ans = 0;
  for (int i = 0; i < n; i++)
    ans += h[i] > a[i];
  cout << ans;
}

int main() {

  FASTIO;

  cout << fixed << setprecision(25);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define ll long long
#define pb push_back
#define F first
#define S second
#define ld long double
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define vi vector<ll>
#define all(v) (v).begin(), (v).end()
const int inf = 1e9 + 10;

void solve() {
  ll n, m;
  cin >> n >> m;
  vi a(n, 0), h(n, 0);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  for (int i = 0; i < m; i++) {
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    a[x] = max(a[x], h[y]);
    a[y] = max(a[y], h[x]);
  }
  ll ans = 0;
  for (int i = 0; i < n; i++)
    ans += h[i] > a[i];
  cout << ans;
}

int main() {

  FASTIO;

  cout << fixed << setprecision(25);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = a; i < ll(b); i++)
#define repr(i, a, b) for (ll i = a; i >= ll(b); i--)
#define endl "\n"
#define ALL(x) x.begin(), x.end()
#define ALLR(x) x.rbegin(), x.rend()
#define INF 1e9
#define DEBUG(x) cout << "debug: " << x << endl

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

  int ans = 0;
  rep(i, 0, n) {
    int nh = h[i];
    int maxh = 0;
    for (auto x : graph[i]) {
      maxh = max(maxh, h[x]);
    }
    if (nh > maxh)
      ans++;
  }

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


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = a; i < ll(b); i++)
#define repr(i, a, b) for (ll i = a; i >= ll(b); i--)
#define endl "\n"
#define ALL(x) x.begin(), x.end()
#define ALLR(x) x.rbegin(), x.rend()
#define INF 1e9
#define DEBUG(x) cout << "debug: " << x << endl

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

  int ans = 0;
  rep(i, 0, n) {
    int nh = h[i];
    int maxh = 0;
    for (auto x : graph[i]) {
      maxh = max(maxh, h[x]);
    }
    if (nh > maxh)
      ans++;
  }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  int n, m;
  int count = 0;
  cin >> n >> m;
  vector<long long> h(n);
  vector<int> a(m);
  vector<int> b(m);
  vector<int> ng(n);
  rep(i, n) cin >> h.at(i);
  rep(j, m) cin >> a.at(j) >> b.at(j);

  rep(j, m) {
    if (h.at(a.at(j) - 1) > h.at(b.at(j) - 1)) {
      ng.at(b.at(j)) = 1;
    } else if (h.at(a.at(j) - 1) < h.at(b.at(j) - 1)) {
      ng.at(a.at(j) - 1) = 1;
    } else {
      ng.at(a.at(j) - 1) = 1;
      ng.at(b.at(j) - 1) = 1;
    }
  }
  rep(i, n) {
    if (ng.at(i) == 0) {
      count++;
    }
  }
  cout << count << endl;
}


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

int main() {
  int n, m;
  int count = 0;
  cin >> n >> m;
  vector<long long> h(n);
  vector<int> a(m);
  vector<int> b(m);
  vector<int> ng(n);
  rep(i, n) cin >> h.at(i);
  rep(j, m) cin >> a.at(j) >> b.at(j);

  rep(j, m) {
    if (h.at(a.at(j) - 1) > h.at(b.at(j) - 1)) {
      ng.at(b.at(j) - 1) = 1;
    } else if (h.at(a.at(j) - 1) < h.at(b.at(j) - 1)) {
      ng.at(a.at(j) - 1) = 1;
    } else {
      ng.at(a.at(j) - 1) = 1;
      ng.at(b.at(j) - 1) = 1;
    }
  }
  rep(i, n) {
    if (ng.at(i) == 0) {
      count++;
    }
  }
  cout << count << endl;
}
Problem p02689 (C++)

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

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

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

  vector<long long> cnt_i(N, 0);

  for (int i = 0; i < M; i++) {
    cin >> A.at(i) >> B.at(i);

    if (H.at(A.at(i) - 1) < H.at(B.at(i) - 1)) {
      cnt_i.at(A.at(i) - 1)++;
    } else if (H.at(A.at(i) - 1) > H.at(B.at(i) - 1)) {
      cnt_i.at(B.at(i) - 1)++;
    } else {
      cnt_i.at(A.at(i) - 1)++;
      cnt_i.at(B.at(i) - 1)++;
    }
  }

  long long cnt_ans = 0;

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

  cout << cnt_ans << "\n";
}

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

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

  vector<long long> H(N);
  vector<long long> A(M);
  vector<long long> B(M);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }

  vector<long long> cnt_i(N, 0);

  for (int i = 0; i < M; i++) {
    cin >> A.at(i) >> B.at(i);

    if (H.at(A.at(i) - 1) < H.at(B.at(i) - 1)) {
      cnt_i.at(A.at(i) - 1)++;
    } else if (H.at(A.at(i) - 1) > H.at(B.at(i) - 1)) {
      cnt_i.at(B.at(i) - 1)++;
    } else {
      cnt_i.at(A.at(i) - 1)++;
      cnt_i.at(B.at(i) - 1)++;
    }
  }

  long long cnt_ans = 0;

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

  cout << cnt_ans << "\n";
}
Problem p02689 (C++)

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

int main() {
  int N, M, H[10010], MAX[10010];
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    cin >> H[i];
    MAX[i] = 0;
  }
  for (int i = 1; i <= M; i++) {
    int A, B;
    cin >> A >> B;
    MAX[A] = max(MAX[A], H[B]);
    MAX[B] = max(MAX[B], H[A]);
  }
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += H[i] > MAX[i];
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N, M, H[100010], MAX[100010];
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    cin >> H[i];
    MAX[i] = 0;
  }
  for (int i = 1; i <= M; i++) {
    int A, B;
    cin >> A >> B;
    MAX[A] = max(MAX[A], H[B]);
    MAX[B] = max(MAX[B], H[A]);
  }
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += H[i] > MAX[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

int main(void) {

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

  vector<int> high(n);

  vector<vector<bool>> bridge(n, vector<bool>(n, false));

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

  int a, b;
  vector<bool> flags(n, true);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;

    a--;
    b--;
    if (high[a] > high[b])
      flags[b] = false;
    else if (high[a] < high[b])
      flags[a] = false;
    else {
      flags[a] = false;
      flags[b] = false;
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (flags[i])
      ans++;
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main(void) {

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

  vector<int> high(n);

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

  int a, b;
  vector<bool> flags(n, true);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;

    a--;
    b--;
    if (high[a] > high[b])
      flags[b] = false;
    else if (high[a] < high[b])
      flags[a] = false;
    else {
      flags[a] = false;
      flags[b] = false;
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (flags[i])
      ans++;
  }

  cout << ans << endl;

  return 0;
}
Problem p02689 (C++)

Buggy submission (status: Time Limit Exceeded):
#define MAX 100000
#include <iostream>
#include <vector>
using namespace std;

int N, M;
int h[MAX];

int main() {
  cin >> N >> M;
  vector<int> ini(N + 1, 1);
  for (int i = 1; i <= N; i++) {
    cin >> h[i];
  }
  // cout << ini.size();
  int a, b;
  for (int j = 1; j <= M; j++) {
    cin >> a >> b;
    if (h[a] > h[b]) {
      ini[b] = 0;
    } else if (h[a] < h[b]) {
      ini[a] = 0;
    } else {
      ini[a] = 0;
      ini[b] = 0;
    }
  }
  int sum = 0;
  for (int j = 1; j <= N; j++) {
    sum += ini[j];
  }
  cout << sum << endl;
  return 0;
}

Fixed submission:
#define MAX 200000
#include <iostream>
#include <vector>
using namespace std;

int N, M;
int h[MAX];

int main() {
  cin >> N >> M;
  vector<int> ini(N + 1, 1);
  for (int i = 1; i <= N; i++) {
    cin >> h[i];
  }
  // cout << ini.size();
  int a, b;
  for (int j = 1; j <= M; j++) {
    cin >> a >> b;
    if (h[a] > h[b]) {
      ini[b] = 0;
    } else if (h[a] < h[b]) {
      ini[a] = 0;
    } else {
      ini[a] = 0;
      ini[b] = 0;
    }
  }
  int sum = 0;
  for (int j = 1; j <= N; j++) {
    sum += ini[j];
  }
  cout << sum << 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<uint64_t> h(n);
  for (auto &it : h) {
    cin >> it;
  }

  set<int> good;
  for (int i = 0; i < n; i++) {
    good.insert(i);
  }

  for (int i = 0; i < m; i++) {
    int a, b;
    a--;
    b--;
    if (h.at(a) == h.at(b)) {
      good.erase(a);
      good.erase(b);
    }
    if (h.at(a) < h.at(b))
      good.erase(a);
    if (h.at(b) < h.at(a))
      good.erase(b);
  }
  cout << good.size() << endl;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<uint64_t> h(n);
  for (auto &it : h) {
    cin >> it;
  }

  set<int> good;
  for (int i = 0; i < n; i++) {
    good.insert(i);
  }

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (h.at(a) == h.at(b)) {
      good.erase(a);
      good.erase(b);
    }
    if (h.at(a) < h.at(b))
      good.erase(a);
    if (h.at(b) < h.at(a))
      good.erase(b);
  }
  cout << good.size() << endl;
}
Problem p02689 (C++)

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

int main() {
  long long n, m, x;
  x = 0;
  cin >> n >> m;
  vector<long long> h(n);
  vector<long long> a(m);
  vector<long long> b(m);
  vector<long long> sum(n);
  for (int i = 0; i < n; i++) {
    cin >> h.at(i);
  }
  for (long long i = 0; i < m; i++) {
    cin >> a.at(i) >> b.at(i);
  }
  for (long long i = 0; i < m; i++) {
    if (h.at(a.at(i)) < h.at(b.at(i))) {
      sum.at(a.at(i)) = 1;
    } else if (h.at(a.at(i)) > h.at(b.at(i))) {
      sum.at(b.at(i)) = 1;
    }
  }
  for (long long i = 0; i < n; i++) {
    if (sum.at(i) == 0) {
      x++;
    }
  }
  cout << x << endl;
}


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

int main() {
  long long n, m, x;
  x = 0;
  cin >> n >> m;
  vector<long long> h(n);
  vector<long long> a(m);
  vector<long long> b(m);
  vector<long long> sum(n);
  for (int i = 0; i < n; i++) {
    cin >> h.at(i);
  }
  for (long long i = 0; i < m; i++) {
    cin >> a.at(i) >> b.at(i);
  }
  for (long long i = 0; i < m; i++) {
    if (h.at(a.at(i) - 1) <= h.at(b.at(i) - 1)) {
      sum.at(a.at(i) - 1) = 1;
    }
    if (h.at(a.at(i) - 1) >= h.at(b.at(i) - 1)) {
      sum.at(b.at(i) - 1) = 1;
    }
  }
  for (long long i = 0; i < n; i++) {
    if (sum.at(i) == 0) {
      x++;
    }
  }
  cout << x << endl;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>

#define int long long
#define rr register

#define MAXN 100010
#define inf 1e18

using namespace std;

inline int read() {
  int s = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    f |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    s = s * 10 + (ch ^ 48);
    ch = getchar();
  }
  return f ? -s : s;
}

struct Edge {
  int nxt;
  int to;
} e[MAXN];

int n, m, ans, tot;

int a[MAXN], head[MAXN];

inline void add(int from, int to) {
  e[++tot].to = to;
  e[tot].nxt = head[from];
  head[from] = tot;
}

void dfs(int x) {
  for (rr int i = head[x]; i; i = e[i].nxt) {
    int to = e[i].to;
    if (a[x] <= a[to])
      return;
  }
  ans++;
}

signed main() {
  n = read();
  m = read();
  for (rr int i = 1; i <= n; i++)
    a[i] = read();
  for (rr int i = 1; i <= m; i++) {
    int x = read(), y = read();
    add(x, y);
    add(y, x);
  }
  for (rr int i = 1; i <= n; i++)
    dfs(i);
  cout << ans << "\n";
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>

#define int long long
#define rr register

#define MAXN 1000010
#define inf 1e18

using namespace std;

inline int read() {
  int s = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    f |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    s = s * 10 + (ch ^ 48);
    ch = getchar();
  }
  return f ? -s : s;
}

struct Edge {
  int nxt;
  int to;
} e[MAXN];

int n, m, ans, tot;

int a[MAXN], head[MAXN];

inline void add(int from, int to) {
  e[++tot].to = to;
  e[tot].nxt = head[from];
  head[from] = tot;
}

void dfs(int x) {
  for (rr int i = head[x]; i; i = e[i].nxt) {
    int to = e[i].to;
    if (a[x] <= a[to])
      return;
  }
  ans++;
}

signed main() {
  n = read();
  m = read();
  for (rr int i = 1; i <= n; i++)
    a[i] = read();
  for (rr int i = 1; i <= m; i++) {
    int x = read(), y = read();
    add(x, y);
    add(y, x);
  }
  for (rr int i = 1; i <= n; i++)
    dfs(i);
  cout << ans << "\n";
}
Problem p02689 (C++)

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

const int N = 1005;
int best[N], h[N];

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

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

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

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    best[x] = max(best[x], h[y]);
    best[y] = max(best[y], h[x]);
  }

  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (h[i] > best[i])
      ans++;
  cout << ans << endl;
}


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

const int N = 1e5 + 5;
int best[N], h[N];

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

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

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

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    best[x] = max(best[x], h[y]);
    best[y] = max(best[y], h[x]);
  }

  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (h[i] > best[i])
      ans++;
  cout << ans << endl;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

int H[11000];
bool good[11000];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; i++)
    cin >> H[i];

  fill(good, good + N, 1);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    if (H[a] <= H[b])
      good[a] = 0;
    if (H[a] >= H[b])
      good[b] = 0;
  }

  int cnt = 0;
  for (int i = 0; i < N; i++)
    if (good[i])
      cnt++;
  cout << cnt << '\n';
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

int H[110000];
bool good[110000];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; i++)
    cin >> H[i];

  fill(good, good + N, 1);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    if (H[a] <= H[b])
      good[a] = 0;
    if (H[a] >= H[b])
      good[b] = 0;
  }

  int cnt = 0;
  for (int i = 0; i < N; i++)
    if (good[i])
      cnt++;
  cout << cnt << '\n';
  return 0;
}
Problem p02689 (C++)

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

typedef long long ll;

#define Canuc80k                                                               \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define I_am ios_base::sync_with_stdio(false);
#define REP(i, a, b) for (int i = a; i < b; i++)
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = a; i >= b; i--)

const int N = 1e6 + 1;
const int M = 1e9 + 7;

string str;
pair<int, int> a[N];
int n, m, h[N], cnt = 0;
bool pp[N];

int main() {
  I_am Canuc80k;

  cin >> n >> m;
  FOR(i, 1, n) {
    cin >> h[i];
    pp[i] = true;
  }

  FOR(i, 1, m)
  cin >> a[i].first >> a[i].second;

  sort(a + 1, a + m + 1);

  FOR(i, 1, m) {
    int now = h[a[i].first];
    bool ok = false;

    FOR(j, i, m) {
      if (a[j].first != a[i].first || j == m) {
        if (h[a[j].second] >= now)
          pp[a[i].second] = false;
        if (h[a[j].second] <= now)
          pp[a[j].second] = false;
        i = j - 1;
        break;
      } else {
        if (h[a[j].second] >= now)
          pp[a[i].second] = false;
        if (h[a[j].second] <= now)
          pp[a[j].second] = false;
      }
    }
  }

  FOR(i, 1, n)
  if (pp[i])
    cnt++;

  cout << cnt;
}

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

typedef long long ll;

#define Canuc80k                                                               \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define I_am ios_base::sync_with_stdio(false);
#define REP(i, a, b) for (int i = a; i < b; i++)
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = a; i >= b; i--)

const int N = 1e6 + 1;
const int M = 1e9 + 7;

string str;
pair<int, int> a[N];
int n, m, h[N], cnt = 0;
bool pp[N];

int main() {
  I_am Canuc80k;

  cin >> n >> m;
  FOR(i, 1, n) {
    cin >> h[i];
    pp[i] = true;
  }

  FOR(i, 1, m)
  cin >> a[i].first >> a[i].second;

  sort(a + 1, a + m + 1);

  FOR(j, 1, m) {
    if (h[a[j].second] >= h[a[j].first])
      pp[a[j].first] = false;
    if (h[a[j].second] <= h[a[j].first])
      pp[a[j].second] = false;
  }

  FOR(i, 1, n)
  if (pp[i])
    cnt++;

  cout << cnt;
}
Problem p02689 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define py printf("Yes\n")
#define pn printf("No\n")
#define in cin >>
using namespace std;
int main() {
  int n, m, h[n], ma[n];
  in n >> m;
  for (int i = 1; i <= n; i++) {
    in h[i];
    ma[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    in 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>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define py printf("Yes\n")
#define pn printf("No\n")
#define in cin >>
using namespace std;
int main() {
  int n, m, h[100000], ma[100000];
  in n >> m;
  for (int i = 1; i <= n; i++) {
    in h[i];
    ma[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    in 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: 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);
  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;
}

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);
  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;
}