alexjercan/bugnet huggingface dataset:
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> height(N);
  for (int i = 0; i < N; i++) {
    cin >> height.at(i);
  }
  vector<pair<int, int>> way(M);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    way.at(i) = make_pair(a, b);
  }
  vector<bool> good(N, true);
  for (int i = 0; i < M; i++) {
    if (height.at(way.at(i).first - 1) == height.at(way.at(i).second - 1)) {
      good.at(way.at(i).first - 1) = false;
      good.at(way.at(i).second - 1) = false;
    } else if (height.at(way.at(i).first - 1) <
               height.at(way.at(i).second - 1)) {
      good.at(way.at(i).first - 1) = false;
    } else {
      good.at(way.at(i).second - 1) = false;
    }
  }
  int total = 0;
  for (int i = 0; i < N; i++) {
    if (good.at(i)) {
      total += 1;
    }
  }
  cout << total << endl;
}

Error: TLE

Fixed submission:

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

bool good(int i, int H, int M, vector<int> &height,
          vector<pair<int, int>> &way) {
  bool check = true;
  for (int j = 0; j < M; j++) {
    if (way.at(j).first == i || way.at(j).second == i) {
      check = false;
    }
  }
  if (check) {
    return true;
  } else {
    bool ans = true;
    for (int j = 0; j < M; j++) {
      if (way.at(j).first == i && H <= height.at(way.at(j).second - 1)) {
        ans = false;
      } else if (way.at(j).second == i && H <= height.at(way.at(j).first - 1)) {
        ans = false;
      }
    }
    return ans;
  }
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> height(N);
  for (int i = 0; i < N; i++) {
    cin >> height.at(i);
  }
  vector<pair<int, int>> way(M);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    way.at(i) = make_pair(a, b);
  }
  int total = 0;
  for (int i = 0; i < N; i++) {
    if (good(i + 1, height.at(i), M, height, way)) {
      total += 1;
    }
  }
  cout << total << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, n, m, y = 0;
  long long int h[100002];
  long long int x[100002];
  cin >> n >> m;
  for (int i = 1; i <= 100000; i++) {
    h[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  for (int i = 1; i <= 100001; i++) {
    x[i] = 0;
  }
  for (int i = 1; i <= m; i++) {
    cin >> a;
    cin >> b;
    if (h[a] <= h[b]) {
      x[a] = 1;
    }
    if (h[b] <= h[a]) {
      x[b] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (x[i] == 0) {
      y++;
    }
  }
  cout << y << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, n, m, y = 0;
  long long int h[10002];
  long long int x[10002];
  cin >> n >> m;
  for (int i = 1; i <= 10000; i++) {
    h[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  for (int i = 1; i <= 10001; i++) {
    x[i] = 0;
  }
  for (int i = 1; i <= m; i++) {
    cin >> a;
    cin >> b;
    if (h[a] <= h[b]) {
      x[a] = 1;
    }
    if (h[b] <= h[a]) {
      x[b] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (x[i] == 0) {
      y++;
    }
  }
  cout << y << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/

#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 <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<int> c(m);
  rep(i, n) {
    cin >> h[i];
    c[i] = 0;
  }
  int a[m], b[m];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    c[a[i] - 1] = max(c[a[i] - 1], h[b[i] - 1]);
    c[b[i] - 1] = max(c[b[i] - 1], h[a[i] - 1]);
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (h[i] > c[i])
      count++;
  }
  cout << count << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

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

bool solve(int N, int M, int *H, int *A, int *B, int n) {

  for (int m = 0; m < M; m++) {
    if (A[m] == n + 1) {
      int bm = B[m] - 1;
      if (H[bm] >= H[n]) {
        return false;
      }
    }
    if (B[m] == n + 1) {
      int am = A[m] - 1;
      if (H[am] >= H[n]) {
        return false;
      }
    }
  }
  return true;
}

int main() {
  int N, M;
  cin >> N >> M;
  // vector<int> H(N), A(M), B(M);
  int *H, *A, *B;
  H = new int[N];
  A = new int[M];
  B = new int[M];
  for (int n = 0; n < N; n++) {
    cin >> H[n];
  }
  bool *is_high;
  is_high = new bool[N];
  for (int n = 0; n < N; n++) {
    is_high[n] = true;
  }
  for (int m = 0; m < M; m++) {
    cin >> A[m] >> B[m];
    if (H[A[m] - 1] < H[B[m] - 1]) {
      is_high[A[m] - 1] = false;
    } else if (H[A[m] - 1] > H[B[m] - 1]) {
      is_high[B[m] - 1] = false;
    } else if (H[A[m] - 1] == H[B[m] - 1]) {
      is_high[A[m] - 1] = false;
      is_high[B[m] - 1] = false;
    }
  }

  int cnt = 0;
  for (int n = 0; n < N; n++) {
    if (is_high[n] == true) {
      cnt++;
    }
  }
  cout << cnt;
  return 0;
}

Error: TLE

Fixed submission:

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

bool solve(int N, int M, int *H, int *A, int *B, int n) {

  for (int m = 0; m < M; m++) {
    if (A[m] == n + 1) {
      int bm = B[m] - 1;
      if (H[bm] >= H[n]) {
        return false;
      }
    }
    if (B[m] == n + 1) {
      int am = A[m] - 1;
      if (H[am] >= H[n]) {
        return false;
      }
    }
  }
  return true;
}

int main() {
  int N, M;
  cin >> N >> M;
  // vector<int> H(N), A(M), B(M);
  int *H, *A, *B;
  H = new int[N];
  A = new int[M];
  B = new int[M];
  for (int n = 0; n < N; n++) {
    cin >> H[n];
  }

  for (int m = 0; m < M; m++) {
    cin >> A[m] >> B[m];
  }

  int cnt = 0;
  for (int n = 0; n < N; n++) {
    bool is_high = true;
    for (int m = 0; m < M; m++) {
      if (A[m] == n + 1) {
        int bm = B[m] - 1;
        if (H[bm] >= H[n]) {
          is_high = false;
          break;
        }
      }
      if (B[m] == n + 1) {
        int am = A[m] - 1;
        if (H[am] >= H[n]) {
          is_high = false;
          break;
        }
      }
    }
    if (is_high == true) {
      cnt++;
    }
  }
  cout << cnt;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, M, H, A, B;
  cin >> N >> M;
  vector<vector<int>> data(N + 1);
  int cnt = 0;
  for (int i = 1; i <= N; i++) {
    cin >> H;
    data.at(i).push_back(H);
  }
  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    data.at(A).push_back(data.at(B).at(0));
    data.at(B).push_back(data.at(A).at(0));
  }
  for (int i = 1; i < data.size(); i++) {
    if (data.at(i).size() == 1) {
      cnt++;
      continue;
    }
    bool judge = true;
    for (int j = 1; j < data.at(i).size(); j++) {
      if (data.at(i).at(0) <= data.at(i).at(j)) {
        judge = false;
        break;
      }
    }
    if (judge)
      cnt++;
  }
  cout << cnt << endl;
}

Error: WA

Fixed submission:

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

int main() {
  int N, M, H, A, B;
  cin >> N >> M;
  vector<vector<int>> data(N, vector<int>(M));
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    cin >> H;
    data.at(i).at(0) = H;
  }
  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    data.at(B - 1).push_back(data.at(A - 1).at(0));
    data.at(A - 1).push_back(data.at(B - 1).at(0));
  }
  for (int i = 0; i < M; i++) {
    if (data.at(i).size() == 0) {
      cnt++;
      continue;
    }
    bool judge = true;
    for (int j = 1; j < data.at(i).size(); j++) {
      if (data.at(i).at(0) <= data.at(i).at(j)) {
        judge = false;
        break;
      }
    }
    if (judge)
      cnt++;
  }
  cout << cnt << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
int h[100010];
bool flag[100010];
vector<int> vec[100010];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> h[i + 1];
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    vec[a].push_back(b);
    vec[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    if (flag[i])
      continue;
    for (int j = 0; j < vec[i].size(); j++) {
      if (h[i] > h[vec[i][j]]) {
        flag[vec[i][j]] = true;
      } else {
        flag[i] = true;
        break;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!flag[i])
      ans++;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
int h[100010];
bool flag[100010];
vector<int> vec[100000];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> h[i + 1];
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    vec[a].push_back(b);
    vec[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    if (flag[i])
      continue;
    for (int j = 0; j < vec[i].size(); j++) {
      if (h[i] > h[vec[i][j]]) {
        flag[vec[i][j]] = true;
      } else {
        flag[i] = true;
        break;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!flag[i])
      ans++;
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ii pair<int, int>
#define is pair<int, string>
#define ll long long
#define pf printf
using namespace std;
vector<int> v, vv;

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

  while (n--) {
    int a;
    cin >> a;
    v.push_back(a);
    vv.push_back(0);
  }
  int len = v.size();
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;

    vv[a - 1] = max(vv[a - 1], v[b - 1]);
    vv[b - 1] = max(vv[b - 1], v[a - 1]);
  }

  int cnt = 0;
  for (int i = 0; i < len; i++) {
    if (v[i] > vv[i])
      cnt++;
  }
  cout << cnt << endl;

  return 0;
}


Error: WA

Fixed submission:

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

int main() {
  int n, m;
  vector<int> v[100000], vv;
  scanf("%d %d", &n, &m);
  ll arr[n];

  ll Max = 0;
  for (int i = 0; i < n; i++)
    scanf("%lld", &arr[i]);
  while (m--) {
    ll a, b;
    scanf("%lld %lld", &a, &b);
    if (Max < a)
      Max = a;
    v[a].push_back(b);
  }

  for (int i = 0; i < Max; i++) {
    int len = v[i].size();
    int cnt = 0;
    sort(v[i].begin(), v[i].end());
    for (int j = 1; j < len; j++)
      if (v[i][j] == v[i][j - 1])
        cnt++;

    ll ans = len - cnt;
    vv.push_back(ans);
  }

  int len = vv.size();
  sort(vv.begin(), vv.end());
  cout << vv[len - 1] << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ll n, m, h[100000], a, b, good = 0, tenbo[100000] = {0};
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> h[i];

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

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

  cout << good << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  ll n, m, h[10000], a, b, good = 0, tenbo[10000] = {0};
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> h[i];

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

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

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

/**
 *    author:  Dooloper
 *    created: 03.05.2020 21:47:14
 **/

#include <bits/stdc++.h>

using namespace std;

int cnt[101010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, m, ans = 0;
  cin >> n >> m;
  vector<long long> h(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  for (int i = 0; i < n; i++)
    cnt[i] = 1;

  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;

    if (h[a] >= h[b] && cnt[b] != 0) {
      cnt[b] = 0;
    }
    if (h[a] <= h[b] && cnt[a] != 0) {
      cnt[a] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (cnt[i] == 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

/**
 *    author:  Dooloper
 *    created: 03.05.2020 21:47:14
 **/

#include <bits/stdc++.h>

using namespace std;

int cnt[105];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, m, ans = 0;
  cin >> n >> m;
  vector<long long> h(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  for (int i = 0; i < n; i++)
    cnt[i] = 1;

  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;

    if (h[a] >= h[b] && cnt[b] != 0) {
      cnt[b] = 0;
    }
    if (h[a] <= h[b] && cnt[a] != 0) {
      cnt[a] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (cnt[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;
typedef pair<int, int> P;

int main(void) {
  int N, M;
  cin >> N >> M;
  const int INF = 1e9;
  ll height[N + 10];
  vector<ll> matrix(N + 10, -1);
  for (int i = 1; i <= N; i++)
    cin >> height[i];
  for (int i = 1; i <= M; i++) {
    int a, b;
    cin >> a >> b;
    int c; // 低いほうの番号
    if (height[a] >= height[b]) {
      c = b;
      matrix[c] = INF;
    }
    if (height[a] <= height[b]) {
      c = a;
      matrix[c] = INF;
    }
  }
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (matrix[i] == -1)
      ans++;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int main(void) {
  int N, M;
  cin >> N >> M;
  ll height[N + 10];
  vector<vector<ll>> matrix(N + 10, vector<ll>(N + 10, -1));
  for (int i = 1; i <= N; i++)
    cin >> height[i];
  for (int i = 1; i <= M; i++) {
    int a, b;
    cin >> a >> b;
    int c;
    if (height[a] > height[b])
      c = a;
    else if (height[a] < height[b])
      c = b;
    else
      c = N + 5;
    matrix[a][b] = c;
    matrix[b][a] = c;
  }
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    int cnt = 0;
    for (int j = 1; j <= N; j++) {
      if (matrix[i][j] != -1 && matrix[i][j] != i)
        continue;
      // cout << "i:" << i  << " j:" << j  << " matrix:"<< matrix[i][j] << endl;
      cnt++;
    }
    if (cnt == N)
      ans++;
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, M;
  cin >> N >> M;
  int H[N];
  vector<bool> C(N, true);
  for (int i = 0; i < N; i++)
    cin >> H[i];
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    if (H[a] <= H[b])
      C[a] = false;
    if (H[b] <= H[a])
      C[b] = false;
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (C[i] == true)
      count++;
  }
  cout << count << endl;
}

Error: -11

Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;
  int H[N];
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  int A[M], B[M];
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
  }
  int sum = 0, count = 0;
  for (int i = 0; i < N; i++) {
    bool found = false;
    sum = H[i];
    for (int j = 0; j < M; j++) {
      if (A[j] == i + 1 || B[j] == i + 1) {
        found = true;
        if (H[B[j - 1]] < sum || H[A[j - 1]] < sum)
          count++;
      }
    }
    if (!found)
      count++;
  }
  cout << count << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  bool r[100000];
  int h[100000], a[100000], b[100000], n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    r[i] = true;
  }
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }

  for (int i = 0; i < m; i++) {
    auto dif = h[a[i] - 1] - h[b[i] - 1];
    if (dif > 0) {
      r[b[i] - 1] = false;
    } else if (dif < 0) {
      r[a[i] - 1] = false;
    } else {
      r[a[i] - 1] = false;
      r[b[i] - 1] = false;
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (r[i]) {
      cnt++;
    }
  }

  cout << cnt << endl;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  bool r[100000];
  int h[100000], a[100000], b[100000], n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    r[i] = true;
  }
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }

  for (int i = 0; i < n; i++) {
    auto dif = h[a[i] - 1] - h[b[i] - 1];
    if (dif > 0) {
      r[b[i] - 1] = false;
    } else if (dif < 0) {
      r[a[i] - 1] = false;
    } else {
      r[a[i] - 1] = false;
      r[b[i] - 1] = false;
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (r[i]) {
      cnt++;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, cnt = 0;
  cin >> n >> m;
  vector<int> h(n + 1), ma(n + 1, 0);
  for (i = 1; i <= n; ++i)
    cin >> h[i];
  for (i = 0; i < m; ++i) {
    int t1, t2;
    cin >> t1 >> t2;
    ma[t1] = max(ma[t1], h[t2]);
    ma[t2] = max(ma[t2], h[t1]);
  }
  for (i = 1; i <= n; ++i)
    cnt += h[i] > ma[i];
  cout << cnt << "\\n";
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, cnt = 0;
  cin >> n >> m;
  vector<int> h(n + 1);
  vector<vector<int>> adj(n + 1, vector<int>(n + 1, 0));
  for (i = 1; i <= n; ++i)
    cin >> h[i];
  for (i = 0; i < m; ++i) {
    int t1, t2;
    cin >> t1 >> t2;
    adj[t1][t2]++;
    adj[t2][t1]++;
  }
  for (i = 1; i <= n; ++i) {
    int gdflg = 1;
    for (j = 1; j <= n; ++j)
      if (adj[i][j] > 0 && !(adj[i][j] == 1 && h[i] > h[j]))
        gdflg = 0;
    // cout << i << " " << j << "\\n" ;
    if (gdflg == 1)
      cnt++;
  }
  cout << cnt << "\\n";
  return 0;
}
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 <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map> //map<int, int> x;
#include <numeric>
#include <string>
#include <vector>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define reps(i, x) for (int i = 1; i <= (int)(x); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = ((int)(x)); i > 0; i--)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

using ll = long long; // ll aaaaa;
using namespace std;
int main() {

  int n, m, a, b, ans = 0;
  cin >> n >> m;
  vector<int> h(n);
  vector<int> plan(m);
  rep(i, n) cin >> h[i];
  rep(i, m) {
    cin >> a >> b;
    plan[a - 1] = max(plan[a - 1], h[b - 1]);
    plan[b - 1] = max(plan[b - 1], h[a - 1]);
  }
  rep(i, n) ans += h[i] > plan[i];
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

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

  vector<int> h(n);
  for (auto &x : h)
    cin >> x;

  vector<int> graph[n];

  for (ll i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;

    graph[a - 1].push_back(b - 1);
    graph[b - 1].push_back(a - 1);
  }

  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    int f = 0;
    for (ll j = 0; j < graph[i].size(); j++) {
      if (h[i] <= h[graph[i][j]]) {
        f = 1;
        break;
      }
      // cout << graph[i][j] << " ";
    }

    if (!f) {
      ans++;
      // cout << i+1;
    }
    // cout << endl;
  }

  cout << ans;
}


Error: WA

Fixed submission:

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

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

  vector<int> h(n);
  for (auto &x : h)
    cin >> x;

  int graph[n][n];
  for (ll i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      graph[i][j] = 0;

  for (ll i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;

    graph[a - 1][b - 1] = 1;
    graph[b - 1][a - 1] = 1;
  }

  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    int f = 0;
    for (ll j = 0; j < n; j++) {
      if (graph[i][j] && h[i] <= h[j])
        f = 1;

      // cout << graph[i][j] << " ";
    }

    if (!f) {
      ans++;
      // cout << i+1;
    }
    // cout << endl;
  }

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

#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  // Your code here!
  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.at(i);
  vector<int> res(N, 1);
  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)) {
      res.at(B.at(i) - 1) = 0;
    } else if (H.at(B.at(i) - 1) > H.at(A.at(i) - 1)) {
      res.at(A.at(i) - 1) = 0;
    } else {
      res.at(A.at(i) - 1) = 0;
      res.at(B.at(i) - 1) = 0;
    }
  }

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

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  // Your code here!
  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.at(i);
  vector<vector<int>> G(N, vector<int>(N));
  for (int i = 0; i < M; i++) {
    cin >> A.at(i) >> B.at(i);
    G.at(A.at(i) - 1).at(B.at(i) - 1) = 1;
    G.at(B.at(i) - 1).at(A.at(i) - 1) = 1;
  }

  int cnt = 0;
  int flag;
  for (int i = 0; i < N; i++) {
    flag = 0;
    for (int j = 0; j < M; j++) {
      if (G.at(i).at(j) == 1) {
        if (H.at(i) <= H.at(j)) {
          flag = 1;
        }
      }
    }
    if (flag == 0)
      cnt++;
  }
  cout << cnt << endl;
}