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

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n"
#define ll long long
#define reus                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
int main() {
  reus;
  ll int n, m, h, a, b, x[100002], y[100002] = {0}, c = 0, i;
  // vector <int> v;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> x[i];
  }
  while (m--) {
    cin >> a >> b;
    if (x[a] == x[b]) {
      y[a] = -1;
      y[b] = -1;
    } else if (x[a] > x[b]) {
      y[b] = -1;
    } else if (x[a] < x[b]) {
      y[a] = -1;
    }
  }
  // int k=*max_element(x,x+n);
  for (i = 1; i <= n; i++) {
    if (y[i] == 0) {
      c++;
    }
  }
  cout << c << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n"
#define ll long long
#define reus                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
int main() {
  reus;
  ll int n, m, h, a, b, x[100002], y[100002] = {0}, c = 0, i;
  // vector <int> v;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    if (x[a] == x[b]) {
      y[x[a]] = -1;
      y[x[b]] = -1;
    } else if (x[a] > x[b]) {
      y[x[b]] = -1;
    } else if (x[a] < x[b]) {
      y[x[a]] = -1;
    }
  }
  // int k=*max_element(x,x+n);
  for (i = 0; i < n; i++) {
    if (y[i] == 0) {
      c++;
    }
  }
  cout << c << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

#define INF 1e18
#define PI 3.141592653589793238
typedef long long ll;
#define N 100010

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

  return 0;
}

Error: 0

Fixed submission:

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

#define INF 1e18
#define PI 3.141592653589793238
typedef long long ll;
#define N 10010

int main() {
  int n, m, h[N], ma[N];
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    ma[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    ma[a] = max(ma[a], h[b]);
    ma[b] = max(ma[b], h[a]);
  }
  int ans = 0;
  for (int i = 0; i < n; 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;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> H(n);
  vector<int> Ma(n);
  for (int i = 0; i < n; i++) {
    cin >> H.at(i);
  }
  int a, b;
  for (int k = 0; k < m; k++) {
    cin >> a >> b;
    Ma.at(a - 1) = max(Ma.at(a - 1), H.at(b - 1));
    Ma.at(b - 1) = max(Ma.at(b - 1), H.at(a - 1));
  }
  int ans = 0;
  for (int j = 0; j < n; j++) {
    if (Ma.at(j) < H.at(j)) {
      ans++;
    }
  }

  cout << ans << 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.at(i);
  }
  vector<int> A(N);
  vector<int> B(N);
  for (int h = 0; h < M; h++) {
    cin >> A.at(h) >> B.at(h);
  }

  int count = 0;

  for (int j = 1; j < N + 1; j++) {
    int check = 0;
    for (int k = 0; k < M; k++) {

      if (A.at(k) == j) {
        if (H.at(B.at(k) - 1) >= H.at(j - 1)) {
          check++;
          break;
        }
      } else if (B.at(k) == j) {
        if (H.at(A.at(k) - 1) >= H.at(j - 1)) {
          check++;
          break;
        }
      }
    }
    if (check == 0)
      count++;
  }

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

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <unordered_set>
#include <vector>

#define ll long long int
#define mod 1000000007

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n + 1);
  for (int i = 1; i < h.size(); i++) {
    ll x;
    cin >> x;
    h[i] = x;
  }
  vector<vector<ll>> vec(n + 1);
  for (int i = 0; i < m; i++) {
    ll x, y;
    cin >> x >> y;
    vec[x].push_back(y);
    vec[y].push_back(x);
  }

  ll cnt = 0;
  for (int i = 1; i < vec.size(); i++) {
    if (vec[i].size() == 0) {
      cnt++;
      continue;
    }
    bool b = true;
    for (int j = 0; j < vec[i].size(); j++) {
      if (h[i] <= h[vec[i][j]]) {
        b = false;
        break;
      }
    }
    if (b)
      cnt++;
  }
  cout << cnt;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <unordered_set>
#include <vector>

