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

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

int main(void) {
  ll n, m, ans = 0;
  cin >> n >> m;
  vector<ll> h(n), a(m), b(m);
  vector<bool> ok(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    ok[i] = true;
  }
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    cin >> b[i];
  }
  for (int i = 0; i < m; i++) {
    if (h[a[i] - 1] < h[b[i] - 1]) {
      ok[a[i] - 1] = false;
    } else if (h[a[i] - 1] > h[b[i] - 1]) {
      ok[b[i] - 1] = false;
    } else {
      ok[a[i] - 1] = false;
      ok[b[i] - 1] = 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>
using namespace std;
// #define ON 1
// #define OFF 0

int main() {
  long long int n;
  long long int m;
  long long int *h;
  bool **t;
  long long int ans = 0;
  bool good[100000];
  cin >> n >> m;
  h = (long long int *)malloc(sizeof(long long int) * n);
  for (int i = 0; i < n; i++) {
    good[i] = true;
  }
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  t = (bool **)malloc(sizeof(bool *) * n);
  for (int i = 0; i < n; i++) {
    t[i] = (bool *)malloc(sizeof(bool) * n);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      t[i][j] = false;
    }
  }
  for (int i = 0; i < m; i++) {
    long long int a, b;
    cin >> a >> b;
    a--;
    b--;
    t[a][b] = true;
    t[b][a] = true;
  }
  for (int i = 0; i < n; i++) {
    // printf("good[%d] = %d\\n", i, good[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (t[i][j] == true && h[i] <= h[j]) {
        // printf("t[%d][%d] = %d, h[%d] = %d, h[%d] = %d\\n", i, j, t[i][j], i,
        // (int)h[i], j, (int)h[j]);
        good[i] = false;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (good[i] == true) {
      ans++;
    }
    // printf("good[%d] = %d\\n", i, good[i]);
    // printf("h[%d] = %d\\n", i, (int)h[i]);
  }
  /*
  for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
          cout << t[i][j] << " ";
      }
      cout << endl;
  }
  */
  cout << ans << endl;
  free(t);
  free(h);
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error


#include <algorithm>
#include <iomanip>
#include <iostream>
using namespace std;

void Main() {
  // input
  int N, M;
  cin >> N >> M;
  u_int64_t H[N + 1], nH[N + 1];
  for (int i = 1; i <= N; i++) {
    cin >> H[i];
    nH[i] = 0;
  }

  for (int i = 0; i < M; i++) {
    int from, to;
    cin >> from >> to;
    nH[from] = max(nH[from], H[to]);
    nH[to] = max(nH[to], H[from]);
  }

  int ans = 0;
  for (int i = 1; i <= N; i++) {
    // cout << "H: " << H[i] << ", nH: " << nH[i] << endl;
    if (H[i] > nH[i]) {
      ans++;
    }
  }

  // output
  cout << ans << endl;
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Error: WA

Fixed submission:


#include <algorithm>
#include <iomanip>
#include <iostream>
using namespace std;

void Main() {
  // input
  int N, M;
  cin >> N >> M;
  u_int64_t H[N + 1], nH[N + 1];
  for (int i = 1; i < N; i++) {
    cin >> H[i];
    nH[i] = 0;
  }

  for (int i = 0; i < M; i++) {
    int from, to;
    cin >> from >> to;
    nH[from] = max(nH[from], H[to]);
    nH[to] = max(nH[to], H[from]);
  }

  int ans = 0;
  for (int i = 1; i <= N; i++) {
    cout << "H: " << H[i] << ", nH: " << nH[i] << endl;
    if (H[i] > nH[i]) {
      ans++;
    }
  }

  // output
  cout << ans << endl;
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

signed main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n + 1);
  for (int i = 1; i <= n; ++i)
    cin >> h[i];
  vector<int> a(m + 1), b(m + 1);
  for (int i = 1; i <= m; ++i)
    cin >> a[i] >> b[i];

  vector<int> good(n + 1, 1);
  //    vector<int>noPath(n+1,1);
  for (int i = 1; i <= m; ++i) {
    if (h[a[i]] > h[b[i]])
      good[b[i]] = 0;
    if (h[b[i]] > h[a[i]])
      good[a[i]] = 0;
    if (h[b[i]] == h[a[i]])
      good[b[i]] = good[a[i]] = 0;
    //        noPath[a[i]] = 0;
    //        noPath[b[i]] = 0;
  }

  int ans = 0;
  for (int i = 1; i <= n; ++i)
    ans += good[i];
  //    for (int i = 1; i <= n; ++i) ans += noPath[i];
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

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

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

typedef long long ll;

// #define INF 0x3fffFFFF
// #define INF_NEG (INF * -1)

// int isFirst = 1;
// template <class T> void print(T t) { if (isFirst) cout << t, isFirst = 0;
// else cout << " " << t; }

signed main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n + 1);
  for (int i = 1; i <= n; ++i)
    cin >> h[i];
  vector<int> a(m + 1), b(m + 1);
  for (int i = 1; i <= m; ++i)
    cin >> a[i] >> b[i];

  vector<int> good(n + 1, 1);
  vector<int> not_exist(n + 1, 1);

  for (int i = 1; i <= n; ++i) {
    if (a[i] > b[i])
      good[b[i]] = 0;
    if (b[i] > a[i])
      good[a[i]] = 0;
    if (b[i] == a[i])
      good[b[i]] = good[a[i]] = 0;
    not_exist[a[i]] = 0;
    not_exist[b[i]] = 0;
  }

  int ans = 0;
  for (int i = 1; i <= n; ++i)
    ans += good[i];
  for (int i = 1; i <= n; ++i)
    ans += not_exist[i];
  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;
  int a, b;
  vector<int> good(n, 1);
  vector<int> hi(n);
  for (int i = 0; i < n; i++) {
    cin >> hi.at(i);
  }
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (hi.at(a - 1) > hi.at(b - 1)) {
      good.at(b - 1) = 0;
    } else if (hi.at(a - 1) < hi.at(b - 1)) {
      good.at(a - 1) = 0;
    } else {
      good.at(a - 1) = 0;
      good.at(b - 1) = 0;
    }
  }
  int sum = 0;

  for (int i = 0; i < n; i++) {
    sum += good.at(i);
  }
  cout << sum << 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> good(n, 1);
  vector<int> hi(n);
  for (int i = 0; i < n; i++) {
    cin >> hi.at(i);
  }
  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (hi.at(a) > hi.at(b)) {
      good.at(b) = 0;
    } else
      good.at(a) = 0;
  }
  int sum = 0;
  for (int i = 0; i < m; i++) {
    sum += good.at(i);
  }
  cout << sum << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

