alexjercan/bugnet huggingface dataset:
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

// 166 C

#include <algorithm>
#include <climits>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n, m, buf, a, b, count = 0;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> check(n, true);
  for (int i = 0; i < n; i++) {
    cin >> buf;
    h.at(i) = buf;
  }
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (h.at(a - 1) < h.at(b - 1)) {
      check.at(a - 1) = false;
    } else if (h.at(a - 1) > h.at(b - 1)) {
      check.at(b - 1) = false;
    } else if (h.at(a - 1) == h.at(b - 1)) {
      check.at(a - 1) = false;
      check.at(b - 1) = false;
    }
  }
  for (int i = 0; i < check.size(); i++) {
    if (check.at(i))
      count++;
  }
  cout << count << endl;
}

Error: TLE

Fixed submission:

// 166 C

#include <algorithm>
#include <climits>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n, m, buf, a, b, count = 0;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> check(n, true);
  vector<vector<bool>> v(n, vector<bool>(n, false));
  for (int i = 0; i < n; i++) {
    cin >> buf;
    h.at(i) = buf;
  }
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    v.at(a - 1).at(b - 1) = true;
    v.at(b - 1).at(a - 1) = true;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (v.at(i).at(j)) {
        if (h.at(i) <= h.at(j)) {
          check.at(i) = false;
          break;
        }
      }
    }
  }
  for (int i = 0; i < check.size(); i++) {
    if (check.at(i))
      count++;
  }
  cout << count << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

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

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

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

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

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

  int ans = 0;

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

  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

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

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

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

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

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

  int ans = 0;

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

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

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

#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n, 0);
  rep(i, n) { cin >> h[i]; }
  vector<vector<int>> mat(n);
  int a, b;
  rep(i, m) {
    cin >> a >> b;
    mat[a - 1].push_back(b - 1);
    mat[b - 1].push_back(a - 1);
  }
  int cnt = 0;
  bool flag;
  rep(i, n) {
    flag = true;
    rep(j, mat[i].size()) {
      if (h[i] <= h[mat[i][j]]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Error: 0

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n, 0);
  rep(i, n) { cin >> h[i]; }
  vector<vector<int>> mat(n, vector<int>(n, 0));
  int a, b;
  rep(i, m) {
    cin >> a >> b;
    mat[a - 1][b - 1]++;
    mat[b - 1][a - 1]++;
  }
  int cnt = 0;
  int max_h;
  bool flag;
  rep(i, n) {
    max_h = h[i];
    flag = true;
    rep(j, n) {
      if (mat[i][j] != 0) {
        max_h = max(max_h, h[j]);
        if (max_h == h[j]) {
          flag = false;
        }
      }
    }
    if (max_h == h[i] && flag) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  vector<bool> ans(N, true);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    if (H[a - 1] == H[b - 1]) {
      ans[a - 1] = false;
      ans[b - 1] = false;
      continue;
    }
    int X = a - 1;
    if (H[a - 1] > H[b - 1]) {
      X = b - 1;
    }
    ans[X] = false;
  }
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (ans[i]) {
      cnt++;
    }
  }
  cout << cnt << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  vector<bool> ans(N, true);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    ans[min(H[a - 1] - 1, H[b - 1] - 1)] = false;
  }
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (ans[i]) {
      cnt++;
    }
  }
  cout << cnt << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

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

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

  return 0;
}

Error: 0

Fixed submission:

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

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

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

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

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

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

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

Error: 0

Fixed submission:

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

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

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

#include <cmath>
#include <iostream>
#include <limits>
#include <set>
#include <vector>

using namespace std;

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

Error: 0

Fixed submission:

#include <cmath>
#include <iostream>
#include <limits>
#include <set>
#include <vector>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> ok(n, true);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    if (h[a] <= h[b])
      ok[a] = false;
    if (h[b] <= h[a])
      ok[b] = false;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (ok[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n);
  vector<set<ll>> mat(n, set<ll>());
  rep(i, n) { cin >> h[i]; }
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    mat[a - 1].insert(b - 1);
    mat[b - 1].insert(a - 1);
  }

  ll ans = 0;
  rep(i, n) {
    bool flg = true;
    for (auto &other : mat[i]) {
      if (h[i] <= h[other]) {
        flg = false;
        break;
      }
    }
    if (flg) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n);
  vector<vector<ll>> mat(n, vector<ll>(n, 0));
  rep(i, n) { cin >> h[i]; }
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    mat[a - 1][b - 1] = 1;
    mat[b - 1][a - 1] = 1;
  }

  ll ans = 0;
  rep(i, n) {
    bool flg = true;
    rep(j, n) {
      if (i == j) {
        continue;
      }
      if (mat[i][j]) {
        if (h[i] <= h[j]) {
          flg = false;
          break;
        }
      }
    }

    if (flg) {
      ans++;
    }
  }

  cout << ans << endl;

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