#define ll long long int
#define mod 1000000007

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n + 1);
  for (int i = 1; i < h.size(); i++) {
    ll x;
    cin >> x;
    h[i] = x;
  }
  vector<vector<ll>> vec(n + 1, vector<ll>(n + 1, 0));
  for (int i = 0; i < m; i++) {
    ll x, y;
    cin >> x >> y;
    vec[x][y] = 1;
    vec[y][x] = 1;
  }
  ll cnt = 0;
  for (int i = 1; i < vec.size(); i++) {
    bool b = false;
    for (int j = 1; j < vec[i].size(); j++) {
      if (vec[i][j] == 1) {
        b = true;
        if (h[i] > h[j]) {
          cnt++;
          break;
        }
      }
    }
    if (b == false)
      cnt++;
  }
  cout << cnt;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

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

  int H[N]; // Height
  for (int n = 0; n < N; n++)
    cin >> H[n];

  vector<vector<int>> graph(N);

  for (int m = 0; m < M; m++) {
    int a, b;
    cin >> a >> b;
    graph.at(a - 1).push_back(b - 1);
    graph.at(b - 1).push_back(a - 1);
  }

  int best_point = 0;

  for (int n = 0; n < N; n++) {
    bool is_best = true;
    for (int i = 0; i < (int)(graph.at(n).size()); i++) {
      if (H[n] <= H[graph.at(n).at(i)]) {
        is_best = false;
        break;
      }
    }

    if (is_best)
      best_point++;
  }

  cout << best_point << endl;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)


Fixed submission:

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

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

  int H[N]; // Height
  for (int n = 0; n < N; n++)
    cin >> H[n];

  vector<vector<int>> graph(N);

  for (int m = 0; m < M; m++) {
    int a, b;
    cin >> a >> b;
    graph.at(a).push_back(b);
    graph.at(b).push_back(a);
  }

  int best_point = 0;

  for (int n = 1; n <= N; n++) {
    bool is_best = true;
    for (int i = 0; i < (int)(graph.at(n).size()); i++) {
      if (H[n] < H[graph.at(n).at(i + 1)]) {
        is_best = false;
        break;
      }
    }

    if (is_best)
      best_point++;
  }

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

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

int main() {
  int n, m, h[100000], a[100000], b[100000];
  bool good[100000];
  cin >> n >> m;

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

  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }

  int answer = 0;

  for (int i = 0; i < m; i++) {
    good[a[i] - 1] &= h[a[i] - 1] > h[b[i] - 1];
    good[b[i] - 1] &= h[a[i] - 1] < h[b[i] - 1];
  }

  for (int i = 0; i < n; i++) {
    answer += int(good[i]);
  }

  cout << answer;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, m, h[100000], a[100000], b[100000];
  cin >> n >> m;

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

  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }
  int answer = 0;
  for (int i = 0; i < n; i++) {
    bool good = true;
    for (int j = 0; j < m; j++) {
      if ((i + 1) == a[j] && h[i] <= h[b[j] - 1] ||
          (i + 1) == b[j] && h[i] <= h[a[j] - 1]) {
        good = false;
      }
    }
    // // テスト
    // if(good) cout << i+1 <<endl;
    answer += int(good);
  }

  cout << answer;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  vector<long long> H(N);
  vector<long long> H_2(N, 0);

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

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

    A--;
    B--;

    if (H.at(A) <= H.at(B)) {
      H_2.at(A) = -1;
    }

    if (H.at(B) <= H.at(A)) {
      H_2.at(B) = -1;
    }
  }

  for (int i = 0; i < N; i++) {
    if (H_2.at(i) != -1) {
      counter++;
    }
  }

  cout << counter << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

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

  vector<vector<long long>> AB(N, vector<long long>(M, -1));
  vector<long long> H(N);

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

  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    for (int j = 0; j < M; j++) {
      if (AB.at(A - 1).at(j) == -1) {
        AB.at(A - 1).at(j) = B - 1;
        break;
      }
    }

    for (int j = 0; j < M; j++) {
      if (AB.at(B - 1).at(j) == -1) {
        AB.at(B - 1).at(j) = A - 1;
        break;
      }
    }
  }

  int flag;
  int counter = 0;

  for (int i = 0; i < N; i++) {
    flag = 0;
    for (int j = 0; j < M; j++) {
      if (AB.at(i).at(j) == -1)
        break;

      if (H.at(i) <= H.at(AB.at(i).at(j))) {
        flag = 1;
      }
    }

    if (flag == 0) {
      counter++;
    }
  }

  cout << counter << endl;

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

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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> height(n), good_obs(n, 1);
  int a, b;
  int h;

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

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

    if (height[a] < height[b]) {
      good_obs[a] = 0;
    } else if (height[a] > height[b]) {
      good_obs[b] = 0;
    } else {
      good_obs[a] = 0;
      good_obs[b] = 0;
    }
  }

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

  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int n, k;
  int d;
  int a;
  cin >> n >> k;
  vector<int> people(n, 1);

  for (int i = 0; i < k; i++) {
    cin >> d;

    for (int j = 0; j < d; j++) {
      cin >> a;
      people[a - 1] = 0;
    }
  }

  cout << accumulate(people.begin(), people.end(), 0) << endl;
}
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.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<bool> S(N, true);
  for (int i = 0; i < M; i++) {
    if (H.at(A.at(i) - 1) > H.at(B.at(i) - 1)) {
      S.at(B.at(i) - 1) = false;
    } else if (H.at(A.at(i) - 1) < H.at(B.at(i) - 1)) {
      S.at(A.at(i) - 1) = false;
    } else {
      S.at(A.at(i) - 1) = false;
      S.at(B.at(i) - 1) = false;
    }
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (S.at(i)) {
      count++;
    }
  }
  cout << count << endl;
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)


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<bool> S(N, true);
  for (int i = 0; i < M; i++) {
    if (H.at(A.at(i)) > H.at(B.at(i))) {
      S.at(B.at(i)) = false;
    } else {
      S.at(A.at(i)) = false;
    }
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (S.at(i)) {
      count++;
    }
  }
  cout << count << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

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

  int n, m;
  cin >> n >> m;
  vector<long long int> h(n);
  vector<bool> ans(n, 1);
  int count = 0;
  for (auto &i : h)
    cin >> i;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (h[a] >= h[b])
      ans[b] = 0;
    if (h[b] >= h[a])
      ans[a] = 0;
  }
  for (bool b : ans)
    count += b ? 1 : 0;
  cout << count;
}

