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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;
int main() {
  int n, m;
  cin >> n >> m;

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

  bool flag[n];
  fill(flag, flag + n, true);

  for (int i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    if (h[a - 1] > h[b - 1])
      flag[b - 1] = false;
    else if (h[a - 1] < h[b - 1])
      flag[a - 1] = false;
    else if (h[a - 1] == h[b - 1]) {
      flag[a - 1] = false;
      flag[b - 1] = false;
    }
  }

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


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

long long digit(long long n) {
  long long ans = 0;
  while (n > 0) {
    n /= 10;
    ans++;
  }
  return ans;
}

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

  vector<int> h(n);
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }
  int a, b;
  bool ans[100];
  for (int i = 1; i <= 100; i++) {
    ans[i] = true;
  }
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    if (h[a] > h[b]) {
      ans[b] = false;
    } else if (h[b] > h[a]) {
      ans[a] = false;
    }
  }
  int tmp = 1;
  for (int i = 1; i <= n; i++) {
    if (h[i] == true)
      tmp++;
  }
  cout << tmp << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  map<int, vector<int>> graph;
  vector<int> h(n, 0);
  vector<int> connect(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    connect[a]++;
    connect[b]++;
    graph[a].push_back(b);
  }
  int total = 0;
  vector<int> ans(n, 0);

  for (auto it : graph) {
    int obs = it.first;
    for (auto ele : it.second) {
      if (h[obs] > h[ele]) {
        ans[obs]++;
      } else if (h[obs] < h[ele]) {
        ans[ele]++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (connect[i] == ans[i] || (connect[i] == 0 && ans[i] == 0)) {
      total++;
    }
  }
  cout << total;
  return 0;
}


Error: WA

Fixed submission:

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

int ans = 0;

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

  vector<int> connect(n, 0);

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    connect[a]++;
    connect[b]++;
  }
  int total = 0;
  vector<int> ans(n, 0);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < graph[i].size(); j++) {
      if (h[i] > h[graph[i][j]]) {
        ans[i]++;
      } else {
        ans[graph[i][j]]++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (ans[i] == connect[i] || (connect[i] == 0 && ans[i] == 0))
      total++;
  }
  cout << total;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<int> adj[100010];
int a[100010];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    int m = adj[i].size(), f = 1;
    for (int j = 0; j < m; j++)
      if (a[i] <= a[adj[i][j]])
        f = 0;
    // cout<<f<<'\\n';

    res += f;
  }

  cout << res;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<int> adj[100010];
