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

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N, M;
  vector<int> H;
  vector<bool> ok;

  int res = 0;

  std::cin >> N >> M;

  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    H.push_back(tmp);
    ok.push_back(true);
  }

  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    if (H[A - 1] <= H[B - 1]) {
      ok[A - 1] = false;
    }
    if (H[A - 1] >= H[B - 1]) {
      ok[B - 1] = false;
    }
  }

  for (int i = 0; i < N; i++) {
    if (ok[i]) {
      res++;
    }
  }

  cout << res;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
using namespace std;

vector<bool> seen;

void DFS(vector<vector<int>> next, int v, bool flag) {
  if (flag) {
    seen[v] = true;
  }
  for (int i = 0; i < next[v].size(); i++) {
    if (!seen[next[v][i]]) {
      DFS(next, next[v][i], true);
    }
  }
}

int main() {
  int N, M;
  vector<long long int> H;
  vector<vector<int>> next;

  cin >> N >> M;

  int res = M;

  next.resize(N);

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

  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    if (H[A - 1] >= H[B - 1]) {
      next[A - 1].push_back(B - 1);
    }
    if (H[B - 1] >= H[A - 1]) {
      next[B - 1].push_back(A - 1);
    }
  }
  seen.assign(N, false);

  for (int i = 0; i < N; i++) {
    if (!seen[i]) {
      DFS(next, i, false);
    }
  }

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

  cout << count;

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

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define db(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\\n'
const int N = 1e6;
int A[N];

int main() {
  ios_base::sync_with_stdio(0);
  int a, b, n, m, d, k, T, cas = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    cin >> A[i];
  map<int, int> mp;
  for (int i = 0; i < m; ++i) {
    cin >> a >> b;
    mp[a] = max(mp[a], A[b]);
    mp[b] = max(mp[b], A[a]);
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    if (A[i] > mp[i] || mp[i] == 0) {
      cerr << A[i] << " " << mp[i] << endl;
      cnt++;
    }
  }
  cout << cnt;
  return 0;
}

Error: WA

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define db(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\\n'
const int N = 1e6;
int f[N], A[N];

int main() {
  ios_base::sync_with_stdio(0);
  int a, b, n, m, d, k, T, cas = 0;
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    cin >> A[i];
  for (int i = 0; i < m; ++i) {
    cin >> a >> b;
    f[a] = max(f[a], b);
    f[b] = max(f[b], a);
  }
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (A[i] > f[A[i]])
      cnt++;
  }
  cout << cnt;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

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

  Graph tree(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a -= 1;
    b -= 1;
    tree[a].push_back(h[b]);
    tree[b].push_back(h[a]);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int i_h = h[i];
    bool ok = true;
    for (int d : tree[i]) {
      if (i_h <= d)
        ok = false;
    }
    if (ok)
      ans += 1;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.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<vector<int>> tree(n, vector<int>(n));
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a -= 1;
    b -= 1;
    tree[a].push_back(h[b]);
    tree[b].push_back(h[a]);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int i_h = h[i];
    int max_h = *max_element(tree[i].begin(), tree[i].end());
    if (i_h > max_h)
      ans += 1;
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long a[100005];
  int t[100005];
  int n, m;
  int i, j, k, ans;
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    cin >> a[i];
  for (i = 1; i <= n; i++)
    t[i] = 1;
  for (i = 1; i <= m; i++) {
    cin >> j >> k;
    if (a[j] > a[k])
      t[k] = 0;
    else
      t[j] = 0;
    if (a[k] == a[j]) {
      t[j] = 0;
      t[k] = 0;
    }
  }
  ans = 0;
  for (i = 1; i <= n; i++) {
    if (t[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  long long a[10005];
  int t[10005];
  int n, m;
  int i, j, k, ans;
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    cin >> a[i];
  for (i = 1; i <= n; i++)
    t[i] = 1;
  for (i = 1; i <= m; i++) {
    cin >> j >> k;
    if (a[j] > a[k])
      t[k] = 0;
    else
      t[j] = 0;
    if (a[k] == a[j]) {
      t[j] = 0;
      t[k] = 0;
    }
  }
  ans = 0;
  for (i = 1; i <= n; i++) {
    if (t[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int n, m;
int a, b;

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

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

  int count = 0;
  for (int i = 1; i < n + 1; i++) {
    if (bad[i] != 1) {
      count++;
    }
  }
  cout << count << endl;
}

Error: TLE

Fixed submission:

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

int n, m;
int a, b;

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

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

  int count = 0;
  bool flag = 0;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < n + 1; j++) {
      if (path[i][j] == 1) {
        if (h[i] <= h[j]) {
          flag = 1;
          break;
        }
      }
    }
    if (flag != 1) {
      count++;
    }
    flag = 0;
  }

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

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

int main(void) {
  // Your code here!
  int n, m;
  cin >> n >> m;

  vector<int> H(n);
  // int a,b;
  // vector<int> s(n);
  vector<int> ans(n, 1);

  vector<int> A(m);
  vector<int> B(m);

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

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

    if (H[A[i] - 1] <= H[B[i] - 1])
      ans[A[i] - 1] = 0;
    if (H[B[i] - 1] <= H[A[i] - 1])
      ans[B[i] - 1] = 0;
  }

  int ct = 0;

  for (int i = 0; i < n; i++)
    if (ans[i] == 1)
      ct++;
  // for(int i=0;i<n;i++) if(s[i]==0) ct++;
  cout << ct << endl;
}


Error: 0

Fixed submission:

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

int main(void) {
  // Your code here!
  int n, m;
  cin >> n >> m;

  vector<int> H(n);
  int a, b;
  vector<int> s(n);
  vector<vector<int>> mas(n, vector<int>(n));

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

  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    // cout<<a<<b<<endl;
    mas[a - 1][b - 1]++;
    mas[b - 1][a - 1]++;
    s[a - 1]++;
    s[b - 1]++;
  }

  int ct = 0;

  for (int i = 0; i < n; i++) {
    int c = 0;
    for (int j = 0; j < n; j++) {
      if (mas[i][j] > 0) {
        if (H[i] < H[j]) {
          break;
          // cout<<i<<" "<<j<<endl;
        } else
          c++;

        if (c == s[i]) {
          ct++;
          break;
        }
      }
    }
  }

  for (int i = 0; i < n; i++)
    if (s[i] == 0)
      ct++;
  cout << ct << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  int64_t n, m;
  cin >> n >> m;
  int64_t h[100000];
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  int64_t a[100000], b[100000];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }
  int s[100000] = {0};
  for (int i = 0; i < m; i++) {
    if (h[a[i] - 1] > h[b[i] - 1]) {
      s[b[i] - 1] = 1;
    } else if (h[a[i] - 1] < h[b[i] - 1]) {
      s[a[i] - 1] = 1;
    } else {
      s[a[i] - 1] = 1;
      s[b[i] - 1] = 1;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] != 0) {
      ans += 1;
    }
  }
  cout << n - ans;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int64_t h[100000];
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  int64_t a[100000], b[100000];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }
  int s[100000] = {0};
  for (int i = 0; i < n; i++) {
    if (h[a[i] - 1] >= h[b[i] - 1]) {
      s[b[i] - 1] = 1;
    }
    if (h[a[i] - 1] <= h[b[i] - 1]) {
      s[a[i] - 1] = 1;
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 1) {
      ans += 1;
    }
  }
  cout << n - ans;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, h[100001], ans, a[100001];
vector<int> v[100001];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    a[x]++;
    a[y]++;
    v[x].insert(v[x].begin() + a[x] - 1, y);
    v[y].insert(v[y].begin() + a[y] - 1, x);
  }
  for (int i = 1; i <= n; i++) {
    int fl = 1;
    if (v[i].size() == 0) {
      ans++;
      continue;
    }
    for (int j = 0; j <= v[i].size() - 1; j++) {
      if (h[i] <= h[v[i][j]]) {
        fl = 0;
        break;
      }
    }
    ans += fl;
  }
  cout << ans;
}


