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

#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep3(i, a, b) for (ll i = a; i >= b; i--)
#include <bits/stdc++.h>

using namespace std;

int main(void) {
  ll n, m, ans = 0;
  cin >> n >> m;
  ll h[n];
  bool isGood[n];
  rep(i, n) {
    cin >> h[i];
    isGood[i] = true;
  }
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    if (h[a - 1] > h[b - 1]) {
      isGood[b - 1] = false;
    } else if (h[a - 1] == h[b - 1]) {
      isGood[a - 1] = false;
      isGood[b - 1] = false;
    } else {
      isGood[a - 1] = false;
    }
  }
  rep(i, n) {
    if (isGood[i]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep3(i, a, b) for (ll i = a; i >= b; i--)
#include <bits/stdc++.h>

using namespace std;

int main(void) {
  ll n, m, ans = 0;
  cin >> n >> m;
  ll h[n], pos[n][n];
  rep(i, n) { cin >> h[i]; }
  rep(i, n) {
    rep(j, n) { pos[i][j] = 0; }
  }
  rep(i, n) { pos[i][i] = h[i]; }
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    pos[a - 1][b - 1] = h[b - 1];
    pos[b - 1][a - 1] = h[a - 1];
  }
  rep(i, n) {
    bool isMax = true;
    rep(j, n) {
      if (i != j and pos[i][j] >= pos[i][i]) {
        isMax = false;
        break;
      }
    }
    if (isMax) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> H(N + 10);
  vector<ll> ma(N + 10);
  FOR(i, 1, N + 1) {
    cin >> H[i];
    ma[i] = 0;
  }
  ll ans = 0;
  REP(i, M) {
    ll A, B;
    cin >> A >> B;
    ma[A] = max(ma[A], H[B]);
    ma[B] = max(ma[B], H[A]);
  }
  FOR(i, 1, N + 1) if (H[i] > ma[i]) ans++;
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> H(N);
  vector<ll> A(M);
  vector<ll> B(M);
  REP(i, N) { cin >> H[i]; }
  REP(i, M) { cin >> A[i] >> B[i]; }
  ll ans = 0;
  FOR(i, 1, N + 1) {
    bool good = true;
    REP(j, M) {
      ll temp;
      if (A[j] == i)
        temp = B[j];
      else if (B[j] == i)
        temp = A[j];
      else
        continue;
      if (H[i - 1] <= H[temp - 1])
        good = false;
    }
    if (good)
      ans++;
  }
  cout << ans << endl;

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

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

#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, s, n) for (long long i = (s); i < (long long)(n); i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;

const ll INF = (1LL << 60);

int main() {

  ll n, m;
  cin >> n >> m;
  vll h(n);
  rep(i, n) cin >> h[i];
  ll a, b;
  vector<bool> c(n, true);
  rep(i, m) {
    cin >> a >> b;
    if (h[a - 1] >= h[b - 1]) {
      c[b - 1] = false;
    }
    if (h[b - 1] >= h[a - 1]) {
      c[a - 1] = false;
    }
  }

  ll cnt = 0;
  rep(i, n) if (c[i]) cnt++;

  cout << cnt << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, s, n) for (long long i = (s); i < (long long)(n); i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;

const ll INF = (1LL << 60);

int main() {

  ll n, m;
  cin >> n >> m;
  vll h(n + 1);
  rep(i, n) cin >> h[i];
  vector<vector<bool>> bridge(n, vector<bool>(n, false));

  ll ina, inb;
  rep(i, m) {
    cin >> ina >> inb;
    if (h[inb - 1] - h[ina - 1] >= 0)
      bridge[ina - 1][inb - 1] = true;
    if (h[ina - 1] - h[inb - 1] >= 0)
      bridge[inb - 1][ina - 1] = true;
  }

  ll bad = 0;
  rep(i, n) {
    rep(j, n) {
      if (bridge[i][j]) {
        bad++;
        break;
      }
    }
  }

  cout << (n - bad) << endl;

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

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

int main() {
  ll N, M;
  cin >> N >> M;
  int count = 0;
  vector<int> H(N);
  vector<int> A(M);
  vector<int> B(M);
  vector<bool> ans(N, true);

  // 展望台高さ登録
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }

  // 橋登録
  for (int i = 0; i < M; i++) {
    cin >> A.at(i) >> B.at(i);
    A.at(i)--;
    B.at(i)--;
  }
  // 橋の相手が高いければfalse
  for (int i = 0; i < M; i++) {
    if (H.at(A.at(i)) >= H.at(B.at(i))) {
      ans.at(B.at(i)) = false;
    }
    if (H.at(B.at(i)) >= H.at(A.at(i))) {
      ans.at(A.at(i)) = false;
    }
  }

  for (int i = 0; i < N; i++) {
    if (ans.at(i))
      count++;
  }
  cout << count << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;
  int count = 0;
  vector<int> H(N);
  vector<int> A(M);
  vector<int> B(M);
  bool ans = true;

  // 展望台高さ登録
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }

  // 橋登録
  for (int i = 0; i < M; i++) {
    cin >> A.at(i) >> B.at(i);
    A.at(i)--;
    B.at(i)--;
  }
  // 橋の相手が高いければfalse
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (A.at(j) == i) {
        if (H.at(B.at(j)) == -1) {
          ans = false;
          break;
        }
        if (H.at(B.at(j)) >= H.at(i)) {
          ans = false;
        }
      }
      if (B.at(j) == i) {
        if (H.at(A.at(j)) == -1) {
          ans = false;
          break;
        }
        if (H.at(A.at(j)) >= H.at(i)) {
          ans = false;
        }
      }
    }
    if (ans) {
      count++;
      H.at(i) = -1;
    }
    ans = true;
  }
  cout << count << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

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

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

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

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

Error: 0

Fixed submission:

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

int main() {
  int n, m, a, b;
  cin >> n >> m;
  int cost[n][n];
  fill(cost[0], cost[n], 0);

  int i;
  for (i = 0; i < n; i++) {
    cin >> cost[i][i];
  }
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    cost[a - 1][b - 1] = cost[b - 1][b - 1];
    cost[b - 1][a - 1] = cost[a - 1][a - 1];
  }
  int j, flag, ans = 0;
  for (i = 0; i < n; i++) {
    flag = 1;
    for (j = 0; j < n; j++) {
      if (i == j or cost[i][j] == 0)
        continue;
      if (cost[i][i] <= cost[i][j]) {
        flag = 0;
        break;
      }
    }
    if (flag == 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
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++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  int N, M;
  cin >> N >> M;
  int ans = 0;
  vector<int> H(N);
  rep(i, N) { cin >> H.at(i); }
  vector<int> A(M);
  vector<int> B(M);
  rep(i, M) { cin >> A.at(i) >> B.at(i); }
  vector<int> C(N, 0);
  rep(i, M) {
    if (H.at(A.at(i) - 1) < H.at(B.at(i) - 1)) {
      C.at(A.at(i) - 1)++;
    } else if (H.at(A.at(i) - 1) > H.at(B.at(i) - 1)) {
      C.at(B.at(i) - 1)++;
    } else {
      C.at(A.at(i) - 1)++;
      C.at(B.at(i) - 1)++;
    }
  }
  rep(i, N) {
    if (C.at(i) == 0) {
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Error: TLE

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() {
  int64_t N, M;
  cin >> N >> M;
  int64_t ans = 0;
  vector<int64_t> H(N);
  rep(i, N) { cin >> H.at(i); }
  vector<int64_t> A(M);
  vector<int64_t> B(M);
  rep(i, M) { cin >> A.at(i) >> B.at(i); }
  vector<int64_t> C(N);
  rep(i, N) {
    bool flag = false;
    rep(j, M) {
      if (i + 1 == A.at(j)) {
        if (H.at(i) <= H.at(B.at(j) - 1)) {
          flag = true;
        }
      }
      if (flag)
        break;
      if (i + 1 == B.at(j)) {
        if (H.at(i) <= H.at(A.at(j) - 1)) {
          flag = true;
        }
      }
      if (flag)
        break;
    }
    if (!flag)
      ans++;
  }
  cout << ans << endl;

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

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

const int N = 100010;

int main(void) {
  // input
  int n, m, h[N], ma[N];
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    ma[i] = 0;
  }
  // O(n)
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    ma[a] = max(ma[a], h[b]);
    ma[b] = max(ma[b], h[a]);
  }
  // O(n)
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (h[i] > ma[i]) {
      ans++;
      // cout << "i = " << i << endl;
    }
  }
  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;
  cin >> n >> m;
  vector<int> h(n);
  vector<int> a(m);
  vector<int> b(m);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }

  // calc
  vector<vector<int>> d(n, vector<int>(n));

  for (int i = 0; i < m; i++) {
    d[a[i] - 1][b[i] - 1] = 1;
    d[b[i] - 1][a[i] - 1] = 1;
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    bool ok = true;
    for (int j = 0; j < n; j++) {
      if (d[i][j] == 1) {
        if (h[i] <= h[j]) {
          ok = false;
          break;
        }
      }
    }
    if (ok) {
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}
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 < n; i++)
#define vec vector
typedef int64_t intl;
#define fi first
#define se second
#define pushb push_back
#define popb pop_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
vec<int> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};

int main() {
  int N, M;
  cin >> N >> M;
  vec<intl> H(N);
  vec<bool> best(N, 1);
  Rep(i, N) { cin >> H.at(i); }
  vec<pair<int, int>> AB(M);
  Rep(i, M) {
    cin >> AB.at(i).fi;
    AB.at(i).fi--;
    cin >> AB.at(i).se;
    AB.at(i).se--;
    if (H.at(AB.at(i).fi) >= H.at(AB.at(i).se)) {
      best.at(AB.at(i).se) = 0;
    }
    if (H.at(AB.at(i).fi) <= H.at(AB.at(i).se)) {
      best.at(AB.at(i).fi) = 0;
    }
  }

  int sum = 0;
  Rep(i, N) { sum += best.at(i); }
  cout << sum;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for (int i = 0; i < n; i++)
#define vec vector
typedef int64_t intl;
#define fi first
#define se second
#define pushb push_back
#define popb pop_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
vec<int> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};

int main() {
  int N, M;
  cin >> N >> M;
  vec<intl> H(N);
  vec<bool> best(N, 1);
  Rep(i, N) { cin >> H.at(i); }
  vec<pair<int, int>> AB(M);
  Rep(i, M) {
    cin >> AB.at(i).fi;
    AB.at(i).fi--;
    cin >> AB.at(i).se;
    AB.at(i).se--;
  }

  Rep(i, N) {
    Rep(j, M) {
      if (i == AB.at(j).fi && H.at(i) <= H.at(AB.at(j).se)) {
        best.at(i) = 0;
      }
      if (i == AB.at(j).se && H.at(i) <= H.at(AB.at(j).fi)) {
        best.at(i) = 0;
      }
    }
  }
  int sum = 0;
  Rep(i, N) { sum += best.at(i); }
  cout << sum;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

//
//  main.cpp
//  atcoder166
//
//  Created by zer0 on 2020/05/03.
//  Copyright © 2020 zer0. All rights reserved.
//

#include <iostream>
#include <vector>

using namespace std;

int main(int argc, const char *argv[]) {
  int n, m;
  int ans = 0;
  cin >> n >> m;

  vector<long long> H(n, 0), h(n, 0), A(m, 0), B(m, 0);

  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++) {
    long long a = A[i] - 1;
    long long b = B[i] - 1;

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

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

//
//  main.cpp
//  atcoder166
//
//  Created by zer0 on 2020/05/03.
//  Copyright © 2020 zer0. All rights reserved.
//

#include <iostream>
#include <vector>

using namespace std;

int main(int argc, const char *argv[]) {
  int n, m;
  int ans = 0;
  cin >> n >> m;

  vector<long long> H(n, 0), A(m, 0), B(m, 0);

  for (int i = 0; i < n; i++) {
    cin >> H[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> A[i] >> B[i];
  }
  int add = 0;
  for (int i = 0; i < n; i++) {
    add = 0;
    for (int j = 0; j < m; j++) {

      if (i == A[j] - 1) {
        if (H[i] <= H[B[j] - 1]) {
          add++;
        }
      } else if (i == B[j] - 1) {
        if (H[i] <= H[A[j] - 1]) {
          add++;
        }
      }
    }
    if (add == 0) {
      ans++;
    }
  }

  cout << ans << endl;

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

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

int main() {
  int64_t n, m;
  int64_t a, b;
  int64_t ans = 0;

  cin >> n >> m;
  vector<int64_t> h;
  for (int64_t i = 0; i < n; i++) {
    cin >> a;
    h.push_back(a);
  }
  vector<int64_t> rnk(n, 0);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (h[a - 1] < h[b - 1] && rnk[b - 1] == 0) {
      rnk[a - 1] = 1;
    } else if (h[a - 1] > h[b - 1] && rnk[a - 1] == 0) {
      rnk[b - 1] = 1;
    } else {
      rnk[a - 1] = 1;
      rnk[b - 1] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (rnk[i] == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int64_t n, m;
  int64_t a, b;
  int64_t ans = 0;

  cin >> n >> m;
  vector<int64_t> h(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a;
    h.push_back(a);
  }
  vector<int64_t> rnk(n, 2);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (h[a] < h[b]) {
      rnk[a] = 0;
      rnk[b] = 1;
    } else {
      rnk[a] = 1;
      rnk[b] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (rnk[i] == 1 || rnk[i] == 2) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9 + 7;
const int N = 1e6 + 5;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

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

  int h[n + 1];
  vector<bool> f(n + 1, 1);
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  int u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    if (h[u] >= h[v]) {
      f[v] = 0;
    }
    if (h[u] <= h[v]) {
      f[u] = 0;
    }
  }

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

  cout << ans;

  return 0;
}

Error: WA

Fixed submission:

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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9 + 7;
const int N = 1e6 + 5;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

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

  int h[n];
  vector<bool> f(n + 1, 1);
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  int u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    if (h[u] >= h[v]) {
      f[v] = 0;
    } else if (h[u] <= h[v]) {
      f[u] = 0;
    }
  }

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

  cout << ans;

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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define invrepr(i, a, b) for (int i = b - 1; i >= a; i--)
#define invrep(i, n) invrepr(i, 0, n)

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

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

  ll i, j, h;
  ll Q, M, K, P, A, B, N;

  long double x;

  string S;

  ll ans = 0;
  ll count = 0;
  ll flag = 0;
  ll temp = 0;

  vector<ll> aa, bb, hh, ff;
  ll a, b;
  cin >> N >> M;
  ll d;
  rep(i, N) {
    cin >> temp;
    hh.push_back(temp);
    ff.push_back(0);
  }
  rep(i, M) {
    cin >> a >> b;
    aa.push_back(a);
    bb.push_back(b);
  }

  rep(i, M) {
    if (hh[aa[i] - 1] >= hh[bb[i] - 1]) {
      ff[bb[i] - 1]++;
    }
    if (hh[bb[i] - 1] >= hh[aa[i] - 1]) {
      ff[aa[i] - 1]++;
    }
  }
  rep(i, N) {
    if (ff[i] == 0) {
      ans++;
    }
  }

  // rep(i,N)cout<<ff[i];
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define invrepr(i, a, b) for (int i = b - 1; i >= a; i--)
#define invrep(i, n) invrepr(i, 0, n)

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

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

  ll i, j, h;
  ll Q, M, K, P, A, B, N;

  long double x;

  string S;

  ll ans = 0;
  ll count = 0;
  ll flag = 0;
  ll temp = 0;

  vector<ll> aa, bb, hh, ff;
  ll a, b;
  cin >> N >> M;
  ll d;
  rep(i, N) {
    cin >> temp;
    hh.push_back(temp);
    ff.push_back(0);
  }
  rep(i, M) {
    cin >> a >> b;
    aa.push_back(a);
    bb.push_back(b);
  }
  rep(i, N) {
    rep(j, M) {
      if (aa[j] - 1 == i) {
        if (hh[bb[j] - 1] >= hh[i]) {
          ff[i]++;
        }
      } else if (bb[j] - 1 == i) {
        if (hh[aa[j] - 1] >= hh[i]) {
          ff[i]++;
        }
      }
    }
  }

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

  // rep(i,N)cout<<ff[i];
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#define MAX 100000
using namespace std;
int main() {
  int N, M, count, Root[MAX], A, B;
  long long H[MAX];
  count = 0;
  scanf("%d %d", &N, &M);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &H[i]);
    Root[i] = 1;
  }

  for (int i = 0; i < M; i++) {
    scanf("%d %d", &A, &B);
    if (H[A - 1] < H[B - 1])
      Root[A - 1] = 0;
    else if (H[B - 1] < H[A - 1])
      Root[B - 1] = 0;
    else if (H[A - 1] == H[B - 1])
      Root[A - 1] = Root[B - 1] = 0;
  }

  for (int i = 0; i < N; i++) {
    if (Root[i] == 1)
      count++;
  }
  printf("%d\\n", count);
  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>
#include <iostream>
#define MAX 100000
using namespace std;
int main() {
  int N, M, count, H[MAX], Root[MAX][MAX], A, B;
  count = 0;
  scanf("%d %d", &N, &M);
  for (int i = 0; i < N; i++) {
    scanf("%d", &H[i]);
    for (int j = 0; j < N; j++) {
      Root[i][j] = -1;
    }
  }

  for (int i = 0; i < M; i++) {
    scanf("%d %d", &A, &B);
    Root[A][B] = 0;
    Root[B][A] = 0;
  }

  for (int i = 0; i < N; i++) {
    int flag = 0;
    for (int j = 0; j < N; j++) {
      if (Root[i][j] == 0) {
        if (H[i] <= H[j]) {
          flag = 1;
          break;
        }
      }
    }
    if (flag == 0)
      count++;
  }
  printf("%d\\n", count);
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  vector<vector<ll>> adj(n);
  ll a, b;
  rep(i, m) {
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  vector<bool> IsGood(n, 1);
  rep(i, n) {
    if (IsGood[i]) {
      rep(j, adj[i].size()) {
        if (h[i] > h[adj[i][j]])
          IsGood[adj[i][j]] = 0;
        else if (h[i] == h[adj[i][j]])
          IsGood[i] = IsGood[adj[i][j]] = 0;
        else
          IsGood[i] = 0;
      }
    }
  }
  ll ans = 0;
  rep(i, n) ans += IsGood[i];
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  vector<vector<bool>> adj(n, vector<bool>(n, 0));
  ll a, b;
  rep(i, m) {
    cin >> a >> b;
    a--;
    b--;
    adj[a][b] = adj[b][a] = 1;
  }
  vector<bool> IsGood(n, 1);
  rep(i, n) {
    if (IsGood[i]) {
      rep(j, n) {
        if (adj[i][j]) {
          if (h[i] > h[j])
            IsGood[j] = 0;
          else if (h[i] == h[j])
            IsGood[i] = IsGood[j] = 0;
          else
            IsGood[i] = 0;
        }
      }
    }
  }
  ll ans = 0;
  rep(i, n) ans += IsGood[i];
  cout << ans << endl;
  return 0;
}
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++)
#define repbtw(i, a, b) for (int i = a; i <= (int)(b); i++)
#define all(v) v.begin(), v.end()
#define pr(x) cout << x << endl

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

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

  vector<bool> good(n, true);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    if (h.at(a - 1) == h.at(b - 1)) {
      good.at(a - 1) = false;
      good.at(b - 1) = false;
    } else if (h.at(a - 1) > h.at(b - 1)) {
      good.at(b - 1) = false;
    } else {
      good.at(a - 1) = false;
    }
  }

  int cnt = 0;
  rep(i, n) {
    if (good.at(i))
      cnt++;
  }

  pr(cnt);
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repbtw(i, a, b) for (int i = a; i <= (int)(b); i++)
#define all(v) v.begin(), v.end()
#define pr(x) cout << x << endl

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

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

  vector<vector<bool>> has_road(n, vector<bool>(n, false));
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    has_road.at(a - 1).at(b - 1) = true;
    has_road.at(b - 1).at(a - 1) = true;
  }

  int cnt = 0;
  rep(i, n) {
    int good = true;
    rep(j, n) {
      if (has_road.at(i).at(j)) {
        if (h.at(j) >= h.at(i)) {
          good = false;
          break;
        }
      }
    }

    if (good)
      cnt++;
  }

  pr(cnt);
  return 0;
}