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

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <map>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> flag(N, 0);
  vector<long long> H(N);
  for (int i = 0; i < N; i++)
    cin >> H.at(i);

  int A, B;
  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    if (H.at(B - 1) < H.at(A - 1)) {
      flag.at(B - 1) = 1;
    } else if (H.at(A - 1) < H.at(B - 1)) {
      flag.at(A - 1) = 1;
    } else if (H.at(A - 1) == H.at(B - 1)) {
      flag.at(A - 1) = 1;
      flag.at(B - 1) = 1;
    }
  }

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

  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <map>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

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

  int ans = 0;
  vector<int> flag(N, 0);
  for (int i = 0; i < N; i++) {
    if (flag.at(i) == 1)
      continue;
    for (int j = 0; j < N; j++) {
      if (conection.at(i).at(j) == 1) {
        if (H.at(j) < H.at(i)) {
          flag.at(j) = 1;
        } else {
          flag.at(i) = 1;
          break;
        }
      }
    }
    if (flag.at(i) == 0)
      ans++;
  }

  cout << ans << endl;

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

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n + 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;
}

Error: 0

Fixed submission:

#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;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

vector<ll> H;
using Graph = vector<vector<int>>;

ll search(const Graph &G, int v) {
  int idx = v;
  ll score = H[v];
  for (auto next_v : G[v]) {
    if (score <= H[next_v]) {
      score = H[next_v];
      idx = next_v;
    }
  }
  return idx;
}

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

  set<pair<int, int>> ch;
  Graph G(N);
  rep(i, N) {
    ll h;
    cin >> h;
    H.push_back(h);
  }
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    pair<int, int> c = make_pair(a, b);
    if (0 != ch.count(c))
      continue;
    ch.insert(c);
    G[a].push_back(b);
    G[b].push_back(a);
  }

  int cnt = 0;
  rep(i, N) {
    if (i == search(G, i))
      cnt++;
  }
  cout << cnt << endl;
}


Error: 0

Fixed submission:

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

vector<ll> H;
using Graph = vector<vector<int>>;

ll search(const Graph &G, int v) {
  int idx = v;
  ll score = H[v];
  for (auto next_v : G[v]) {
    if (score <= H[next_v]) {
      score = H[next_v];
      idx = next_v;
    }
  }
  return idx;
}

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

  vector<vector<int>> ch(N, vector<int>(N, 0));
  Graph G(N);
  rep(i, N) {
    ll h;
    cin >> h;
    H.push_back(h);
  }
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (0 != ch[a][b])
      continue;
    ch[a][b]++;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  int cnt = 0;
  rep(i, N) {
    if (i == search(G, i))
      cnt++;
  }
  cout << cnt << endl;
}
Problem p02689 (C++) — buggy submission, verdict: 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, 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;
}

Error: 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, 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;
}
Problem p02689 (C++) — buggy submission, verdict: 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 <= 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;
}

Error: WA

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 <= 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;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n), d(n), a(m), b(m);
  rep(i, n) {
    cin >> h[i];
    d[i]++;
  }
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    if (h[a[i]] < h[b[i]])
      d[a[i]] = 0;
    else if (h[a[i]] > h[b[i]])
      d[b[i]] = 0;
    else {
      d[a[i]] = 0;
      d[b[i]] = 0;
    }
  }
  int ans = 0;
  rep(i, n) {
    if (d[i])
      ans++;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

#include <algorithm>
#include <boost/math/common_factor_rt.hpp>
#include <boost/math/constants/constants.hpp>
#include <iostream>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_set>

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; ++i)

