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

#pragma GCC optimize("Ofast", "-funroll-loops", "-fdelete-null-pointer-checks")
#pragma GCC target("ssse3", "sse3", "sse2", "sse", "avx2", "avx", "popcnt")
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define endl '\\n'

const ll MOD = 1e9 + 7;

void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<vector<int>> g(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    g[x - 1].push_back(y - 1);
    g[y - 1].push_back(x - 1);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    bool ok = 1;
    for (int j : g[i]) {
      if (h[i] <= h[j]) {
        ok = 0;
        break;
      }
    }
    ans += ok;
  }
  cout << ans << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ll t = 1;
  for (ll tt = 1; tt <= t; tt++) {
    // cout << "case #" << tt << ":\\n";
    solve();
  }

  return 0;
}


Error: 0

Fixed submission:

#pragma GCC optimize("Ofast", "-funroll-loops", "-fdelete-null-pointer-checks")
#pragma GCC target("ssse3", "sse3", "sse2", "sse", "avx2", "avx", "popcnt")
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define endl '\\n'

const ll MOD = 1e9 + 7;

void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<vector<int>> g(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    g[--x].push_back(--y);
    g[--y].push_back(--x);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    bool ok = 1;
    for (int j : g[i]) {
      if (h[i] <= h[j]) {
        ok = 0;
        break;
      }
    }
    ans += ok;
  }
  cout << ans << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ll t = 1;
  for (ll tt = 1; tt <= t; tt++) {
    // cout << "case #" << tt << ":\\n";
    solve();
  }

  return 0;
}
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++)
void sort2array(double *a, long *b, long n) {
  for (int i = 0; i < n; i++) {
    b[i] = i;
  }
  sort(b, b + n, [a](long i, long j) -> bool { return a[i] < a[j]; });
}
// bを何回足せばaを超えるか
int wtover(int a, int b) {
  if (a % b > 0)
    return (a / b) + 1;
  else
    return a / b;
}
const int INF = 100000001, ID_MAX = 20;
int bi_e[ID_MAX] = {0};
// 2進数表示したときの最高桁
int bi_max(long n) {
  int m = 0;
  for (m; pow(2, m) <= n; m++)
    ;
  m = m - 1;
  return m;
}
// bi_eに二進数表示したやつを代入
void bi_exs(long n) {
  rep(i, ID_MAX) { bi_e[i] = 0; }
  if (n < pow(2, ID_MAX)) {
    int m = bi_max(n);
    long l;
    for (m; m > -1; m--) {
      l = pow(2, m);
      bi_e[m] = n / l;
      n = n % l;
    }
  }
}
// x^n mod m (nが負の時は０)
long myPow(long x, long n, long m) {
  if (n < 0)
    return 0;
  if (n == 0)
    return 1;
  if (n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}
const int N = 100001;
int n, m;
vector<int> a[N];

int main() {
  int i, x, y;
  // 入力
  cin >> n >> m;
  int h[n];
  rep(i, n) { cin >> h[i]; }
  rep(i, m) {
    cin >> x >> y;
    a[x - 1].push_back(y);
    a[y - 1].push_back(x);
  }
  // 処理
  int cou = 0;
  rep(i, n) {
    bool tof = true;
    rep(j, a[i].size()) {
      if (h[i] <= h[a[i].at(j) - 1]) {
        tof = false;
        break;
      }
    }
    if (tof)
      cou = cou + 1;
  }
  // 出力
  cout << cou << endl;
}


Error: 0

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
void sort2array(double *a, long *b, long n) {
  for (int i = 0; i < n; i++) {
    b[i] = i;
  }
  sort(b, b + n, [a](long i, long j) -> bool { return a[i] < a[j]; });
}
// bを何回足せばaを超えるか
int wtover(int a, int b) {
  if (a % b > 0)
    return (a / b) + 1;
  else
    return a / b;
}
const int INF = 100000001, ID_MAX = 20;
int bi_e[ID_MAX] = {0};
// 2進数表示したときの最高桁
int bi_max(long n) {
  int m = 0;
  for (m; pow(2, m) <= n; m++)
    ;
  m = m - 1;
  return m;
}
// bi_eに二進数表示したやつを代入
void bi_exs(long n) {
  rep(i, ID_MAX) { bi_e[i] = 0; }
  if (n < pow(2, ID_MAX)) {
    int m = bi_max(n);
    long l;
    for (m; m > -1; m--) {
      l = pow(2, m);
      bi_e[m] = n / l;
      n = n % l;
    }
  }
}
// x^n mod m (nが負の時は０)
long myPow(long x, long n, long m) {
  if (n < 0)
    return 0;
  if (n == 0)
    return 1;
  if (n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}
int n, m;

int main() {
  int i, j, x, y;
  // 入力
  cin >> n >> m;
  int h[n];
  rep(i, n) { cin >> h[i]; }
  int a[n][n];
  memset(a, 0, sizeof(a));
  rep(i, m) {
    cin >> x >> y;
    a[x - 1][y - 1] = 1;
    a[y - 1][x - 1] = 1;
  }
  // 処理
  int cou = 0;
  rep(i, n) {
    bool tof = true;
    rep(j, n) {
      if (a[i][j] > 0 && h[i] <= h[j]) {
        tof = false;
      }
    }
    if (tof)
      cou++;
  }
  // 出力
  cout << cou << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

inline bool valid(int x, int n) { return 0 <= x && x < n; }

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};

template <typename T> inline T pop(queue<T> &q) {
  T front = q.front();
  q.pop();
  return front;
}

template <typename T> inline T gcd(T a, T b) {
  for (; b; a %= b, swap(a, b))
    ;
  return a;
}

template <typename T> tuple<T, T, T> xgcd(T a, T b) {
  if (b == 0)
    return {1, 0, a};
  T x, y, g;
  tie(x, y, g) = xgcd(b, a % b);
  return {y, x - (a / b) * y, g};
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int N;
  cin >> N;
  vvi graph(N + 1);
  vi H(N + 1);

  int M;
  cin >> M;
  for (int i = 1; i <= N; i++)
    cin >> H[i];
  while (M--) {
    int A, B;
    cin >> A >> B;
    graph[A].push_back(B);
    graph[B].push_back(A);
  }

  int rst = 0;
  for (int i = 1; i <= N; i++) {
    bool isgood = 1;
    for (int j : graph[i]) {
      if (H[i] <= H[j]) {
        isgood = 0;
        break;
      }
    }
    if (isgood)
      ++rst;
  }
  cout << rst;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

inline bool valid(int x, int n) { return 0 <= x && x < n; }

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};

template <typename T> inline T pop(queue<T> &q) {
  T front = q.front();
  q.pop();
  return front;
}

template <typename T> inline T gcd(T a, T b) {
  for (; b; a %= b, swap(a, b))
    ;
  return a;
}

template <typename T> tuple<T, T, T> xgcd(T a, T b) {
  if (b == 0)
    return {1, 0, a};
  T x, y, g;
  tie(x, y, g) = xgcd(b, a % b);
  return {y, x - (a / b) * y, g};
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int N;
  cin >> N;
  vvi graph(N + 1);
  vi H(N + 1);

  int M;
  cin >> M;
  while (M--) {
    int A, B;
    cin >> A >> B;
    graph[A].push_back(B);
    graph[B].push_back(A);
  }

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

  int rst = 0;
  for (int i = 1; i <= N; i++) {
    bool isgood = 1;
    for (int j : graph[i]) {
      if (H[i] <= H[j]) {
        isgood = 0;
        break;
      }
    }
    if (isgood)
      ++rst;
  }
  cout << rst;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
  int N, M, A, B, count = 0;
  cin >> N >> M;
  vector<set<int>> vect(N + 1);
  int ele[N + 1];
  for (int i = 1; i <= N; i++) {
    cin >> ele[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> A;
    cin >> B;
    vect[A].insert(B);
    vect[B].insert(A);
  }
  for (int i = 1; i <= N; i++) {
    bool pos = true;
    for (auto itr = vect[i].begin(); itr != vect[i].end(); itr++) {
      if (ele[i] <= ele[*itr]) {
        pos = false;
        break;
      }
    }
    if (pos) {
      count++;
    }
  }
  cout << count << "\\n";
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
  int N, M, A, B, count = 0;
  int ele[N + 1];
  vector<set<int>> vect(N + 1);
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    cin >> ele[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> A;
    cin >> B;
    vect[A].insert(B);
    vect[B].insert(A);
  }
  for (int i = 1; i <= N; i++) {
    bool pos = true;
    for (auto itr = vect[i].begin(); itr != vect[i].end(); itr++) {
      if (ele[i] <= ele[*itr]) {
        pos = false;
        break;
      }
    }
    if (pos) {
      count++;
    }
  }
  cout << count << "\\n";
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, m;
ll ans;
vector<vector<ll>> a;
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n);
  vector<ll> cnts(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  a.resize(n);
  vector<ll> b(m), c(m);
  for (int i = 0; i < m; i++) {
    cin >> b[i] >> c[i];
    if (h[b[i] - 1] > h[c[i] - 1])
      cnts[b[i] - 1]++;
    if (h[c[i] - 1] > h[b[i] - 1])
      cnts[c[i] - 1]++;
    a[b[i] - 1].emplace_back(c[i] - 1);
    a[c[i] - 1].emplace_back(b[i] - 1);
  }
  for (ll i = 0; i < n; i++) {
    if (cnts[i] == a[i].size())
      ans++;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, m;
ll ans;
vector<vector<ll>> a;
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n);
  vector<ll> cnts(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  a.resize(n);
  vector<ll> b(n), c(n);
  for (int i = 0; i < m; i++) {
    cin >> b[i] >> c[i];
    if (h[b[i] - 1] > h[c[i] - 1])
      cnts[b[i] - 1]++;
    if (h[c[i] - 1] > h[b[i] - 1])
      cnts[c[i] - 1]++;
    a[b[i] - 1].emplace_back(c[i] - 1);
    a[c[i] - 1].emplace_back(b[i] - 1);
  }
  for (ll i = 0; i < n; i++) {
    if (a[i].size() == 0) {
      ans++;
      continue;
    }
    if (cnts[i] == a[i].size())
      ans++;
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = a; i < ll(b); i++)
#define repr(i, a, b) for (ll i = a; i >= ll(b); i--)
#define endl "\\n"
#define ALL(x) x.begin(), x.end()
#define ALLR(x) x.rbegin(), x.rend()
#define INF 1e9
#define DEBUG(x) cout << "debug: " << x << endl

int n, m;
vector<int> graph[100010];
int main() {
  cin >> n >> m;
  vector<int> h(n);
  rep(i, 0, n) cin >> h[i];
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  int ans = 0;
  rep(i, 0, n) {
    int nh = h[i];
    int maxh = 0;
    for (auto x : graph[i]) {
      maxh = max(maxh, h[x]);
    }
    if (nh > maxh)
      ans++;
  }

  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = a; i < ll(b); i++)
#define repr(i, a, b) for (ll i = a; i >= ll(b); i--)
#define endl "\\n"
#define ALL(x) x.begin(), x.end()
#define ALLR(x) x.rbegin(), x.rend()
#define INF 1e9
#define DEBUG(x) cout << "debug: " << x << endl

int n, m;
vector<int> graph[100010];
int main() {
  cin >> n >> m;
  vector<int> h(m);
  rep(i, 0, n) cin >> h[i];
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  int ans = 0;
  rep(i, 0, n) {
    int nh = h[i];
    int maxh = 0;
    for (auto x : graph[i]) {
      maxh = max(maxh, h[x]);
    }
    if (nh > maxh)
      ans++;
  }

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

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

int main() {
  int N, M, H[100010], MAX[100010];
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    cin >> H[i];
    MAX[i] = 0;
  }
  for (int i = 1; i <= M; i++) {
    int A, B;
    cin >> A >> B;
    MAX[A] = max(MAX[A], H[B]);
    MAX[B] = max(MAX[B], H[A]);
  }
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += H[i] > MAX[i];
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int N, M, H[10010], MAX[10010];
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    cin >> H[i];
    MAX[i] = 0;
  }
  for (int i = 1; i <= M; i++) {
    int A, B;
    cin >> A >> B;
    MAX[A] = max(MAX[A], H[B]);
    MAX[B] = max(MAX[B], H[A]);
  }
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += H[i] > MAX[i];
  }
  cout << ans << endl;
  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, i, s = 0, x, y;

  cin >> n >> m;

  ll h[n + 5];

  map<ll, ll> c, d;

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

  for (i = 1; i <= m; i++) {

    cin >> x >> y;

    d[x] = 1;
    d[y] = 1;

    if (h[x] > h[y]) {
      c[y] = 1;
    } else if (h[x] < h[y]) {
      c[x] = 1;
    } else {
      c[x] = 1;
      c[y] = 1;
    }
  }

  for (i = 1; i <= n; i++) {

    if (d[i] == 0) {
      s++;

    } else if (c[i] == 0) {
      s++;
    }
  }

  cout << s << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
map<string, ll> mp;
map<ll, ll> mpp;
int main() {
  ll n, m, i, s = 0, x, y;

  cin >> n >> m;

  ll h[n + 5];

  ll c[n + 5], d[n + 5];

  memset(c, 0, sizeof(c));
  memset(d, 0, sizeof(d));

  for (i = 1; i <= n; i++)
    cin >> h[i];

  ll a[n + 5][n + 5];

  memset(a, 0, sizeof(a));

  for (i = 0; i < m; i++) {

    cin >> x >> y;

    if (h[x] > h[y]) {
      c[y] = 1;
    } else if (h[x] < h[y]) {
      c[x] = 1;
    } else {
      c[x] = 1;
      c[y] = 1;
    }

    d[x] = 1;
    d[y] = 1;
  }

  for (i = 1; i <= n; i++) {

    if (d[i] == 0) {
      s++;
      continue;
    } else if (c[i] == 0) {
      s++;
    }
  }

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

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n + 1);
  vector<bool> s(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
    s[i] = true;
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    if (h[a] <= h[b])
      s[a] = false;
    if (h[a] >= h[b])
      s[b] = false;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i])
      ans++;
  }
  cout << ans << endl;
}

Error: TLE

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 pii = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  vector<pii> x(m);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    x[i].first = a;
    x[i].second = b;
  }
  int cnt = 0;
  rep(i, n) {
    bool s = false;
    rep(j, m) {
      if (i + 1 == x[j].first) {
        if (h[i] <= h[x[j].second - 1]) {
          s = true;
          break;
        }
      }
      if (i + 1 == x[j].second) {
        if (h[i] <= h[x[j].first - 1]) {
          s = true;
          break;
        }
      }
    }
    if (s)
      cnt++;
  }
  cout << n - cnt << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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

  vector<ll> A(M + 1), B(M + 1);
  for (int i = 1; i <= M; i++) {
    cin >> A[i] >> B[i];
  }

  vector<vector<ll>> bridge(N + 1, vector<ll>());
  for (int i = 1; i <= M; i++) {
    bridge[A[i]].push_back(B[i]);
    bridge[B[i]].push_back(A[i]);
  }

  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    ll h = H[i];
    bool good = true;
    for (int j = 0; j < bridge[i].size(); j++) {
      if (h <= H[bridge[i][j]]) {
        good = false;
        break;
      }
    }
    if (good)
      ans++;
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

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

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

  vector<ll> A(M + 1), B(M + 1);
  for (int i = 1; i <= M; i++) {
    cin >> A[i] >> B[i];
  }

  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    ll h = H[i];
    bool good = true;
    for (int j = 1; j <= M; j++) {
      if (A[j] == i) {
        if (h <= H[B[j]]) {
          good = false;
          break;
        }
      } else if (B[j] == i) {
        if (h <= H[A[j]]) {
          good = false;
          break;
        }
      }
    }
    if (good)
      ans++;
  }

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

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

