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

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

vector<bool> good;
vector<bool> seen;
vector<int> H;

void dfs(const vector<vector<int>> &G, int v) {
  if (seen[v])
    return;
  seen[v] = true;
  for (auto next_v : G[v]) {
    if (H[v] <= H[next_v]) {
      good[v] = false;
    }
    if (seen[next_v])
      continue;
    dfs(G, next_v);
  }
}

int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    int h;
    cin >> h;
    H.push_back(h);
  }

  vector<vector<int>> road(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    road[a].push_back(b);
    road[b].push_back(a);
  }
  good.assign(N, true);
  seen.assign(N, false);
  for (int i = 0; i < N; i++) {
    dfs(road, i);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (good[i]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

vector<bool> good;
vector<bool> seen;
vector<int> H;

void dfs(const vector<vector<int>> &G, int v) {
  seen[v] = true;
  for (auto next_v : G[v]) {
    if (H[v] <= H[next_v]) {
      good[v] = false;
    }
    if (seen[next_v])
      continue;
    dfs(G, next_v);
  }
}

int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    int h;
    cin >> h;
    H.push_back(h);
  }

  vector<vector<int>> road(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    road[a].push_back(b);
    road[b].push_back(a);
  }
  good.assign(N, true);
  for (int i = 0; i < N; i++) {
    seen.assign(N, false);
    dfs(road, i);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (good[i]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define rrep(i, n, a) for (int i = n; i >= a; i--)
#define FOR(i, n) for (int i = 0; i < n; i++)
#define all(s) s.begin(), s.end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define pcnt(n) __builtin_popcount(n)
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const int INF = 1e18;
const double PI = acos(-1);

int ans;
vi h(100010);
vvi c(100010);

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m, a, b;
  cin >> n >> m;

  rep(i, 0, n) { cin >> h[i]; }
  rep(i, 0, m) {
    cin >> a >> b;
    a--;
    b--;
    c[a].push_back(b);
    c[b].push_back(a);
  }
  rep(i, 0, n) {
    bool ok = true;
    for (auto x : c[i]) {
      if (h[x] >= h[i]) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      ans++;
    }
  }
  cout << ans << endl;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define rrep(i, n, a) for (int i = n; i >= a; i--)
#define FOR(i, n) for (int i = 0; i < n; i++)
#define all(s) s.begin(), s.end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define pcnt(n) __builtin_popcount(n)
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const int INF = 1e18;
const double PI = acos(-1);

int ans;
vi h(100010);
vvi c(100010);
bool visited[100010];

void solve(int s) {
  if (visited[s]) {
    return;
  } else {
    int tmp = h[s];
    bool ok = 1;
    for (auto x : c[s]) {
      if (h[x] >= tmp) {
        ok = false;
      }
      if (!visited[x])
        solve(x);
    }
    if (ok) {
      ans++;
    }
  }
}

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m, a, b;
  cin >> n >> m;

  rep(i, 0, n) { cin >> h[i]; }
  rep(i, 0, m) {
    cin >> a >> b;
    a--;
    b--;
    c[a].push_back(b);
    c[b].push_back(a);
  }
  rep(i, 0, n) {
    if (visited[i]) {
      continue;
    } else {
      solve(i);
    }
  }
  cout << ans << 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: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n);
  vector<ll> a(n);
  vector<ll> b(n);
  vector<ll> good(n, 1);
  vector<ll> counter(n, 0);
  for (ll i = 0; i < n; i++) {
    cin >> h[i];
  }
  for (ll i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    if (h[a[i] - 1] < h[b[i] - 1]) {
      good[a[i] - 1] = 0;
    } else if (h[a[i] - 1] == h[b[i] - 1]) {
      good[a[i] - 1] = 0;
      good[b[i] - 1] = 0;
    } else {
      good[b[i] - 1] = 0;
    }
    counter[a[i] - 1]++;
    counter[b[i] - 1]++;
  }

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    if (good[i] == 1)
      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)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<long long int> H(N);
  rep(i, N) cin >> H.at(i);
  vector<long long int> X(N, 1);
  rep(i, M) {
    ll A, B;
    cin >> A >> B;
    if (H.at(A - 1) < H.at(B - 1))
      X.at(A - 1) = 0;
    if (H.at(A - 1) == H.at(B - 1)) {
      X.at(A - 1) = 0;
      X.at(B - 1) = 0;
    }
    if (H.at(A - 1) > H.at(B - 1))
      X.at(B - 1) = 0;
  }
  long long int counter = 0;
  rep(i, N) {
    if (X.at(i) == 1)
      counter++;
  }
  cout << counter << 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>
#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() {
  long long int N, M;
  cin >> N >> M;
  vector<long long int> H(N);
  rep(i, N) cin >> H.at(i);
  vector<int> X(N, 1);
  rep(i, M) {
    long long int A, B;
    cin >> A >> B;
    if (H.at(A) < H.at(B))
      X.at(A) = 0;
    if (H.at(A) > H.at(B))
      X.at(B) = 0;
  }

  int counter = 0;
  rep(i, N) {
    if (X.at(i) == 1)
      counter++;
  }
  cout << counter << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
using namespace std;
int n, m, i, j, k, ans, l, hi[100005], w[100005] = {0};
struct ROAD {
  int a, b;
} d[100005];
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d", &hi[i]);
  }
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &d[i].a, &d[i].b);
    if (hi[d[i].a] > hi[d[i].b]) {
      w[d[i].a]++;
      w[d[i].b] = -1e9;
    } else if (hi[d[i].a] < hi[d[i].b]) {
      w[d[i].a] = -1e9;
      w[d[i].b]++;
    } else if (hi[d[i].a] == hi[d[i].b]) {
      w[d[i].a] = -1e9;
      w[d[i].b] = -1e9;
    }
  }
  for (i = 1; i <= n; i++) {
    if (w[i] >= 0)
      ans++;
  }
  printf("%d\\n", ans);
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
using namespace std;
int n, m, i, j, k, ans, l, hi[10005], w[10005] = {0};
struct ROAD {
  int a, b;
} d[10005];
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d", &hi[i]);
  }
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &d[i].a, &d[i].b);
    if (hi[d[i].a] > hi[d[i].b]) {
      w[d[i].a]++;
      w[d[i].b] = -1e9;
    } else if (hi[d[i].a] < hi[d[i].b]) {
      w[d[i].a] = -1e9;
      w[d[i].b]++;
    } else if (hi[d[i].a] == hi[d[i].b]) {
      w[d[i].a] = -1e9;
      w[d[i].b] = -1e9;
    }
  }
  for (i = 1; i <= n; i++) {
    if (w[i] >= 0)
      ans++;
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

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

  long long int H[N + 1];

  bool A[N + 1];

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

  long long int a, b;
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    if (H[a] < H[b]) {
      A[a] = false;
    } else if (H[a] > H[b]) {
      A[b] = false;
    } else {
      A[a] = false;
      A[b] = false;
    }
  }

  int cnt = 0;

  for (int i = 1; i <= N; i++) {
    if (A[i] == true)
      cnt++;
  }

  cout << cnt << endl;

  return 0;
}