int main() {
  ll N, M, t1, t2, t;
  vector<ll> H, ind;
  cin >> N >> M;
  rep(i, N) {
    cin >> t;
    H.push_back(t);
    ind.push_back(i);
  }

  /*sort(ind.begin(), ind.end(), [&H](size_t i1, size_t i2) {
        return H[i1] < H[i2];
  });*/

  /*rep(i, ind.size()){
    cout << ind[i] << endl;
  }*/

  vector<vector<ll>> G(N);
  rep(i, M) {
    cin >> t1 >> t2;
    G[t1 - 1].push_back(t2 - 1);
    G[t2 - 1].push_back(t1 - 1);
  }

  ll mem;
  ll ans = 0;

  rep(i, N) {
    if (G[i].size() == 0) {
      ans++;
      // cout << "Yes" << i << endl;
      continue;
    }

    mem = 0;
    rep(j, G[i].size()) {
      if (H[i] <= H[G[i][j]]) {
        break;
      }
      mem++;
    }
    // cout << mem << G[i].size() << endl;
    if (mem == (G[i].size())) {
      ans++;
    }
    /*for(int j=ind.size()-1; j>=0; j--){
      auto itr = find(G[i].begin(), G[i].end(), ind[j]);
      size_t index = distance(G[i].begin(), itr);
          if (index != G[i].size()) {
        mem = ind[j];
        break;
      }
    }
    if(H[i]>H[mem]){
      ans++;
    }*/
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <boost/math/common_factor_rt.hpp>
#include <boost/math/constants/constants.hpp>
#include <iostream>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_set>

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; ++i)

int main() {
  ll N, M, t1, t2, t;
  vector<ll> H, ind;
  cin >> N >> M;
  rep(i, N) {
    cin >> t;
    H.push_back(t);
    ind.push_back(i);
  }

  sort(ind.begin(), ind.end(),
       [&H](size_t i1, size_t i2) { return H[i1] < H[i2]; });

  /*rep(i, ind.size()){
    cout << ind[i] << endl;
  }*/

  vector<vector<ll>> G(N);
  rep(i, M) {
    cin >> t1 >> t2;
    G[t1 - 1].push_back(t2 - 1);
    G[t2 - 1].push_back(t1 - 1);
  }

  ll mem;
  ll ans = 0;

  rep(i, N) {
    if (G[i].size() == 0) {
      ans++;
      continue;
    }

    for (int j = ind.size() - 1; j >= 0; j--) {
      auto itr = find(G[i].begin(), G[i].end(), ind[j]);
      size_t index = distance(G[i].begin(), itr);
      if (index != G[i].size()) {
        mem = ind[j];
        break;
      }
    }
    if (H[i] > H[mem]) {
      ans++;
    }
  }

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

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


Error: WA

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[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;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (int i = 0; i < n; i++)
    cin >> h.at(i);
  vector<bool> ok(n, true);
  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;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (int i = 0; i < n; i++)
    cin >> h.at(i);
  vector<pair<int, int>> pairs(m);

  for (int i = 0; i < m; i++) {
    cin >> pairs[i].first >> pairs[i].second;
    // cout << pairs[i].first << " " << pairs[i].second << endl;
  }

  sort(pairs.begin(), pairs.end());

  int count = 0;
  int d = 1;
  while (d <= n) {
    bool check = true;
    for (int j = 0; j < m; j++) {
      if (pairs[j].first == d || pairs[j].second == d) {
        if (pairs[j].first == d) {
          if (h.at((pairs[j].first) - 1) <= h.at((pairs[j].second) - 1)) {
            check = false;
          }
        }
        if (pairs[j].second == d) {
          if (h.at((pairs[j].second) - 1) <= h.at((pairs[j].first) - 1)) {
            check = false;
          }
        }
      }
    }
    if (check) {
      count++;
    }
    d++;
  }
  cout << count << endl;
}
Problem p02689 (C++) — buggy submission, verdict: 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(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;
}

Error: -11

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(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;
}
Problem p02689 (C++) — buggy submission, verdict: 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<vector<int>> road(N, vector<int>(0));
  for (int i = 0; i < M; i++) {
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    road[tmp1 - 1].push_back(tmp2 - 1);
    road[tmp2 - 1].push_back(tmp1 - 1);
  }
  int res = 0;
  for (int i = 0; i < N; i++) {
    bool can = true;
    for (int j = 0; j < road[i].size(); j++) {
      if (H[i] <= H[road[i][j]]) {
        can = false;
        break;
      }
    }
    if (can)
      res++;
  }
  cout << res << endl;
}


Error: TLE

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<vector<char>> road(N, vector<char>(N, 'x'));
  for (int i = 0; i < M; i++) {
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    road[tmp1 - 1][tmp2 - 1] = 'o';
    road[tmp2 - 1][tmp1 - 1] = 'o';
  }
  int res = 0;
  vector<bool> seen(N, false);
  for (int i = 0; i < N; i++) {
    if (!seen[i]) {
      bool can = true;
      for (int j = 0; j < N; j++) {
        if (road[i][j] == 'o') {
          if (H[i] <= H[j]) {
            can = false;
            break;
          } else
            seen[j] = true;
        }
      }
      if (can)
        res++;
    }
  }
  cout << res << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define mod 1000000007    // 10^9+7
#define INF 1000000000000 // 10^12
#define F first
#define S second
#define P pair<int, int>
#define all(vec) vec.begin(), vec.end()
int n, m;
int h[200000];
int ans = 0;
vector<int> vec[200000];
signed main() {
  cin >> n >> m;
  rep(i, n) cin >> h[i + 1];
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    vec[a].push_back(b);
    vec[b].push_back(a);
  }
  rep(i, n) {
    int l = vec[i + 1].size();
    bool gt = true;
    rep(j, l) {
      if (h[i + 1] <= h[vec[i + 1][j]])
        gt = false;
    }
    if (gt) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define mod 1000000007    // 10^9+7
#define INF 1000000000000 // 10^12
#define F first
#define S second
#define P pair<int, int>
#define all(vec) vec.begin(), vec.end()
int n, m;
int h[20000];
int ans = 0;
vector<int> vec[200000];
signed main() {
  cin >> n >> m;
  rep(i, n) cin >> h[i + 1];
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    vec[a].push_back(b);
    vec[b].push_back(a);
  }

  rep(i, n) {
    int l = vec[i + 1].size();
    bool gt = true;
    rep(j, l) {
      if (h[i + 1] <= h[vec[i + 1][j]])
        gt = false;
    }
    if (gt) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define _GLIBCXX_DEBUG
#define int long long
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1) {
  unsigned day;
  if (dow < dow1)
    dow += 7;
  day = dow - dow1;
  day += 7 * n - 6;
  return day;
}
unsigned DayToWeekNumber(unsigned day) { return (day - 1) / 7 + 1; }
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0) {
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
  int N, M;
  cin >> N >> M;
  int H[N + 1];
  REP(i, N + 1) cin >> H[i];
  int A[M];
  int B[M];
  vector<int> C(N + 1);
  rep(i, M) {
    cin >> A[i] >> B[i];
    if (H[A[i]] <= H[B[i]])
      C[A[i]] = 1;
    if (H[A[i]] >= H[B[i]])
      C[B[i]] = 1;
  }
  int ans = 0;
  REP(i, N + 1) if (C[i] == 0) ans++;
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N + 1);
  for (int i = 1; i <= N; i++) {
    cin >> H[i];
  }
  vector<int> A(M + 1);
  vector<int> B(M + 1);
  for (int i = 1; i <= M; i++) {
    cin >> A[i] >> B[i];
  }
  int ans = 0;
  bool C = true;
  vector<int> wrong(N);
  for (int i = 1; i <= N; i++) {
    C = true;
    for (int j = 1; j <= M; j++) {
      if (i == wrong[j]) {
        C = false;
        break;
      }
    }
    if (C == false) {
      continue;
    }
    for (int j = 1; j <= M; j++) {
      if (A[j] == i) {
        if (H[A[j]] <= H[B[j]]) {
          C = false;
          break;
        }
        wrong[i] = B[j];
      } else if (B[j] == i) {
        if (H[A[j]] >= H[B[j]]) {
          C = false;
          break;
        }
        wrong[i] = A[j];
      }
    }
    if (C == false) {
      continue;
    }
    ans++;
  }
  cout << ans << endl;
}