Error: -11

Fixed submission:

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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define faster                                                                 \\
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define ll long long
#define ld long double
#define endl "\\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define bins(v, x) binary_search(v.begin(), v.end(), x)
const double pi = 2 * acos(0.0);
const int INF = 1e9 + 1;
const int mod = 1e9 + 7;
const int mod1 = 998244353;

ll modExp(ll base, ll exp, ll mod) {
  ll res = 1;
  while (exp > 0) {
    if (exp % 2 == 1) {
      res = (res * base) % mod;
    }
    exp = exp >> 1;
    base = (base * base) % mod;
  }
  return res;
}

ll inverse(ll base, ll exp, ll mod) { return modExp(base, exp - 2, mod); }

bool compare(const pair<int, int> &i, const pair<int, int> &j) {
  return (i.S > j.S || (i.S == j.S && i.F > j.F));
}

void test() {
  int n, m;
  cin >> n >> m;

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

  int u, v;
  vector<int> adj[n + 1];
  for (int i = 1; i <= m; ++i) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  int good = 0;
  int maxe[n + 1] = {0};
  for (int i = 1; i <= n; ++i) {
    if (!adj[i].empty()) {
      int mx = -1;
      for (auto x : adj[i]) {
        mx = max(mx, h[x]);
      }
      maxe[i] = mx;
    }
  }

  for (int i = 1; i <= n; ++i) {
    if (adj[i].empty()) {
      good++;
    }
    if (h[i] > maxe[i] && maxe[i] != 0) {
      // cout << h[i] << " " << maxe[i] << endl;
      good++;
    }
  }

  cout << good;
}

