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

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

#define FOR(i, l, r) for (size_t i = (l); i < (r); i = i + 1)
#define REP(i, n) FOR(i, 0, n)
using ll = long long;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  REP(i, N) { cin >> H[i]; }
  vector<int> D(N);
  vector<int> A(M);
  vector<int> B(M);
  REP(i, M) {
    cin >> A[i];
    cin >> B[i];
  }

  int start, end;
  REP(i, M) {
    start = A[i] - 1;
    end = B[i] - 1;
    if (H[start] > H[end]) {
      D[end] = -1;
      if (D[start] != -1) {
        D[start] = 1;
      }
    } else if (H[start] < H[end]) {
      D[start] = -1;
      if (D[end] != -1) {
        D[end] = 1;
      }
    } else {
      D[start] = -1;
      D[end] = -1;
    }
  }
  int count = 0;
  REP(i, N) {
    if (D[i] != -1) {
      count++;
    }
  }
  cout << count << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

#define FOR(i, l, r) for (size_t i = (l); i < (r); i = i + 1)
#define REP(i, n) FOR(i, 0, n)
using ll = long long;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  REP(i, N) { cin >> H[i]; }
  vector<vector<int>> D(N, vector<int>(N, 0));
  int start, end;
  REP(i, M) {
    cin >> start;
    cin >> end;
    start--;
    end--;
    D[start][end] = 1;
    D[end][start] = 1;
  }
  int count = 0;
  REP(i, N) {
    int judge = 1;
    REP(j, N) {
      int hikaku = D[i][j];
      if (hikaku == 1 && H[i] <= H[j]) {
        judge = 0;
        break;
      }
    }
    if (judge == 1) {
      count++;
    }
  }

  cout << count << endl;

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

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

const int N = 1e5 + 5;
int best[N], h[N];

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

  int n, m;
  cin >> n >> m;

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

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    best[x] = max(best[x], h[y]);
    best[y] = max(best[y], h[x]);
  }

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


Error: 0

Fixed submission:

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

const int N = 1005;
int best[N], h[N];

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

  int n, m;
  cin >> n >> m;

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

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    best[x] = max(best[x], h[y]);
    best[y] = max(best[y], h[x]);
  }

  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (h[i] > best[i])
      ans++;
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  int N, M, A, B, ans = 0;
  cin >> N >> M;
  vector<long long> H(N, 0);
  vector<long long> maxHigh(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    maxHigh[A - 1] = max(maxHigh[A - 1], H[B - 1]);
    maxHigh[B - 1] = max(maxHigh[B - 1], H[A - 1]);
  }
  for (int i = 0; i < N; i++) {
    if (H[i] > maxHigh[i]) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main(void) {
  bool roadFlag = false;
  long long N, M, A, B, highSum = 0, ans = 0;
  cin >> N >> M;
  vector<long long> H(N, 0);
  vector<pair<long long, int>> HList;
  vector<int> HighFlag(N, 1);
  vector<int> visitFlag(N, 0);
  vector<vector<int>> AB(N, vector<int>(N, 0));

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

  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    AB[min(A, B) - 1][max(A, B) - 1] = 1;
    visitFlag[A - 1] = 1;
    visitFlag[B - 1] = 1;
  }
  for (int i = 0; i < N; i++) {
    HList.clear();
    for (int j = i + 1; j < N; j++) {
      if (HighFlag[j] == 0)
        break;
      if (AB[i][j] == 1) {
        HList.push_back(make_pair(H[j], j));
        roadFlag = true;
      }
    }
    if (roadFlag) {
      HList.push_back(make_pair(H[i], i));
      roadFlag = false;
    }
    if (HList.size() != 0) {
      sort(HList.begin(), HList.end(), greater<pair<long long, int>>());
      if (HList[0].first != HList[1].first) {
        highSum++;
        for (long long j = 1; j < HList.size(); j++) {
          HighFlag[HList[j].second] = 0;
        }
      }
    }
  }

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

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

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using P = pair<ll, ll>;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

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

  vector<ll> H(N);
  vector<vector<ll>> L(N);

  rep(i, N) { cin >> H[i]; }

  ll a, b;
  rep(i, M) {
    cin >> a >> b;
    a--;
    b--;
    L[a].push_back(b);
    L[b].push_back(a);
  }

  vector<ll> ans(N);
  rep(i, N) {
    rep(j, L[i].size()) {
      if (H[i] <= H[L[i][j]])
        ans[i] = 1;
    }
  }

  ll count = 0;
  rep(i, N) {
    if (ans[i] == 0)
      count++;
  }

  cout << count << endl;

  return 0;
}
// Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using P = pair<ll, ll>;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  ll N, M;
  vector<ll> H(N);
  vector<vector<ll>> L(N);

  cin >> N >> M;
  rep(i, N) { cin >> H[i]; }
  ll a, b;
  rep(i, M) {
    cin >> a >> b;
    a--;
    b--;
    L[a].push_back(b);
    L[b].push_back(a);
  }

  vector<ll> ans(N);
  rep(i, N) {
    rep(j, L[i].size()) {
      if (H[i] <= H[L[i][j]])
        ans[i] = 1;
    }
  }

  ll count = 0;
  rep(i, N) {
    if (ans[i] == 0)
      count++;
  }

  cout << count << endl;

  return 0;
}
// Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded



