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

#include <algorithm>
#include <cstring>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define MAX_N 100000
#define MAX_M 100000
using namespace std;

typedef long long ll;
ll H[MAX_N];
vector<ll> v[MAX_N];
ll M, N;
ll good;

void solve() {

  good = 0;
  for (ll i = 0; i < N; i++) {
    ll height = 0;
    for (ll j = 0; j < v[i].size(); j++) {
      height = max(H[v[i][j]], height);
    }
    if (height < H[i] || v[i].size() == 0) {
      good++;
    }
  }
  cout << good << endl;
}

int main() {
  ll a, b;
  cin >> N >> M;
  for (ll i = 0; i < N; i++) {
    cin >> H[i];
  }
  for (ll i = 0; i < M; i++) {
    cin >> a >> b;
    v[a - 1].push_back(b - 1);
    v[b - 1].push_back(a - 1);
  }
  solve();

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define MAX_N 100000
#define MAX_M 100000
#define INF 1000000001
using namespace std;

typedef long long ll;
ll H[MAX_N];
vector<ll> v[MAX_N];
ll M, N;
ll good;

void solve() {
  ll height = 0;
  good = 0;
  for (ll i = 0; i < N + 1; i++) {
    for (ll j = 0; j < v[i].size(); j++) {
      height = max(H[v[i][j] - 1], height);
    }
    if (height < H[i] || v[i].size() == 0) {
      good++;
    }
  }
  cout << good << endl;
}

int main() {
  ll a, b;
  cin >> N >> M;
  for (ll i = 0; i < N + 1; i++) {
    cin >> H[i];
  }
  for (ll i = 0; i < M; i++) {
    cin >> a >> b;
    v[a - 1].push_back(b);
    v[b - 1].push_back(a);
  }
  solve();

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

// ABC166 C

#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
const lint mod = 1000000007;

lint ans = 0;
lint n, m;
lint h[200001];
lint a[200001], b[200001];
lint score[200001];
lint res = 0;

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

  rep(i, n) { scanf("%lld", &h[i + 1]); }
  rep(i, m) { scanf("%lld %lld", &a[i], &b[i]); }

  rep(i, m) {
    score[a[i]] = max(score[a[i]], h[b[i]]);
    score[b[i]] = max(score[b[i]], h[a[i]]);
  }
  reps(i, 1, n + 1) {
    if (score[i] < h[i])
      ans++;
  }

  printf("%lld\\n", ans);
}


Error: 0

Fixed submission:

// ABC166 C

#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
const lint mod = 1000000007;

lint ans = 0;
lint n, m;
lint h[200001];
lint a[200001], b[200001];
lint score[21];
lint res = 0;

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

  rep(i, n) { scanf("%lld", &h[i + 1]); }
  rep(i, m) { scanf("%lld %lld", &a[i], &b[i]); }

  rep(i, m) {
    score[a[i]] = max(score[a[i]], h[b[i]]);
    score[b[i]] = max(score[b[i]], h[a[i]]);
  }
  reps(i, 1, n + 1) {
    if (score[i] < h[i])
      ans++;
  }

  printf("%lld\\n", ans);
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int gcd(int p, int q) {
  if (p % q == 0) {
    return q;
  }
  return gcd(q, p % q);
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  rep(i, n) { cin >> h[i]; }

  vector<bool> G(n, true);

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

  int cnt = 0;
  rep(i, n) {
    if (G[i]) {
      cnt++;
    }
  }

  cout << cnt << endl;
}


Error: 0

Fixed submission:

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

int gcd(int p, int q) {
  if (p % q == 0) {
    return q;
  }
  return gcd(q, p % q);
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  rep(i, n) { cin >> h[i]; }

  vector<bool> G(true, n);

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

  int cnt = 0;
  rep(i, n) {
    if (G[i]) {
      cnt++;
    }
  }

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

#include <bits/stdc++.h>
int main() {
  int N, M;
  std::cin >> N >> M;
  std::vector<int> H(N);
  for (auto &e : H)
    std::cin >> e;
  std::vector<std::vector<int>> edge(N);
  for (int i = 0; i < M; ++i) {
    int s, t;
    std::cin >> s >> t;
    --s;
    --t;
    edge[s].emplace_back(t);
    edge[t].emplace_back(s);
  }
  int ans = 0;
  int cv = 0;
  std::for_each(edge.begin(), edge.end(), [&](auto &v) {
    int maxi = -1;
    std::for_each(v.begin(), v.end(),
                  [&](int id) { maxi = std::max(maxi, H[id]); });
    if (maxi == -1 or H[cv] > maxi) {
      ++ans;
    }
    ++cv;
  });
  std::cout << ans << std::endl;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
int main() {
  int N, M;
  std::cin >> N >> M;
  std::vector<int> H(N);
  for (auto &e : H)
    std::cin >> e;
  std::vector<std::vector<int>> edge(N);
  for (int i = 0; i < M; ++i) {
    int s, t;
    std::cin >> s >> t;
    --s;
    --t;
    edge[s].emplace_back(t);
    edge[t].emplace_back(s);
  }
  int ans = 0;
  int cv = 0;
  for (auto &v : edge) {
    auto itr = std::max_element(v.begin(), v.end());
    if (itr == v.end() and *itr < H[cv])
      ++ans;
    ++cv;
  }
  std::cout << ans << std::endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 1; i <= (int)n; i++)
#define ll long long
#define BIT_FLAG_0 (1 << 0) // 0000 0000 0000 0001
#define BIT_FLAG_1 (1 << 1) // 0000 0000 0000 0010
#define BIT_FLAG_2 (1 << 2) // 0000 0000 0000 0100
#define BIT_FLAG_3 (1 << 3) // 0000 0000 0000 1000
#define BIT_FLAG_4 (1 << 4) // 0000 0000 0001 0000
#define BIT_FLAG_5 (1 << 5) // 0000 0000 0010 0000
#define BIT_FLAG_6 (1 << 6) // 0000 0000 0100 0000
#define BIT_FLAG_7 (1 << 7) // 0000 0000 1000 0000

int main() {
  int n, m;
  int h[100001], aa[100001];
  cin >> n >> m;

  rep(i, n) {
    cin >> h[i];
    aa[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    aa[a] = max(aa[a], h[b]);
    aa[b] = max(aa[b], h[a]);
  }
  int ans = 0;
  rep(i, n) ans += h[i] > aa[i];
  cout << ans << endl;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
#define ll long long
#define BIT_FLAG_0 (1 << 0) // 0000 0000 0000 0001
#define BIT_FLAG_1 (1 << 1) // 0000 0000 0000 0010
#define BIT_FLAG_2 (1 << 2) // 0000 0000 0000 0100
#define BIT_FLAG_3 (1 << 3) // 0000 0000 0000 1000
#define BIT_FLAG_4 (1 << 4) // 0000 0000 0001 0000
#define BIT_FLAG_5 (1 << 5) // 0000 0000 0010 0000
#define BIT_FLAG_6 (1 << 6) // 0000 0000 0100 0000
#define BIT_FLAG_7 (1 << 7) // 0000 0000 1000 0000

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

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

int N, M;
int a, b;
vector<int> H;
vector<int> A;
// vector <int> B;

void input() {
  cin >> N >> M;
  H.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  A.resize(N);
  //  B.resize(N);
  for (int i = 0; i < N; i++) {
    A[i] = 0;
    //    B[i]=0;
  }

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

void solve() {
  int d = 0;
  for (int i = 0; i < N; i++) {
    //    if((H[i]>A[i])&&H[i]>B[i]){
    if (H[i] > A[i]) {
      d += 1;
    }
  }
  cout << d << endl;
}

int main() {
  input();
  solve();
  return 0;
}


Error: TLE

Fixed submission:

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

int N, M;
vector<int> H;
vector<vector<int>> B;

void input() {
  cin >> N >> M;
  H.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  B.resize(M, vector<int>(2));
  for (int i = 0; i < M; i++) {
    cin >> B[i][0] >> B[i][1];
  }
}

void solve() {
  int d = N;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if ((B[j][0] == i + 1 && H[i] <= H[B[j][1] - 1]) ||
          (B[j][1] == i + 1 && H[i] <= H[B[j][0] - 1])) {
        d -= 1;
        break;
      }
    }
  }
  cout << d << endl;
}

int main() {
  input();
  solve();
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>

#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

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

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

  vector<int> max_num(N, 0);
  for (int i = 0; i < M; ++i) {
    int A, B;
    cin >> A >> B;
    max_num[A - 1] = max(max_num[A - 1], H[B - 1]);
    max_num[B - 1] = max(max_num[B - 1], H[A - 1]);
  }

  int result = 0;
  for (int i = 0; i < N; ++i) {
    if (H[i] > max_num[i] || max_num[i] == 0)
      ++result;
  }

  cout << result;
}

Error: -6
double free or corruption (out)


Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>

#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

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

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

  vector<int> max_num(N, 0);
  for (int i = 0; i < N; ++i) {
    int A, B;
    cin >> A, B;
    max_num[A - 1] = max(max_num[A - 1], B);
    max_num[B - 1] = max(max_num[B - 1], A);
  }

  int result = 0;
  for (int i = 0; i < N; ++i) {
    if (i + 1 > max_num[i] || max_num[i] == 0)
      ++result;
  }

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

#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
  int n, m, ans = 0;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> good(n, true);
  rep(i, n) { cin >> h.at(i); }
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (h.at(a) <= h.at(b))
      good.at(a) = false;
    if (h.at(b) <= h.at(a))
      good.at(b) = false;
  }
  for (auto a : good)
    if (a)
      ans++;

  cout << ans << endl;

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
  int n, m, ans;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> good(n, false);
  rep(i, n) { cin >> h.at(i); }
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (h.at(a) <= h.at(b))
      good.at(a) = false;
    if (h.at(b) <= h.at(a))
      good.at(b) = false;
  }
  for (auto a : good)
    if (a)
      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;

const int M = (int)1e5;
const int N = (int)1e4;
const int inf = 0x3f3f3f3f;
const ll mod = (ll)1e9 + 7;

int n, m, cnt;
int head[M + 5];
struct node {
  int v, nx;
} Edge[M * 2 + 5];

int h[M + 5];
int can[M + 5];

void init() {
  cnt = 0;
  for (int i = 1; i <= n; ++i) {
    head[i] = -1;
    can[i] = -1;
  }
}

void add(int u, int v) {
  Edge[cnt].v = v;
  Edge[cnt].nx = head[u];
  head[u] = cnt++;
}

void work(int u) {
  for (int i = head[u]; ~i; i = Edge[i].nx) {
    int v = Edge[i].v;
    if (h[u] <= h[v]) {
      can[u] = 0;
      return;
    }
  }
  can[u] = 1;
  for (int i = head[u]; ~i; i = Edge[i].nx) {
    int v = Edge[i].v;
    can[v] = 0;
  }
}

int main() {
  //    freopen("input.txt", "r", stdin);
  //    freopen("output.txt", "w", stdout);
  scanf("%d %d", &n, &m);
  init();
  for (int i = 1; i <= n; ++i)
    scanf("%d", &h[i]);
  for (int i = 1, u, v; i <= m; ++i)
    scanf("%d %d", &u, &v), add(u, v), add(v, u);
  for (int i = 1; i <= n; ++i)
    if (!~can[i])
      work(i);
  int res = 0;
  for (int i = 1; i <= n; ++i)
    res += can[i];
  printf("%d\\n", res);
  return 0;
}


Error: 0

Fixed submission:

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

typedef long long ll;

const int M = (int)1e4;
const int N = (int)1e4;
const int inf = 0x3f3f3f3f;
const ll mod = (ll)1e9 + 7;

int n, m, cnt;
int head[M + 5];
struct node {
  int v, nx;
} Edge[M * 2 + 5];

int h[M + 5];
int can[M + 5];

void init() {
  cnt = 0;
  for (int i = 1; i <= n; ++i) {
    head[i] = -1;
    can[i] = -1;
  }
}

void add(int u, int v) {
  Edge[cnt].v = v;
  Edge[cnt].nx = head[u];
  head[u] = cnt++;
}

void work(int u) {
  for (int i = head[u]; ~i; i = Edge[i].nx) {
    int v = Edge[i].v;
    if (h[u] <= h[v]) {
      can[u] = 0;
      return;
    }
  }
  can[u] = 1;
  for (int i = head[u]; ~i; i = Edge[i].nx) {
    int v = Edge[i].v;
    can[v] = 0;
  }
}

int main() {
  //    freopen("input.txt", "r", stdin);
  //    freopen("output.txt", "w", stdout);
  scanf("%d %d", &n, &m);
  init();
  for (int i = 1; i <= n; ++i)
    scanf("%d", &h[i]);
  for (int i = 1, u, v; i <= n - 1; ++i)
    scanf("%d %d", &u, &v), add(u, v), add(v, u);
  for (int i = 1; i <= n; ++i)
    if (!~can[i])
      work(i);
  int res = 0;
  for (int i = 1; i <= n; ++i)
    res += can[i];
  printf("%d\\n", res);
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define N 100010
#define fi(n) for (long long i = 0; i < n; i++)
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int ma[N];
  int h[N];
  ll n, m;
  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 << '\\n';
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define fi(n) for (long long i = 0; i < n; i++)
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n);
  vector<pair<ll, ll>> v;
  ll a, b;
  fi(n) { cin >> h[i]; }
  fi(m) {
    cin >> a >> b;
    v.push_back({a, b});
  }
  ll count = 0;
  for (ll i = 1; i <= n; i++) {
    bool flag = true;
    for (ll j = 0; j < m; j++) {
      if (v[j].first == i) {
        if (h[v[j].second - 1] >= h[i - 1]) {
          flag = false;
          break;
        }
      } else if (v[j].second == i) {
        if (h[v[j].first - 1] >= h[i - 1]) {
          flag = false;
          break;
        }
      }
    }
    if (flag)
      count++;
  }
  cout << count;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
constexpr int N = 100005;
bool hikui[N];
int main() {
  using namespace std;
  int n, m;
  cin >> n >> m;
  int h[N];
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (h[a] < h[b])
      hikui[a] = true;
    if (h[a] == h[b])
      hikui[a] = hikui[b] = true;
    if (h[a] > h[b])
      hikui[b] = true;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (!hikui[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  // std::fill(roadIsBelongsTo, roadIsBelongsTo+100004, -1);
  using namespace std;
  int n, m;
  cin >> n >> m;
  std::vector<int> h(n + 1);
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  bool michi[n + 1][n + 1];
  bool hikui[n + 1];
  fill(michi[0], michi[n + 1], false);
  fill(hikui, hikui + n + 1, false);
  // int ans = n;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (!michi[a][b]) {
      michi[a][b] = michi[b][a] = true;
      if (h.at(a) < h.at(b))
        hikui[a] = true;

      else if (h.at(a) == h.at(b)) {
        hikui[a] = true;
        hikui[b] = true;
      }

      else
        hikui[b] = true;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (!hikui[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define PI 3.14159265358979323846264338327950L

ll res = 0;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  ll N, M;
  cin >> N >> M;
  vector<ll> H(N + 50);
  vector<ll> ma(N + 50);
  for (int i = 1; i <= N; i++) {
    cin >> H[i];
    ma[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    ll a, b;
    cin >> a >> b;
    ma[a] = max(ma[a], H[b]);
    ma[b] = max(ma[b], H[a]);
  }
  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += H[i] > ma[i];
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define PI 3.14159265358979323846264338327950L

ll res = 0;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  ll N, M;
  cin >> N >> M;
  vector<ll> H(N);
  vector<ll> ma(N);
  for (int i = 1; i <= N; i++) {
    cin >> H[i];
    ma[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    ll a, b;
    cin >> a >> b;
    ma[a] = max(ma[a], H[b]);
    ma[b] = max(ma[b], H[a]);
  }
  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += H[i] > ma[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;
  vector<int> h(n);
  vector<bool> flag(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])
      flag[a] = false;
    if (h[b] <= h[a])
      flag[b] = false;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (flag[i])
      ++ans;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n, m, s;
  cin >> n >> m;
  vector<int> high(n), a(n), b(n);
  set<int> good, bad, takaiyo;
  for (int i = 0; i < n; ++i) {
    cin >> high[i];
    takaiyo.emplace(high[i]);
  }
  for (int i = 0; i < m; ++i) {
    cin >> a[i] >> b[i];
    good.emplace(max(high[a[i] - 1], high[b[i] - 1]));
    bad.emplace(min(high[a[i] - 1], high[b[i] - 1]));
  }
  for (auto itr = bad.begin(); itr != bad.end(); ++itr) {
    good.erase(*itr);
  }
  s = takaiyo.size() - good.size() - bad.size();
  s += good.size();
  cout << s << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  vector<int> h(n);
  rep(i, n) scanf("%d", &h[i]);

  vector<vector<int>> g(n);
  rep(i, m) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  int ans = 0;
  rep(i, n) {
    bool ok = true;
    for (auto j : g[i])
      if (h[i] <= h[j])
        ok = false;
    if (ok)
      ans++;
  }
  printf("%d\\n", ans);
  return 0;
}

Error: WA

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
const int inf = 1000000000; // 10^9
const ll MOD = 1e9 + 7;
// 加算代入演算子は+=！！！！！
// int 2^31 10^9まで
int n, k;
vector<int> d;
vector<vector<int>> a;

void input() {
  cin >> n >> k;
  d.resize(k); // resizeは要素の数変える
  a.resize(k, vector<int>());
  rep(i, k) {
    cin >> d[i];
    a[i].resize(d[i]);
    rep(j, d[i]) { cin >> a[i][j]; }
  }
}

void solve() {
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    bool have = false;
    for (auto v : a) {
      for (auto p : v) {
        if (p == i)
          have = true;
      }
    }
    if (!have)
      ans++;
  }
  cout << ans << endl;
}

int main() {
  input();
  solve();
  return 0;
}
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<pair<long long, int>> H(n + 1);

  for (int i = 1; i <= n; i++) {
    cin >> H[i].first;
  }

  vector<pair<int, int>> v(m + 1);
  for (int i = 1; i <= m; i++) {
    cin >> v[i].first >> v[i].second;
  }

  // cout << v[5].second << endl; // 5
  for (int j = 1; j <= m; j++) {
    long long a = v[j].first;
    long long b = v[j].second;
    // cout <<  "loop" << a << " " << b << endl;

    if (H[a].first <= H[b].first) {
      H[a].second = 1;
    } else {
      H[b].second = 1;
    }
    if (H[b].first == H[a].first) {
      H[b].second = 1;
    }
    // if(H[b].second <= H[a].first) {
    //     H[b].second = 1;
    // }
  }

  int ret = n;
  for (int i = 1; i <= n; i++) {
    // cout << i << " " << H[i].second << endl;
    if (H[i].second == 1) {
      ret--;
    }
  }

  cout << ret << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> H(n + 1);

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

  vector<pair<int, int>> v(m + 1);
  for (int i = 1; i <= m; i++) {
    cin >> v[i].first >> v[i].second;
  }

  // cout << v[5].second << endl; // 5
  int ret = n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int opposite = 0;
      if (v[j].first == i) {
        opposite = v[j].second;
      } else if (v[j].second == i) {
        opposite = v[j].first;
      }

      if (opposite > 0) {
        if (H[opposite] >= H[i]) {
          ret--;
          break;
        }
      }
    }
  }

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

#include <bits/stdc++.h>

// 短縮
#define rep(i, n) for (int i = 0; i < (n); ++i)
// sort()用
#define all(v) v.begin(), v.end()

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  rep(i, N) cin >> H.at(i);
  vector<int> A(M);
  vector<int> B(M);
  vector<int> NN(N);

  rep(i, M) { cin >> A.at(i) >> B.at(i); }
  rep(i, N) { NN.at(i) = 1; }

  rep(i, M) {
    if (H.at(A.at(i) - 1) > H.at(B.at(i) - 1)) {
      NN.at(B.at(i) - 1) = 0;
    } else if (H.at(A.at(i) - 1) == H.at(B.at(i) - 1)) {
      NN.at(B.at(i) - 1) = 0;
      NN.at(A.at(i) - 1) = 0;
    } else {
      NN.at(A.at(i) - 1) = 0;
    }
  }

  int sum = 0;
  rep(i, N) {
    if (NN.at(i) == 1) {
      sum++;
    }
  }
  cout << sum;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

// 短縮
#define rep(i, n) for (int i = 0; i < (n); ++i)
// sort()用
#define all(v) v.begin(), v.end()

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  rep(i, N) cin >> H.at(i);
  vector<int> A(M);
  vector<int> B(M);
  vector<int> NN(N);
  vector<vector<int>> path(N, vector<int>(M));

  rep(i, M) { cin >> A.at(i) >> B.at(i); }
  rep(i, N) { NN.at(i) = 1; }

  rep(i, M) {
    if (H.at(A.at(i) - 1) > H.at(B.at(i) - 1)) {
      NN.at(B.at(i) - 1) = 0;
    } else if (H.at(A.at(i) - 1) == H.at(B.at(i) - 1)) {
      NN.at(B.at(i) - 1) = 0;
      NN.at(A.at(i) - 1) = 0;
    } else {
      NN.at(A.at(i) - 1) = 0;
    }
  }

  int sum = 0;
  rep(i, N) {
    if (NN.at(i) == 1) {
      sum++;
    }
  }
  cout << sum;
  return 0;
}