// Peaks
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> height(N);
  vector<bool> vec(N, true);
  for (int i = 0; i < N; i++) {
    int temp;
    cin >> temp;
    height[i] = temp;
  }
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    if (height[a - 1] <= height[b - 1]) {
      vec[a - 1] = false;
    }
    if (height[b - 1] <= height[a - 1]) {
      vec[b - 1] = false;
    }
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (vec[i] == true) {
      count++;
    }
  }

  cout << count << "\\n";
  return 0;
}

Error: 0

Fixed submission:

// Peaks
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> graph(N, vector<int>(M));
  vector<int> height(N);
  for (int i = 0; i < N; i++) {
    int temp;
    cin >> temp;
    height[i] = temp;
  }
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    graph[a - 1][b - 1] = 1;
    graph[b - 1][a - 1] = 1;
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    bool flag = true;
    for (int j = 0; j < M; j++) {
      if (graph[i][j] == 1) {
        if (height[i] <= height[j]) {
          flag = false;
        }
      }
    }
    if (flag) {
      count++;
    }
  }

  cout << count << "\\n";
  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.at(i);
  vector<int> a(m);
  vector<int> b(m);
  for (int i = 0; i < m; i++)
    cin >> a.at(i) >> b.at(i);

  vector<vector<int>> p(n, vector<int>(0));

  for (int i = 0; i < m; i++) {
    p.at(a.at(i) - 1).push_back(b.at(i));
    p.at(b.at(i) - 1).push_back(a.at(i));
  }

  int l = 0;

  for (int i = 0; i < n; i++) {
    int x = 0;
    int y = p.at(i).size();
    for (int j = 0; j < y; j++) {
      if (h.at(i) <= h.at(p.at(i).at(j) - 1)) {
        x++;
      }
    }
    if (x == 0) {
      l++;
    }
  }
  cout << l << 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.at(i);
  vector<int> a(m);
  vector<int> b(m);
  for (int i = 0; i < m; i++)
    cin >> a.at(i) >> b.at(i);

  vector<int> p(n);

  for (int i = 1; i <= n; i++) {
    int x = 0;
    for (int j = 0; j < m; j++) {
      if (a.at(j) == i) {
        if (h.at(b.at(j) - 1) >= h.at(i - 1) || p.at(b.at(j) - 1) == 1) {
          x++;
          break;
        }
      }
    }
    for (int j = 0; j < m; j++) {
      if (b.at(j) == i) {
        if (h.at(a.at(j) - 1) >= h.at(i - 1) || p.at(a.at(j) - 1) == 1) {
          x++;
          break;
        }
      }
    }
    if (x == 0)
      p.at(i - 1) = 1;
  }
  int l = 0;
  for (int i = 0; i < n; i++) {
    if (p.at(i) == 1)
      l++;
  }
  cout << l << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

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

  vector<int> h(n, 0);
  vector<bool> good(n, true);

  for (int i = 0; i != n; i++)
    cin >> h.at(i);
  int i1, i2;
  for (int i = 0; i != m; i++) {
    cin >> i1 >> i2;
    i1--;
    i2--;
    if (!(h.at(i1) > h.at(i2)))
      good.at(i1) = false;
    if (!(h.at(i2) > h.at(i1)))
      good.at(i2) = false;
  }
  int out = 0;
  for (auto i : good)
    if (i)
      out++;
  cout << out << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

vector<vector<bool>> path(1e5, vector<bool>(1e5, false));
vector<bool> reached;
vector<int> h;
int n;
int top;
bool is_single;

