alexjercan/bugnet huggingface dataset:
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;
using ll = long long int;

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<vector<int>> to(n);
  rep(i, n) cin >> h[i];
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  int cnt = 0;
  rep(i, n) {
    bool b = true;
    for (int j = 0; j < to[i].size(); j++) {
      if (h[i] <= h[to[i][j]])
        b = false;
    }
    if (b)
      cnt++;
  }
  cout << cnt << endl;
}

Error: -11

Fixed submission:

#include <iostream>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
using ll = long long int;

int main(void) {
  int n, m;
  vector<int> h(n);
  vector<vector<int>> to(n);
  cin >> n >> m;
  rep(i, n) cin >> h[i];
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  int cnt = 0;
  rep(i, n) {
    bool b = true;
    for (int j = 0; j < to[i].size(); j++) {
      if (h[i] <= h[to[i][j]])
        b = false;
    }
    if (b)
      cnt++;
  }
  cout << cnt << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long N, M;
  cin >> N >> M;
  vector<long long> h(N), A(M), B(M);
  vector<pair<long long, long long>> H(N), C(M);
  vector<bool> F(N, true);
  map<long long, long long> mp;
  for (int i = 0; i < N; i++) {
    cin >> h[i];
    H[i] = make_pair(h[i], i + 1);
    mp[i + 1] = h[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
    C[i] = make_pair(A[i], B[i]);
  }
  long long ans = 0;
  // sort(H.begin(),H.end());
  for (int i = 0; i < M; i++) {
    if (mp[A[i]] > mp[B[i]]) {
      F[B[i] - 1] = false;
    } else if (mp[A[i]] < mp[B[i]])
      F[A[i] - 1] = false;
    else
      F[B[i] - 1] = F[A[i] - 1] = false;
  }
  for (int i = 0; i < N; i++) {
    if (F[i] == true)
      ans++;
  }
  /*for(int i = 0; i < N; i++){
      bool flag = true;
      for(int j = 0; j < M; j++){
          if(A[j] == H[i].second && mp[B[j]] >= mp[A[j]]){
              flag = false;
              break;
          }
          else if(B[j] == H[i].second && mp[A[j]] >= mp[B[j]]){
              flag = false;
              break;
          }
      }
      if(flag == true) ans++;
  }*/
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long N, M;
  cin >> N >> M;
  vector<long long> h(N), A(M), B(M);
  vector<pair<long long, long long>> H(N), C(M);
  map<long long, long long> mp;
  for (int i = 0; i < N; i++) {
    cin >> h[i];
    H[i] = make_pair(h[i], i + 1);
    mp[i + 1] = h[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
    C[i] = make_pair(A[i], B[i]);
  }
  long long ans = 0;
  sort(H.begin(), H.end());
  for (int i = 0; i < N; i++) {
    bool flag = true;
    for (int j = 0; j < M; j++) {
      if (A[j] == H[i].second && mp[B[j]] >= mp[A[j]]) {
        flag = false;
        break;
      } else if (B[j] == H[i].second && mp[A[j]] >= mp[B[j]]) {
        flag = false;
        break;
      }
    }
    if (flag == true)
      ans++;
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 100010;
int h[N];
struct edge {
  int v;
  int next;
} e[2 * N];
int p[N], eid;
void init() {
  memset(p, -1, sizeof(p));
  eid = 0;
}
void insert(int u, int v) {
  e[eid].v = v;
  e[eid].next = p[u];
  p[u] = eid++;
}
int main() {
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  ios::sync_with_stdio(false);
  init();
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    insert(u, v);
    insert(v, u);
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    int maxn = -1;
    for (int j = p[i]; j != -1; j = e[j].next) {
      int v = e[j].v;
      maxn = max(maxn, h[v]);
    }
    if (h[i] > maxn) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 100010;
int h[N];
struct edge {
  int v;
  int next;
} e[N];
int p[N], eid;
void init() {
  memset(p, -1, sizeof(p));
  eid = 0;
}
void insert(int u, int v) {
  e[eid].v = v;
  e[eid].next = p[u];
  p[u] = eid++;
}
int main() {
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  ios::sync_with_stdio(false);
  init();
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    insert(u, v);
    insert(v, u);
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    int maxn = -1;
    for (int j = p[i]; j != -1; j = e[j].next) {
      int v = e[j].v;
      maxn = max(maxn, h[v]);
    }
    if (h[i] > maxn) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <functional>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> H(n);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> H[i];
  }
  vector<int> a(m);
  vector<int> b(m);
  vector<int> ABcount(n);
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    ABcount[a[i] - 1]++;
    ABcount[b[i] - 1]++;
  }
  int ABcountsub[100001] = {};
  for (int i = 0; i < m; i++) {
    if (H[a[i] - 1] > H[b[i] - 1]) {
      ABcountsub[a[i] - 1]++;
    } else if (H[a[i] - 1] < H[b[i] - 1]) {
      ABcountsub[b[i] - 1]++;
    }
  }

  for (int i = 0; i < n; i++) {
    if (ABcount[i] == ABcountsub[i]) {
      sum++;
    }
  }
  cout << sum;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <functional>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> H(n);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> H[i];
  }
  vector<int> a(m);
  vector<int> b(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }
  vector<int> ABcount(n);
  for (int i = 1; i <= n; i++) {
    long abcount = 0;
    abcount = (int)std::count(a.begin(), a.end(), i) +
              (int)std::count(b.begin(), b.end(), i);
    ABcount[i - 1] = abcount;
  }
  int ABcountsub[100001] = {};
  for (int i = 0; i < m; i++) {
    if (H[a[i] - 1] > H[b[i] - 1]) {
      ABcountsub[a[i] - 1]++;
    } else if (H[a[i] - 1] < H[b[i] - 1]) {
      ABcountsub[b[i] - 1]++;
    }
  }

  for (int i = 0; i < n; i++) {
    if (ABcount[i] == ABcountsub[i]) {
      sum++;
    }
  }
  cout << sum;

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

#include "bits/stdc++.h"

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define SORT(v, n) std::sort(v, v + n);
#define VSORT(v) std::sort(v.begin(), v.end());
#define VRSORT(v) std::sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int n, m, ans, a, b;
int h[100001], out[100001];

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

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

  for (int i = 1; i <= m; i++) {
    cin >> a >> b;

    if (h[a] >= h[b])
      out[b] = 1;

    if (h[b] >= h[a])
      out[a] = 1;
  }

  for (int i = 1; i <= n; i++)
    if (!out[i])
      ans++;

  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define SORT(v, n) std::sort(v, v + n);
#define VSORT(v) std::sort(v.begin(), v.end());
#define VRSORT(v) std::sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(void) {
  int n, m;
  int good = 0;
  vector<int> H;         // 各ノードの高さ
  vector<int> G[100001]; // 各グラフ要素に対し、接続するノードの高さ
  cin >> n >> m;
  REP(i, n) {
    int tmp;
    cin >> tmp;
    H.push_back(tmp);
  }

  REP(i, m) {
    int a, b;
    cin >> a >> b;
    a = a - 1;
    b = b - 1;
    G[a].push_back(H[b]);
    G[b].push_back(H[a]);
  }

  REP(i, n) {
    int max = *max_element(ALL(G[i]));
    if (H[i] > max)
      good++;
  }

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

#include "bits/stdc++.h"
#define rep(i, cc, n) for (int i = cc; i < (n); ++i)
#define drep(i, cc, n) for (int i = cc; i > (n); --i)
using namespace std;
using ll = long long;

int main() {
  int N, M, count = 0, now;
  // string S;
  cin >> N >> M;
  vector<int> H(N), 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]); // ノードAに対するノードBの中における最大値
    ma[b] = max(ma[b], H[a]); // ノードBに対するノードAの中における最大値
  }
  rep(i, 0, N) {
    if (H[i] > ma[i])
      ++count;
  }
  cout << count << endl;
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"
#define rep(i, cc, n) for (int i = cc; i < (n); ++i)
#define drep(i, cc, n) for (int i = cc; i > (n); --i)
using namespace std;
using ll = long long;

int main() {
  int N, M, count = 0, max = 0;
  // string S;
  cin >> N >> M;
  vector<ll> H(N);
  vector<int> A(M), B(M), c(N); // c = hens
  vector<vector<int>> hen(N, vector<int>(N));
  rep(i, 0, N) { cin >> H[i]; }
  rep(i, 0, M) {
    cin >> A[i] >> B[i];
    ++c[A[i] - 1];
    ++c[B[i] - 1];
    hen[A[i]][c[A[i]]] = B[i];
  }

  rep(i, 0, N) {
    if (c[i] == 0)
      ++count;
    else {
      max = 1;
      rep(j, 0, c[i]) {
        if (H[i] <= H[hen[i][j]])
          max = 0;
      }
      if (max > 0)
        count++;
    }
  }
  cout << count << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define eb emplace_back
// #define st first
#define sc second

using namespace std;

const ll mod = 1e9 + 7;
const int e = 1e5 + 69;
const int base = 311;

// dung inverse module de tinh nCk
// beginer 78
// mbeginer
// cach tao hoan vi tu n so : n*(n+1)/2;

// vector<pair<ll,ll>>adj[e];
vector<ll> adj[e];

/*ll Pow(ll n, ll dem)
{
    if(dem == 0) return 1;
    if(dem == 1) return n ;
    ll t = Pow(n, dem/2);
    if(dem % 2 == 0) return (t*t);
    else return ((t * t) * n);
}*/

/*ll C(ll k, ll n)
{
    if(k == 0) return 1;
    if(n < k) return 0;
    return (gt[n]%mod * (igt[k]%mod * igt[n-k]%mod)%mod)%mod;
}*/

int n, m, k;
ll h[e];

int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  map<ll, ll> kt;
  for (int i = 1; i <= m; i++) {
    ll u, v;
    cin >> u >> v;
    // adj[u].pb(v);
    // adj[v].pb(u);
    if (h[u] >= h[v])
      kt[v]++;
    if (h[v] >= h[u])
      kt[u]++;
  }
  ll dem = 0;
  for (int i = 1; i <= n; i++) {
    if (kt[i] == 0)
      dem++;
  }
  cout << dem;
}
/*

*/


Error: WA

Fixed submission:

#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define eb emplace_back
// #define st first
#define sc second

using namespace std;

const ll mod = 1e9 + 7;
const int e = 50 + 69;
const int base = 311;

// dung inverse module de tinh nCk
// beginer 78
// mbeginer
// cach tao hoan vi tu n so : n*(n+1)/2;

// vector<pair<ll,ll>>adj[e];
vector<ll> adj[e];

/*ll Pow(ll n, ll dem)
{
    if(dem == 0) return 1;
    if(dem == 1) return n ;
    ll t = Pow(n, dem/2);
    if(dem % 2 == 0) return (t*t);
    else return ((t * t) * n);
}*/

/*ll C(ll k, ll n)
{
    if(k == 0) return 1;
    if(n < k) return 0;
    return (gt[n]%mod * (igt[k]%mod * igt[n-k]%mod)%mod)%mod;
}*/

int n, m, k;
ll h[e];

int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  map<ll, ll> kt;
  for (int i = 1; i <= m; i++) {
    ll u, v;
    cin >> u >> v;
    // adj[u].pb(v);
    // adj[v].pb(u);
    if (h[u] > h[v])
      kt[u]++;
    else
      kt[v]++;
  }
  ll dem = 0;
  for (int i = 1; i <= n; i++) {
    if (kt[i] > 0)
      dem++;
  }
  cout << dem;
}
/*

*/
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

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

  vector<int> H(N, 0);
  vector<int> A(M, 0);
  vector<int> B(M, 0);

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

  for (int i = 0; i < M; i++) {
    cin >> A.at(i) >> B.at(i);
  }

  vector<int> good(N, 1);

  for (int i = 0; i < M; i++) {
    if (H.at(A.at(i) - 1) > H.at(B.at(i) - 1)) {
      good.at(B.at(i) - 1) = 0;
    } else if (H.at(A.at(i) - 1) == H.at(B.at(i) - 1)) {
      good.at(A.at(i) - 1) = 0;
      good.at(B.at(i) - 1) = 0;
    } else {
      good.at(A.at(i) - 1) = 0;
    }
  }

  int count = 0;
  for (int i = 0; i < N; i++) {
    if (good.at(i)) {
      count++;
    }
  }
  cout << count;
}

