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

#include <iostream>
using namespace std;

int main() {
  long long int N, M;
  cin >> N >> M;
  long long int H[N];
  for (int i = 0; i < N; i++)
    cin >> H[i];
  long long int A[M], B[M];
  for (int i = 0; i < M; i++)
    cin >> A[i] >> B[i];

  bool flag[N];
  for (int i = 0; i < N; i++)
    flag[i] = true;

  for (int i = 0; i < M; i++) {
    if (H[A[i] - 1] >= H[B[i] - 1])
      flag[B[i] - 1] = false;
    if (H[B[i] - 1] >= H[A[i] - 1])
      flag[A[i] - 1] = false;
  }

  int res = 0;
  for (int i = 0; i < N; i++) {
    if (flag[i] == true)
      res++;
  }

  cout << res << endl;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long long int N, M;
  cin >> N >> M;
  long long int H[N];
  for (int i = 0; i < N; i++)
    cin >> H[i];
  long long int A[M], B[M];
  for (int i = 0; i < M; i++)
    cin >> A[i] >> B[i];

  bool flag[N];
  for (int i = 0; i < N; i++)
    flag[i] = true;

  for (int i = 0; i < 1000; i++) {
    for (int j = 0; j < M; j++) {
      if (H[A[j]] > H[B[j]]) {
        H[B[j]] = H[A[j]];
        flag[B[j]] = false;
      }
      if (H[B[j]] > H[A[j]]) {
        H[A[j]] = H[B[j]];
        flag[A[j]] = false;
      }
    }
    for (int j = M - 1; j >= 0; j--) {
      if (H[A[j]] > H[B[j]]) {
        H[B[j]] = H[A[j]];
        flag[B[j]] = false;
      }
      if (H[B[j]] > H[A[j]]) {
        H[A[j]] = H[B[j]];
        flag[A[j]] = false;
      }
    }
  }

  int res = 0;
  for (int i = 0; i < N; i++) {
    if (flag[i] == true)
      res++;
  }

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

#include <bits/stdc++.h>

// #define int long long
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);
#define rep(i, a, n) for (int i = a; i < n; i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define pii pair<int, int>
#define UMP(x, y) unordered_map<x, y>
#define MP(x, y) map<x, y>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define inf 1e18
#define endl "\\n"
#define coutd(n) cout << fixed << setprecision(n)
#define watch(x) cout << #x << " = " << x << endl;
typedef double db;
typedef long double ld;
const int mod = 1000000007;

using namespace std;

int32_t main() {
  fast

      int n,
      m;
  cin >> n >> m;
  int h[n];
  rep(i, 0, n) cin >> h[i];
  UMP(int, int) mapping;

  int count = 0;
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    if (h[a - 1] > h[b - 1]) {
      if (mapping[a - 1] != -1)
        mapping[a - 1]++;
      mapping[b - 1] = -1;
    } else if (h[a - 1] == h[b - 1]) {
      mapping[a - 1] = -1;
      mapping[b - 1] = -1;
    } else {
      mapping[a - 1] = -1;
      if (mapping[b - 1] != -1)
        mapping[b - 1]++;
    }
  }

  rep(i, 0, n) {
    if (mapping[i] != -1)
      count++;
  }
  cout << count;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define int long long
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);
#define rep(i, a, n) for (int i = a; i < n; i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define pii pair<int, int>
#define UMP(x, y) unordered_map<x, y>
#define MP(x, y) map<x, y>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define inf 1e18
#define endl "\\n"
#define coutd(n) cout << fixed << setprecision(n)
#define watch(x) cout << #x << " = " << x << endl;
typedef double db;
typedef long double ld;
const int mod = 1000000007;

using namespace std;

int32_t main() {
  fast

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

  rep(i, 0, n) {
    bool flag = true;
    rep(j, 0, n) {
      if (graph[i][j] && h[i] <= h[j]) {
        flag = false;
        break;
      }
    }
    if (flag)
      count++;
  }
  cout << count;

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

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

void solve(long long N, long long M, std::vector<long long> H,
           std::vector<long long> A, std::vector<long long> B) {
  long long count = 0;

  map<long long, vector<long long>> hs;
  for (long long i = 0; i < M; i++) {
    hs[A[i]].push_back(H[B[i] - 1]);
    hs[B[i]].push_back(H[A[i] - 1]);
  }

  for (long long i = 0; i < N; i++) {
    if (hs[i + 1].size() == 0 ||
        H[i] > *max_element(hs[i + 1].begin(), hs[i + 1].end()))
      count++;
  }

  cout << count << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> H(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &H[i]);
  }
  std::vector<long long> A(M);
  std::vector<long long> B(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
  }
  solve(N, M, std::move(H), std::move(A), std::move(B));
  return 0;
}