Error: 0

Fixed submission:

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

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

  long long int H[N + 1];

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

  int a, b;
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    A[a][b]++;
    A[b][a]++;
  }

  int ans = 0;
  vector<int> vec{};
  bool flag = true;

  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      if (A[i][j] != 0)
        vec.push_back(j);
    }
    for (auto it = vec.begin(); it != vec.end(); ++it) {
      if (H[i] > H[*it])
        flag = false;
    }
    if (flag)
      ans++;

    flag = true;
  }

  cout << ans << endl;

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

#define MAX 200000
#include <iostream>
#include <vector>
using namespace std;

int N, M;
int h[MAX];

int main() {
  cin >> N >> M;
  vector<int> ini(N + 1, 1);
  for (int i = 1; i <= N; i++) {
    cin >> h[i];
  }
  // cout << ini.size();
  int a, b;
  for (int j = 1; j <= M; j++) {
    cin >> a >> b;
    if (h[a] > h[b]) {
      ini[b] = 0;
    } else if (h[a] < h[b]) {
      ini[a] = 0;
    } else {
      ini[a] = 0;
      ini[b] = 0;
    }
  }
  int sum = 0;
  for (int j = 1; j <= N; j++) {
    sum += ini[j];
  }
  cout << sum << endl;
  return 0;
}

Error: TLE

Fixed submission:

#define MAX 100000
#include <iostream>
#include <vector>
using namespace std;

int N, M;
int h[MAX];

int main() {
  cin >> N >> M;
  vector<int> ini(N + 1, 1);
  for (int i = 1; i <= N; i++) {
    cin >> h[i];
  }
  // cout << ini.size();
  int a, b;
  for (int j = 1; j <= M; j++) {
    cin >> a >> b;
    if (h[a] > h[b]) {
      ini[b] = 0;
    } else if (h[a] < h[b]) {
      ini[a] = 0;
    } else {
      ini[a] = 0;
      ini[b] = 0;
    }
  }
  int sum = 0;
  for (int j = 1; j <= N; j++) {
    sum += ini[j];
  }
  cout << sum << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main(void) {

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

  vector<int> high(n);

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

  int a, b;
  vector<bool> flags(n, true);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;

    a--;
    b--;
    if (high[a] > high[b])
      flags[b] = false;
    else if (high[a] < high[b])
      flags[a] = false;
    else {
      flags[a] = false;
      flags[b] = false;
    }
  }

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

  cout << ans << endl;

  return 0;
}


