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

#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
typedef long long ll;
#define fin(ans) cout << (ans) << '\\n'
/*

*/
int main() {
  ll N, M;
  cin >> N >> M;
  ll H[100100];
  ll cnt = 0;
  int flags[100100];
  ll first, second;
  // フラグの初期化。最初はすべていい景色
  REPD(i, 1, N + 1)
  flags[i] = 1;

  // 1~Nまでに入れた
  REPD(i, 1, N + 1)
  cin >> H[i];
  /*
  どっちかがどっちかより小さかったら小さい方のフラグを0に
  同じ場合は両方のフラグを0に
  */
  REP(i, M) {
    cin >> first >> second;
    if (H[first] < H[second])
      flags[first] = 0;
    else if (H[second] < H[first])
      flags[second] = 0;
    else
      flags[first] = flags[second] = 0;
  }

  // 数える
  REPD(i, 1, N + 1)
  if (flags[i])
    cnt++;
  fin(cnt);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
typedef long long ll;
#define fin(ans) cout << (ans) << '\\n'
/*

*/
int main() {
  int N, M;
  cin >> N >> M;
  ll H[100100];
  int cnt = 0;
  // int AB[10010][10010] = {0};
  // bool AB[100][100] = {false};
  map<ll, int> matrix;
  int flags[100100] = {0};
  int temp[2];
  // 1~Nまでに入れた
  for (int i = 1; i < N + 1; i++) {
    cin >> H[i];
  }
  REP(i, M) {
    cin >> temp[0] >> temp[1];
    matrix[temp[0] * 100000 + temp[1]] = matrix[temp[1] * 100000 + temp[0]] = 1;
  }
  int first, second;
  REPD(i, 1, N + 1) { flags[i] = 1; }
  for (const auto &[key, value] : matrix) {
    first = key % 100000;
    second = key / 100000;
    // cout << first << " " << second << endl;
    // if(first > second){break;}
    if (H[first] < H[second]) {
      // cout << "!" << endl;
      flags[first] = 0;
    } else if (H[second] < H[first]) {
      flags[second] = 0;
    } else {
      flags[first] = flags[second] = 0;
    }
    // std::cout << key << " => " << value << "\\n";
  }
  REPD(i, 1, N + 1) {
    // cout << flags[i] << endl;
    if (flags[i])
      cnt++;
  }
  fin(cnt);
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
int main() {
  int N, M, A, B, count, H[100001] = {0}, peak[100001] = {0};
  count = scanf("%d %d", &N, &M);
  rep(i, N) count = scanf("%d", &H[i]);
  rep(i, M) {
    count = scanf("%d %d", &A, &B);
    A--, B--;
    peak[A] = (peak[A] > H[B]) ? peak[A] : H[B];
    peak[B] = (H[A] > peak[B]) ? H[A] : peak[B];
  }
  count = 0;
  rep(i, N) count += H[i] > peak[i];
  return printf("%d\\n", count), 0;
}

Error: 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, count = 0, peak;
  cin >> N >> M;
  vector<int> H(N, 0);
  vector<vector<int>> road(N, vector<int>(N, 0));
  rep(i, N) cin >> H.at(i);
  rep(i, M) {
    cin >> a >> b;
    road.at(a - 1).at(b - 1)++;
    road.at(b - 1).at(a - 1)++;
  }
  rep(i, N) {
    peak = 0;
    rep(j, N) {
      if (road.at(i).at(j) != 0)
        peak = max(H.at(j), peak);
    }
    if (H.at(i) > peak)
      count++;
  }
  return cout << count << endl, 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
static const int N_MAX = 100010;

using namespace std;

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

void solve() {

  int res = 0;

  for (int i = 1; i <= N; i++) {
    bool highest = true;
    for (int j = 0; j < G[i].size(); j++) {
      if (H[i] <= H[G[i][j]]) {
        highest = false;
        break;
      }
    }
    if (highest == true)
      res += 1;
  }
  printf("%d", res);
}

int main() {

  cin >> N >> M;
  int h;
  for (int i = 1; i <= N; i++) {
    cin >> h;
    H[i] = h;
  }
  int u, v;
  for (int i = 0; i < M; i++) {
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  solve();
  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
#include <vector>
static const int N_MAX = 10000;

using namespace std;

int N, M;
vector<int> G[N_MAX + 1];
long long H[N_MAX + 1];

void solve() {

  int res = 0;

  for (int i = 1; i <= N; i++) {
    bool highest = true;
    for (int j = 0; j < G[i].size(); j++) {
      if (H[i] <= H[G[i][j]]) {
        highest = false;
        break;
      }
    }
    if (highest == true)
      res += 1;
  }
  printf("%d", res);
}

int main() {

  cin >> N >> M;
  int h;
  for (int i = 1; i <= N; i++) {
    cin >> h;
    H[i] = h;
  }
  int u, v;
  for (int i = 0; i < M; i++) {
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  solve();
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int main() {
  int N, M;
  cin >> N;
  cin >> M;
  vector<long> height(N);
  vector<bool> good(N, true);
  for (int i = 0; i < N; ++i) {
    cin >> height[i];
  }
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a;
    cin >> b;
    a--;
    b--;
    if (height[a] < height[b]) {
      good[a] = false;
    } else if (height[b] < height[a]) {
      good[b] = false;
    } else if (height[a] == height[b]) {
      good[a] = false;
      good[b] = false;
    }
  }

  int ngood = 0;
  for (int i = 0; i < N; ++i) {
    if (good[i])
      ngood++;
  }
  cout << ngood << endl;
  return 0;
}

Error: MLE

Fixed submission:

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

int main() {
  int N, M;
  cin >> N;
  cin >> M;
  vector<long> height(N);
  vector<bool> good(N, true);
  vector<vector<bool>> adj(N, vector<bool>(N, false));
  for (int i = 0; i < N; ++i) {
    cin >> height[i];
  }
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a;
    cin >> b;
    a--;
    b--;
    if (height[a] < height[b]) {
      good[a] = false;
    } else if (height[b] < height[a]) {
      good[b] = false;
    } else if (height[a] == height[b]) {
      good[a] = false;
      good[b] = false;
    }
  }

  int ngood = 0;
  for (int i = 0; i < N; ++i) {
    if (good[i])
      ngood++;
  }
  cout << ngood << endl;
  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<int> a(m), b(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }
  int ans = n;
  vector<int> temp(n, 0);
  for (int i = 0; i < m; i++) {
    if ((h[a[i] - 1] <= h[b[i] - 1]) && (temp[a[i] - 1] == 0)) {
      ans = ans - 1;
      temp[a[i] - 1] = 1;
    }
    if ((h[b[i] - 1] <= h[a[i] - 1]) && (temp[b[i] - 1] == 0)) {
      ans = ans - 1;
      temp[b[i] - 1] = 1;
    }
  }
  cout << ans << endl;
  return 0;
}

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<int> a(m), b(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }
  int ind = 0;
  int ans = n;
  for (int i = 0; i < n; i++) {
    ind = 0;
    for (int j = 0; j < m; j++) {
      if (i + 1 == a[j]) {
        if (h[i] <= h[b[j] - 1]) {
          ind = 1;
        }
      } else if (i + 1 == b[j]) {
        if (h[i] <= h[a[j] - 1]) {
          ind = 1;
        }
      }
    }
    if (ind == 1) {
      ans = ans - 1;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll n, m;
  scanf("%lld %lld", &n, &m);
  vector<ll> h(n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &h[i]);
  }
  vector<ll> data[n];
  for (ll i = 0; i < m; i++) {
    ll a, b;
    scanf("%lld %lld", &a, &b);
    data[a - 1].push_back(b - 1);
    data[b - 1].push_back(a - 1);
  }
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    ll h_max = 0;
    for (ll j = 0; j < data[i].size(); j++) {
      h_max = max(h_max, h[data[i][j]]);
    }
    if (h_max < h[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  ll n, m;
  scanf("%lld %lld", &n, &m);
  vector<ll> h(n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &h[i]);
  }
  vector<vector<ll>> data(n, vector<ll>(n, 0));
  for (int i = 0; i < m; i++) {
    ll a, b;
    scanf("%lld %lld", &a, &b);
    data[a - 1][b - 1] = 1;
    data[b - 1][a - 1] = 1;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ll sum = 0;
    for (int j = 0; j < n; j++) {
      sum += data[i][j];
      if (data[i][j] == 1 && h[i] <= h[j]) {
        break;
      }
      if (j == n - 1)
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

const int INT_INF = 1e9;
const long long LONG_INF = 1e18;
const long long MOD = 1e9 + 7;

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<int> ma(n, 0);
  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--;
    ma[a] = max(ma[a], h[b]);
    ma[b] = max(ma[b], h[a]);
  }

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

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

const int INT_INF = 1e9;
const long long LONG_INF = 1e18;
const long long MOD = 1e9 + 7;

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<vector<int>> v(n, vector<int>(n, 0));
  vector<bool> flag(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]) {
      flag[b] = false;
    } else if (h[a] < h[b]) {
      flag[a] = false;
    } else if (h[a] == h[b]) {
      flag[a] = false;
      flag[b] = false;
    }
  }

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

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, ans = 0;
  cin >> n >> m;
  long long h[n], mm[n];
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    mm[i] = 0;
  }
  long long a[m], b[m];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    mm[a[i] - 1] = max(mm[a[i] - 1], h[b[i] - 1]);
    mm[b[i] - 1] = max(mm[b[i] - 1], h[a[i] - 1]);
  }
  for (int i = 0; i < n; i++) {
    if (h[i] > mm[i])
      ans++;
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  long long h[n];
  for (int i = 0; i < n; i++)
    cin >> h[i];
  long long a[m], b[m];
  for (int i = 0; i < m; i++)
    cin >> a[i] >> b[i];
  long long int ok[n];
  long long int count = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    ok[i] = 1;
  }
  while (count < n) {
    int top = 0;
    for (int i = 0; i < n; i++) {
      if (ok[i] == 1 && ok[top] == 0)
        top = i;
      if (h[top] < h[i] && ok[i] == 1)
        top = i;
    }
    // cerr << top <<endl;
    bool chance = true;
    for (int i = 0; i < m; i++) {
      if (a[i] - 1 == top && h[top] <= h[b[i] - 1])
        chance = false;
      if (b[i] - 1 == top && h[top] <= h[a[i] - 1])
        chance = false;
    }
    if (chance) {
      ans++;
      cerr << h[top] << endl;
    }
    count++;
    ok[top] = 0;
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string.h>
#include <vector>

using namespace std;

int main() {

  long long int N, M;
  long long int A, B;
  long long int count = 0;

  cin >> N >> M;
  long long int tab[N + 5];            // obs
  vector<long long int> cores[100005]; // linked roads

  for (long long int i = 1; i <= N; i++) {
    cin >> tab[i];
  }

  for (long long int i = 0; i < M; i++) {
    cin >> A >> B; // road A linked to B
    cores[A].push_back(B);
    cores[B].push_back(A);
  }

  for (long long int i = 1; i <= N; ++i) {

    bool good = true;
    for (long long int it : cores[i]) {
      if (tab[it] >= tab[i]) {
        good = false;
        break;
      }
    }
    if (good) {
      count++;
    }
  }

  cout << count;

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <string.h>
#include <vector>

using namespace std;

int main() {

  long long int N, M;
  long long int A, B;
  long long int count = 0;

  cin >> N >> M;
  long long int tab[N + 5];           // obs
  vector<long long int> cores[10005]; // linked roads

  for (long long int i = 1; i <= N; i++) {
    cin >> tab[i];
  }

  for (long long int i = 0; i < M; i++) {
    cin >> A >> B; // road A linked to B
    cores[A].push_back(B);
    cores[B].push_back(A);
  }

  for (long long int i = 1; i <= N; ++i) {

    bool good = true;
    for (long long int it : cores[i]) {
      if (tab[it] >= tab[i]) {
        good = false;
        break;
      }
    }
    if (good) {
      count++;
    }
  }

  cout << count;

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

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

int main() {

  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> heights(n);
  for (int &x : heights) {
    scanf("%d", &x);
  }
  vector<int> tempheights(n);
  tempheights = heights;
  // vector<vector<int> > matrix(n, vector<int>(n));
  int f, s;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &f, &s);
    int a = heights[f - 1], b = heights[s - 1];
    if (a > b)
      tempheights[s - 1] = 0;
    else if (a < b)
      tempheights[f - 1] = 0;
    else {
      tempheights[f - 1] = 0;
      tempheights[s - 1] = 0;
    }
  }
  int count = 0;
  for (int &x : tempheights) {
    if (x)
      count++;
  }
  printf("%d", count);

  return 0;
}


Error: WA

Fixed submission:

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

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> heights(n);
  for (int &x : heights) {
    scanf("%d", &x);
  }
  vector<vector<int>> matrix(n, vector<int>(n));
  int f, s;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &f, &s);
    matrix[f - 1][s - 1] = 1;
    matrix[s - 1][f - 1] = 1;
  }
  int max, count = 0;
  for (int i = 0; i < n; i++) {
    max = heights[i];
    bool good = true;
    for (int j = 0; j < n; ++j) {
      if (matrix[i][j] && i != j) {
        if (heights[j] >= max) {
          good = false;
        }
      }
    }
    if (good)
      count++;
  }
  printf("%d", count);

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

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

typedef long long ll;
typedef long long int lli;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;

const int N = (int)2e5 + 5;
const int maxN = (int)1e6 + 6;
const ll Mod = (ll)1e9 + 7;
const int inf = (int)2e9;
const ll Inf = (ll)1e18;

long long int qq = 0, aa = 1, m, nn, a2 = 0, i, j;
vector<long long int> vvv[maxN];
vector<long long int> vv;

void fun() {
  long long int a1 = 0;
  for (i = 1; i <= nn; i++) {
    set<long long int> st(vvv[i].begin(), vvv[i].end());
    vector<long long int> v(st.begin(), st.end());
    for (j = 0; j < v.size(); j++) {
      // cout<<v[j]<<" ";
      if (vv[i - 1] > vv[v[j] - 1]) {
        a1++;
      } else {
      }
    }

    if (a1 == v.size()) {
      a2++;
      // cout<<i<<" ";
    }

    a1 = 0;
  }
  cout << a2 << endl;
}
int main() {
  long long int x, y;
  cin >> nn >> m;
  for (i = 0; i < nn; i++) {
    cin >> x;
    vv.push_back(x);
  }
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    vvv[x].push_back(y);
    vvv[y].push_back(x);
  }

  fun();
}


Error: WA

Fixed submission:

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

typedef long long ll;
typedef long long int lli;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;

const int N = (int)2e5 + 5;
const int maxN = (int)1e6 + 6;
const ll Mod = (ll)1e9 + 7;
const int inf = (int)2e9;
const ll Inf = (ll)1e18;

long long int qq = 0, aa = 1, m, nn, a2 = 0, i, j;
vector<long long int> v[maxN];
vector<long long int> vv;

int fun() {
  long long int a1 = 0;
  for (i = 1; i <= nn; i++) {
    for (j = 0; j < v[i].size(); j++) {
      if (vv[i] >= vv[v[i][j]]) {
        a1++;
      } else {
        a1 = 0;
      }
    }
    if (a1 == v[i].size()) {
      a2++;
      // cout<<i<<" ";
    }
    a1 = 0;
  }
  cout << a2 << endl;
}
int main() {
  long long int x, y, z, j, a, t;
  cin >> nn >> m;
  for (i = 0; i < nn; i++) {
    cin >> x;
    vv.push_back(x);
  }
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }

  fun();
}
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;
typedef float fl;
typedef long long ll;

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


