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

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


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n, m, i;
  cin >> n >> m;
  ll ara[n + 5];
  bool ara1[n + 5];
  for (i = 1; i <= n; i++) {
    cin >> ara[i];
    ara1[ara[i]] = false;
  }
  long ans = 0;
  int a, b;
  for (i = 1; i <= m; i++) {
    cin >> a >> b;
    if (ara[a] < ara[b])
      ara1[a] = true;
    else if (ara[b] > ara[a])
      ara1[b] = true;
    else {
      ara1[a] = true;
      ara1[b] = true;
    }
  }
  for (i = 1; i <= n; i++) {
    if (ara1[ara[i]] == false)
      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;
  vector<ll> h(n), a(m), b(m), ans(n, 1);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  for (int i = 0; i < m; i++)
    cin >> a[i] >> b[i];

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

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

  cout << count << endl;
}


Error: 0

Fixed submission:

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

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

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

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

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


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (size_t i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<vector<int>> ab(n);
  for (size_t i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    ab[a - 1].push_back(b);
    ab[b - 1].push_back(a);
  }
  int ans = 0;
  for (size_t i = 0; i < n; i++) {
    int tf = 1;
    for (size_t ii = 0; ii < size(ab[i]); ii++) {
      if (h[i] <= h[ab[i][ii] - 1]) {
        tf = 0;
      }
    }
    if (tf == 1) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (size_t i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<vector<int>> a(m, vector<int>(2));
  for (size_t i = 0; i < m; i++) {
    cin >> a[i][0] >> a[i][1];
  }
  int ans = 0;
  for (size_t i = 0; i < n; i++) {
    int g = 1;
    for (size_t ii = 0; ii < 2; ii++) {
      for (size_t iii = 0; iii < m; iii++) {
        if (a[iii][ii] == i + 1 &&
            h[a[iii][ii] - 1] <= h[a[iii][(ii + 1) % 2] - 1]) {
          g = 0;
        }
      }
    }
    if (g == 1) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
typedef long long int lld;
typedef unsigned long long int llu;
#define INF (lld)(9223372036854775807)
#define IINF (int)(2147483647)

using namespace std;
int main(void) {
  lld n, m, a, b, s = 0;
  cin >> n >> m;
  vector<lld> h(n);
  for (lld i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<vector<int>> p(n);
  for (lld i = 0; i < m; i++) {
    cin >> a >> b;
    p[a - 1].push_back(b - 1);
    p[b - 1].push_back(a - 1);
  }

  for (lld i = 0; i < n; i++) {
    for (auto &t : p[i]) {
      if (h[t] >= h[i]) {
        goto no;
      }
    }
    s++;
  no:;
  }

  cout << s << "\\n";
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
typedef long long int lld;
typedef unsigned long long int llu;
#define INF (lld)(9223372036854775807)
#define IINF (int)(2147483647)

using namespace std;
int main(void) {
  lld n, m, a, b, s = 0;
  cin >> n >> m;
  vector<lld> h(n);
  for (lld i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<vector<int>> p(10000);
  for (lld i = 0; i < m; i++) {
    cin >> a >> b;
    p[a - 1].push_back(b - 1);
    p[b - 1].push_back(a - 1);
  }

  for (lld i = 0; i < n; i++) {
    for (auto &t : p[i]) {
      if (h[t] >= h[i]) {
        goto no;
      }
    }
    s++;
  no:;
  }

  cout << s << "\\n";
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long N, M;
  cin >> N >> M;
  long long H[N];
  vector<bool> flag(N - 1, true);
  long long a, b;

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

  for (int k = 0; k < M; k++) {
    cin >> a >> b;
    if (H[a - 1] == H[b - 1]) {
      flag[b - 1] = false;
      flag[a - 1] = false;
    } else if (H[a - 1] > H[b - 1]) {
      flag[b - 1] = false;
    } else if (H[a - 1] < H[b - 1]) {
      flag[a - 1] = false;
    }
  }

  long long ans = 0;
  for (int j = 0; j < N; j++) {
    if (flag[j]) {
      ans++;
    }
  }

  cout << ans << endl;
}

Error: -11

Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<long long> H(N - 1, 0);
  vector<bool> flag(N - 1, true);
  int a, b;
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }

  for (int k = 0; k < M; k++) {
    cin >> a >> b;
    if (H[a - 1] >= H[b - 1]) {
      flag[b - 1] = false;
    } else if (H[a - 1] <= H[b - 1]) {
      flag[a - 1] = false;
    }
  }

  int ans = 0;
  for (int j = 0; j < N; j++) {
    if (flag[j]) {
      ans++;
    }
  }

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

#include <iostream>
#include <queue>
using namespace std;
const int MAX = 200000;
struct edge {
  int next = 0, to = 0;
} edges[MAX];
int h[MAX], flag[MAX], head[MAX] = {0}, lower;
int cnt = 1;
void add(int a, int b) {
  edges[cnt].to = b;
  edges[cnt].next = head[a];
  head[a] = cnt++;
}
int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    cin >> h[i];
  }
  while (M--) {
    int a, b;
    cin >> a >> b;
    ;
    add(a, b);
    add(b, a);
  }
  cnt = 0;
  queue<int> Q;
  for (int i = 1; i <= N; i++) {
    if (flag[i])
      continue;
    Q.push(i);
    while (!Q.empty()) {
      int c = Q.front();
      if (flag[c]) {
        Q.pop();
        continue;
      }
      flag[c] = 1;
      Q.pop();
      int t;
      lower = 0;
      for (t = head[c]; t; t = edges[t].next) {
        int d = edges[t].to;
        if (h[d] >= h[c])
          lower = 1;
        if (flag[d])
          continue;
        Q.push(d);
      }
      if (!lower) {
        cnt++;
      }
    }
  }
  cout << cnt;
  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
#include <queue>
using namespace std;
struct edge {
  int next = 0, to = 0;
} edges[10010];
int h[10010], flag[10010], head[10010] = {0}, lower;
int cnt = 1;
void add(int a, int b) {
  edges[cnt].to = b;
  edges[cnt].next = head[a];
  head[a] = cnt++;
}
int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    cin >> h[i];
  }
  while (M--) {
    int a, b;
    cin >> a >> b;
    ;
    add(a, b);
    add(b, a);
  }
  cnt = 0;
  queue<int> Q;
  for (int i = 1; i <= N; i++) {
    if (flag[i])
      continue;
    Q.push(i);
    while (!Q.empty()) {
      int c = Q.front();
      if (flag[c]) {
        Q.pop();
        continue;
      }
      flag[c] = 1;
      Q.pop();
      int t;
      lower = 0;
      for (t = head[c]; t; t = edges[t].next) {
        int d = edges[t].to;
        if (h[d] >= h[c])
          lower = 1;
        if (flag[d])
          continue;
        Q.push(d);
      }
      if (!lower) {
        cnt++;
      }
    }
  }
  cout << cnt;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#define rep(a, i, n) for (int i = (a); i < (n); i++)
#define ZERO 0
typedef long long ll;
using namespace std;

void set_one(ll *a, ll n) {
  rep(0, i, n) { a[i] = 1; }
}

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

  ll h[n];
  rep(0, i, n) { cin >> h[i]; }

  ll a[m], b[m];
  rep(0, i, m) { cin >> a[i] >> b[i]; }

  ll s[n];
  set_one(s, n);

  rep(0, i, m) {
    if (h[a[i] - 1] > h[b[i] - 1])
      s[b[i] - 1] = ZERO;
    else if (h[a[i] - 1] < h[b[i] - 1])
      s[a[i] - 1] = ZERO;
    else if (h[a[i] - 1] == h[b[i] - 1]) {
      s[a[i] - 1] = ZERO;
      s[b[i] - 1] = ZERO;
    }
  }

  rep(0, i, n) {
    if (s[i] != ZERO)
      count++;
  }
  cout << count << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#define rep(a, i, n) for (int i = (a); i < (n); i++)
typedef long long ll;

using namespace std;

void set_zero(ll *a, ll n) {
  rep(0, i, n) { a[i] = 0; }
}

int main() {
  ll n, m, count = 0;
  cin >> n >> m;
  ll h[n], a[m], b[m];

  set_zero(a, m);
  set_zero(b, m);

  rep(0, i, n) { cin >> h[i]; }

  rep(0, i, m) { cin >> a[i] >> b[i]; }

  rep(0, i, n) {
    rep(0, j, m) {
      if (a[j] == i + 1 && h[i] <= h[b[j] - 1]) {
        break;
      }

      if (b[j] == i + 1 && h[i] <= h[a[j] - 1]) {
        break;
      }
      if (j == m - 1) {
        count++;
      }
    }
  }
  cout << count << endl;
}
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;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> ok(n, true);

  rep(i, n) cin >> h[i];

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    if (h[a] <= h[b])
      ok[a] = false;
    if (h[b] <= h[a])
      ok[b] = false;
  }

  int ans = 0;
  rep(i, n) {
    if (ok[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vpii = vector<pair<int, int>>;

int main() {
  ll n, m;
  cin >> n >> m;
  vi data(n + 1);
  data[0] = 0;
  for (int i = 1; i < n + 1; i++) {
    cin >> data[i];
  }
  vi A(n + 1);
  vi B(n + 1);
  A[0] = 0;
  B[0] = 0;
  for (int i = 1; i <= m; i++) {
    cin >> A[i] >> B[i];
  }
  int cnt = 0;
  vector<bool> highest(n + 1, true);
  highest[0] = false;
  for (int i = 1; i <= m; i++) {
    if (data[A[i]] > data[B[i]]) {
      highest[B[i]] = false;
    } else if (data[A[i]] < data[B[i]]) {
      highest[A[i]] = false;
    } else {
      highest[A[i]] = false;
      highest[B[i]] = false;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (highest[i] == true)
      cnt++;
  }
  cout << cnt << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

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

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

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

  cout << sum;

  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  vector<int> C(N);
  vector<int> H(N);
  cin >> N >> M;
  int a, b;
  for (int i = 0; i < N; i++)
    cin >> H[i];

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

  cout << sum;

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

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

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

  vector<int> height(N);
  vector<int> out(N);
  vector<vector<int>> path(M, vector<int>(2));

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

  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> path.at(i).at(j);
    }
  }

  for (int i = 0; i < M; i++) {
    if (height.at(path.at(i).at(0) - 1) > height.at(path.at(i).at(1) - 1)) {
      out.at(path.at(i).at(1) - 1) = 0;
    } else if (height.at(path.at(i).at(0) - 1) <
               height.at(path.at(i).at(1) - 1)) {
      out.at(path.at(i).at(0) - 1) = 0;
    } else if (height.at(path.at(i).at(0) - 1) ==
               height.at(path.at(i).at(1) - 1)) {
      out.at(path.at(i).at(0) - 1) = 0;
      out.at(path.at(i).at(1) - 1) = 0;
    }
  }

  // outの非ゼロの要素数を出力
  for (int i = 0; i < N; i++) {
    if (out.at(i) != 0) {
      count++;
    }
  }

  cout << count << endl;
}


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


Fixed submission:

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

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

  vector<int> height(N);
  vector<int> out(N);
  vector<vector<int>> path(N, vector<int>(2));

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

  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> path.at(i).at(j);
    }
  }

  for (int i = 0; i < M; i++) {
    if (height.at(path.at(i).at(0)) > height.at(path.at(i).at(1))) {
      out.at(path.at(i).at(1)) = 0;
    } else if (height.at(path.at(i).at(0)) < height.at(path.at(i).at(1))) {
      out.at(path.at(i).at(0)) = 0;
    } else if (height.at(path.at(i).at(0)) == height.at(path.at(i).at(1))) {
      out.at(path.at(i).at(0)) = 0;
      out.at(path.at(i).at(1)) = 0;
    }
  }

  // outの非ゼロの要素数を出力
  for (int i = 0; i < N; i++) {
    if (out.at(i) != 0) {
      count++;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vector<bool> ans(n + 1, 1);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;

    ans[x] = ans[x] && (a[x] > a[y]);
    ans[y] = ans[y] && (a[y] > a[x]);
  }
  int count = 0;
  for (int i = 1; i <= n; i++) {
    if (ans[i]) {
      count++;
    }
  }

  cout << count;

  return 0;
}


Error: -6
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif

  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1);
  for (int i = 1; i < n; i++) {
    cin >> a[i];
  }
  vector<bool> ans(n + 1, 1);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;

    ans[x] = ans[x] && (a[x] > a[y]);
    ans[y] = ans[y] && (a[y] > a[x]);
  }
  int count = 0;
  for (int i = 1; i <= n; i++) {
    if (ans[i]) {
      count++;
    }
  }

  cout << count;

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

#include <bits/stdc++.h>
// typedef pair<int,int> pii;
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int64_t> h(n);
  //    vector<vector<int>> root(n,vector<int>(n,0));
  vector<queue<int>> root(n);
  for (int ix = 0; ix < n; ix++)
    cin >> h.at(ix);
  for (int ix = 0; ix < m; ix++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    root.at(a).push(b);
    root.at(b).push(a);
    //        root.at(a).at(b) = root.at(b).at(a) = 1;
  }
  int cnt = 0;
  for (int ix = 0; ix < n; ix++) {
    int64_t v = h.at(ix);
    bool can = true;
    while (!root.at(ix).empty()) {
      int64_t a = root.at(ix).front();
      root.at(ix).pop();
      if (h.at(a) >= v)
        can = false;
      if (can == false)
        break;
    }
    //
    if (can)
      cnt++;
  }
  cout << cnt << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int64_t> h(n);
  vector<vector<int>> root(n, vector<int>(n, 0));
  for (int ix = 0; ix < n; ix++)
    cin >> h.at(ix);
  for (int ix = 0; ix < m; ix++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    root.at(a).at(b) = root.at(b).at(a) = 1;
  }
  int cnt = 0;
  for (int ix = 0; ix < n; ix++) {
    int64_t v = h.at(ix);
    bool can = true;
    for (int ix2 = 0; ix2 < n; ix2++) {
      if (root.at(ix).at(ix2) == 1 && h.at(ix2) >= v) {
        can = false;
      }
      if (can == false)
        break;
    }
    if (can)
      cnt++;
  }
  cout << cnt << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
#define N 100010
int main() {
  int n, m, h[N], ma[N];
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
    ma[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    ma[a] = max(ma[a], h[b]);
    ma[b] = max(ma[b], h[a]);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += h[i] > ma[i];
  }
  cout << ans << endl;
}

Error: WA

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    int h;
    cin >> h;
    vec.at(i) = h;
  }
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    int h;
    cin >> h;
    v.at(i) = h;
  }
  int c = v.size();
  int d = 0;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    int o, p;
    o = vec.at(a - 1);
    p = vec.at(b - 1);
    for (int j = 0; j < c; j++) {
      if (min(o, p) == v.at(j)) {
        v.erase(v.begin() + j);
        c--;
        break;
      }
    }
  }
  cout << c << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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

  vector<int> A(M);
  vector<int> B(M);
  for (int i = 0; i < M; i++) {
    cin >> A.at(i) >> B.at(i);
    if (H.at(A.at(i) - 1) > H.at(B.at(i) - 1))
      high.at(B.at(i) - 1) = 0;
    else if (H.at(A.at(i) - 1) < H.at(B.at(i) - 1))
      high.at(A.at(i) - 1) = 0;
    else {
      high.at(A.at(i) - 1) = 0;
      high.at(B.at(i) - 1) = 0;
    }
  }

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