Error: MLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main(void) {

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

  vector<int> high(n);

  vector<vector<bool>> bridge(n, vector<bool>(n, false));

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

  int a, b;
  vector<bool> flags(n, true);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;

    a--;
    b--;
    if (high[a] > high[b])
      flags[b] = false;
    else if (high[a] < high[b])
      flags[a] = false;
    else {
      flags[a] = false;
      flags[b] = false;
    }
  }

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

  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, A, B;
  cin >> N >> M;
  int count = 0;
  vector<int> H(N); // 高さ

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

  vector<int> answer(N, 0);

  // vector<vector<int>> graph(N,vector<int>(N,0));//グラフ生成

  //   for(int i = 0;i < M;i++){
  //     cin >> A >> B;
  //     graph.at(A-1).at(B-1)++;
  //     graph.at(B-1).at(A-1)++;
  //   }
  //
  // for(int i = 0;i < N;i++){
  //   for(int j = 0;j < N;j++){
  //     if(i == j) continue;
  //     if(graph.at(i).at(j) != 0){
  //       if(H.at(i) <= H.at(j)){
  //         count--;
  //         break;
  //       }
  //     }
  //   }
  // }

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

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

  // for(int i = 0;i < N; i++){
  //   for(int j  = 0;j < N;j++){
  //     cout << graph.at(i).at(j) << " ";
  //   }
  //   cout << endl;
  // }
  cout << count << endl;
  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  int N, M, A, B;
  cin >> N >> M;
  int count = N;
  vector<int> H(N); // 高さ

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

  vector<vector<int>> graph(N, vector<int>(N, 0)); // グラフ生成

  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    graph.at(A - 1).at(B - 1)++;
    graph.at(B - 1).at(A - 1)++;
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j)
        continue;
      if (graph.at(i).at(j) != 0) {
        if (H.at(i) <= H.at(j)) {
          count--;
          break;
        }
      }
    }
  }
  // for(int i = 0;i < N; i++){
  //   for(int j  = 0;j < N;j++){
  //     cout << graph.at(i).at(j) << " ";
  //   }
  //   cout << endl;
  // }
  cout << count << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> h(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  vector<int> a(m), b(m);
  for (int i = 0; i < m; i++)
    cin >> a[i] >> b[i];
  vector<int> good(n, 1);
  for (int i = 0; i < m; i++) {
    if (h[a[i] - 1] < h[b[i] - 1])
      good[a[i] - 1] = 0;
    else if (h[a[i] - 1] > h[b[i] - 1])
      good[b[i] - 1] = 0;
    else {
      good[a[i] - 1] = 0;
      good[b[i] - 1] = 0;
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; i++)
    if (good[i] == 1)
      cnt++;
  cout << cnt << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> h(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  vector<int> a(m), b(m);
  for (int i = 0; i < m; i++)
    cin >> a[i] >> b[i];
  vector<int> good(n, 1);
  for (int i = 0; i < m; i++) {
    if (h[a[i]] < h[b[i]])
      good[a[i]] = 0;
    else if (h[a[i]] > h[a[i]])
      good[b[i]] = 0;
    else {
      good[a[i]] = 0;
      good[b[i]] = 0;
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; i++)
    if (good[i] == 1)
      cnt++;
  cout << cnt << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, n) for (int i = 1; i <= (n); ++i)
#define all(x) (x).begin(), (x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Sort2(x) sort((x).begin(), (x).end(), greater<int>())
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  using Graph = vector<vector<ll>>; // グラフ型
  Graph G(n);                       // グラフ
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
    //        g[a-1][b-1] = 1; g[b-1][a-1] = 1;
  }
  ll ans = 0;
  rep(i, n) {
    bool flg = true, flg2 = false;
    for (auto c : G[i]) {
      flg2 = true;
      if (h[c] >= h[i])
        flg = false;
    }
    //        cout << flg << flg2 << endl;
    if (flg || !flg2)
      ans++;
  }
  cout << ans << endl;
}

/*
Ctrl+@ でコンソールを開け、以下で実行。
g++ c.cpp
./a.out

サンプルのダウンロードは oj d URL
テストは oj t
コード変えたらコンパイルする
不正解ならWAが出る
*/

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, n) for (int i = 1; i <= (n); ++i)
#define all(x) (x).begin(), (x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Sort2(x) sort((x).begin(), (x).end(), greater<int>())
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  int g[n][n];
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    g[a - 1][b - 1] = 1;
    g[b - 1][a - 1] = 1;
  }
  int ans = 0;
  rep(i, n) {
    bool flg = true, flg2 = false;
    rep(j, n) {
      if (g[i][j] == 1) {
        flg2 = true;
        if (h[j] >= h[i])
          flg = false;
      }
    }
    //        cout << flg << flg2 << endl;
    if (flg || !flg2)
      ans++;
  }
  cout << ans << endl;
}