int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  faster;
  cout.precision(10);
  cout << fixed;

  int t = 1;
  // cin >> t;
  while (t--)
    test();

  return 0;
}

Error: WA

Fixed submission:

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

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

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

  int u, v;
  vector<int> adj[n + 1];
  for (int i = 1; i <= m; ++i) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  int good = 0;
  for (int i = 1; i <= n; ++i) {
    if (adj[i].empty()) {
      good++;
    }
    if (h[i] > *max_element(adj[i].begin(), adj[i].end())) {
      good++;
    }
  }

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

#include <bits/stdc++.h>
#define st first
#define nd second

using ll = long long;
using namespace std;
using pii = pair<int, int>;
const int N = 1e5 + 10;
std::vector<int> gr[N];
int h[N];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &h[i]);
  }
  int x, y;
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &x, &y);
    gr[x].push_back(y);
    gr[y].push_back(x);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    bool io = true;
    for (auto it : gr[i]) {
      if (h[i] <= h[it]) {
        io = false;
        break;
      }
    }
    if (io)
      ans++;
  }
  printf("%d", ans);
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define st first
#define nd second

using ll = long long;
using namespace std;
using pii = pair<int, int>;
const int N = 1e5;
std::vector<int> gr[N];
int h[N];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &h[i]);
  }
  int x, y;
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &x, &y);
    gr[x].push_back(y);
    gr[y].push_back(x);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    bool io = true;
    for (auto it : gr[i]) {
      if (h[i] <= h[it]) {
        io = false;
        break;
      }
    }
    if (io)
      ans++;
  }
  printf("%d", ans);
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, M;
  cin >> N >> M;
  int high[N];
  int ma[N];
  for (int i = 1; i <= N; i++) {
    cin >> high[i];
    ma[i] = 0;
  }

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

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

Error: 0

Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> high(N);
  int ma[N];
  for (int i = 1; i <= N; i++) {
    cin >> high[i];
    ma[i] = 0;
  }

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

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