int main() {

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

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

  vector<vector<int>> ab(m, vector<int>(2));
  rep(i, m) cin >> ab[i][0] >> ab[i][1];

  vector<int> ok(n, 1);
  rep(i, m) {
    if (h[ab[i][0] - 1] <= h[ab[i][1] - 1])
      ok[ab[i][0] - 1] = 0;
    if (h[ab[i][1] - 1] <= h[ab[i][0] - 1])
      ok[ab[i][1] - 1] = 0;
  }

  cout << accumulate(ok.begin(), ok.end(), 0) << endl;

  return 0;
}


Error: TLE

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;
  cin >> n >> m;

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

  vector<vector<int>> ab(m, vector<int>(2));
  rep(i, m) cin >> ab[i][0] >> ab[i][1];

  bool ok = true;
  int count = 0;
  rep(i, n) {
    ok = true;
    int j;
    for (j = 0; j < m && ok; ++j) {
      if (i == ab[j][0] - 1 && h[i] <= h[ab[j][1] - 1])
        ok = false;
      else if (i == ab[j][1] - 1 && h[i] <= h[ab[j][0] - 1])
        ok = false;
    }
    if (ok)
      ++count;
  }

  cout << count << endl;

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

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

vector<int> adj[123456];
vector<int> hs;

bool is_good(int x) {
  for (int node : adj[x]) {
    if (hs[node] >= hs[x])
      return false;
  }
  return true;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, h;
  cin >> n >> m;
  hs.resize(n + 1);
  for (int i = 1; i <= n; ++i)
    cin >> hs[i];
  for (int i = 0, x, y; i < m; ++i) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    cnt += is_good(i);
  }
  cout << cnt << endl;
  return 0;
}