Error: 0

Fixed submission:

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

int main() {
  cin >> N >> M;
  int h[N];
  rep(i, N) cin >> h[i];
  int R[N][N];
  rep(i, N) { rep(j, N) R[i][j] = 0; }
  rep(k, M) {
    int i, j;
    cin >> i >> j;
    i--;
    j--;
    R[i][j] = R[j][i] = 1;
  }

  int ans = 0;
  rep(i, N) {
    int count_i = 0, count = 0;
    rep(j, N) {
      if (R[i][j] == 1) {
        count_i++;
        if (h[i] > h[j])
          count++;
      }
    }
    if (count_i == count)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

/************************************
/ AUTHOR : YATHARTH GOSWAMI         /
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> h(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  vector<pair<int, int>> v(m);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[i] = mp(a, b);
  }
  vector<bool> ans(n, true);
  for (int i = 0; i < m; i++) {
    if (h[v[i].F - 1] > h[v[i].S - 1]) {
      ans[v[i].S - 1] = false;
    } else if (h[v[i].F - 1] < h[v[i].S - 1]) {
      ans[v[i].F - 1] = false;
    } else {
      ans[v[i].F - 1] = false;
      ans[v[i].S - 1] = false;
    }
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (ans[i] == true)
      count++;
  }
  cout << count << endl;
  return 0;
}


Error: 0

Fixed submission:

/************************************
/ AUTHOR : YATHARTH GOSWAMI         /
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> h(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  vector<pair<int, int>> v(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[i] = mp(a, b);
  }
  vector<bool> ans(n, true);
  for (int i = 0; i < m; i++) {
    if (h[v[i].F - 1] > h[v[i].S - 1]) {
      ans[v[i].S - 1] = false;
    } else if (h[v[i].F - 1] < h[v[i].S - 1]) {
      ans[v[i].F - 1] = false;
    } else {
      ans[v[i].F - 1] = false;
      ans[v[i].S - 1] = false;
    }
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (ans[i] == true)
      count++;
  }
  cout << count << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  vector<pair<long long, long long>> AB(M);
  vector<long long> HH(N);
  for (int i = 0; i < M; i++) {
    cin >> AB.at(i).first >> AB.at(i).second;
    HH.at(AB.at(i).first - 1) =
        max(HH.at(AB.at(i).first - 1), H.at(AB.at(i).second - 1));
    HH.at(AB.at(i).second - 1) =
        max(HH.at(AB.at(i).second - 1), H.at(AB.at(i).first - 1));
  }

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

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


Error: TLE

Fixed submission:

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

int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  vector<pair<long long, long long>> AB(M);
  for (int i = 0; i < M; i++) {
    cin >> AB.at(i).first >> AB.at(i).second;
  }

  vector<long long> HH(N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (AB.at(j).first == i + 1) {
        HH.at(i) = max(HH.at(i), H.at(AB.at(j).second - 1));
      } else if (AB.at(j).second == i + 1) {
        HH.at(i) = max(HH.at(i), H.at(AB.at(j).first - 1));
      }
    }
  }

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

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