int a[100010];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    int m = adj[a[i]].size(), f = 1;
    for (int j = 0; j < m; j++)
      if (a[i] < adj[a[i]][j])
        f = 0;
    res += f;
  }

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

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<long> H(N);
  vector<bool> highest(N, true);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    if (H[a - 1] > H[b - 1]) {
      highest[b - 1] = false;
    } else if (H[a - 1] < H[b - 1]) {
      highest[a - 1] = false;
    } else {
      highest[a - 1] = false;
      highest[b - 1] = false;
    }
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (highest[i]) {
      count += 1;
    }
  }
  cout << count << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<long> H(N);
  vector<vector<bool>> road(N, vector<bool>(N));
  vector<bool> jimei(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  vector<int> neighbor(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    road[a - 1][b - 1] = true;
    road[b - 1][a - 1] = true;
    neighbor[a - 1] += 1;
    neighbor[b - 1] += 1;
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (jimei[i])
      continue;
    if (neighbor[i] == 0) {
      count += 1;
      continue;
    }
    bool good = true;
    int k = 0;
    for (int j = 0; j < N; j++) {
      if (i == j)
        continue;
      if (road[i][j]) {
        if (H[i] > H[j]) {
          jimei[j] = true;
          k += 1;
          if (neighbor[i] == k)
            break;
        } else {
          jimei[i] = true;
          good = false;
          break;
        }
      }
    }
    if (good)
      count += 1;
  }
  cout << count << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

#define INF (int)1e9 + 7
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rrep(i, a, b) for (int i = a; i >= b; --i)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<long long>>
#define pii pair<int, int>
#define pll pair<long, long>
#define vpii vector<pii>
#define vpll vector<pll>
#define N 100005
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795

ll binPowM(ll a, ll b, ll m) {
  ll ans = 1;
  while (b > 0) {
    if (b & 1)
      ans = ans * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return ans % m;
}
ll f(ll x, ll y, ll a) { return (a & x) * (a & y); }

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[n + 1];
  for (int i = 1; i <= m; i++) {
    ll x, y;
    cin >> x >> y;

    a[x].push_back(y);
    a[y].push_back(x);
  }
  ll cnt = 0;
  for (int i = 1; i <= n; i++) {
    ll ans = h[i];
    ll flag = 0;
    for (int j = 0; j < a[i].size(); j++) {
      if (ans <= h[a[i][j]]) {
        flag = 1;
        break;
      }
    }
    if (!flag)
      cnt++;
  }
  cout << cnt << "\\n";
  return 0;
}


Error: 0

Fixed submission:

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

#define INF (int)1e9 + 7
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rrep(i, a, b) for (int i = a; i >= b; --i)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<long long>>
#define pii pair<int, int>
#define pll pair<long, long>
#define vpii vector<pii>
#define vpll vector<pll>
#define N 100005
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795

ll binPowM(ll a, ll b, ll m) {
  ll ans = 1;
  while (b > 0) {
    if (b & 1)
      ans = ans * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return ans % m;
}
ll f(ll x, ll y, ll a) { return (a & x) * (a & y); }

int main() {
  ll n, m;
  cin >> n >> m;
  vector<int> h(n + 1);
  for (int i = 1; i <= m; i++) {
    cin >> h[i];
  }
  vector<int> a[n + 1];
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;

    a[x].push_back(y);
    a[y].push_back(x);
  }
  ll cnt = 0;
  for (int i = 1; i <= n; i++) {
    ll ans = h[i];
    ll flag = 0;
    for (int j = 0; j < a[i].size(); j++) {
      if (ans <= h[a[i][j]]) {
        flag = 1;
        break;
      }
    }
    if (!flag)
      cnt++;
  }
  cout << cnt << "\\n";
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int ans, h[100002], n, m, x, y, l;
vector<int> ar[100002];
bool ok;

int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    ar[x].push_back(y);
    ar[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    l = ar[i].size();
    ok = true;
    for (int j = 0; j < l; j++) {
      if (h[i] <= h[ar[i][j]])
        ok = false;
      // cout<<i<<" "<<h[i]<<" "<<h[ar[i][j]]<<"\\n";
    }
    if (ok == true)
      ans++;
    // cout<<h[i]<<" "<<h[ar[i][j]]<<"\\n";
  }
  cout << ans << "\\n";
}

Error: 0

Fixed submission:

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

int ans, h[100000], n, m, x, y, l;
vector<int> ar[100000];
bool ok;

int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    ar[x].push_back(y);
    ar[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    l = ar[i].size();
    ok = true;
    for (int j = 0; j < l; j++) {
      if (h[i] <= h[ar[i][j]])
        ok = false;
      // cout<<i<<" "<<h[i]<<" "<<h[ar[i][j]]<<"\\n";
    }
    if (ok == true)
      ans++;
    // cout<<h[i]<<" "<<h[ar[i][j]]<<"\\n";
  }
  cout << ans << "\\n";
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
typedef pair<int, int> P;

int main() {
  int N, M, tmp;
  cin >> N >> M;
  vector<int> H, ans;
  for (int i = 0; i < N; i++) {
    cin >> tmp;
    H.push_back(tmp);
    ans.push_back(1);
  }
  vector<int> A, B;
  int tmpa, tmpb;
  for (int i = 0; i < M; i++) {
    cin >> tmpa >> tmpb;
    if (H[tmpa - 1] >= H[tmpb - 1]) {
      ans[tmpb - 1] = 0;
    }
    if (H[tmpb - 1] >= H[tmpa - 1]) {
      ans[tmpa - 1] = 0;
    }
  }
  int sum = 0;
  for (int i = 0; i < N; ++i) {
    sum += ans[i];
  }
  cout << sum << endl;

  return 0;
}

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 <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
typedef pair<int, int> P;

int main() {
  long N, M, tmp;
  cin >> N >> M;
  vector<long> H, ans;
  for (long i = 0; i < N; i++) {
    cin >> tmp;
    H.push_back(tmp);
    ans.push_back(1);
  }
  vector<long> A, B;
  long tmpa, tmpb;
  for (long i = 0; i < M; i++) {
    cin >> tmpa >> tmpb;
    if (H.at(tmpa) >= H.at(tmpb)) {
      ans.at(tmpb) = 0;
    }
    if (H.at(tmpb) >= H.at(tmpa)) {
      ans.at(tmpa) = 0;
    }
  }
  long sum = 0;
  for (long i = 0; i < N; ++i) {
    sum += ans.at(i);
  }
  cout << sum << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> H(n);
  vector<int> good_tenbo;

  for (int i = 0; i < n; i++) {
    cin >> H.at(i);
    good_tenbo.push_back(0);
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    good_tenbo.at(a - 1) = max(good_tenbo.at(a - 1), H.at(b - 1));
    good_tenbo.at(b - 1) = max(good_tenbo.at(b - 1), H.at(a - 1));
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += H.at(i) > good_tenbo.at(i);
  }
  cout << ans << endl;
  return 0;
}

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


Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> H(n);
  unordered_set<int> good_tenbo;
  vector<vector<int>> AB(m, vector<int>(2));

  for (int i = 0; i < n; i++) {
    cin >> H.at(i);
    good_tenbo.insert(i);
  }
  for (int i = 0; i < m; i++) {
    int a;
    int b;
    cin >> AB.at(i).at(0);
    cin >> AB.at(i).at(1);

    int Ha = H.at(a);
    int Hb = H.at(b);

    if (Ha < Hb) {
      good_tenbo.insert(b);
      good_tenbo.erase(a);
    } else if (Ha > Hb) {
      good_tenbo.insert(a);
      good_tenbo.erase(b);
    } else {
      good_tenbo.erase(b);
      good_tenbo.erase(a);
    }
  }
  cout << good_tenbo.size() << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>; // グラフ型
using pint = pair<int, int>;

int main() {
  int N, M;
  cin >> N >> M;
  vector<long long> H(N);
  REP(i, N)
  cin >> H[i];
  vector<int> G(N, 1);
  vector<bool> seen(N, false);
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (H[a] > H[b]) {
      G[b] = 0;
    } else if (H[a] == H[b]) {
      G[a] = G[b] = 0;
    } else {
      G[a] = 0;
    }
  }

  ll ans = 0;
  REP(i, N) { ans += G[i]; }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>; // グラフ型
using pint = pair<int, int>;

int main() {
  int N, M;
  cin >> N >> M;
  vector<long long> H(N);
  REP(i, N)
  cin >> H[i];
  vector<vector<ll>> G(N, vector<ll>(N));
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(H[b]);
    G[b].push_back(H[a]);
  }
  ll ans = 0;
  REP(i, N) {
    bool ok = true;
    for (auto g : G[i]) {
      if (g >= H[i]) {
        ok = false;
      }
    }
    if (ok)
      ans++;
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <cmath>
#include <ctime>
#include <map>
#include <math.h>
#define R(i, n) for (int i = 0; i < n; i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SL(a) scanf("%lld", &a)
#define SL2(a, b) scanf("%lld%lld", &a, &b)
#define SL3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define SA(i, n, a) R(i, n) scanf("%d", a + i)
#define SAL(i, n, a) R(i, n) scanf("%lld", a + i)
#define SC(a) scanf("%c", &a);
#define P(a) printf("%d", a)
#define PL(a) printf("%lld", a)
using namespace std;
using ll = long long;
using PR = pair<int, int>;
const ll MOD = 1e+9 + 7;
const int INF = 1e+9;

int N, M, H[100000];

int main() {
  S2(N, M);
  SA(i, N, H);
  vector<vector<int>> g(N);
  R(i, M) {
    int a = 1, b = 1;
    S2(a, b);
    g[a - 1].push_back(b - 1);
    g[b - 1].push_back(a - 1);
  }
  int ans = 0;
  R(i, N) {
    priority_queue<int> hei;
    R(j, g[i].size()) { hei.push(H[g[i][j]]); }
    if (hei.empty())
      ans++;
    else {
      if (hei.top() < H[i])
        ans++;
    }
  }
  P(ans);
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <cmath>
#include <ctime>
#include <map>
#include <math.h>
#define R(i, n) for (int i = 0; i < n; i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SL(a) scanf("%lld", &a)
#define SL2(a, b) scanf("%lld%lld", &a, &b)
#define SL3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define SA(i, n, a) R(i, n) scanf("%d", a + i)
#define SAL(i, n, a) R(i, n) scanf("%lld", a + i)
#define SC(a) scanf("%c", &a);
#define P(a) printf("%d", a)
#define PL(a) printf("%lld", a)
using namespace std;
using ll = long long;
using PR = pair<int, int>;
const ll MOD = 1e+9 + 7;
const int INF = 1e+9;

int N, M, H[100000];

int main() {
  S2(N, M);
  SA(i, N, H);
  vector<int> g[100000];
  R(i, M) {
    int a = 1, b = 1;
    S2(a, b);
    g[a - 1].push_back(b - 1);
    g[b - 1].push_back(a - 1);
  }
  int ans = 0;
  R(i, N) {
    priority_queue<int> hei;
    R(j, g[i].size()) { hei.push(H[g[i][j]]); }
    if (hei.empty())
      ans++;
    if (hei.top() < H[i])
      ans++;
  }
  P(ans);
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> H(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> H[i];
  }
  vector<int> flag(n, 1);
  int s, t;
  for (int i = 0; i < m; i++) {
    cin >> s >> t;
    s--;
    t--;
    int hs = H[s];
    int ht = H[t];
    if (hs == ht) {
      flag[t] = 0;
      flag[s] = 0;
    }
    if (hs > ht) {
      flag[t] = 0;
    }
    if (hs < ht) {
      flag[s] = 0;
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (flag[i] == 1) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
static const int MAX = 100000;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> H(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> H[i];
  }
  int G[n][n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      G[i][j] = MAX;
    }
  }
  vector<int> flag(n, 1);

  int s, t;
  for (int i = 0; i < m; i++) {
    cin >> s >> t;
    s--;
    t--;
    // G[s][t]=1;
    // G[t][s]=1;
    if ((H[s] == H[t])) {
      flag[t] = 0;
      flag[s] = 0;
    }
    if ((flag[s] == 1) && (flag[t] == 1) && (H[s] > H[t])) {
      flag[t] = 0;
    }
    if ((flag[s] == 1) && (flag[t] == 1) && (H[s] < H[t])) {
      flag[s] = 0;
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    // cout<<i<<" "<<flag[i]<<endl;
    if (flag[i] == 1) {
      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 < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  vector<bool> ok(N, true);
  rep(i, N) cin >> H[i];
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--; // 0-indexedに直す
    if (H[a] <= H[b])
      ok[a] = false;
    if (H[b] <= H[a])
      ok[b] = false;
  }
  int ans = 0;
  rep(i, N) if (ok[i]) ans++;
  cout << ans << endl;
  return 0;
}


Error: -11

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>;
const int inf{int(1e9)};
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  vector<bool> ok(N, true);
  rep(i, N) cin >> H[i];
  rep(i, M) {
    int a, b;
    a--;
    b--; // 0-indexedに直す
    if (H[a] <= H[b])
      ok[a] = false;
    if (H[b] <= H[a])
      ok[b] = false;
  }
  int ans = 0;
  rep(i, N) if (ok[i]) ans++;
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

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

void fnInput(vector<int> &rvnNode, vector<vector<int>> &rvvnEdge) {
  int nNodeSiz, nEdgeSiz;
  cin >> nNodeSiz >> nEdgeSiz;
  rvnNode.resize(nNodeSiz);
  // rvvnEdge.resize(nNodeSiz, vector<int>(nNodeSiz, 0));
  rvvnEdge.resize(nNodeSiz);

  for (int &rnNode : rvnNode)
    cin >> rnNode;

  for (int i = 0; i <= nEdgeSiz; i++) {
    int nLeft, nRigt;
    cin >> nLeft >> nRigt;
    rvvnEdge[nLeft - 1].push_back(nRigt - 1);
    rvvnEdge[nRigt - 1].push_back(nLeft - 1);
  }
}

int fnPeakCnt(const vector<int> cnrvnNode,
              const vector<vector<int>> &cnrvvnEdge) {
  int nPeakCnt = 0;

  for (int nBgn = 0; nBgn < cnrvnNode.size(); nBgn++) {
    bool bPeak = true;
    for (int nEnd : cnrvvnEdge[nBgn])
      if (cnrvnNode[nBgn] <= cnrvnNode[nEnd]) {
        bPeak = false;
        break;
      }

    if (bPeak)
      nPeakCnt++;
  }
  return nPeakCnt;
}

int main() {
  vector<int> vnNode;
  vector<vector<int>> vvnEdge;

  fnInput(vnNode, vvnEdge);
  cout << fnPeakCnt(vnNode, vvnEdge) << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

struct StEdge {
  StEdge() : m_nBgn(0), m_nEnd(0) {}

  int m_nBgn;
  int m_nEnd;
};

void fnInput(vector<int> &rvnNode, vector<StEdge> &rvoEdge) {
  int nNodeSiz, nEdgeSiz;
  cin >> nNodeSiz >> nEdgeSiz;
  rvnNode.resize(nNodeSiz);
  rvoEdge.resize(nEdgeSiz);

  for (int &rnNode : rvnNode)
    cin >> rnNode;

  for (StEdge &roEdge : rvoEdge)
    cin >> roEdge.m_nBgn >> roEdge.m_nEnd;
}

int fnPeakCnt(const vector<int> cnrvnNode, const vector<StEdge> &cnrvoEdge) {
  vector<vector<int>> vvnEdge(cnrvnNode.size(),
                              vector<int>(cnrvnNode.size(), -1));

  for (StEdge oEdge : cnrvoEdge)
    if (cnrvnNode[oEdge.m_nBgn - 1] > cnrvnNode[oEdge.m_nEnd - 1]) {
      vvnEdge[oEdge.m_nBgn - 1][oEdge.m_nEnd - 1] = 1;
      vvnEdge[oEdge.m_nEnd - 1][oEdge.m_nBgn - 1] = 0;
    } else if (cnrvnNode[oEdge.m_nBgn - 1] < cnrvnNode[oEdge.m_nEnd - 1]) {
      vvnEdge[oEdge.m_nBgn - 1][oEdge.m_nEnd - 1] = 0;
      vvnEdge[oEdge.m_nEnd - 1][oEdge.m_nBgn - 1] = 1;
    } else {
      vvnEdge[oEdge.m_nBgn - 1][oEdge.m_nEnd - 1] = 0;
      vvnEdge[oEdge.m_nEnd - 1][oEdge.m_nBgn - 1] = 0;
    }

  int nPeakCnt = 0;

  for (int i = 0; i < vvnEdge.size(); i++) {
    bool bPeak = true;

    for (int j = 0; j < vvnEdge[i].size(); j++)
      if (vvnEdge[i][j] == 0) {
        bPeak = false;
        break;
      }

    if (bPeak)
      nPeakCnt++;
  }
  return nPeakCnt;
}

int main() {
  vector<int> vnNode;
  vector<StEdge> voEdge;

  fnInput(vnNode, voEdge);
  cout << fnPeakCnt(vnNode, voEdge) << endl;

  return 0;
}