bool dfs(int x) {
  reached.at(x) = true;
  if (h.at(x) > top) {
    top = h.at(x);
    is_single = true;
  } else if (h.at(x) == top)
    is_single = false;

  for (int i = 0; i != n; i++) {
    if (!reached.at(i))
      if (path.at(i).at(x))
        dfs(i);
  }
  return is_single;
}

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

  h.resize(n);
  path.resize(n, vector<bool>(n));
  reached.resize(n, false);

  for (int i = 0; i != n; i++)
    cin >> h.at(i);
  int i1, i2;
  for (int i = 0; i != m; i++) {
    cin >> i1 >> i2;
    i1--;
    i2--;
    path.at(i1).at(i2) = true;
    path.at(i2).at(i1) = true;
  }

  int out = 0;
  int cur_h = 0;
  for (int i = 0; i != n; i++) {
    cur_h = h.at(i);
    bool flag = true;
    for (int j = 0; j != n; j++) {
      if (h.at(j) >= cur_h && path.at(i).at(j)) {
        flag = false;
        break;
      }
    }
    if (flag)
      out++;
  }
  cout << out << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <numeric>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N, M;
  int a, b;
  set<int> st;
  cin >> N >> M;
  // int H[N];
  vector<int> H(N + 1);
  for (int i = 1; i <= N; i++) {
    cin >> H.at(i);
  }
  for (int j = 1; j <= M; j++) {
    cin >> a >> b;
    // cout << H[a] << " " << H[b] << endl;
    if (H.at(a) == H.at(b)) {
      st.insert(a);
      st.insert(b);
    }
    if (H.at(a) > H.at(b)) {
      st.insert(b);
    }
    if (H.at(a) < H.at(b)) {
      st.insert(a);
    }
  }
  cout << N - st.size();
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <numeric>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N, M;
  int a, b;
  set<int> st;
  cin >> N >> M;
  long H[N];
  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]) {
      st.insert(a);
      st.insert(b);
    }
    if (H[a] > H[b]) {
      st.insert(b);
    }
    if (H[a] < H[b]) {
      st.insert(a);
    }
  }
  cout << N - st.size();
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  vector<vector<int>> t(n, vector<int>(n));
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    t[a][b] = true;
    t[b][a] = true;
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    bool ok = true;
    for (int j = 0; j < n; j++) {
      if (t[i][j] == true) {
        if (h[i] <= h[j])
          ok = false;
      }
    }
    if (ok)
      cnt++;
  }
  cout << cnt << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main(void) {
  uint N;
  uint M;

  cin >> N;
  cin >> M;

  vector<uint> H(N);

  for (uint i = 0; i < N; i++)
    cin >> H[i];

  vector<uint> result(N, 1);

  for (uint i = 0; i < M; i++) {
    uint s;
    uint g;
    cin >> s;
    cin >> g;
    if (H[s - 1] < H[g - 1])
      result[s - 1] = 0;
    else if (H[g - 1] < H[s - 1])
      result[g - 1] = 0;
    else {
      result[s - 1] = 0;
      result[g - 1] = 0;
    }
  }

  cout << accumulate(result.begin(), result.end(), 0) << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  uint N;
  uint M;

  cin >> N;
  cin >> M;

  vector<uint> H(N);

  for (uint i = 0; i < N; i++)
    cin >> H[i];

  vector<vector<uint>> map(N, vector<uint>(N, 0));

  for (uint i = 0; i < M; i++) {
    uint s;
    uint g;
    cin >> s;
    cin >> g;
    map[s - 1][g - 1] = 1;
    map[g - 1][s - 1] = 1;
  }

  uint result = N;

  for (uint i = 0; i < N; i++) {
    for (uint j = 0; j < N; j++) {
      if (map[i][j]) {
        if (H[i] <= H[j]) {
          result--;
          break;
        }
      }
    }
  }

  cout << result << endl;

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans = 0;
  cin >> n >> m;
  vector<int> h(n + 1);
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  vector<bool> bit(n + 1, 1);
  for (int i = 1; i <= m; i++) {
    int a, b, min_h = 0;
    cin >> a >> b;
    if (h[a] == h[b]) {
      bit[a] = 0;
      bit[b] = 0;
      continue;
    }
    min_h = min(h[a], h[b]);
    if (min_h == h[a])
      bit[a] = 0;
    else
      bit[b] = 0;
  }
  for (int i = 1; i <= n; i++)
    if (bit[i])
      ans++;
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans = 0;
  cin >> n >> m;
  vector<int> h(n + 1);
  for (int i = 1; i <= n; i++)
    cin >> h[i];

  vector<bool> bit(n + 1, 1);
  for (int i = 1; i <= m; i++) {
    int a, b, min_h = 0;
    cin >> a >> b;
    min_h = min(h[a], h[b]);
    bit[min_h] = 0;
  }
  for (int i = 1; i <= n; i++)
    if (bit[i])
      ans++;
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#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() {
  ll n, m;
  cin >> n >> m;

  vector<int> h(n);
  rep(i, n) { cin >> h.at(i); }

  vector<int> a(m), b(m);
  rep(i, m) { cin >> a.at(i) >> b.at(i); }

  ll count = 0;
  vector<bool> ans(n, true);
  rep(i, m) {

    // rep(j,m){
    //     if(a.at(j)-1==i){
    //         if(h.at(b.at(j)-1)>=h.at(i)){
    //             ans = false;
    //         }
    //     }
    //     // else if(b.at(j)-1==i){
    //     //     if(h.at(a.at(j)-1)>=h.at(i)){
    //     //         ans = false;
    //     //     }
    //     // }
    // }
    if (h.at(a.at(i) - 1) == h.at(b.at(i) - 1)) {
      ans.at(a.at(i) - 1) = false;
      ans.at(b.at(i) - 1) = false;
    } else if (h.at(a.at(i) - 1) > h.at(b.at(i) - 1)) {
      ans.at(b.at(i) - 1) = false;
    } else {
      ans.at(a.at(i) - 1) = false;
    }
  }

  rep(i, n) {
    if (ans.at(i)) {
      count++;
    }
  }

  cout << count << endl;
  return 0;
}

Error: TLE

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() {
  ll n, m;
  cin >> n >> m;

  vector<int> h(n);
  rep(i, n) { cin >> h.at(i); }

  vector<int> a(m), b(m);
  rep(i, m) { cin >> a.at(i) >> b.at(i); }

  ll count = 0;

  rep(i, n) {
    bool ans = true;
    rep(j, m) {
      if (a.at(j) - 1 == i) {
        if (h.at(b.at(j) - 1) >= h.at(i)) {
          ans = false;
        }
      } else if (b.at(j) - 1 == i) {
        if (h.at(a.at(j) - 1) >= h.at(i)) {
          ans = false;
        }
      }
    }
    if (ans) {
      count++;
    }
  }

  cout << count << endl;
  return 0;
}