// 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]);
  }

  vector<bool> flags(N, true);
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (H[a] <= H[b])
      flags[a] = false;
    if (H[b] <= H[a])
      flags[b] = false;
  }
  int ans = 0;
  rep(i, N) if (flags[i]) ans++;
  cout << ans << endl;
  return 0;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
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) {
  int count = 0;
  bool flag = true;
  vector<bool> flags(N, false);

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

    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])) {
        flag = false;
        break;
      }
    }

    if (flag) {
      count++;
      for (int j = 0; j < M; j++) {
        if (i + 1 == A[j]) {
          flags[B[j] - 1] = true;
        } else if (i + 1 == B[j]) {
          flags[A[j] - 1] = true;
        }
      }
      // cout<<i<<endl;
    }
  }

  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;

int main() {
  int n, m, a, b, ans = 0;
  cin >> n >> m;
  vector<int> high(n);
  vector<int> view(n, 0);
  vector<vector<int>> road(m, vector<int>(2));
  for (int i = 0; i < n; i++)
    cin >> high.at(i);
  for (int j = 0; j < m; j++) {
    cin >> a >> b;
    a--;
    b--;
    if (high.at(a) <= high.at(b))
      view.at(a)++;
    if (high.at(b) <= high.at(a))
      view.at(b)++;
  }

  for (int i = 0; i < n; i++) {
    if (view.at(i) == 0)
      ans++;
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int n, m, a, b, jud, ans = 0;
  cin >> n >> m;
  vector<int> high(n);
  for (int i = 0; i < n; i++)
    cin >> high.at(i);
  vector<vector<int>> road(m, vector<int>(2));
  for (int j = 0; j < m; j++)
    cin >> road.at(j).at(0) >> road.at(j).at(1);

  vector<vector<int>> map(n, vector<int>(n, 0));
  for (int i = 0; i < m; i++) {
    a = road.at(i).at(0) - 1;
    b = road.at(i).at(1) - 1;
    map.at(a).at(b) = high.at(b);
    map.at(b).at(a) = high.at(a);
  }

  for (int i = 0; i < n; i++) {
    jud = 0;
    for (int j = 0; j < m; j++) {
      if (high.at(i) <= map.at(i).at(j))
        jud++;
    }
    if (jud == 0)
      ans++;
  }

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

#include <cstdio>
const int MAXN = 1e5 + 5;
bool good[MAXN];
int H[MAXN];
int a, b, M, N;

int main() {
  scanf(" %d%d", &N, &M);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &H[i]);
    good[i] = true;
  }
  for (int i = 0; i < M; ++i) {
    scanf(" %d%d", &a, &b);
    good[a] &= (H[a] > H[b]);
    good[b] &= (H[b] > H[a]);
  }
  int ret = 0;
  for (int i = 1; i <= N; ++i) {
    if (good[i])
      ++ret;
  }
  printf("%d\\n", ret);
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
const int MAXN = 105;
bool good[MAXN];
int H[MAXN];
int a, b, M, N;

int main() {
  scanf(" %d%d", &N, &M);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &H[i]);
    good[i] = true;
  }
  for (int i = 0; i < M; ++i) {
    scanf(" %d%d", &a, &b);
    good[a] &= (H[a] > H[b]);
    good[b] &= (H[b] > H[a]);
  }
  int ret = 0;
  for (int i = 1; i <= N; ++i) {
    if (good[i])
      ++ret;
  }
  printf("%d\\n", ret);
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, M;
  cin >> N >> M;
  int H[N], ma[N];
  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: 0

