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

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < (n); ++i)
#define ALL(n) begin(n), end(n)
using ll = long long;
const ll INF = 1e18;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  REP(i, 0, N) cin >> H[i];
  vector<int> A(M), B(M);
  REP(i, 0, M) cin >> A[i] >> B[i];

  vector<set<int>> network(N);
  REP(i, 0, M) {
    network[A[i] - 1].insert(B[i] - 1);
    network[B[i] - 1].insert(A[i] - 1);
  }

  int cnt = 0;
  REP(i, 0, N) {
    int h = H[i];
    bool top_flag = true;
    for (auto j : network[i]) {
      if (h <= H[j]) {
        top_flag = false;
        break;
      }
    }
    if (top_flag)
      ++cnt;
  }

  cout << cnt << endl;

  return 0;
}


Error: TLE

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < (n); ++i)
#define ALL(n) begin(n), end(n)
using ll = long long;
const ll INF = 1e18;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  REP(i, 0, N) cin >> H[i];
  vector<int> A(M), B(M);
  REP(i, 0, M) cin >> A[i] >> B[i];

  int cnt = 0;
  REP(i, 0, N) {
    int h = H[i];
    bool not_top_flag = false;
    REP(j, 0, M) {
      if (A[j] - 1 == i) {
        if (h <= H[B[j] - 1]) {
          not_top_flag = true;
          break;
        }
      }
    }
    if (!not_top_flag) {
      REP(j, 0, M) {
        if (B[j] - 1 == i) {
          if (h <= H[A[j] - 1]) {
            not_top_flag = true;
            break;
          }
        }
      }
    }
    if (!not_top_flag)
      ++cnt;
  }
  cout << cnt << endl;

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

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, m, h[100010], ma[100010];
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
    ma[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    ma[a] = max(ma[a], h[b]);
    ma[b] = max(ma[b], h[a]);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += h[i] > ma[i];
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  long long a, b;
  vector<long long> h(n);
  bool c[n][n];
  for (long long i = 0; i < n; i++) {
    cin >> h[i];
    for (long long j = 0; j < n; j++) {
      c[i][j] = false;
    }
  }
  for (long long i = 0; i < m; i++) {
    cin >> a >> b;
    c[a - 1][b - 1] = true;
    c[b - 1][a - 1] = true;
  }
  long long ans = n;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      if ((c[i][j]) && (h[i] <= h[j])) {
        ans--;
        break;
      }
    }
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int tenbosu = 0;
  cin >> tenbosu;
  vector<long long> takasa(tenbosu, 0);
  int pathC = 0;
  cin >> pathC;
  int a, b;
  vector<int> ToF(tenbosu, 0);
  for (int i = 0; i < tenbosu; i++) {
    cin >> takasa[i];
  }
  for (int i = 0; i < pathC; i++) {
    cin >> a;
    cin >> b;
    if (takasa[a - 1] >= takasa[b - 1]) {
      ToF[b - 1] = 1;
    }
    if (takasa[a - 1] <= takasa[b - 1]) {
      ToF[a - 1] = 1;
    }
  }

  int c = 0;
  for (int i = 0; i < tenbosu; i++) {
    if (ToF[i] == 0) {
      c++;
    }
  }
  cout << c;
}


Error: TLE

Fixed submission:

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

