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

#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <vector>
#define all(x) (x).begin(), (x).end()
typedef long long ll;

using namespace std;

int main() {
  int N, M, sum;
  cin >> N >> M;
  std::vector<long> v(N), ans(N, 1);

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

  cout << sum;
}

Error: WA

Fixed submission:

#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  std::vector<long> v(N), ans(N, 1);

  for (int i = 1; i <= N; i++) {
    long H;
    cin >> H;
    v[i] = H;
  }
  for (int i = 1; i <= M; i++) {
    int A, B;
    cin >> A >> B;
    if (v[A] > v[B]) {
      ans[B - 1] = 0;
    } else if (v[A] < v[B]) {
      ans[A - 1] = 0;
    } else {
      ans[A - 1] = 0;
      ans[B - 1] = 0;
    }
  }
  int sum = std::accumulate(ans.begin(), ans.end(), 0L);
  cout << sum;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

static const int NMAX = 100100;

int main() {
  int n, m;
  int h[NMAX], ma[NMAX]; // ma[i]: 展望台 i から一本で行ける山の標高の最大値
  cin >> n >> m;
  REP(i, n) cin >> h[i];
  REP(i, n) ma[i] = 0; // 初期化
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    ma[a] = max(ma[a], h[b]);
    ma[b] = max(ma[b], h[a]);
  }

  int cnt = 0;

  REP(i, n) {
    if (h[i] > ma[i])
      ++cnt;
  }

  cout << cnt << endl;
  return 0;
}

Error: 0

Fixed submission:

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

static const int NMAX = 10010;

int main() {
  int n, m;
  int h[NMAX], ma[NMAX]; // ma[i]: 展望台 i から一本で行ける山の標高の最大値
  cin >> n >> m;
  REP(i, n) cin >> h[i];
  REP(i, n) ma[i] = 0; // 初期化
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    ma[a] = max(ma[a], h[b]);
    ma[b] = max(ma[b], h[a]);
  }

  int cnt = 0;

  REP(i, n) {
    if (h[i] > ma[i])
      ++cnt;
  }

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