Fixed submission:

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

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

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    ans += X[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9 + 7)
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REP1(i, n) for (ll i = 1; i <= n; i++)

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

  vector<ll> h(n + 10);
  REP(i, n) cin >> h[i];
  vector<ll> a(m + 10);
  vector<ll> b(m + 10);
  vector<ll> t(n + 10);
  REP(i, n) t[n] = 0;
  REP(i, m) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    if (h[a[i]] >= h[b[i]]) {
      t[b[i]] = 1;
    }
    if (h[b[i]] >= h[a[i]]) {
      t[a[i]] = 1;
    }
  }
  ll ans = 0;

  REP(i, n) {
    if (t[i] == 0)
      ans++;
  }

  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9 + 7)
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REP1(i, n) for (ll i = 1; i <= n; i++)

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

  vector<ll> h(n);
  REP(i, n) cin >> h[i];
  vector<ll> a(m);
  vector<ll> b(m);
  vector<ll> t(n);
  REP(i, n) t[n] = 0;
  REP(i, m) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    if (h[a[i]] >= h[b[i]]) {
      t[b[i]] = 1;
    }
    if (h[b[i]] >= h[a[i]]) {
      t[a[i]] = 1;
    }
  }
  ll ans = 0;

  REP(i, n) {
    if (t[i] == 0)
      ans++;
  }

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

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

using ll = long long;
using namespace std;

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

Error: 0

Fixed submission:

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

using ll = long long;
using namespace std;

int main() {
  ll n, m;
  cin >> n >> m;
  ll hs[n];
  ll ab[n][n];
  rep(i, n) {
    rep(j, n) { ab[i][j] = 0; }
  }
  rep(i, n) { cin >> hs[i]; }
  ll a, b;
  rep(i, m) {
    cin >> a >> b;
    ab[a - 1][b - 1]++;
    ab[b - 1][a - 1]++;
  }
  int count = 0;
  rep(i, n) {
    bool isHighest = true;
    rep(j, n) {
      if (i == j) {
        continue;
      }
      if (ab[i][j] != 0) {
        if (hs[i] <= hs[j]) {
          isHighest = false;
        }
      }
    }
    if (isHighest) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  bool vis[100010];
  int tot = 0;
  int h[100010], a, b;
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  for (int j = 1; j <= m; j++) {
    cin >> a >> b;
    if (h[a] < h[b])
      vis[a] = true;
    else if (h[a] == h[b])
      vis[a] = vis[b] = true;
    else
      vis[b] = true;
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i] == false) {
      tot++;
    }
  }
  cout << tot;
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  bool vis[100010];
  int tot = 0;
  int h[10010], a, b;
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  for (int j = 1; j <= m; j++) {
    cin >> a >> b;
    if (h[a] < h[b])
      vis[a] = true;
    else if (h[a] == h[b])
      vis[a] = vis[b] = true;
    else
      vis[b] = true;
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i] == false) {
      tot++;
    }
  }
  cout << tot;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int N, M, H[100010];
vector<int> G[100010];