int main() {
  int tenbosu = 0;
  cin >> tenbosu;
  vector<long> takasa(tenbosu, 0);
  int pathC = 0;
  cin >> pathC;
  vector<vector<int>> P(tenbosu, vector<int>(tenbosu, 0));

  for (int i = 0; i < tenbosu; i++) {
    cin >> takasa[i];
  }
  int a, b;
  a = -1;
  b = -1;
  for (int i = 0; i < pathC; i++) {
    cin >> a;
    cin >> b;
    P[a - 1][b - 1] = 1;
    P[b - 1][a - 1] = 1;
  }
  int flag = 0;
  int count = 0;
  for (int i = 0; i < tenbosu; i++) {
    flag = 0;
    for (int j = 0; j < tenbosu; j++) {
      if (P[i][j] == 1) {
        // cout<<"takasa["<<i<<"],takasa["<<j<<"]="<<takasa[i]<<"
        // "<<takasa[j]<<endl;
        if (takasa[i] <= takasa[j]) {
          // cout<<i<<"から"<<j<<"の経路で上回ってる"<<endl;
          flag = 1;
        }
      }
    }
    if (flag == 0) {
      count += 1;
      // cout<<"展望台"<<i<<"でカウント+1"<<endl;
    }
  }
  cout << count;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll maxn = 1e5 + 5;
int h[maxn], m, n;
vector<ll> g[maxn];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> h[i];
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    bool f = true;
    for (int j = 0; j < g[i].size(); j++) {

      if (h[g[i][j]] >= h[i])
        f = false;
    }
    if (f)
      ans++;
  }
  cout << ans;
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll maxn = 1e4 + 5;
int g[maxn][maxn], h[maxn], m, n;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    g[a][b] = 1, g[b][a] = 1;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    bool f = true;
    for (int j = 1; j <= n; j++) {
      if (g[i][j])
        if (h[j] >= h[i])
          f = false;
    }
    if (f)
      ans++;
  }
  cout << ans;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define All(a) a.begin(), a.end()
#define INF 1000000007
const int MOD = 1000000007;
// accumulate(vec.begin(), vec.end(), 0)

int gcd(int x, int y) {
  if (x % y == 0)
    return y;
  else
    return gcd(y, x % y);
}

int main() {
  int n, m;
  int cnt = 0;
  cin >> n >> m;
  vector<int> H(n);
  vector<bool> C(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;
    a--, b--;
    if (H[a] == H[b]) {
      C[a] = false;
      C[b] = false;
    } else if (H[a] > H[b])
      C[b] = false;
    else
      C[a] = false;
  }
  cout << accumulate(All(C), 0) << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define All(a) a.begin(), a.end()
#define INF 1000000007
const int MOD = 1000000007;
// accumulate(vec.begin(), vec.end(), 0)

int gcd(int x, int y) {
  if (x % y == 0)
    return y;
  else
    return gcd(y, x % y);
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> H(n);
  for (int i = 0; i < n; i++)
    cin >> H[i];
  vector<vector<bool>> G(n, vector<bool>(n, false));
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a][b] = true;
    G[b][a] = true;
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int now = 0;
    for (int j = 0; j < n; j++) {
      if (G[i][j])
        now = max(now, H[j]);
    }
    //  cout<< now <<endl;
    if (now < H[i])
      ans++;
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
struct edge {
  int v, nxt;
} e[200010];
int head[200010], cnt, n, m, w[100010], x, y, ans;
inline void add(int u, int v) {
  e[++cnt].v = v;
  e[cnt].nxt = head[u];
  head[u] = cnt;
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; ++i)
    w[i] = read();
  for (int i = 1; i <= m; ++i)
    x = read(), y = read(), add(x, y), add(y, x);
  for (int u = 1; u <= n; ++u) {
    bool flag = 1;
    for (int i = head[u]; i; i = e[i].nxt) {
      int v = e[i].v;
      flag &= w[u] > w[v];
    }
    if (flag)
      ans++;
  }
  return printf("%d\\n", ans) & 0;
}

Error: 2

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
struct edge {
  int v, nxt;
} e[200010];
int head[200010], cnt, n, m, w[100010], x, y, ans;
inline void add(int u, int v) {
  e[++cnt].v = v;
  e[cnt].nxt = head[u];
  head[u] = cnt;
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; ++i)
    w[i] = read();
  for (int i = 1; i <= m; ++i)
    x = read(), y = read(), add(x, y), add(y, x);
  for (int u = 1; u <= n; ++u) {
    bool flag = 1;
    for (int i = head[u]; i; i = e[i].nxt) {
      int v = e[i].v;
      flag &= w[u] > w[v];
    }
    if (flag)
      ans++;
  }
  return printf("%d\\n", ans);
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>