#include <bits/stdc++.h>

#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)

using namespace std;

template <class T> using vec = std::vector<T>;
typedef long long ll;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const long long INF = 1LL << 60;

int lcm(int a, int b) {
  // 最小公倍数
  return a / __gcd(a, b) * b;
}

int n, m;

int main() {
  cin >> n >> m;
  vec<int> h(n, 0);
  rep(i, n) { cin >> h[i]; }
  vec<int> v(n);
  iota(v.begin(), v.end(), 0); // 1からはじめるm要素の列
  set<int> s;

  int a, b;
  rep(i, m) {
    cin >> a >> b;
    a--;
    b--;

    if (h[a] >= h[b]) {
      s.insert(b);
    }

    if (h[b] >= h[a]) {
      s.insert(a);
    }
  }
  int ans = n - s.size();
  // for(auto e:s){
  //     cout<<e+1<<" ";
  // }
  // cout<<endl;

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:



#include <bits/stdc++.h>

#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)

using namespace std;

template <class T> using vec = std::vector<T>;
typedef long long ll;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const long long INF = 1LL << 60;

int lcm(int a, int b) {
  // 最小公倍数
  return a / __gcd(a, b) * b;
}

int n, m;

int main() {
  cin >> n >> m;
  vec<int> h(n, 0);
  rep(i, n) { cin >> h[i]; }
  vec<vec<bool>> adj(n, vec<bool>(n, false));
  int a, b;
  rep(i, m) {
    cin >> a >> b;
    a--;
    b--;
    // cout<<a<<" :" <<b<<endl;
    adj[a][b] = true;
    adj[b][a] = true;
  }
  int ans = n;
  vec<int> v;
  // cout<<ans<<endl;
  rep(i, n) {
    if (std::find(v.begin(), v.end(), i) != v.end()) {
      ans--;
      continue;
    }
    rep(j, n) {
      // cout<<i<<";"<<j<<endl;
      if (adj[i][j]) {

        if (h[i] <= h[j]) {
          // cout<<h[i]<<":"<<h[j]<<endl;
          ans--;
          break;
        } else {
          v.push_back(j);
        }
      }
    }
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>

#define NREP() for (ll i = 0; i < n; i++)
#define MREP() for (ll j = 0; j < m; j++)
#define REP(i, n) for (ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(t, x)                                                              \\
  t ipt;                                                                       \\
  cin >> ipt;                                                                  \\
  x.push_back(ipt);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, tmp, sum, a, b, c, d, k, m, h, w, q, x, y;
string s, t;

int main() {
  cin >> n >> m;
  vl h(n);
  vl mx(n);

  NREP() {
    cin >> h[i];
    mx[i] = 0;
  }

  MREP() {
    cin >> a >> b;
    mx[a - 1] = max(mx[a - 1], h[b - 1]);
    mx[b - 1] = max(mx[b - 1], h[a - 1]);
  }

  ans = 0;
  NREP() {
    if (h[i] > mx[i])
      ans++;
  }

  MSG(ans)
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define NREP() for (ll i = 0; i < n; i++)
#define MREP() for (ll j = 0; j < m; j++)
#define REP(i, n) for (ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(t, x)                                                              \\
  t ipt;                                                                       \\
  cin >> ipt;                                                                  \\
  x.push_back(ipt);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, tmp, sum, a, b, c, d, k, m, h, w, q, x, y;
string s, t;

int main() {
  cin >> n >> m;
  vl h(n);
  vl a(m);
  vl b(m);
  vector<bool> searched(n);

  NREP() {
    cin >> h[i];
    searched[i] = false;
  }

  MREP() { cin >> a[j] >> b[j]; }

  ans = 0;
  NREP() {
    bool is_ok = true;
    MREP() {
      if (a[j] == (i + 1)) {
        if (h[a[j] - 1] <= h[b[j] - 1]) {
          is_ok = false;
          break;
        }
      }
    }

    if (is_ok == false)
      continue;

    MREP() {
      if (b[j] == (i + 1)) {
        if (h[b[j] - 1] <= h[a[j] - 1]) {
          is_ok = false;
          break;
        }
      }
    }

    if (is_ok)
      ans++;
  }

  MSG(ans)
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, r, a, b;
  int c = 0;
  cin >> n >> r;
  vector<int> h(n);
  vector<int> l(n);
  for (int i = 0; i < n; i++) {
    cin >> h.at(i);
    l.at(i) = 1;
  }
  for (int i = 0; i < r; i++) {
    cin >> a >> b;
    a -= 1, b -= 1;
    if (h.at(a) < h.at(b)) {
      l.at(b) *= 1, l.at(a) *= 0;
    } else if (h.at(a) > h.at(b)) {
      l.at(a) *= 1, l.at(b) = 0;
    } else {
      l.at(a) *= 0, l.at(b) *= 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (l.at(i) == 1) {
      c++;
    }
  }
  cout << c << 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, r, a, b;
  int c = 0;
  cin >> n >> r;
  vector<int> h(n);
  vector<int> l(n);
  for (int i = 0; i < n; i++) {
    cin >> h.at(i);
    l.at(i) = 1;
  }
  for (int i = 0; i < r; i++) {
    cin >> a >> b;
    if (h.at(a) < h.at(b)) {
      l.at(b) *= 1, l.at(a) *= 0;
    } else if (h.at(a) > h.at(b)) {
      l.at(a) *= 1, l.at(b) = 0;
    } else {
      l.at(a) *= 0, l.at(b) *= 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (l.at(i) == 1) {
      c++;
    }
  }
  cout << c << 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;
  int cnt = n;
  set<int> st;
  vector<int> h(n);
  rep(i, n) { cin >> h[i]; }
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    int x, y;
    x = h[a - 1];
    y = h[b - 1];
    int mn = min(x, y);
    if (x == y) {
      st.insert(a);
      st.insert(b);
    } else if (mn == x) {
      st.insert(a);
    } else if (mn == y) {
      st.insert(b);
    }
  }
  cnt -= st.size();
  cout << cnt << endl;
}

Error: -11

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;
  int cnt = n;
  set<int> st;
  vector<int> h;
  rep(i, n) { cin >> h[i]; }
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    int x, y;
    x = h[a - 1];
    y = h[b - 1];
    int mn = min(x, y);
    if (x == y) {
      st.insert(a);
      st.insert(b);
    } else if (mn == x) {
      st.insert(a);
    } else if (mn == y) {
      st.insert(b);
    }
  }
  cnt -= st.size();
  cout << cnt << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a) begin((a)), end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))
#define each(i, map) for (auto &i : map)

int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> H(N);
  rep(i, 0, N) cin >> H[i];
  vector<int> ok(N, 1);
  rep(i, 0, M) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    if (H[a] < H[b])
      ok[a] = 0;
    else if (H[a] > H[b])
      ok[b] = 0;
    else
      ok[a] = ok[b] = 0;
  }

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a) begin((a)), end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))
#define each(i, map) for (auto &i : map)

