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

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

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

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

  int count = 0;
  for (int i = 0; i < n; i++) {
    bool flg = true;
    long long ab_size = ab[i].size();
    long long hi = h[i];
    for (int j = 0; j < ab_size; j++) {
      if (hi <= h[ab[i][j]])
        flg = false;
    }
    if (flg)
      count++;
  }
  cout << count << "\\n";
}

Error: TLE

Fixed submission:

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<long long> h(n);
  for (int i = 0; i < n; i++) {
    long long tmp;
    cin >> tmp;
    h[i] = tmp;
  }

  vector<vector<int>> ab;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    ab.push_back({a, b});
  }

  int count = 0;
  for (int i = 1; i <= n; i++) {
    bool flg = true;
    for (int j = 0; j < m; j++) {
      if (ab[j][0] == i) {
        if (h[ab[j][0] - 1] <= h[ab[j][1] - 1]) {
          flg = false;
        }
      } else if (ab[j][1] == i) {
        if (h[ab[j][1] - 1] <= h[ab[j][0] - 1]) {
          flg = false;
        }
      }
    }
    // cout << i << " " << flg << endl;
    if (flg)
      count++;
  }
  cout << count << "\\n";
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

// #pragma region ALL(include define etc)
#include <algorithm>  // max(a, b) min(a, b) reverse() sort()
#include <cmath>      // abs(絶対値) sin cos tan(角度 / 180.0 * 3.141592)
#include <functional> // sort(a, a + N, greater<型>());
#include <iostream>   // swap(a, b)
#include <math.h>
#include <string>
#include <vector> // vec.push_back(a) vec.pop_back()
#define int long long
#define ll long long
using namespace std;
// #pragma endregion

signed main() {
  int n;
  int m;
  int h[1000000] = {0};
  int m1, m2;

  // int k, d;
  int all = 0;
  // int a;

  int box[1000000] = {0};

  // string str;

  cin >> n >> m;
  // cin >> d;
  // cin >> str;

  // cout << a;

  for (int i = 1; i <= n; i++) {
    cin >> h[i];
    box[i] = h[i];
    /*for (int j = 0; j < d; j++)
    {
            cin >> a;
            box[a]++;
    }*/
  }

  for (int i = 1; i <= m; i++) {
    cin >> m1 >> m2;

    if (h[m1] < h[m2]) {
      box[m1] = 0;
    } else if (h[m1] == h[m2]) {
      box[m1] = 0;
      box[m2] = 0;
    } else {
      box[m2] = 0;
    }
  }

  for (int i = 1; i <= n; i++) {
    if (box[i] != 0) {
      all++;
    }
    // cout << box[i] << "\\n";
  }

  cout << all << "\\n";

  /*if (str=="ABC")
  {
          cout << "ARC\\n";
  }
  else
  {
          cout << "ABC\\n";
  }*/
}

Error: 0

Fixed submission:

// #pragma region ALL(include define etc)
#include <algorithm>  // max(a, b) min(a, b) reverse() sort()
#include <cmath>      // abs(絶対値) sin cos tan(角度 / 180.0 * 3.141592)
#include <functional> // sort(a, a + N, greater<型>());
#include <iostream>   // swap(a, b)
#include <math.h>
#include <string>
#include <vector> // vec.push_back(a) vec.pop_back()
#define int long long
#define ll long long
using namespace std;
// #pragma endregion