Error: TLE

Fixed submission:

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

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

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

  vector<int> A(M);
  vector<int> B(M);
  for (int i = 0; i < M; i++) {
    cin >> A.at(i) >> B.at(i);
    if (H.at(A.at(i) - 1) > H.at(B.at(i) - 1))
      high.erase(remove(high.begin(), high.end(), B.at(i)), high.end());
    else if (H.at(A.at(i) - 1) < H.at(B.at(i) - 1))
      high.erase(remove(high.begin(), high.end(), A.at(i)), high.end());
    else {
      high.erase(remove(high.begin(), high.end(), B.at(i)), high.end());
      high.erase(remove(high.begin(), high.end(), A.at(i)), high.end());
    }
  }

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

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<long> h(n);
  vector<bool> good(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    good[i] = true;
  }
  int a, b, h_a, h_b;
  vector<set<int>> neighboor(n);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    h_a = h[a - 1];
    h_b = h[b - 1];
    if (h_a == h_b) {
      good[a - 1] = good[b - 1] = false;
    } else if (h_a > h_b)
      good[b - 1] = false;
    else
      good[a - 1] = false;
  }
  int c = 0;
  for (int i = 0; i < n; i++) {
    if (good[i])
      c++;
  }
  cout << c << endl;
  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<long> h(n);
  vector<bool> good(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    good[i] = true;
  }
  int a, b;
  vector<set<int>> neighboor(n);
  // set up neighboor list
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    neighboor[a - 1].insert(b);
    neighboor[b - 1].insert(a);
  }
  // check good obs
  long h_a, h_b;
  set<int>::iterator it;
  for (int i = 0; i < m; i++) {
    a = i;
    h_a = h[a];
    it = neighboor[a].begin();
    while (it != neighboor[a].end()) {
      b = int(*it) - 1;
      // cout << " " << b << " " << endl;
      h_b = h[b];
      // compare height
      if (h_a == h_b) {
        good[a] = good[b] = false;
      } else if (h_a > h_b)
        good[b] = false;
      else
        good[a] = false;
      it++;
    }
  }
  // scan god obs
  int c = 0;
  for (int i = 0; i < n; i++) {
    if (good[i])
      c++;
  }
  cout << c << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int H[MAXN];
bool Bad[MAXN];

int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 1; i <= N; ++i)
    cin >> H[i];

  for (int i = 1; i <= M; ++i) {
    int u, v;
    cin >> u >> v;

    if (H[u] <= H[v])
      Bad[u] = true;
    if (H[v] <= H[u])
      Bad[v] = true;
  }

  int ans = 0;
  for (int i = 1; i <= N; ++i)
    if (!Bad[i])
      ans++;

  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10005;
int H[MAXN];
bool Bad[MAXN];

int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 1; i <= N; ++i)
    cin >> H[i];

  for (int i = 1; i <= M; ++i) {
    int u, v;
    cin >> u >> v;

    if (H[u] <= H[v])
      Bad[u] = true;
    if (H[v] <= H[u])
      Bad[v] = true;
  }

  int ans = 0;
  for (int i = 1; i <= N; ++i)
    if (!Bad[i])
      ans++;

  cout << ans << endl;

  return 0;
}