int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> H(N);
  rep(i, 0, N) cin >> H[i];
  vector<vector<int>> towers(N, vector<int>(N, 0));
  rep(i, 0, M) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    towers[a][b] = H[b];
    towers[b][a] = H[a];
  }

  int ans = 0;
  rep(i, 0, N) {
    rep(j, 0, N) {
      if (towers[i][j] != 0) {
        if (towers[i][j] >= H[i])
          break;
      }
    }
    ++ans;
  }

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

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  vector<int> A(M);
  vector<int> B(M);
  rep(i, N) { cin >> H.at(i); }
  vector<int> toudai(N, 1);
  rep(i, M) {
    int A, B;
    cin >> A >> B;
    if (H.at(A - 1) >= H.at(B - 1)) {
      toudai.at(B - 1) = 0;
    }
    if (H.at(B - 1) >= H.at(A - 1)) {
      toudai.at(A - 1) = 0;
    }
  }

  int ans = 0;
  rep(i, N) {
    if (toudai.at(i) == 1) {
      ans++;
    }
  }
  cout << ans << endl;
}


Error: TLE

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;
  cin >> N >> M;
  vector<int> H(N);
  vector<int> A(M);
  vector<int> B(M);
  rep(i, N) { cin >> H.at(i); }
  vector<vector<int>> L(N, vector<int>(N));
  rep(i, M) {
    int A, B;
    cin >> A >> B;
    L.at(A - 1).at(B - 1)++;
    L.at(B - 1).at(A - 1)++;
  }
  int ans = 0;
  rep(i, N) {
    int key = 1;
    rep(j, N) {
      if (L.at(i).at(j) > 0) {
        if (H.at(i) <= H.at(j)) {
          key = 0;
          break;
        }
      }
    }
    if (key == 1) {
      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() {
  int n, m, ans = 0;
  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;
  }

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

  cout << ans << 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() {
  int n, m, ans = 0;
  cin >> n >> m;
  vector<int> h(n), a(m), b(m);
  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 = 1; i <= n; i++) {
    vector<int> tmp;
    bool ok = true;
    for (int j = 0; j < m; j++) {
      if (a[j] == i)
        tmp.push_back(b[j]);
      if (b[j] == i)
        tmp.push_back(a[j]);
    }
    if (tmp.size() == 0)
      ans++;
    else {
      for (int k = 0; k < tmp.size(); k++)
        if (h[i - 1] <= h[tmp[k] - 1])
          ok = false;
      if (ok)
        ans++;
    }
  }

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define PI acos(-1)
typedef long long ll;
ll gcd(ll x, ll y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int h[n];
  rep(i, n) { cin >> h[i]; }
  vector<bool> f(n, true);

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    int c = min(a, b);
    int d = max(a, b);
    if (h[c - 1] > h[d - 1])
      f[d - 1] = false;
    else if (h[c - 1] < h[d - 1])
      f[c - 1] = false;
    else {
      f[c - 1] = false;
      f[d - 1] = false;
    }
  }
  ll ans = 0;
  rep(i, n) {
    if (f[i] == true) {
      ans++;
    }
  }

  cout << ans;

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define PI acos(-1)
typedef long long ll;
ll gcd(ll x, ll y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int h[n];
  rep(i, n) { cin >> h[i]; }
  int a[n][n];
  rep(i, n) {
    for (int j = 0; j < n; j++) {
      if (h[i] < h[j])
        a[i][j] = 0;
      else if (h[i] == h[j])
        a[i][j] = 2;
      else
        a[i][j] = 1;
    }
  }

  vector<bool> f(n, true);
  rep(i, m) {
    int p, q;
    cin >> p >> q;

    if (a[min(p, q) - 1][max(p, q) - 1] == 0)
      f[p - 1] = false;
    if (a[min(p, q) - 1][max(p, q) - 1] == 2) {
      f[p - 1] = false;
      f[q - 1] = false;
    }
  }

  ll ans = 0;
  rep(i, n) {
    if (f[i] == true) {

      ans++;
    }
  }

  cout << ans;

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

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

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


Error: 0

Fixed submission:

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

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

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
using namespace std;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<int> h(n), t(n, 0);
  rep(j, 0, n) cin >> h[j];
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    if (h[a] < h[b])
      t[a]++;
    if (h[a] > h[b])
      t[b]++;
    if (h[a] == h[b]) {
      t[a]++;
      t[b]++;
    }
  }
  int cnt = 0;
  rep(i, 0, n) if (t[i] != 0) cnt++;
  cout << n - cnt << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
using namespace std;

int main() {
  ll n, m;
  cin >> n >> m;
  const int N = 10000;
  vector<int64_t> h(N);
  set<int64_t> t;
  rep(j, 0, n) cin >> h[j];
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    if (h[a] < h[b])
      t.insert(a);
    if (h[a] > h[b])
      t.insert(b);
    if (h[a] == h[b]) {
      t.insert(a);
      t.insert(b);
    }
  }
  if (n > t.size())
    cout << n - t.size() << endl;
  else
    cout << "0" << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

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

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

  vector<int64_t> H(N);
  rep(i, N) cin >> H.at(i);

  vector<int> ten(N, 1);

  rep(i, M) {
    int A, B;
    cin >> A >> B;

    if (H.at(A - 1) >= H.at(B - 1))
      ten.at(B - 1) = 0;
    if (H.at(B - 1) >= H.at(A - 1))
      ten.at(A - 1) = 0;
  }

  int ans = 0;
  rep(i, N) {
    if (ten.at(i) == 1)
      ans++;
  }

  cout << ans;
}

Error: WA

Fixed submission:

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

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

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

  vector<int64_t> H(N);
  rep(i, N) cin >> H.at(i);

  vector<int> ten(N, 1);

  rep(i, M) {
    int A, B;
    cin >> A >> B;

    if (H.at(A - 1) > H.at(B - 1))
      ten.at(B - 1) = 0;
    else if (H.at(B - 1) > H.at(A - 1))
      ten.at(A - 1) = 0;
  }

  int ans = 0;
  rep(i, M) {
    if (ten.at(i) == 1)
      ans++;
  }

  cout << ans;
}