#define ll long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

int gcd(int a, int b) { return (a % b) ? gcd(b, a % b) : b; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

using Graph = vector<vector<int>>;

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

  int h[n];
  REP(i, n) cin >> h[i];

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

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    bool flag = true;
    int height = h[i];
    for (auto next : G[i]) {
      if (height <= h[next]) {
        flag = false;
      }
    }
    if (flag)
      ans++;
  }

  cout << ans << endl;
}

int main(void) {
  solve_C();

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>

#define ll long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

int gcd(int a, int b) { return (a % b) ? gcd(b, a % b) : b; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

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

  int h[n];
  REP(i, n) cin >> h[i];

  int a[m], b[m];
  int graph[n][n];
  REP(i, n) { REP(j, n) graph[i][j] = 0; }
  REP(i, m) {
    cin >> a[i] >> b[i];
    graph[a[i] - 1][b[i] - 1] = graph[b[i] - 1][a[i] - 1] += 1;
  }

  int ans = 0, ctr = 0;
  for (int i = 0; i < n; i++) {
    int height = h[i];
    bool flag = true;
    for (int j = 0; j < n; j++) {

      if (graph[i][j] >= 1) {
        if (height <= h[j])
          flag = false;
        ctr++;
        graph[i][j]--;
      }
    }
    if (flag) {
      ans++;
    }
  }

  cout << ans << endl;
}

int main(void) {
  solve_C();

  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> v(n);
  for (int i = 0; i < n; i++)
    v[i] = i + 1;
  vector<int> h(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];

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

  int ans = 0;
  for (int i = 0; i < n; i++)
    if (v[i] != 0)
      ans++;

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

Error: 0

Fixed submission:

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

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

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

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

  int ans = 0;
  for (int i = 0; i < n; i++) {
    bool good = true;
    for (int j = 0; j < n; j++) {
      if (w[i][j] != 0 && v[i] <= v[j]) {
        good = false;
        break;
        // cout << v[i] << " " << v[j] << endl;
      }
    }
    if (good)
      ans++;
  }

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

#include <bits/stdc++.h>
using ll = long long;
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<int> a(m), b(m);
  for (int i = 0; i < m; i++) {
    int ai, bi;
    cin >> ai >> bi;
    a[i] = ai - 1;
    b[i] = bi - 1;
  }

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

  int ans = 0;
  for (int i = 0; i < n; i++)
    if (g[i])
      ans++;

  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using ll = long long;
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<int> a(n), b(n);
  for (int i = 0; i < m; i++) {
    int ai, bi;
    cin >> ai >> bi;
    a[i] = ai - 1;
    b[i] = bi - 1;
  }

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

  int ans = 0;
  for (int i = 0; i < n; i++)
    if (g[i])
      ans++;

  cout << ans << endl;

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

#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <tuple>

#define rep(i, m, n) for (int i = (m); i < (n); ++i)
#define rem(i, m, n) for (int i = (m); i > (n); --i)
#define MOD 1000000007

using namespace std;

using ll = long long int;
using std::swap;

vector<int> v;
vector<int> w;
// vector<long long int> vll;
// vector<long long int> wll;
// vector<vector<int>> vec(50,vector<int>(4,0));
// vector<vector<int>> vec;

int main() {
  int N, M;
  int ans = 0;
  cin >> N >> M;
  v.resize(N);
  w.resize(N, 1);

  rep(i, 0, N) cin >> v[i];
  rep(i, 0, M) {
    int A, B;
    cin >> A >> B;
    if (v[A - 1] > v[B - 1]) {
      w[B - 1] = 0;
    } else if (v[A - 1] < v[B - 1]) {
      w[A - 1] = 0;
    } else if (v[A - 1] == v[B - 1]) {
      w[A - 1] = 0;
      w[B - 1] = 0;
    }
  }
  ans = count(w.begin(), w.end(), 1);
  cout << ans << '\\n';
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <tuple>

#define rep(i, m, n) for (int i = (m); i < (n); ++i)
#define rem(i, m, n) for (int i = (m); i > (n); --i)
#define MOD 1000000007

using namespace std;

using ll = long long int;
using std::swap;

vector<int> v;
vector<int> w;
vector<long long int> vll;
vector<long long int> wll;
// vector<vector<int>> vec(50,vector<int>(4,0));
vector<vector<int>> vec;

int main() {
  int N, M;
  int ans = 0;
  cin >> N >> M;
  v.resize(N);
  w.resize(N, 1);
  vec.resize(N, vector<int>(N, 0));

  rep(i, 0, N) cin >> v[i];
  rep(i, 0, M) {
    int A, B;
    cin >> A >> B;
    if (v[A - 1] > v[B - 1]) {
      w[B - 1] = 0;
    } else if (v[A - 1] < v[B - 1]) {
      w[A - 1] = 0;
    } else {
      w[A - 1] = 0;
      w[B - 1] = 0;
    }
  }
  rep(i, 0, N) {
    if (w[i] == 1)
      ++ans;
  }
  cout << ans << '\\n';
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>

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

  for (int i = 0; i < m; i++) {
    int a, b;
    std::cin >> a >> b;
    ma[a] = std::max(ma[a], h[b]);
    ma[b] = std::max(ma[b], h[a]);
  }

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

  std::cout << ans;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>

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

  for (int i = 0; i < m; i++) {
    int a, b;
    std::cin >> a >> b;
    ma[a] = std::max(ma[a], h[b]);
    ma[b] = std::max(ma[b], h[a]);
  }

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

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

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

int main() {
  int n, m, h, a, b, ans = 0;
  cin >> n >> m;
  vector<int> height(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> h;
    height.at(i) = h;
  }
  vector<int> top(n + 1);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (height[a] > height[b]) {
      top[b]--;
    } else if (height[a] < height[b]) {
      top[a]--;
    } else {
      top[a]--;
      top[b]--;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (top[i] == 0) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: 2

Fixed submission:

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

int main() {
  int n, m, h, a, b, ans = 0;
  cin >> n >> m;
  vector<int> height(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> h;
    height.at(i) = h;
  }
  vector<int> top(n + 1);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (height[a] > height[b]) {
      top[b]--;
    } else if (height[a] < height[b]) {
      top[a]--;
    } else {
      top[a]--;
      top[b]--;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (top[i] == 0) {
      ans++;
    }
  }
  cout << ans << endl;
  return ans;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

// #include <algorithm>
#include <iostream>
#include <list>
#include <map> //連想配列
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector> //動的配列

#define rep(i, N) for (int i = 0; i < N; i++)
#define ll long long
using namespace std;

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

  ll H[N + 1];
  ll H_flag[N + 1];
  rep(i, N + 1) { H_flag[i] = 1; }
  H_flag[0] = 0;

  H[0] = 0;
  rep(i, N) { cin >> H[i + 1]; }

  ll first, second;
  rep(i, M) {
    cin >> first >> second;
    if (H[first] == H[second]) {
      H_flag[first] = 0;
      H_flag[second] = 0;
    } else if (H[first] < H[second]) {
      H_flag[first] = 0;
    } else if (H[first] > H[second]) {
      H_flag[second] = 0;
    }
  }
  int result = 0;
  for (int i = 1; i < N + 1; i++) {
    if (H_flag[i] != 0) {
      result++;
    }
  }
  cout << result << endl;
  return 0;
}


Error: TLE

Fixed submission:

// #include <algorithm>
#include <iostream>
#include <list>
#include <map> //連想配列
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector> //動的配列

#define rep(i, N) for (int i = 0; i < N; i++)
#define ll long long
using namespace std;

int main() {
  ll N, M;
  ll H[N + 1];
  ll H_flag[N + 1];
  rep(i, N + 1) { H_flag[i] = 1; }
  H_flag[0] = 0;

  H[0] = 0;
  cin >> N >> M;
  rep(i, N) { cin >> H[i + 1]; }

  ll first, second;
  rep(i, M) {
    cin >> first >> second;
    if (H[first] == H[second]) {
      H_flag[first] = 0;
      H_flag[second] = 0;
    } else if (H[first] < H[second]) {
      H_flag[first] = 0;
    } else if (H[first] > H[second]) {
      H_flag[second] = 0;
    }
  }
  int result = 0;
  for (int i = 1; i < N + 1; i++) {
    if (H_flag[i] != 0) {
      result++;
    }
  }
  cout << result << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

/*                        ______
 _______   /\\     |``\\   |        |  /
    |     /  \\    |__/   |____    |/
    |    / _ _\\   |  \\   |        |\\
    |   /      \\  |   \\  |______  |  \\

            Dept. of CSE
        Comilla  University

*/
#include <bits/stdc++.h>
#define pi 2 * acos(0.0)
#define ll long long
#define FIO                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define Node struct node
#define spc " "
#define E 2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx, ny) nx >= 0 && nx < n &&ny >= 0 && ny < m
#define ee endl
#define pii pair<int, int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[] = {0, 0, +1, -1};
int fy[] = {+1, -1, 0, 0};

using namespace std;
/// check n=1;
/// check corner case;
const int maX = 1e5 + 1;
vector<ll> Graph[maX], cost[maX];
ll visit[maX];

int main() {
  ll n, k, i, j, cc = 0;
  cin >> n >> k;
  ll ara[n + 1];
  for (i = 1; i <= n; i++)
    cin >> ara[i];
  for (i = 1; i <= k; i++) {
    ll x, y;
    cin >> x >> y;
    Graph[x].pb(y);
    Graph[y].pb(x);
  }
  for (i = 1; i <= n; i++) {
    ll l = 0;
    for (j = 0; j < Graph[i].size(); j++) {
      ll u = Graph[i][j];
      if (ara[i] <= ara[u]) {
        l = 1;
        break;
      }
    }
    if (l == 0)
      cc++;
  }
  cout << cc << endl;
  return 0;
}


Error: 0

Fixed submission:

/*                        ______
 _______   /\\     |``\\   |        |  /
    |     /  \\    |__/   |____    |/
    |    / _ _\\   |  \\   |        |\\
    |   /      \\  |   \\  |______  |  \\

            Dept. of CSE
        Comilla  University

*/
#include <bits/stdc++.h>
#define pi 2 * acos(0.0)
#define ll long long
#define FIO                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define Node struct node
#define spc " "
#define E 2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx, ny) nx >= 0 && nx < n &&ny >= 0 && ny < m
#define ee endl
#define pii pair<int, int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[] = {0, 0, +1, -1};
int fy[] = {+1, -1, 0, 0};

using namespace std;
/// check n=1;
/// check corner case;
const int maX = 1e3 + 1;
vector<ll> Graph[maX], cost[maX];
ll visit[maX];

int main() {
  ll n, k, i, j, cc = 0;
  cin >> n >> k;
  ll ara[n + 1];
  for (i = 1; i <= n; i++)
    cin >> ara[i];
  for (i = 1; i <= k; i++) {
    ll x, y;
    cin >> x >> y;
    Graph[x].pb(y);
    Graph[y].pb(x);
  }
  for (i = 1; i <= n; i++) {
    ll l = 0;
    for (j = 0; j < Graph[i].size(); j++) {
      ll u = Graph[i][j];
      if (ara[i] <= ara[u]) {
        l = 1;
        break;
      }
    }
    if (l == 0)
      cc++;
  }
  cout << cc << endl;
  return 0;
}