int main() {
  cin >> N >> M;
  rep(i, N) cin >> H[i];
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    // aとbは0インデックスに揃える
    a--;
    b--;
    G[a].push_back(b);
    // 無向グラフなのでbにもaを追加する
    G[b].push_back(a);
  }
  int ans = 0;
  rep(i, N) {
    bool check = true;
    for (auto g : G[i]) {
      if (H[i] <= H[g])
        check = false;
    }
    if (check)
      ans++;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

int N, M, H[10010];
vector<int> G[10010];

int main() {
  cin >> N >> M;
  rep(i, N) cin >> H[i];
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    // aとbは0インデックスに揃える
    a--;
    b--;
    G[a].push_back(b);
    // 無向グラフなのでbにもaを追加する
    G[b].push_back(a);
  }
  int ans = 0;
  rep(i, N) {
    bool check = true;
    for (auto g : G[i]) {
      if (H[i] <= H[g])
        check = false;
    }
    if (check)
      ans++;
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  [[maybe_unused]] long long int n, m, i, j, c = 0, h[1000010], a[1000010],
                                             b[1000010], x[1000010], ans = 0;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> h[i];
    x[i] = 0;
  }
  for (i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    if (h[a[i] - 1] > h[b[i] - 1]) {
      x[b[i] - 1]++;
    } else if (h[a[i] - 1] < h[b[i] - 1]) {
      x[a[i] - 1]++;
    } else {
      x[a[i] - 1]++;
      x[b[i] - 1]++;
    }
  }
  for (i = 0; i < n; i++) {
    if (x[i] == 0) {
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long int n, m, i = 0, j, c = 0, h[100010], a[100010], b[100010],
                      x[100010], ans = 0;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> h[i];
    x[i] = 0;
  }
  for (i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    x[min(h[a[i] - 1], h[b[i] - 1])] = 1;
    if (h[a[i] - 1] == h[b[i] - 1]) {
      x[a[i] - 1] = 1;
      x[b[i] - 1] = 1;
    }
  }
  for (i = 0; i < n; i++) {
    if (x[i] == 0) {
      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;

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

  vector<ll> h(n);
  vector<int> to[1000005];

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

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  bool goo;
  int cnt = 0;

  for (int i = 0; i < n; i++) {
    goo = true;
    int hig = h.at(i);

    for (auto x : to[i]) {
      if (hig <= h.at(x)) {
        goo = false;
      }
    }

    if (goo)
      cnt++;
  }

  cout << cnt << endl;

  return 0;
}


Error: -11

Fixed submission:

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

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

  vector<ll> h;
  vector<int> to[1000005];

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

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  bool goo;
  int cnt = 0;

  for (int i = 0; i < n; i++) {
    goo = true;
    int hig = h.at(i);

    for (auto x : to[i]) {
      if (hig <= h.at(x)) {
        goo = false;
      }
    }

    if (goo)
      cnt++;
  }

  cout << cnt << 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> pll;

int H[110000];
bool good[110000];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; i++)
    cin >> H[i];

  fill(good, good + N, 1);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    if (H[a] <= H[b])
      good[a] = 0;
    if (H[a] >= H[b])
      good[b] = 0;
  }

  int cnt = 0;
  for (int i = 0; i < N; i++)
    if (good[i])
      cnt++;
  cout << cnt << '\\n';
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

int H[11000];
bool good[11000];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; i++)
    cin >> H[i];

  fill(good, good + N, 1);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    if (H[a] <= H[b])
      good[a] = 0;
    if (H[a] >= H[b])
      good[b] = 0;
  }

  int cnt = 0;
  for (int i = 0; i < N; i++)
    if (good[i])
      cnt++;
  cout << cnt << '\\n';
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>

#define int long long
#define rr register

#define MAXN 1000010
#define inf 1e18

using namespace std;

inline int read() {
  int s = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    f |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    s = s * 10 + (ch ^ 48);
    ch = getchar();
  }
  return f ? -s : s;
}

struct Edge {
  int nxt;
  int to;
} e[MAXN];

int n, m, ans, tot;

int a[MAXN], head[MAXN];

inline void add(int from, int to) {
  e[++tot].to = to;
  e[tot].nxt = head[from];
  head[from] = tot;
}

void dfs(int x) {
  for (rr int i = head[x]; i; i = e[i].nxt) {
    int to = e[i].to;
    if (a[x] <= a[to])
      return;
  }
  ans++;
}

signed main() {
  n = read();
  m = read();
  for (rr int i = 1; i <= n; i++)
    a[i] = read();
  for (rr int i = 1; i <= m; i++) {
    int x = read(), y = read();
    add(x, y);
    add(y, x);
  }
  for (rr int i = 1; i <= n; i++)
    dfs(i);
  cout << ans << "\\n";
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>

#define int long long
#define rr register

#define MAXN 100010
#define inf 1e18

using namespace std;

inline int read() {
  int s = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    f |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    s = s * 10 + (ch ^ 48);
    ch = getchar();
  }
  return f ? -s : s;
}

struct Edge {
  int nxt;
  int to;
} e[MAXN];

int n, m, ans, tot;

int a[MAXN], head[MAXN];

inline void add(int from, int to) {
  e[++tot].to = to;
  e[tot].nxt = head[from];
  head[from] = tot;
}

void dfs(int x) {
  for (rr int i = head[x]; i; i = e[i].nxt) {
    int to = e[i].to;
    if (a[x] <= a[to])
      return;
  }
  ans++;
}

signed main() {
  n = read();
  m = read();
  for (rr int i = 1; i <= n; i++)
    a[i] = read();
  for (rr int i = 1; i <= m; i++) {
    int x = read(), y = read();
    add(x, y);
    add(y, x);
  }
  for (rr int i = 1; i <= n; i++)
    dfs(i);
  cout << ans << "\\n";
}