signed main() {
  int n;
  int m;
  int h[10000] = {0};
  int m1, m2;

  // int k, d;
  int all = 0;
  // int a;

  int box[10000] = {0};

  // string str;

  cin >> n >> m;
  // cin >> d;
  // cin >> str;

  // cout << a;

  for (int i = 1; i <= n; i++) {
    cin >> h[i];
    box[i] = h[i];
    /*for (int j = 0; j < d; j++)
    {
            cin >> a;
            box[a]++;
    }*/
  }

  for (int i = 1; i <= m; i++) {
    cin >> m1 >> m2;

    if (h[m1] < h[m2]) {
      box[m1] = 0;
    } else if (h[m1] == h[m2]) {
      box[m1] = 0;
      box[m2] = 0;
    } else {
      box[m2] = 0;
    }
  }

  for (int i = 1; i <= n; i++) {
    if (box[i] != 0) {
      all++;
    }
    // cout << box[i] << "\\n";
  }

  cout << all << "\\n";

  /*if (str=="ABC")
  {
          cout << "ARC\\n";
  }
  else
  {
          cout << "ABC\\n";
  }*/
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
const int MOD = 1000000007;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> H;
  vector<ll> check;
  vector<ll> A, B;
  ll count = 0;
  ll c;
  for (int i = 0; i < N; i++) {
    cin >> c;
    H.push_back(c);
    check.push_back(1);
  }
  for (int i = 0; i < M; i++) {
    cin >> c;
    A.push_back(c);
    cin >> c;
    B.push_back(c);
  }
  for (int i = 0; i < M; i++) {
    if (H[A[i] - 1] == H[B[i] - 1]) {
      check[A[i] - 1] = 0;
      check[B[i] - 1] = 0;
    } else {
      H[A[i] - 1] > H[B[i] - 1] ? check[B[i] - 1] = 0 : check[A[i] - 1] = 0;
    }
  }
  for (int i = 0; i < N; i++) {

    count += check[i];
  }
  cout << count;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
const int MOD = 1000000007;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> H;
  vector<ll> A, B;
  map<ll, ll> MAP;
  ll a, b, h;
  vector<ll> BIG;
  vector<ll> BIGchar;
  ll ch = 1;

  for (ll i = 0; i < N; i++) {

    cin >> h;
    H.push_back(h);
    BIG.push_back(h);
    BIGchar.push_back(0);
  }
  for (ll i = 0; i < M; i++) {

    cin >> a >> b;
    A.push_back(a);
    B.push_back(b);
  }
  for (int i = 0; i < M; i++) {
    if (BIG[A[i] - 1] > BIG[B[i - 1]]) {

      BIG[B[i - 1]] = BIG[A[i] - 1];
      if (BIGchar[A[i] - 1] == 0 && BIGchar[B[i] - 1] == 0) {

        BIGchar[A[i] - 1] = ch;
        BIGchar[B[i] - 1] = ch;
        ch = ch + 1;
        MAP[ch]++;
      } else if (BIGchar[A[i] - 1] != 0 && BIGchar[B[i] - 1] == 0) {

        BIGchar[A[i - 1]] = BIGchar[B[i] - 1];
      } else if (BIGchar[A[i] - 1] == 0 && BIGchar[B[i] - 1] != 0) {

        BIGchar[B[i - 1]] = BIGchar[A[i] - 1];
      } else {
      }

    } else {

      for (int j = 0; j <= i; j++) {
        if (BIGchar[i] == BIGchar[B[i] - 1]) {
          BIGchar[B[i - 1]] = BIGchar[A[i] - 1];
        }
        if (BIGchar[i] == BIGchar[A[i] - 1]) {
          BIGchar[A[i - 1]] = BIGchar[A[i] - 1];
        }
      }
    }
  }
  // ここで確かめ
  for (int i = M - 1; i >= 0; i--) {

    if (BIG[A[i] - 1] == BIG[B[i] - 1]) {
      BIG[B[i - 1]] = BIG[A[i] - 1];

    } else {

      BIG[A[i - 1]] = BIG[B[i] - 1];
    }
  }
  for (int i = 0; i >= 0; i++) {
    if (BIG[A[i] - 1] == H[A[i - 1]] && BIG[B[i] - 1] == H[B[i - 1]]) {
      BIGchar[i] = M + 1;
    }
  }
  for (int i = 0; i < M; i++) {
    MAP[BIGchar[i]]++;
  }
  ll cnt = 0;

  for (int i = 1; i <= M; i++) {
    if (MAP[i] != 0) {
      cnt++;
    }
  }
  cout << cnt + MAP[0];
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (ll i = n; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}
const int INF = 1e9;
const ll LLINF = 1e16;

int main(void) {
  ll n, m;
  cin >> n >> m;
  vector<bool> tenb(n, true);
  vector<ll> h(n);
  vector<pair<ll, ll>> miti(m);
  REP(i, n) { cin >> h[i]; }
  REP(i, m) {
    cin >> miti[i].first >> miti[i].second;
    miti[i].first--;
    miti[i].second--;
  }

  REP(i, m) {
    if (h[miti[i].first] < h[miti[i].second]) {
      tenb[miti[i].first] = false;
    } else if (h[miti[i].first] > h[miti[i].second]) {
      tenb[miti[i].second] = false;
    } else {
      tenb[miti[i].first] = false;
      tenb[miti[i].second] = false;
    }
  }

  ll cnt = 0;
  REP(i, n) {
    if (tenb[i]) {
      cnt++;
    }
  }

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (ll i = n; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}
const int INF = 1e9;
const ll LLINF = 1e16;

int main(void) {
  ll n, m;
  cin >> n >> m;
  vector<bool> tenb(n, true);
  vector<ll> h(n);
  vector<pair<ll, ll>> miti(m);
  REP(i, m) { cin >> h[i]; }
  REP(i, m) {
    cin >> miti[i].first >> miti[i].second;
    miti[i].first--;
    miti[i].second--;
  }

  REP(i, m) {
    if (miti[i].first != miti[i].second) {
      tenb[min(miti[i].first, miti[i].second)] = false;
    }
  }

  ll cnt = 0;
  REP(i, n) {
    if (tenb[i]) {
      cnt++;
    }
  }

  cout << cnt << 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 < n; ++i)
#define arep(x, n) for (int x : n)
using namespace std;

const double PI = acos(-1);

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  rep(i, n) cin >> h.at(i);
  vector<vector<int>> ab(m, vector<int>(2));
  rep(i, m) cin >> ab.at(i).at(0) >> ab.at(i).at(1);

  vector<int> tmp(n);

  rep(i, m) {
    int subA = ab.at(i).at(0), subB = ab.at(i).at(1);
    if (h.at(subA - 1) < h.at(subB - 1)) {
      tmp.at(subA - 1) = 1;
    } else if (h.at(subA - 1) > h.at(subB - 1)) {
      tmp.at(subB - 1) = 1;
    } else {
      tmp.at(subA - 1) = 1;
      tmp.at(subB - 1) = 1;
    }
  }

  int cnt = 0;
  rep(i, n) cnt += tmp.at(i);
  cout << n - cnt << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#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.at(i);

  vector<vector<int>> ab(m, vector<int>(2));
  rep(i, m) rep(j, 2) cin >> ab.at(i).at(j);

  int judge_alone = 0;
  vector<int> alone(n);
  vector<int> good(n);

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int x = 0; x < 2; x++) {
        if (i + 1 == ab.at(j).at(x)) {
          judge_alone = 1;
          if (x == 0) {
            if (h.at(i) <= h.at(ab.at(j).at(1) - 1)) {
              good.at(i) = 1;
              break;
            } else {
              continue;
            }
          } else {
            if (h.at(i) <= h.at(ab.at(j).at(0) - 1)) {
              good.at(i) = 1;
              break;
            } else {
              continue;
            }
          }
        } else {
          continue;
        }
      }
      if (good.at(i) == 1) {
        break;
      } else {
        continue;
      }

      if (judge_alone == 0) {
        alone.at(i) = 1;
      } else {
        continue;
      }
    }
  }
  rep(i, n) good.at(i) += alone.at(i);

  for (int i = 0; i < n; i++) {
    if (good.at(i) == 0) {
      good.at(i) = 1;
    } else {
      good.at(i) = 0;
    }
  }
  int sum_good_num = 0;
  rep(i, n) sum_good_num += good.at(i);
  cout << sum_good_num << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  long int n, m;
  cin >> n >> m;
  vector<long int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<long int> a(m), b(m);
  // vector<vector<bool>> link(n,vector<bool>(n));
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    // link[a[i]-1][b[i]-1]=true;
    // link[b[i]-1][a[i]-1]=true;
  }

  vector<int> ans(n, 1);
  for (int i = 0; i < m; i++) {
    if (h[a[i] - 1] == h[b[i] - 1]) {
      ans[a[i] - 1] = 0;
      ans[b[i] - 1] = 0;
    } else if (h[a[i] - 1] < h[b[i] - 1]) {
      ans[a[i] - 1] = 0;
    } else {
      ans[b[i] - 1] = 0;
    }
  }

  long int count = 0;
  for (int i = 0; i < n; i++) {
    if (ans[i]) {
      count++;
    }
  }

  cout << count;

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  long int n, m;
  cin >> n >> m;
  vector<long int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<long int> a(m), b(m);
  vector<vector<bool>> link(n, vector<bool>(n));
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    link[a[i] - 1][b[i] - 1] = true;
    link[b[i] - 1][a[i] - 1] = true;
  }

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

  long int count = 0;
  for (int i = 0; i < n; i++) {
    if (ans[i]) {
      count++;
    }
  }

  cout << count;

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

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

  vector<int> hei(n + 1);

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

  vector<int> vec[200001];

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;

    vec[x].push_back(y);
    vec[y].push_back(x);
  }

  int cnt = 0;

  for (int i = 1; i <= n; i++) {
    int flag = 0;

    for (auto x : vec[i]) {
      if (hei[i] <= hei[x]) {
        flag = 1;
        break;
      }
    }

    if (flag == 0)
      cnt++;
  }

  cout << cnt << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

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

  vector<int> hei(n);

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

  vector<int> vec[200001];

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;

    vec[x].push_back(y);
    vec[y].push_back(x);
  }

  int cnt = 0;

  for (int i = 1; i <= n; i++) {
    int flag = 0;

    for (auto x : vec[i]) {
      if (hei[i] <= hei[x]) {
        flag = 1;
        break;
      }
    }

    if (flag == 0)
      cnt++;
  }

  cout << cnt << endl;

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

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