/*
Ctrl+@ でコンソールを開け、以下で実行。
g++ c.cpp
./a.out

サンプルのダウンロードは oj d URL
テストは oj t
コード変えたらコンパイルする
不正解ならWAが出る
*/
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

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

Error: -6
/usr/include/c++/12/debug/vector:442:
In function:
    std::debug::vector<_Tp, _Allocator>::reference std::debug::vector<_Tp, 
    _Allocator>::operator[](size_type) [with _Tp = long long int; _Allocator 
    = std::allocator<long long int>; reference = long long int&; size_type = 
    long unsigned int]

Error: attempt to subscript container with out-of-bounds index 4, but 
container only holds 4 elements.

Objects involved in the operation:
    sequence "this" @ 0x7ffce0041060 {
      type = std::debug::vector<long long, std::allocator<long long> >;
    }


Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

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

#include <iostream>
#include <map>
using namespace std;
using ll = long long;

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

  // つながっているか？
  multimap<int, int> connected;
  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    connected.insert(make_pair(a - 1, b - 1));
    connected.insert(make_pair(b - 1, a - 1));
  }

  int ans = 0;
  bool continuable = false;
  for (int i = 0; i < n; i++) {
    continuable = false;
    auto itr = connected.lower_bound(i);
    auto last = connected.upper_bound(i);
    while (itr != last) {
      if (h[i] <= h[itr->second]) {
        continuable = true;
        break;
      }
      ++itr;
    }
    if (continuable)
      continue;
    ans++;
  }
  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
using ll = long long;

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

  // つながっているか？
  bool connected[n][n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      connected[i][j] = false;
    }
  }

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

  int ans = 0;
  bool continuable = false;
  for (int i = 0; i < n; i++) {
    continuable = false;
    for (int j = 0; j < n; j++) {
      if (!connected[i][j])
        continue;
      if (h[i] <= h[j]) {
        continuable = true;
        break;
      }
    }
    if (continuable)
      continue;
    ans++;
  }
  cout << ans;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

/* 166-C.cpp
 *     Created on : May 3, 2020
 *     Time       : 7:47:31 PM
 *     Author     : null_ptr
 */
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<long long int> height(n), ans(n, 1);
  for (int i = 0; i < n; ++i)
    cin >> height[i];

  int u, v;

  for (int i = 0; i < m; ++i) {
    cin >> u >> v;
    --u, --v;
    if (height[u] >= height[v])
      ans[v] = 0;

    if (height[v] >= height[u])
      ans[u] = 0;
  }
  int cnt = 0;
  for (int i = 0; i < n; ++i)
    if (ans[i])
      cnt++;

  cout << cnt;
}


Error: WA

Fixed submission:

/* 166-C.cpp
 *     Created on : May 3, 2020
 *     Time       : 6:23:31 PM
 *     Author     : null_ptr
 */
#include <iostream>
#include <vector>

using namespace std;

const int inf = 1e9;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> height(n), ans(n);

  vector<vector<int>> roads(n, vector<int>(n));

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

  int u, v;
  for (int i = 0; i < m; ++i) {
    cin >> u >> v;
    if (height[u - 1] >= height[v - 1])
      ans[u - 1] = 1, ans[v - 1] = 0;
    else
      ans[v - 1] = 1, ans[u - 1] = 0;
  }
  int cnt = 0;
  for (int i = 0; i < n; ++i)
    cnt += ans[i];

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

#include <bits/stdc++.h>

using namespace std;

const int n = 100005;

int main() {
  int N, M;
  int H[n];

  cin >> N >> M;
  vector<int> ma(N, 0);

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

  int count = 0;
  for (int i = 0; i < N; i++) {
    if (ma[i] < H[i])
      ++count;
  }

  cout << count << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int n = 100005;

int main() {
  int N, M;
  int H[n];
  vector<int> ma(N + 1, 0);

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

  int count = 0;
  for (int i = 0; i < N; i++) {
    if (ma[i] < H[i])
      ++count;
  }

  cout << count << endl;
  return 0;
}