#include <bits/stdc++.h>
using namespace std;
int h[100010], maxv[100010];
int main() {
  int a, b;
  cin >> a >> b;
  for (int i = 0; i < a; i++) {
    cin >> h[i];
  }
  for (int i = 0; i < b; i++) {
    int x, y;
    cin >> x >> y;
    maxv[x - 1] = max(h[y - 1], maxv[x - 1]);
    maxv[y - 1] = max(h[x - 1], maxv[y - 1]);
  }
  int ans = 0;
  for (int i = 0; i < a; i++) {
    ans += h[i] > maxv[i];
  }
  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int h[10010], maxv[10010];
int main() {
  int a, b;
  cin >> a >> b;
  for (int i = 0; i < a; i++) {
    cin >> h[i];
  }
  for (int i = 0; i < b; i++) {
    int x, y;
    cin >> x >> y;
    maxv[x] = max(h[y], maxv[x]);
    maxv[y] = max(h[x], maxv[y]);
  }
  int ans = 0;
  for (int i = 0; i < a; i++) {
    ans += h[i] > maxv[i];
  }
  cout << ans;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

#define ll long long

int main() {
  ll n, m;
  ll a, b;
  ll i, j;
  ll count = 0;
  cin >> n >> m;
  vector<ll> h(n + 1);
  vector<ll> chk(n + 1);
  for (i = 1; i <= n; i++) {
    cin >> h[i];
  }
  vector<vector<int>> vc(n + 1, vector<int>(1));
  for (i = 1; i <= m; i++) {
    cin >> a >> b;
    if (a < b) {
      vc[a].push_back(b);
    } else {
      vc[b].push_back(a);
    }
    if (h[a] > h[b])
      chk[b]++;
    else
      chk[a]++;
    if (h[a] == h[b])
      chk[b]++;
  }
  for (i = 1; i <= n; i++) {
    sort(vc[i].begin(), vc[i].end());
  }
  for (i = 1; i <= n; i++) {
    for (j = 0; j < vc[i].size() - 1; j++) {
      if (vc[i][j] == vc[i][j + 1]) {
        if (h[i] > h[vc[i][j]])
          chk[vc[i][j]]--;
        else
          chk[i]--;
        if (h[i] == h[vc[i][j]])
          chk[vc[i][j]]--;
      }
    }
  }

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

  if (count < 0)
    count = 0;
  cout << count;
  return 0;
}

Error: -11

Fixed submission:

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

#define ll long long

int main() {
  ll n, m;
  ll a, b;
  ll i, j;
  ll count = 0;
  cin >> n >> m;
  vector<ll> h(n + 1);
  vector<ll> chk(n + 1);
  for (i = 1; i <= n; i++) {
    cin >> h[i];
  }
  vector<vector<int>> vc(m + 1, vector<int>(1));
  for (i = 1; i <= m; i++) {
    cin >> a >> b;
    if (a < b) {
      vc[a].push_back(b);
    } else {
      vc[b].push_back(a);
    }
    if (h[a] > h[b])
      chk[b]++;
    else
      chk[a]++;
    if (h[a] == h[b])
      chk[b]++;
  }
  for (i = 1; i <= n; i++) {
    sort(vc[i].begin(), vc[i].end());
  }
  for (i = 1; i <= n; i++) {
    for (j = 0; j < vc[i].size() - 1; j++) {
      if (vc[i][j] == vc[i][j + 1]) {
        if (h[a] > h[b])
          chk[b]--;
        else
          chk[a]--;
        if (h[a] == h[b])
          chk[b]--;
      }
    }
  }

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

  if (count < 0)
    count = 0;
  cout << count;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

// C: Peak
int main() {
  int N, M;
  cin >> N >> M;

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

  for (int j = 1; j <= M; ++j) {
    int a, b;
    cin >> a >> b;
    m[a] = max(m[a], H[b]);
    m[b] = max(m[b], H[a]);
  }
  int ans = 0;
  for (int i = 1; i <= N; ++i) {
    // cout << H[i] << " - " << m[i] << endl;
    ans += H[i] > m[i];
  }
  cout << ans << endl;
}


Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

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

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

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

  vector<long long> A(1000000), B(1000000);
  for (int i = 0; i < M; ++i)
    cin >> A[i] >> B[i];

  vector<int> S(1000000);
  for (int i = 0; i < N; ++i)
    S[i] = 0;

  for (int i = 0; i < M; ++i) {
    if (H[A[i]] > H[B[i]]) {
      ++S[A[i]];
    } else {
      ++S[B[i]];
    }
  }
  int sum = 0;
  for (int i = 0; i < N; ++i) {
    if (S[i] == 0) {
      ++sum;
    }
  }

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

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m, a, b, ans = 0;
  cin >> n >> m;
  vector<bool> z(n, true);
  vector<int> h(n);
  for (auto &i : h) {
    cin >> i;
  }
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (h[a - 1] == h[b - 1]) {
      z[a - 1] = false;
      z[b - 1] = false;
    } else if (h[a - 1] < h[b - 1]) {
      z[a - 1] = false;
    } else {
      z[b - 1] = false;
    }
  }
  for (auto i : z) {
    if (i) {
      ans++;
    }
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, m, a, b, ans = 0;
  cin >> n >> m;
  vector<bool> z(n, true);
  vector<int> h(n);
  for (auto &i : h) {
    cin >> i;
  }
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (h[a - 1] == h[b - 1]) {
      z[a - 1] = false;
      z[b - i] = false;
    } else if (h[a - 1] < h[b - 1]) {
      z[a - 1] = false;
    } else {
      z[b - 1] = false;
    }
  }
  for (int i = 0; i < n; i++) {
    if (z[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <sstream>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;

int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> H(N);
  rep(i, N) cin >> H.at(i);
  vector<ll> J(N);
  rep(i, N) J.at(i) = 0;
  ll A, B;

  ll count = 0;
  rep(i, M) {
    cin >> A >> B;
    A--;
    B--;
    if (H.at(A) > H.at(B))
      J.at(B)++;
    else if (H.at(A) < H.at(B))
      J.at(A)++;
    else {
      J.at(A)++;
      J.at(B)++;
    }
  }

  rep(i, N) if (J.at(i) == 0) count++;
  cout << count << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <sstream>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;

int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> H(N);
  rep(i, N) cin >> H.at(i);
  vector<ll> J(N);
  rep(i, M) J.at(i) = 0;
  ll A, B;

  ll count = 0;
  rep(i, M) {
    cin >> A >> B;
    A--;
    B--;
    if (H.at(A) > H.at(B))
      J.at(B)++;
    else if (H.at(A) < H.at(B))
      J.at(A)++;
    else {
      J.at(A)++;
      J.at(B)++;
    }
  }

  rep(i, N) if (J.at(i) == 0) count++;
  cout << count << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

const int N = 2e5 + 10, M = N;
int w[N];

bool vis[N];

int h[N], e[M], ne[M], idx;
void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }
int n, m;
int cnt;
void dfs(int u, int fa) {
  vis[u] = 1;
  int flag = 0;
  for (int i = h[u]; i != -1; i = ne[i]) {
    int v = e[i];
    if (w[v] >= w[u])
      flag = 1;
    if (v == fa)
      continue;
    if (!vis[v])
      dfs(v, u);
  }
  if (!flag)
    cnt++;
}

int main() {
  idx = 0;
  memset(h, -1, sizeof h);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d", &w[i]);
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    add(a, b), add(b, a);
  }

  for (int i = 1; i <= n; i++) {
    if (!vis[i])
      dfs(i, 0);
  }

  printf("%d\\n", cnt);
}

Error: 0

Fixed submission:

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

const int N = 1e5 + 10, M = N << 1;
int w[N];

bool vis[N];

int h[N], e[M], ne[M], idx;
void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }
int n, m;
int cnt;
void dfs(int u, int fa) {
  vis[u] = 1;
  int flag = 0;
  for (int i = h[u]; i != -1; i = ne[i]) {
    int v = e[i];
    if (w[v] >= w[u])
      flag = 1;
    if (v == fa)
      continue;

    dfs(v, u);
  }
  if (!flag)
    cnt++;
}

int main() {
  memset(h, -1, sizeof h);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d", &w[i]);
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    add(a, b), add(b, a);
  }

  for (int i = 1; i <= n; i++) {
    if (!vis[i])
      dfs(i, 0);
  }

  printf("%d\\n", cnt);
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define acc_io                                                                 \\
  cin.tie(0);                                                                  \\
  ios::sync_with_stdio(false)
#define MOD 1e9 + 7
#define ll long long
#define all(x) x.begin(), x.end()
#define vvl vector<vector<ll>>
#define vl vector<ll>
#define rep(i, sta, end) for (ll i = sta; i < end; i++)
// name[i]   -> vl  name(i)
// name[i][j]-> vvl name(i,vl(j))
// or-> ||

signed main() {
  acc_io;
  ll n, m;
  cin >> n >> m;
  vl h(n + 1);
  rep(i, 1, n + 1) cin >> h[i];
  vl a(m + 1), b(m + 1);
  rep(i, 1, m + 1) cin >> a[i] >> b[i];

  vl good(n + 1, 1);
  rep(j, 1, m + 1) {
    if (h[a[j]] <= h[b[j]]) {
      good[a[j]] = 0;
    }
    if (h[a[j]] >= h[b[j]]) {
      good[b[j]] = 0;
    }
  }
  ll cnt = 0;
  rep(i, 1, n + 1) {
    if (good[i])
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define acc_io                                                                 \\
  cin.tie(0);                                                                  \\
  ios::sync_with_stdio(false)
#define MOD 1e9 + 7
#define ll long long
#define all(x) x.begin(), x.end()
#define vvl vector<vector<ll>>
#define vl vector<ll>
#define rep(i, sta, end) for (ll i = sta; i < end; i++)
// name[i]   -> vl  name(i)
// name[i][j]-> vvl name(i,vl(j))
// or-> ||

signed main() {
  acc_io;
  ll n, m;
  cin >> n >> m;
  vl h(n + 1);
  rep(i, 1, n + 1) cin >> h[i];
  vl a(m + 1), b(m + 1);
  rep(i, 1, m + 1) cin >> a[i] >> b[i];

  vl good(n + 1, 1);
  rep(i, 1, n + 1){rep(j, 1, m + 1){if (good[i] == 0){break;
}
if (a[j] == i) {
  if (h[i] <= h[b[j]]) {
    good[i] = 0;
  } else {
    good[b[j]] = 0;
  }
} else if (b[j] == i) {
  if (h[i] <= h[a[j]]) {
    good[i] = 0;
  } else {
    good[a[j]] = 0;
  }
}
}
}
;
ll cnt = 0;
rep(i, 1, n + 1) {
  if (good[i])
    cnt++;
}
cout << cnt << endl;
return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m;
  int count = 0;
  cin >> n >> m;
  vector<long long> h(n);
  vector<int> a(m);
  vector<int> b(m);
  vector<int> ng(n);
  rep(i, n) cin >> h.at(i);
  rep(j, m) cin >> a.at(j) >> b.at(j);

  rep(j, m) {
    if (h.at(a.at(j) - 1) > h.at(b.at(j) - 1)) {
      ng.at(b.at(j) - 1) = 1;
    } else if (h.at(a.at(j) - 1) < h.at(b.at(j) - 1)) {
      ng.at(a.at(j) - 1) = 1;
    } else {
      ng.at(a.at(j) - 1) = 1;
      ng.at(b.at(j) - 1) = 1;
    }
  }
  rep(i, n) {
    if (ng.at(i) == 0) {
      count++;
    }
  }
  cout << count << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int n, m;
  int count = 0;
  cin >> n >> m;
  vector<long long> h(n);
  vector<int> a(m);
  vector<int> b(m);
  vector<int> ng(n);
  rep(i, n) cin >> h.at(i);
  rep(j, m) cin >> a.at(j) >> b.at(j);

  rep(j, m) {
    if (h.at(a.at(j) - 1) > h.at(b.at(j) - 1)) {
      ng.at(b.at(j)) = 1;
    } else if (h.at(a.at(j) - 1) < h.at(b.at(j) - 1)) {
      ng.at(a.at(j) - 1) = 1;
    } else {
      ng.at(a.at(j) - 1) = 1;
      ng.at(b.at(j) - 1) = 1;
    }
  }
  rep(i, n) {
    if (ng.at(i) == 0) {
      count++;
    }
  }
  cout << count << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

#define pb push_back
#define all(in) in.begin(), in.end()

using ll = long long; // typedef long long ll; と同意
using ull = unsigned long long;
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> data(n);
  rep(i, n) cin >> data[i];
  vector<int> ans(n, 1);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (data[a] >= data[b])
      ans[b] = 0;
    if (data[a] <= data[b])
      ans[a] = 0;
  }
  int answer = 0;
  rep(i, n) answer += ans[i];
  cout << answer << endl;
}

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


Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  int ans = n;
  vector<int> data1(n);
  for (int i = 0; i < n; i++)
    cin >> data1.at(i);
  vector<int> data2(m), data3(m);
  for (int i = 0; i < m; i++)
    cin >> data2.at(i) >> data3.at(i);
  // 入力
  for (int i = 1; i <= n; i++) {
    int height = data1.at(i - 1);
    for (int j = 0; j < m; j++) {
      if (data2.at(j) = i && data1.at(data3.at(j) - 1) > height) {
        ans -= 1;
        break;
      }
      if (data3.at(j) = i && data1.at(data2.at(j) - 1) > height) {
        ans -= 1;
        break;
      }
    }
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#define pi 3.14159265358979323846264338327950

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

  // 高さの入力
  std::vector<int> H(N);
  for (auto &r : H)
    std::cin >> r;

  // 道の入力
  std::vector<int> A(M);
  std::vector<int> B(M);
  for (auto i{0}; i < M; ++i)
    std::cin >> A[i] >> B[i];

  std::vector<bool> flag(N);
  std::fill(flag.begin(), flag.end(), true);
  int count{0};
  for (auto i{0}; i < M; ++i) {
    if (H[A[i] - 1] == H[B[i] - 1]) {
      flag[A[i] - 1] = false;
      flag[B[i] - 1] = false;
    } else if (H[A[i] - 1] < H[B[i] - 1])
      flag[A[i] - 1] = false;
    else
      flag[B[i] - 1] = false;
  }
  for (bool b : flag)
    if (b)
      ++count;

  std::cout << count << std::endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#define pi 3.14159265358979323846264338327950

int main() {
  int N, M;
  std::cin >> N >> M;
  // 高さの入力
  std::vector<int> H(N);
  for (auto &r : H)
    std::cin >> r;
  // 道の入力
  std::vector<std::vector<int>> R(2, std::vector<int>(M));
  for (auto i{0}; i < M; ++i)
    std::cin >> R[0][i] >> R[1][i];

  int count{0};
  for (auto num{0}; num < N; ++num) {
    bool flag = false;
    for (int i{0}; i < M; ++i) {
      if (num + 1 == R[0][i])
        if (H[num] <= H[R[1][i] - 1]) {
          flag = true;
          break;
        }
      if (num + 1 == R[1][i])
        if (H[num] <= H[R[0][i] - 1]) {
          flag = true;
          break;
        }
    }
    if (flag == true)
      ++count;
  }
  std::cout << N - count << std::endl;

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

#include <bits/stdc++.h>
#define mkp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll>::iterator itii;
const ll inf = 1e6;
ll lower[inf];
ll road[inf];
int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> vi;
  for (ll i = 0; i < n; i++) {
    ll a;
    cin >> a;
    vi.push_back(a);
  }
  for (ll i = 0; i < m; i++) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    if (vi[a] < vi[b]) {
      lower[b]++;
    } else if (vi[a] > vi[b]) {
      lower[a]++;
    }
    road[a]++;
    road[b]++;
  }
  ll cnt = 0;
  for (ll i = 0; i < n; i++) {
    if (lower[i] == road[i])
      cnt++;
    else if (road[i] == 0)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define mkp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll>::iterator itii;
const ll inf = 1e6;
ll lower[inf];
ll road[inf];
int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> vi;
  for (ll i = 0; i < n; i++) {
    ll a;
    cin >> a;
    vi.push_back(a);
  }
  for (ll i = 0; i < m; i++) {
    ll a, b;
    cin >> a >> b;
    a = vi[--a];
    b = vi[--b];
    if (a < b) {
      lower[b]++;
    } else if (a > b) {
      lower[a]++;
    }
    road[a]++;
    road[b]++;
  }
  ll cnt = 0;
  for (ll i = 0; i < n; i++) {
    ll tmp = vi[i];
    if (lower[tmp] == road[tmp])
      cnt++;
    else if (road[tmp] == 0)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <bits/stdc++.h>

#define PI 3.141592653
#define rep(i, a, n) for (int i = a; i < (int)n; ++i)
#define SZ(x) ((int)(x).size()) // size() unsigned -> int
#define descSort(a) sort(a.begin(), a.end(), std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x, ll y) {
  if (x % y == 0)
    return y;
  return gcd(y, x % y);
}

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<ll> h(n);
  vector<ll> ma(n);
  rep(i, 0, n) cin >> h[i];
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    ma[a] = max(ma[a], h[b]);
    ma[b] = max(ma[b], h[a]);
  }
  int ans = 0;
  rep(i, 0, n) { ans += h[i] > ma[i]; }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:


#include <bits/stdc++.h>

#define PI 3.141592653
#define rep(i, a, n) for (int i = a; i < (int)n; ++i)
#define SZ(x) ((int)(x).size()) // size() unsigned -> int
#define descSort(a) sort(a.begin(), a.end(), std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x, ll y) {
  if (x % y == 0)
    return y;
  return gcd(y, x % y);
}

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<ll> h(n);
  vector<vector<bool>> load(n + 1, vector<bool>(n + 1));
  rep(i, 0, n) cin >> h[i];
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    load[a][b] = load[b][a] = true;
  }
  int ans = 0;
  rep(i, 0, n) {
    int num = 0;
    rep(j, 0, n) {
      if (i == j)
        continue;
      if (load[i][j] == false)
        num = true;
      else if (load[i][j] && h[i] <= h[j]) {
        num = false;
        break;
      } else
        num = true;
    }
    ans += num;
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
vector<vector<int>> g(1e5 + 10);
int h[100005];
int n, m;
// bool dfs(int v,int h)
// {
// 	if(vis[v])
// 	return false;

// 	for(int i=g[v].begin();i<g[v].size();i++)

// }
int main() {
  // your code goes here

  cin >> n >> m;
  // int h[n];
  for (int i = 0; i < n; i++)
    cin >> h[i];
  g.resize(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vector<int> vis(n, 0);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (vis[i] == 1)
      continue;
    int flag = 1;
    for (int j = 0; j < g[i].size(); j++) {
      if (h[g[i][j]] >= h[i]) {
        flag = 0;
        break;
      }
    }
    if (flag) {
      cnt++;
      // cout<<i<<"\\n";
      for (int j = 0; j < g[i].size(); j++) {
        vis[g[i][j]] = 1;
      }
    }
  }
  cout << cnt;

  return 0;
}

Error: MLE

Fixed submission:

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

int main() {
  int N, M;
  cin >> N;
  cin >> M;
  vector<long> height(N);
  vector<bool> good(N, true);
  vector<vector<bool>> adj(N, vector<bool>(N, false));
  for (int i = 0; i < N; ++i) {
    cin >> height[i];
  }
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a;
    cin >> b;
    a--;
    b--;
    if (height[a] < height[b]) {
      good[a] = false;
    } else if (height[b] < height[a]) {
      good[b] = false;
    } else if (height[a] == height[b]) {
      good[a] = false;
      good[b] = false;
    }
  }

  int ngood = 0;
  for (int i = 0; i < N; ++i) {
    if (good[i])
      ngood++;
  }
  cout << ngood << endl;
  return 0;
}