Error: WA

Fixed submission:

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

typedef unsigned long long int ulli;
const int N = 10000;

int main() {
  ulli n, m, h[N], ma[N];
  cin >> n >> m;
  for (ulli i = 1; i <= m; i++) {
    cin >> h[i];
    ma[i] = 0;
  }
  for (ulli i = 0; i < m; i++) {
    ulli a, b;
    cin >> a >> b;
    ma[a] = max(ma[a], h[b]);
    ma[b] = max(ma[b], h[a]);
  }
  ulli count = 0;
  for (ulli i = 1; i <= n; i++)
    count += (h[i] > ma[i]);
  cout << count;
  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;

  int H[N], ma[N];

  for (int i = 0; i < N; i++) {
    cin >> H[i];
    ma[i] = 0;
  }

  for (int i = 0; i < M; i++) {
    int a, b;

    cin >> a >> b;

    ma[a - 1] = max(ma[a - 1], H[b - 1]);
    ma[b - 1] = max(ma[b - 1], H[a - 1]);
  }

  for (int i = 0; i < N; i++) {
    if (H[i] > ma[i])
      ans++;
  }

  cout << ans << endl;

  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  int N, M, ans = 0;
  int H[N], ma[N];

  cin >> N >> M;

  for (int i = 0; i < N; i++) {
    cin >> H[i];
    ma[i] = 0;
  }

  for (int i = 0; i < M; i++) {
    int a, b;

    cin >> a >> b;

    ma[a - 1] = max(ma[a - 1], H[b - 1]);
    ma[b - 1] = max(ma[b - 1], H[a - 1]);
  }

  for (int i = 0; i < N; 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;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()    // 昇順ソート
#define rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
  int N, M;
  cin >> N >> M;
  vector<LL> H(N);
  rep(i, N) cin >> H[i];
  vector<LL> A(M);
  vector<LL> B(M);
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    A[i] = a;
    B[i] = b;
  }
  vector<bool> ok(N, true);

  rep(i, M) {
    if (H[A[i]] <= H[B[i]])
      ok[A[i]] = false;
    if (H[B[i]] <= H[A[i]])
      ok[B[i]] = false;
  }

  int ans = 0;
  rep(i, N) {
    if (ok[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 < n; i++)
#define all(x) (x).begin(), (x).end()    // 昇順ソート
#define rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
  int N, M;
  cin >> N >> M;
  vector<LL> H(N);
  rep(i, N) cin >> H[i];
  vector<LL> A(N);
  vector<LL> B(N);
  rep(i, M) cin >> A[i] >> B[i];

  vector<bool> ok(N, true);

  rep(i, M) {
    if (H[A[i] - 1] <= H[B[i] - 1])
      ok[A[i] - 1] = false;
    if (H[B[i] - 1] <= H[A[i] - 1])
      ok[B[i] - 1] = false;
  }

  int ans = 0;
  rep(i, N) {
    if (ok[i])
      ans++;
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <list>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define ll long long

int main() {
  ll N, M;
  scanf("%lld %lld", &N, &M);

  vector<ll> H(N);
  for (ll i = 0; i < N; i++)
    scanf("%lld", &(H[i]));

  vector<vector<ll>> pass(N, vector<ll>());
  for (ll i = 0; i < M; i++) {
    ll A, B;
    scanf("%lld %lld", &A, &B);
    pass[A - 1].push_back(B - 1);
    pass[B - 1].push_back(A - 1);
  }

  vector<ll> pm(N, -1);
  for (ll i = 0; i < N; i++) {
    if (pm[i] != -1)
      continue;

    bool res = true;
    for (auto to : pass[i]) {
      if (H[to] >= H[i]) {
        res = false;
      }
      if (H[to] <= H[i]) {
        pm[to] = false;
      }
    }

    pm[i] = res;
  }

  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    if (pm[i] == 1)
      ans++;
  }
  printf("%lld\\n", ans);
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <list>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define ll long long

int main() {
  ll N, M;
  scanf("%lld %lld", &N, &M);

  vector<ll> H(N);
  for (ll i = 0; i < N; i++)
    scanf("%lld", &(H[i]));

  vector<vector<bool>> pass(N, vector<bool>(N, false));
  for (ll i = 0; i < M; i++) {
    ll A, B;
    scanf("%lld %lld", &A, &B);
    pass[A - 1][B - 1] = true;
    pass[B - 1][A - 1] = true;
  }

  vector<ll> pm(N, -1);
  for (ll i = 0; i < N; i++) {
    if (pm[i] != -1)
      continue;

    bool res = true;
    for (ll j = 0; j < N; j++) {
      if (pass[i][j]) {
        if (H[j] >= H[i]) {
          res = false;
        } else {
          pm[j] = false;
        }
      }
    }

    pm[i] = res;
  }

  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    if (pm[i] == 1)
      ans++;
  }
  printf("%lld\\n", ans);
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  vector<int> heights(N), good_flags(N, 1);

  // 高さの格納
  for (int i = 0; i < N; i++) {
    cin >> heights.at(i);
  }
  // 道の格納とフラグの更新
  for (int i = 0; i < M; i++) {
    int a, b, ah, bh;
    cin >> a >> b;

    ah = heights.at(a - 1);
    bh = heights.at(b - 1);

    if (ah == bh) {
      good_flags.at(a - 1) = 0;
      good_flags.at(b - 1) = 0;
    } else if (ah < bh) {
      good_flags.at(a - 1) = 0;
    } else {
      good_flags.at(b - 1) = 0;
    }
  }

  ans = accumulate(good_flags.begin(), good_flags.end(), 0);

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

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

  int ans = N;

  vector<int> heights(N), a(M), b(M);

  // 高さの格納
  for (int i = 0; i < N; i++) {
    cin >> heights.at(i);
  }
  // 道の格納
  for (int i = 0; i < M; i++) {
    cin >> a.at(i) >> b.at(i);
  }

  // それぞれの灯台iがいい灯台か愚直に判定
  for (int i = 0; i < N; i++) {
    int h = heights.at(i);
    int bad_flg = 0;

    for (int j = 0; j < M; j++) {
      int num_a, num_b, ah, bh;
      num_a = a.at(j);
      num_b = b.at(j);
      ah = heights.at(num_a - 1);
      bh = heights.at(num_b - 1);

      // 灯台iを含む道のときに判定
      if (num_a - 1 == i || num_b - 1 == i) {
        if (h == ah) {
          if (h <= bh) {
            bad_flg = 1;
          }
        } else {
          if (h <= ah) {
            bad_flg = 1;
          }
        }
      }
    }
    ans -= bad_flg;
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: 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 < 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;
}

Error: WA

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

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

#define N 100010

int main() {
  int n, m, h[N + 1], ma[N + 1];
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
    ma[i] = 0;
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    ma[a] = max(ma[a], h[b]);
    ma[b] = max(ma[b], h[a]);
  }

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


Error: WA

Fixed submission:

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

int vis[101];

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

  for (int i = 1; i <= K; i++) {
    int d1, v;
    cin >> d1;                      // 1
    for (int j = 1; j <= d1; j++) { // 3
      cin >> v;
      vis[v] = 1;
    }
  }

  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (vis[i] == 0)
      ans++;
  }

  cout << ans;
  return 0;
}