int main() {
  int N, M;
  int tmp1, tmp2, ans = 0;
  cin >> N >> M;
  vector<int> tenbo(N);
  vector<int> maxh(N);
  for (int i = 0; i < N; i++) {
    cin >> tenbo.at(i);
  }
  for (int i = 0; i < M; i++) {
    cin >> tmp1 >> tmp2;
    maxh.at(tmp1 - 1) = max(tenbo.at(tmp2 - 1), maxh.at(tmp1 - 1));
    maxh.at(tmp2 - 1) = max(tenbo.at(tmp1 - 1), maxh.at(tmp2 - 1));
  }
  for (int i = 0; i < N; i++) {
    if (tenbo.at(i) > maxh.at(i))
      ans++;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N, M;
  int tmp1, tmp2, ans = 0;
  bool flag;
  cin >> N >> M;
  vector<int> tenbo(N);
  vector<vector<int>> miti(N, vector<int>(N, 0));
  for (int i = 0; i < N; i++)
    cin >> tenbo.at(i);
  for (int i = 0; i < M; i++) {
    cin >> tmp1 >> tmp2;
    miti.at(tmp1 - 1).at(tmp2 - 1) = 1;
    miti.at(tmp2 - 1).at(tmp1 - 1) = 1;
  }
  for (int i = 0; i < N; i++) {
    flag = true;
    for (int j = 0; j < N; j++) {
      if (miti.at(i).at(j) != 0 && tenbo.at(i) <= tenbo.at(j)) {
        flag = false;
        break;
      }
    }
    if (flag == true)
      ans++;
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
// #include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a), i##formax = (b); i < i##formax; i++)
typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<vector<pair<int, int>>> road(n);
  FOR(i, 0, n) { cin >> h[i]; }

  FOR(i, 0, m) {
    int a, b;
    cin >> a >> b;
    road[a - 1].push_back(make_pair(a - 1, b - 1));
    road[b - 1].push_back(make_pair(b - 1, a - 1));
  }

  int ans = 0;
  FOR(i, 0, n) {
    bool flag = true;
    FOR(j, 0, road[i].size()) {
      if (h[i] <= h[road[i][j].second]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
// #include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a), i##formax = (b); i < i##formax; i++)
typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<vector<pair<int, int>>> road(m);
  FOR(i, 0, n) { cin >> h[i]; }

  FOR(i, 0, m) {
    int a, b;
    cin >> a >> b;
    road[a - 1].push_back(make_pair(a - 1, b - 1));
    road[b - 1].push_back(make_pair(b - 1, a - 1));
  }

  int ans = 0;
  FOR(i, 0, n) {
    bool flag = true;
    FOR(j, 0, road[i].size()) {
      if (h[i] <= h[road[i][j].second]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  vector<vector<int>> vec(N);

  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    vec.at(a - 1).push_back(b - 1);
    vec.at(b - 1).push_back(a - 1);
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    bool flag = true;
    for (int j = 0; j < vec.at(i).size(); j++) {
      if (H[vec.at(i).at(j)] >= H[i]) {
        flag = false;
      }
    }
    if (flag) {
      count++;
    }
  }
  cout << count << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  vector<pair<int, int>> road(M);
  for (int i = 0; i < M; i++) {
    cin >> road.at(i).first;
    cin >> road.at(i).second;
  }

  int count = 0;
  for (int i = 0; i < N; i++) {
    bool takasa = true;
    for (int j = 0; j < M; j++) {
      if (road.at(j).first == i + 1 && H.at(road.at(j).second - 1) >= H.at(i)) {
        takasa = false;
      }
      if (road.at(j).second == i + 1 && H.at(road.at(j).first - 1) >= H.at(i)) {
        takasa = false;
      }
    }
    if (takasa) {
      count++;
    }
  }
  cout << count << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> H(N);
  rep(i, N) { cin >> H.at(i); }
  vector<pair<long long, long long>> AB;
  rep(i, M) {
    long long A, B;
    cin >> A >> B;
    AB.push_back(make_pair(A, B));
    AB.push_back(make_pair(B, A));
  }
  /*for (int j = 0; j < AB.size();j++){
      long long A = AB.at(j).first;
      long long B = AB.at(j).second;
      cout << A << ":" << B << endl;
  }*/
  sort(AB.begin(), AB.end());
  long long logger = -1;
  long long Highest = -1;
  bool most = true;
  long long ans = -1;
  long long A = 0;
  long long B = 0;
  vector<long long> check(N);
  for (int i = 0; i < AB.size(); i++) {
    A = AB.at(i).first;
    check.at(A - 1)++;
    if (logger != A) {
      if (most) {
        ans++;
      }
      Highest = H.at(A - 1);
      logger = A;
      most = true;
    }

    B = AB.at(i).second;
    if (H.at(B - 1) >= Highest) {
      most = false;
    }
  }
  if (most) {
    ans++;
  }
  rep(i, N) {
    if (check.at(i) == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

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

int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> H(N);
  rep(i, N) { cin >> H.at(i); }
  vector<pair<long long, long long>> AB;
  rep(i, M) {
    long long A, B;
    cin >> A >> B;
    AB.push_back(make_pair(A, B));
    AB.push_back(make_pair(B, A));
  }

  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    bool highest = true;
    for (int j = 0; j < AB.size(); j++) {
      long long A = AB.at(j).first;
      if (A != i) {
        continue;
      }
      long long B = AB.at(j).second;
      if (H.at(B - 1) >= H.at(i - 1)) {
        highest = false;
        break;
      }
    }
    if (highest) {
      ans++;
    }
  }

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

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

int main() {
  int n, m, count = 0;
  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 a, b;
    cin >> a >> b;
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }

  for (int i = 0; i < n; i++) {
    int r = 0;
    for (int x : G[i]) {
      if (h[i] <= h[x])
        r++;
    }
    if (r == 0)
      count++;
  }
  cout << count << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int n, m, count = 0;
  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 a, b;
    cin >> a >> b;
    G[a].push_back(b);
  }

  for (int i = 0; i < n; i++) {
    int r = 0;
    for (int x : G[i]) {
      if (h[i] <= h[x])
        r++;
    }
    if (r == 0)
      count++;
  }
  cout << count << endl;
}