Error: TLE

Fixed submission:

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

void solve(long long N, long long M, std::vector<long long> H,
           std::vector<long long> A, std::vector<long long> B) {
  long long count = 0;

  for (long long i = 0; i < N; i++) {
    vector<long long> hs;
    for (long long j = 0; j < M; j++) {
      if ((i + 1) == A[j]) {
        hs.push_back(H[B[j] - 1]);
      } else if ((i + 1) == B[j]) {
        hs.push_back(H[A[j] - 1]);
      }
    }

    if (hs.size() == 0 || H[i] > *max_element(hs.begin(), hs.end()))
      count++;
  }

  cout << count << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> H(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &H[i]);
  }
  std::vector<long long> A(M);
  std::vector<long long> B(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
  }
  solve(N, M, std::move(H), std::move(A), std::move(B));
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

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

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


Error: WA

Fixed submission:

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

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

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

using ll = long long;

int main() {
  ll n, m;
  cin >> n >> m;
  ll arr[n];
  ll garbo[100001] = {0};
  for (ll i = 1; i <= n; ++i) {
    cin >> arr[i];
  }
  for (ll i = 0; i < m; ++i) {
    ll a, b;
    cin >> a >> b;
    if (arr[a] <= arr[b])
      garbo[a] = 1;
    if (arr[a] >= arr[b])
      garbo[b] = 1;
  }
  ll ct = 0;
  for (ll i = 1; i <= n; ++i) {
    if (!garbo[i])
      ct++;
  }
  cout << ct;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
  ll n, m;
  cin >> n >> m;
  map<ll, ll> mp;
  ll arr[n];
  for (ll i = 1; i <= n; ++i) {
    ll tmp;
    cin >> tmp;
    mp[i] = tmp;
    arr[i] = tmp;
  }
  for (ll i = 0; i < m; ++i) {
    ll a, b;
    cin >> a >> b;
    mp[a] = max(mp[a], mp[b]);
    mp[b] = max(mp[b], mp[a]);
  }
  ll ct = 0, garbo = 1;
  for (auto x : mp) {
    if (x.second == arr[garbo]) {
      ct++;
    }
    garbo++;
  }
  cout << ct;
  return 0;
}
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() {
  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) {
    cin >> A[i];
    cin >> B[i];
  }
  vector<bool> p(N, true);

  rep(j, M) {
    if (H[B[j] - 1] > H[A[j] - 1]) {
      p.at(A[j] - 1) = false;
    }
    if (H[B[j] - 1] < H[A[j] - 1]) {
      p.at(B[j] - 1) = false;
    }
    if (H[B[j] - 1] == H[A[j] - 1]) {
      p.at(A[j] - 1) = false;
      p.at(B[j] - 1) = false;
    }
  }
  int ans = 0;
  rep(i, N) {
    if (p[i] == true) {
      ans++;
    }
  }
  cout << ans << endl;
}


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() {
  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) {
    cin >> A[i];
    cin >> B[i];
  }
  ll ans = N;
  // vector<vector<int>> memo(N+1, vector<int>(N+1, 0));
  rep(i, N) {
    bool tmp_flg = true;
    rep(j, M) {
      if (A[j] - 1 == i) {
        // if (memo[i][j] >= 0) {
        //   if (H[B[j] - 1] >= H[A[j] - 1]) {

        //     tmp_flg = false;
        //   }
        // }
        if (H[B[j] - 1] >= H[A[j] - 1]) {
          // memo[i][j] =
          tmp_flg = false;
          break;
        }
      }
      if (B[j] - 1 == i) {
        if (H[B[j] - 1] <= H[A[j] - 1]) {
          tmp_flg = false;
          break;
        }
      }
    }
    if (!tmp_flg) {
      ans -= 1;
    }
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PI 3.1415926535
#define MOD 1000000007

int main() {

  ll N, M;
  cin >> N >> M;

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

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

  ll cnt = 0;
  ll ans[N];
  for (int i = 0; i < N; i++)
    ans[i] = 0;
  for (int j = 0; j < M; j++) {
    if (H[A[j] - 1] >= H[B[j] - 1])
      ans[B[j] - 1]++;
    if (H[A[j] - 1] <= H[B[j] - 1])
      ans[A[j] - 1]++;
  }

  for (int i = 0; i < N; i++)
    if (ans[i] == 0)
      cnt++;
  cout << cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PI 3.1415926535
#define MOD 1000000007

int main() {

  ll N, M;
  cin >> N >> M;

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

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

  ll cnt = 0;
  bool good = true;
  for (int i = 0; i < N; i++) {
    good = true;
    for (int j = 0; j < M; j++) {
      if (i + 1 == A[j]) {
        if (H[A[j] - 1] <= H[B[j] - 1])
          good = false;
      } else if (i + 1 == B[j]) {
        if (H[A[j] - 1] >= H[B[j] - 1])
          good = false;
      }
    }
    if (good)
      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;
  int a[n];
  vector<int> s(n, 1);

  for (int i = 0; i < n; i++)
    cin >> a[i];

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;

    if (a[x - 1] < a[y - 1]) {
      s[x - 1] = 0;
    } else if (a[x - 1] > a[y - 1]) {
      s[y - 1] = 0;
    } else {
      s[x - 1] = 0;
      s[y - 1] = 0;
    }
  }

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

  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

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

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

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      b[i][j] = 0;
    }
  }

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    b[x - 1][y - 1]++;
    b[y - 1][x - 1]++;
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int g = 0;
    int h = 0;
    for (int j = 0; j < n; j++) {
      if (b[i][j] > 0) {
        g++;
        if (a[i] > a[j]) {
          h++;
        }
      }
    }
    if (g == h)
      ans++;
  }

  cout << ans;

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

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<vector<int>> v(n + 1);
  vector<int> f(n + 1);
  vector<pair<long long, int>> arr;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    f[i + 1] = x;
    arr.emplace_back(x, i + 1);
  }
  sort(arr.rbegin(), arr.rend());
  for (; k--;) {
    int c, d;
    cin >> c >> d;
    v[c].push_back(d);
    v[d].push_back(c);
  }
  vector<bool> vis(n + 1, 0);
  int cnt = 0;
  for (auto i : arr) {
    if (!vis[i.second]) {
      bool flg = 1;
      // cout<<i.second<<" ";
      vis[i.second] = 1;
      for (int j : v[i.second]) {
        if (i.first <= f[j]) {
          flg = 0;
          break;
        }
        vis[j] = 1;
        // cout<<j<<" ";
      }
      // cout<<"\\n";
      cnt += flg;
    }
  }
  cout << cnt << "\\n";

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<vector<int>> v(n + 1);
  vector<int> f(n + 1);
  vector<pair<long long, int>> arr;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    f[i + 1] = x;
    arr.emplace_back(x, i + 1);
  }
  sort(arr.rbegin(), arr.rend());
  for (; k--;) {
    int c, d;
    cin >> n >> d;
    v[n].push_back(d);
    v[d].push_back(n);
  }
  vector<bool> vis(n + 1, 0);
  int cnt = 0;
  for (auto i : arr) {
    if (!vis[i.second]) {
      bool flg = 1;
      // cout<<i.second<<" ";
      vis[i.second] = 1;
      for (int j : v[i.second]) {
        if (i.first <= f[j]) {
          flg = 0;
          break;
        }
        vis[j] = 1;
        // cout<<j<<" ";
      }
      // cout<<"\\n";
      cnt += flg;
    }
  }
  cout << cnt << "\\n";

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