Error: 0

Fixed submission:

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

vector<int> adj[123456];
vector<int> hs;

bool is_good(int x) {
  for (int node : adj[x]) {
    if (hs[node] >= hs[x])
      return false;
  }
  return true;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, h;
  cin >> n >> m >> h;
  hs.resize(n + 1);
  for (int i = 1; i <= n; ++i)
    cin >> hs[i];
  for (int i = 0, x, y; i < m; ++i) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    cnt += is_good(i);
  }
  cout << cnt << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

signed main() {
  // cout << fixed << setprecision(10) << flush;

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

  vector<int> good(n, 1);

  // vector<vector<int>> path(n, vector<int>(n, 0));
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (h[a] >= h[b])
      good[b] = 0;
    if (h[a] <= h[b])
      good[a] = 0;
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += good[i];
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

signed main() {
  // cout << fixed << setprecision(10) << flush;

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

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

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int flag = 1;
    for (int j = 0; j < n; j++) {
      if (path[i][j] == 1 && h[i] <= h[j]) {
        flag = 0;
      }
    }
    ans += flag;
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, M;
  cin >> N >> M;
  int H[N], high[N] = {};
  rep(i, N) cin >> H[i];
  rep(i, M) {
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    high[A] = max(high[A], H[B]);
    high[B] = max(high[B], H[A]);
  }
  int ans = 0;
  rep(i, N) {
    if (high[i] < H[i])
      ans++;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N), high(M);
  rep(i, N) cin >> H[i];
  rep(i, M) {
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    high[A] = max(high[A], H[B]);
    high[B] = max(high[B], H[A]);
  }
  int ans = 0;
  rep(i, N) {
    if (high[i] < H[i])
      ans++;
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 7;
int d[N];
bool vis[N];

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> d[i];

  while (m--) {
    int a, b;
    cin >> a >> b;
    if (d[a] < d[b])
      vis[a] = 1;
    if (d[b] < d[a])
      vis[b] = 1;
    if (d[b] == d[a])
      vis[a] = 1, vis[b] = 1;
  }
  long long s = 0;
  for (int i = 1; i <= n; i++)
    if (vis[i] == 0)
      s++;
  cout << s << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define x first
#define y second
#define PII pair<int, int>

using namespace std;
const int N = 1e5 + 7, M = 2 * N;
vector<int> G[M];
bool st[N];
PII a[N];
int n, m, res;

void check(int u) {
  bool flag = true;
  for (auto x : G[u]) {
    if (a[x].y > a[u].y)
      flag = false;
  }
  if (flag)
    res++;
}

int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> a[i].x, a[i].y = i;
  while (m--) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for (int i = 1; i <= n; i++)
    check(a[i].x);

  cout << res << endl;
  return 0;
}