Error: WA

Fixed submission:

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

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

  vector<int> H(N, 0);
  vector<int> A(M, 0);
  vector<int> B(M, 0);

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

  for (int i = 0; i < M; i++) {
    cin >> A.at(i) >> B.at(i);
  }

  int count = 0;
  bool judge = true;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (i == A.at(j) && H.at(i) <= H.at(B.at(j))) {
        judge = false;
        break;
      }
      if (i == B.at(j) && H.at(i) <= H.at(A.at(j))) {
        judge = false;
        break;
      }
    }
    if (judge == true) {
      count++;
    }
    judge = true;
  }

  for (int i = 0; i < M; i++) {
    for (int j = i + 1; j < M; j++) {
      if (A.at(i) == A.at(j) && B.at(i) == B.at(j)) {
        count--;
      } else if (A.at(i) == B.at(j) && B.at(i) == A.at(j)) {
        count--;
      }
    }
  }

  cout << count;
}
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;

int h[100010], a[100010], b[100010];
int ans = 0;

int main() {
  int n, m;
  cin >> n >> m;
  rep(i, n) cin >> h[i];
  rep(j, m) cin >> a[j] >> b[j];

  bool checked[n];
  memset(checked, true, sizeof(checked));

  rep(j, m) {
    if (h[a[j] - 1] > h[b[j] - 1])
      checked[b[j] - 1] = false;
    else if (h[a[j] - 1] < h[b[j] - 1])
      checked[a[j] - 1] = false;
    else {
      checked[a[j] - 1] = false;
      checked[b[j] - 1] = false;
    }
  }

  rep(i, n) if (checked[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;

bool checked[100010];
int h[100010], a[100010], b[100010];
int ans = 0;

bool highest(int i, int m) {
  checked[i] = true;
  int max = h[i];

  rep(j, m) {
    if (a[j] == i + 1) {
      if (max <= h[b[j] - 1]) {
        return false;
      } else
        checked[b[j] - 1] = true;
    } else if (b[j] == i + 1) {
      if (max <= h[a[j] - 1]) {
        return false;
      } else
        checked[a[j] - 1] = true;
    }
  }
  return true;
}

int main() {
  int n, m;
  cin >> n >> m;
  rep(i, n) cin >> h[i];
  rep(j, m) cin >> a[j] >> b[j];

  rep(i, n) {
    if (checked[i] == false) {
      if (highest(i, m))
        ans++;
    }
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#define in(n, m) for (int i = n; i < m; i++)
#define inj(n, m) for (int j = n; j < m; j++)
#define ink(n, m) for (ll k = n; k < m; k++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1LL << 60;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
#define N 100000

int main() {
  int n, M;
  cin >> n >> M;
  int H[N], ma[N];

  in(1, n + 1) {
    cin >> H[i];
    ma[i] = 0;
  }
  in(0, M) {
    int a, b;
    cin >> a >> b;
    ma[a] = max(ma[a], H[b]);
    ma[b] = max(ma[b], H[a]);
  }

  int ans = 0;
  in(1, n + 1) { ans += H[i] > ma[i]; }

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


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#define in(n, m) for (int i = n; i < m; i++)
#define inj(n, m) for (int j = n; j < m; j++)
#define ink(n, m) for (ll k = n; k < m; k++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1LL << 60;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ll N, M;
  cin >> N >> M;
  ll H[10000], ma[10000];

  in(1, N + 1) {
    cin >> H[i];
    ma[i] = 0;
  }
  in(0, M) {
    int a, b;
    cin >> a >> b;
    ma[a] = max(ma[a], H[b]);
    ma[b] = max(ma[b], H[a]);
  }

  int ans = 0;
  in(1, N + 1) { 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() {
  long long N, M;
  cin >> N >> M;
  vector<long long> Lighthouse(N);
  for (int i = 0; i < N; i++) {
    cin >> Lighthouse.at(i);
  }
  vector<int> Good(N, 1);
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    if (Lighthouse.at(A - 1) > Lighthouse.at(B - 1)) {
      Good.at(B - 1) = 0;
    } else if (Lighthouse.at(A - 1) < Lighthouse.at(B - 1)) {
      Good.at(A - 1) = 0;
    } else if (Lighthouse.at(A - 1) == Lighthouse.at(B - 1)) {
      Good.at(A - 1) = 0;
      Good.at(B - 1) = 0;
    }
  }
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    cnt += Good.at(i);
  }
  cout << cnt << endl;
}

Error: 0

Fixed submission:

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

int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> Lighthouse(N);
  for (int i = 0; i < N; i++) {
    cin >> Lighthouse.at(i);
  }
  vector<vector<long long>> Road(N, vector<long long>(N));
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    Road.at(A - 1).at(B - 1) = Lighthouse.at(B - 1);
    Road.at(B - 1).at(A - 1) = Lighthouse.at(A - 1);
  }
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    bool good = true;
    for (int j = 0; j < N; j++) {
      if (Lighthouse.at(i) <= Road.at(i).at(j))
        good = false;
    }
    if (good)
      cnt++;
  }
  cout << cnt << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

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


Error: 0

Fixed submission:

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

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

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

int main() {
  int n, m;
  bitset<100000> bad;
  cin >> n >> m;
  vector<int> hight(n);
  rep(i, n) cin >> hight.at(i);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    if (hight.at(a - 1) <= hight.at(b - 1))
      bad.set(a - 1, 1);
    if (hight.at(b - 1) <= hight.at(a - 1))
      bad.set(b - 1, 1);
  }
  int result = n;
  rep(i, n) if (bad.test(i)) result--;
  cout << result << endl;
}

Error: TLE

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;
  cin >> n >> m;
  vector<int> hight(n);
  vector<pair<int, int>> AtoB(m);
  rep(i, n) cin >> hight.at(i);
  rep(i, m) cin >> AtoB.at(i).first >> AtoB.at(i).second;
  bitset<100000> bad;
  rep(i, n) {
    rep(j, m) {
      if (AtoB.at(j).first - 1 == i) {
        if (hight.at(i) <= hight.at(AtoB.at(j).second - 1)) {
          bad.set(i, 1);
          break;
        }
      }
      if (AtoB.at(j).second - 1 == i) {
        if (hight.at(i) <= hight.at(AtoB.at(j).first - 1)) {
          bad.set(i, 1);
          break;
        }
      }
    }
  }
  int result = n;
  rep(i, n) if (bad.test(i)) result--;
  cout << result << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define int long long

const int N = 1e5 + 5;

int n, m;
int a[N];
vector<int> g[N];

int32_t main() {
  IOS;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int ct = 0;
    for (auto &it : g[i])
      if (a[i] <= a[it])
        ct++;
    ans += (ct == 0);
  }
  cout << ans;
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define lli long long int
#define N 2e5 + 5
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;

int n, m;

int main() {
  IOS;
  cin >> n >> m;
  vector<int> h(n);
  vector<vector<int>> adj(n);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    h.push_back(a);
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int c = 0;
    for (auto &j : adj[i]) {
      if (h[j] >= h[i]) {
        c++;
      }
    }
    ans += (c == 0);
  }

  cout << ans << endl;
}