#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < n; ++i)
#define INF 1001001001
#define MAX_N 100005
#define MAX_M 100005
typedef long long ll;
typedef pair<int, int> P;

vector<int> h(MAX_N);
vector<int> edge[MAX_M];

int main() {
  int n, m;
  cin >> n >> m;
  rep(i, n) cin >> h[i];

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }

  int ans = 0;
  rep(i, n) {
    bool flg = true;
    for (auto e : edge[i]) {
      if (h[i] <= h[e])
        flg = false;
    }
    if (flg)
      ++ans;
  }
  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < n; ++i)
#define INF 1001001001
#define MAX_M 10000
typedef long long ll;
typedef pair<int, int> P;

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

  int ans = 0;
  rep(i, n) {
    bool flg = true;
    for (auto e : edge[i]) {
      if (h[i] <= h[e])
        flg = false;
    }
    if (flg)
      ++ans;
  }
  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int n, m;
int h[100005], a[100005], b[100005];
bool ans[100005], c[100005];
int ANS;
int main(void) {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> h[i + 1];
  }
  for (int i = 0; i <= n; i++) {
    ans[i] = true;
    c[i] = false;
  }
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    c[a[i]] = true;
    c[b[i]] = true;
    if (h[a[i]] == h[b[i]]) {
      ans[a[i]] = false;
      ans[b[i]] = false;
    } else if (h[a[i]] < h[b[i]]) {
      ans[a[i]] = false;
    } else {
      ans[b[i]] = false;
    }
  }
  for (int i = 1; i <= n; i++) {
    // cout<<ans[i]<<" "<<c[i]<<endl;
    if (ans[i] == true)
      ANS++;
  }
  cout << ANS << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int n, m;