#include <bits/stdc++.h>
using namespace std;
#define loop for (int i = 0; i < n; i++)
#define pb push_back
#define int long long int
#define vi vector<int>
#define mod 1000000007
int32_t main() {
  int n;
  int m;
  cin >> n >> m;
  int val[n + 20];
  for (int i = 1; i <= n; i++) {
    int k;
    cin >> k;
    val[i] = k;
  }
  vector<int> adj[n + 1];
  while (m--) {
    int u;
    int v;
    cin >> u >> v;
    adj[u].pb(v);
    adj[v].pb(u);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int flag = true;
    for (auto j : adj[i]) {
      if (val[j] >= val[i]) {
        flag = false;
        break;
      }
    }
    if (flag == true) {
      // cout<<i<<endl;
      ans++;
    }
  }
  cout << ans;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define loop for (int i = 0; i < n; i++)
#define pb push_back
#define int long long int
#define vi vector<int>
#define mod 1000000007
int32_t main() {
  int n;
  int m;
  cin >> n >> m;
  int val[n + 20];
  for (int i = 1; i <= n; i++) {
    int k;
    cin >> k;
    val[i] = k;
  }
  vector<int> adj[n];
  while (m--) {
    int u;
    int v;
    cin >> u >> v;
    adj[u].pb(v);
    adj[v].pb(u);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int flag = true;
    if (adj[i].size() == 0)
      flag = false;
    for (auto j : adj[i]) {
      if (val[j] > val[i]) {
        flag = false;
        break;
      }
    }
    if (flag == true) {
      ans++;
    }
  }
  cout << ans;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
int N, M, H[100001], A, B, cnt;
int main() {
  cin >> N >> M;
  for (int i = 1; i <= N; i++)
    cin >> H[i];
  vector<vector<int>> data(N + 1);
  for (int i = 1; i <= M; i++) {
    cin >> A >> B;
    data.at(A).push_back(B);
    data.at(B).push_back(A);
  }

  for (int i = 1; i <= N; i++) {
    bool f = true;
    for (int j = 0; j < data.at(i).size(); j++) {
      if (H[i] <= H[data.at(i).at(j)]) {
        f = false;
        break;
      }
    }
    if (f)
      cnt++;
  }

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int N, M, H[100001], A[100001], B[100001], cnt;
int main() {
  cin >> N >> M;
  for (int i = 1; i <= N; i++)
    cin >> H[i];
  for (int i = 1; i <= M; i++)
    cin >> A[i] >> B[i];

  for (int i = 1; i <= N; i++) {
    bool f = true;
    for (int j = 1; j <= M; j++) {
      if ((A[j] == i && H[A[j]] <= H[B[j]]) ||
          (B[j] == i && H[B[j]] <= H[A[j]])) {
        f = false;
        break;
      }
    }
    if (f)
      cnt++;
  }

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^18 -> 18回
// double pi = M_PI or acos(-1)

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

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^18 -> 18回
// double pi = M_PI or acos(-1)

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> h(n);
  rep(i, n) cin >> h.at(i);
  vector<ll> a(m), b(m);
  rep(i, m) cin >> a.at(i) >> b.at(i);

  ll ans = 0;
  rep(i, n) { // 展望台ループ
    bool isOk = true;
    rep(j, m) {               // 道ループ
      if (i == a.at(j) - 1) { // a配列に値がある場合
        if (h.at(i) <= h.at(b.at(j) - 1)) {
          isOk = false;
          break;
        }
      } else if (i == b.at(j) - 1) { // b配列に値がある場合
        if (h.at(i) <= h.at(a.at(j) - 1)) {
          isOk = false;
          break;
        }
      }
    }
    if (isOk) {
      ans++;
    }
  }

  cout << ans << endl;

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

#include "bits/stdc++.h"
#include "math.h"

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll, ll>> vp;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define drep(i, a, b) for (ll i = (a); i > (b); --i)
const int MOD = 1000000007;
const int MAX = 510000;

int main() {
  ll n, m, ans = 0;
  cin >> n >> m;
  vll h(n + 1, 0);
  vb ok(n + 1, true);
  rep(i, 1, n + 1) { cin >> h[i]; }
  rep(i, 0, m) {
    ll a, b;
    cin >> a >> b;
    if (h[a] > h[b]) {
      ok[b] = false;
    }
    if (h[a] < h[b]) {
      ok[a] = false;
    }
    if (h[a] == h[b]) {
      ok[a] = false;
      ok[b] = false;
    }
  }
  rep(i, 1, n + 1) {
    if (ok[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include "bits/stdc++.h"
#include "math.h"

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll, ll>> vp;
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define drep(i, a, b) for (ll i = (a); i > (b); --i)
const int MOD = 1000000007;
const int MAX = 510000;

int main() {
  ll n, m, ans = 0;
  cin >> n >> m;
  vll h(n);
  vvll road(n, vll(n, 0));
  vb ok(n, true);
  rep(i, 0, n) { cin >> h[i]; }
  rep(i, 0, m) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    if (h[a] > h[b]) {
      ok[b] = false;
    }
    if (h[a] < h[b]) {
      ok[a] = false;
    }
    if (h[a] == h[b]) {
      ok[a] = false;
      ok[b] = false;
    }
  }
  rep(i, 0, n) {
    if (ok[i]) {
      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;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  vector<int> check(N);
  for (int j = 0; j < M; j++) {
    int A, B;
    cin >> A >> B;
    if (vec.at(A - 1) > vec.at(B - 1)) {
      check.at(B - 1) = 1;
    } else if (vec.at(A - 1) == vec.at(B - 1)) {
      check.at(A - 1) = 1;
      check.at(B - 1) = 1;
    } else if (vec.at(A - 1) < vec.at(B - 1)) {
      check.at(A - 1) = 1;
    }
  }
  int count = 0;
  for (int n = 0; n < N; n++) {
    if (check.at(n) == 0)
      count++;
  }
  cout << count << endl;
}


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


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  for (int j = 0; j < M; j++) {
    int A, B;
    cin >> A >> B;
    if (vec.at(A) == vec.at(B)) {
      vec.at(A - 1) = 0;
      vec.at(B - 1) = 0;
    } else if (vec.at(A) < vec.at(B)) {
      vec.at(A - 1) = 0;
    }
  }
  int count = 0;
  for (int n = 0; n < N; n++) {
    if (vec.at(n) != 0)
      count++;
  }
  cout << count << endl;
}