int h[100005], a[100005], b[100005];
bool ans[100005], c[100005];
int ANS;
int main(void) {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> h[i + 1];
  }
  for (int i = 0; i <= n; i++) {
    ans[i] = true;
    c[i] = false;
  }
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    c[a[i]] = true;
    c[b[i]] = true;
    if (h[a[i]] == h[b[i]]) {
      ans[a[i]] = false;
      ans[b[i]] = false;
    } else {
      ans[min(h[a[i]], h[b[i]])] = false;
    }
  }
  for (int i = 1; i <= n; i++) {
    // cout<<ans[i]<<" "<<c[i]<<endl;
    if (ans[i] == true)
      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 < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  rep(i, N) { cin >> H.at(i); }
  vector<int> d(N);
  rep(i, M) {
    int A, B;
    cin >> A >> B;
    if (H.at(A - 1) > H.at(B - 1)) {
      d.at(B - 1) -= 1000000000000;
    } else if (H.at(A - 1) < H.at(B - 1)) {
      d.at(A - 1) -= 1000000000000;
    } else {
      d.at(A - 1) -= 1000000000000;
      d.at(B - 1) -= 1000000000000;
    }
  }
  int good = 0;
  rep(i, N) {
    if (d.at(i) == 0) {
      good++;
    }
  }
  cout << good << 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;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  rep(i, N) { cin >> H.at(i); }
  vector<int> A(M);
  vector<int> B(M);
  vector<int> d(N);
  rep(i, M) {
    cin >> A.at(i) >> B.at(i);
    if (H.at(A.at(i) - 1) > H.at(B.at(i) - 1)) {
      d.at(A.at(i) - 1)++;
      d.at(B.at(i) - 1) -= 1000000000000;
    } else if (H.at(A.at(i)) < H.at(B.at(i))) {
      d.at(A.at(i) - 1) -= 1000000000000;
      d.at(B.at(i) - 1)++;
    } else {
      d.at(A.at(i) - 1) -= 1000000000000;
      d.at(B.at(i) - 1) -= 1000000000000;
    }
  }
  int good = 0;
  rep(i, N) {
    if (d.at(i) >= 0) {
      good++;
    }
  }
  cout << good << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  int N, M;
  cin >> N >> M;
  int H[N];
  int ans[N];
  rep(i, N) {
    cin >> H[i];
    ans[i] = 1;
  }

  rep(i, M) {
    int A, B;
    cin >> A >> B;
    if (H[A - 1] < H[B - 1]) {
      ans[A - 1] = 0;
    } else if (H[A - 1] > H[B - 1]) {
      ans[B - 1] = 0;
    }

    else {
      ans[A - 1] = 0;
      ans[B - 1] = 0;
    }
  }

  int sum_ = 0;
  rep(i, N) { sum_ += ans[i]; }
  cout << sum_ << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  int N, M;
  cin >> N >> M;
  int H[M];
  int ans[N];
  rep(i, N) {
    cin >> H[i];
    ans[i] = 1;
  }

  rep(i, M) {
    int A, B;
    cin >> A >> B;
    if (H[A - 1] < H[B - 1]) {
      ans[A - 1] = 0;
    } else if (H[A - 1] > H[B - 1]) {
      ans[B - 1] = 0;
    }

    else {
      ans[A - 1] = 0;
      ans[B - 1] = 0;
    }
  }

  int sum_ = 0;
  rep(i, N) { sum_ += ans[i]; }
  cout << sum_ << endl;

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

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

#define sz(x) int(x.size())
#define Task "abc"
#define For(i, a, b) for (int i = (a), _b = (b); i <= b; ++i)
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

bool chk[maxn];
vector<int> adj[maxn];
int h[maxn];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  //  freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    cin >> h[i];
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int ans = 0;
  for (int u = 1; u <= n; ++u) {
    int d = 0;
    for (auto v : adj[u]) {
      d = d + (h[v] >= h[u]);
    }
    if (d == 0)
      ++ans;
  }
  cout << ans;
}


Error: WA

Fixed submission:

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

#define sz(x) int(x.size())
#define Task "abc"
#define For(i, a, b) for (int i = (a), _b = (b); i <= b; ++i)
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

bool chk[maxn];
vector<int> adj[maxn];
int h[maxn];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  //  freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 1; i <= n; ++i)
    cin >> h[i];
  int ans = 0;
  for (int u = 1; u <= n; ++u) {
    int d = 0;
    for (auto v : adj[u]) {
      d = d + (h[v] >= h[u]);
    }
    if (d == 0)
      ++ans;
  }
  cout << ans;
}