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

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

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

vector<int> graph[100010];

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

  rep(i, m) {
    cin >> a >> b;
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  int ans = 0;
  bool f = false;

  rep(i, n) {
    f = false;
    rep(j, graph[i].size()) {
      if (h[i] <= h[graph[i][j]]) {
        f = true;
        break;
      }
    }
    if (!f) {
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

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

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

vector<int> graph[10010];

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

  rep(i, m) {
    cin >> a >> b;
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  int ans = 0;
  bool f = false;

  rep(i, n) {
    f = false;
    rep(j, graph[i].size()) {
      if (h[i] <= h[graph[i][j]]) {
        f = true;
        break;
      }
    }
    if (!f) {
      ans++;
    }
  }
  cout << ans << endl;

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

#include <iostream>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;

int main() {
  ll N, M, a, b, h;
  cin >> N >> M;
  vector<bool> F(N, true);
  vector<ll> H(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> h;
    H[i] = h;
  }

  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    a--;
    b--;
    if (H[a] <= H[b]) {
      F[a] = false;
    }
    if (H[a] >= H[b]) {
      F[b] = false;
    }
  }
  ll ans = 0;
  for (bool f : F) {
    if (f)
      ans++;
  }
  cout << ans << "\\n";
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;

ll parent(ll a, vector<ll> &parents) {
  if (parents[a] == a)
    return a;
  else {
    parents[a] = parent(parents[a], parents);
    return parents[a];
  }
}

void union_tree(ll a, ll b, vector<ll> &parents, vector<ll> &H) {
  ll pa = parent(a, parents);
  ll pb = parent(b, parents);
  ll Hpa = H[pa];
  ll Hpb = H[pb];
  if (Hpa < Hpb)
    parents[b] = pa;
  else
    parents[a] = pb;
}

int main() {
  ll N, M, a, b, h;
  cin >> N >> M;
  vector<ll> parents(N, 0);
  vector<ll> H(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> h;
    parents[i] = i;
    H[i] = h;
  }

  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    union_tree(a, b, parents, H);
  }
  unordered_set<ll> goods;
  for (int i = 0; i < N; i++) {
    goods.insert(parent(i, parents));
  }
  cout << goods.size() << "\\n";
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P>> vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N, long long M, std::vector<long long> H,
           std::vector<long long> A, std::vector<long long> B) {
  vector<bool> b(N, true);
  rep(i, M) {
    if (H[A[i]] <= H[B[i]])
      b[A[i]] = false;
    if (H[B[i]] <= H[A[i]])
      b[B[i]] = false;
  }
  ll res = 0;
  rep(i, N) {
    if (b[i])
      res++;
  }
  cout << res << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> H(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &H[i]);
  }
  std::vector<long long> A(M);
  std::vector<long long> B(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
    A[i]--;
    B[i]--;
  }
  solve(N, M, std::move(H), std::move(A), std::move(B));
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P>> vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N, long long M, std::vector<long long> H,
           std::vector<long long> A, std::vector<long long> B) {
  vector<bool> b(N, true);
  rep(i, N) {
    if (H[A[i]] <= H[B[i]])
      b[A[i]] = false;
    if (H[B[i]] <= H[A[i]])
      b[B[i]] = false;
  }
  ll res = 0;
  rep(i, N) {
    if (b[i])
      res++;
  }
  cout << res << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> H(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &H[i]);
  }
  std::vector<long long> A(M);
  std::vector<long long> B(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
    A[i]--;
    B[i]--;
  }
  solve(N, M, std::move(H), std::move(A), std::move(B));
  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++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  vector<bool> J(N);
  rep(i, N) {
    cin >> H.at(i);
    J.at(i) = true;
  }

  rep(i, M) {
    int A, B;
    cin >> A >> B;
    if (H.at(A - 1) >= H.at(B - 1))
      J.at(B - 1) = false;
    if (H.at(A - 1) <= H.at(B - 1))
      J.at(A - 1) = false;
  }
  int ans = 0;
  rep(i, N) {
    if (J.at(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;
using ll = long long;
using P = pair<int, int>;

int ans = 0;
int N, M;
vector<P> AB;
vector<ll> H;

void judge(int i) {
  int now = i + 1;
  vector<int> TEN(0);
  rep(j, M) {
    if (AB.at(j).first == now)
      TEN.push_back(AB.at(j).second - 1);
    if (AB.at(j).second == now)
      TEN.push_back(AB.at(j).first - 1);
  }

  TEN.erase(unique(TEN.begin(), TEN.end()), TEN.end());

  bool high = true;
  rep(k, TEN.size()) {
    // cout<<TEN.at(k);
    if (H.at(TEN.at(k)) >= H.at(i)) {
      high = false;
      break;
    }
  }

  if (high) {
    ans++;
    // cout << now <<"end" <<endl;
  }
  return;
}

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

  H = vector<ll>(N);
  rep(i, N) cin >> H.at(i);
  AB = vector<P>(M);
  rep(i, M) cin >> AB.at(i).first >> AB.at(i).second;

  rep(i, N) judge(i);

  cout << ans << endl;
}
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> H(N);
  for (long long i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  vector<long long> A(M), B(M);
  for (long long i = 0; i < M; i++) {
    cin >> A.at(i) >> B.at(i);
  }
  vector<long long> ans(N, 0);
  for (long long i = 0; i < M; i++) {

    if (H.at(A.at(i) - 1) > H.at(B.at(i) - 1)) {
      ans.at(B.at(i) - 1) = 1;
    }
    if (H.at(A.at(i) - 1) < H.at(B.at(i) - 1)) {
      ans.at(A.at(i) - 1) = 1;
    }
    if (H.at(A.at(i) - 1) == H.at(B.at(i) - 1)) {
      ans.at(A.at(i) - 1) = 1;
      ans.at(B.at(i) - 1) = 1;
    }
  }
  long long X = 0;
  for (long long i = 0; i < N; i++) {
    if (ans.at(i) == 1) {
      X++;
    }
  }
  cout << N - X << endl;
}


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


Fixed submission:

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

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

    if (H.at(A.at(i) - 1) > H.at(B.at(i) - 1)) {
      ans.at(B.at(i) - 1) = 1;
    }
    if (H.at(A.at(i) - 1) < H.at(B.at(i) - 1)) {
      ans.at(A.at(i) - 1) = 1;
    }
    if (H.at(A.at(i)) == H.at(B.at(i))) {
      ans.at(A.at(i) - 1) = 1;
      ans.at(B.at(i) - 1) = 1;
    }
  }
  long long X = 0;
  for (long long i = 0; i < N; i++) {
    if (ans.at(i) == 1) {
      X++;
    }
  }
  cout << N - X << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n, m;
  cin >> n >> m;
  vector<long int> h(n), c(n);
  for (int i = 0; i < n; i++) {
    c.at(i) = 1;
    cin >> h.at(i);
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (h.at(a - 1) > h.at(b - 1))
      c.at(b - 1) = 0;
    else if (h.at(a - 1) < h.at(b - 1))
      c.at(a - 1) = 0;
    else {
      c.at(b - 1) = 0;
      c.at(a - 1) = 0;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += c.at(i);
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n, m;
  cin >> n >> m;
  vector<long int> h(n), c(n);
  for (int i = 0; i < n; i++)
    c.at(i) = 1;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (h.at(a - 1) > h.at(b - 1))
      c.at(b - 1) = 0;
    else
      c.at(a - 1) = 0;
  }
  int ans = 0;
  for (int i = 0; i < n; i++)
    ans += c.at(i);
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <array>
#include <iostream>

using namespace std;

int main(void) {
  std::array<bool, 100000> is_good_list;
  std::array<int, 100000> height_list;
  int n, m;
  cin >> n;
  cin >> m;
  is_good_list.fill(true);

  // 展望台の高さを登録
  for (int s = 0; s < n; s++) {
    int h;
    cin >> h;
    height_list[s] = h;
  }

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a;
    cin >> b;
    a--;
    b--;
    if (height_list[a] <= height_list[b]) {
      is_good_list[a] = false;
    }
    if (height_list[a] >= height_list[b]) {
      is_good_list[b] = false;
    }
  }
  int good_num = 0;
  for (int i = 0; i < n; i++) {
    if (is_good_list[i]) {
      good_num++;
    }
  }
  cout << good_num;
}

Error: WA

Fixed submission:

#include <array>
#include <iostream>

using namespace std;

int main(void) {
  std::array<bool, 10> is_good_list;
  std::array<int, 10> height_list;
  int n, m;
  cin >> n;
  cin >> m;
  is_good_list.fill(true);

  // 展望台の高さを登録
  for (int s = 0; s < n; s++) {
    int h;
    cin >> h;
    height_list[s] = h;
  }

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a;
    cin >> b;
    a--;
    b--;
    if (height_list[a] <= height_list[b]) {
      is_good_list[a] = false;
    }
    if (height_list[a] >= height_list[b]) {
      is_good_list[b] = false;
    }
  }
  int good_num = 0;
  for (int i = 0; i < n; i++) {
    if (is_good_list[i]) {
      good_num++;
    }
  }
  cout << good_num;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define py printf("Yes\\n")
#define pn printf("No\\n")
#define in cin >>
using namespace std;
int main() {
  int n, m, h[100000], ma[100000];
  in n >> m;
  for (int i = 1; i <= n; i++) {
    in h[i];
    ma[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    in 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: -11

Fixed submission:

#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define py printf("Yes\\n")
#define pn printf("No\\n")
#define in cin >>
using namespace std;
int main() {
  int n, m, h[n], ma[n];
  in n >> m;
  for (int i = 1; i <= n; i++) {
    in h[i];
    ma[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    in 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;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  int i, n, m, a, b, count = 0;
  vector<int> h(N_SIZE);
  vector<bool> ok(N_SIZE, true);
  cin >> n >> m;
  rep(i, n) { cin >> h.at(i); }

  rep(i, m) {
    cin >> a >> b;
    a--;
    b--;
    if (h.at(a) > h.at(b)) {
      ok.at(b) = false;
    } else if (h.at(a) < h.at(b)) {
      ok.at(a) = false;
    } else {
      ok.at(a) = false;
      ok.at(b) = false;
    }
  }
  rep(i, n) {
    if (ok.at(i))
      count++;
  }
  cout << count << endl;
}

Error: 0

Fixed submission:

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

int main(void) {
  int i, n, m, a, b, count = 0;
  vector<int> h(N_SIZE);
  vector<int> buf(N_SIZE);
  cin >> n >> m;
  rep(i, n) { cin >> h.at(i); }
  rep(i, n) { buf.at(i) = h.at(i); }
  rep(i, m) {
    cin >> a >> b;
    if (h.at(a) > h.at(b)) {
      buf.at(b) = 0;
    } else if (h.at(a) < h.at(b)) {
      buf.at(a) = 0;
    } else {
      buf.at(a) = 0;
      buf.at(b) = 0;
    }
  }
  rep(i, n) {
    if (!buf.at(i))
      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 < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)

using ll = long long;

int main() {
  long long int N, M;
  cin >> N >> M;
  // vector<int> H(N+1,0);
  long long int H[N + 1];
  rep(i, N) { cin >> H[i + 1]; }

  vector<int> highest(N + 1, 1);
  rep(i, N + 1) { highest[i] = 1; }
  highest[0] = 0;

  long long int a, b;
  rep(i, M) {
    cin >> a >> b;
    if (H[a] >= H[b]) {
      highest[b] = 0;
    }
    if (H[a] <= H[b]) {
      highest[a] = 0;
    }
  }

  long long int ans = 0;
  rep(i, N + 1) {
    if (highest[i] == 1)
      ans++;
  };

  cout << ans << endl;
}

/*
N^2 = 10^10 なのでTLE
 //vector< vector<bool> > Road(N+1, vector<bool>(N+1,false) );
  bool Road[N+1][N+1];
  //rep(a,N+1)rep(b,N+1){Road[a][b]=false;}
  int a,b;
  rep(i,M){
    cin >> a >> b;
    Road[a][b]=true;
    Road[b][a]=true;
    }

  for(int i=1;i<=N;i++){
    highest = true;
    for(int j=1;j<=N;j++){
      if( (Road[i][j]) && (H[i]<=H[j]) ){
        //cout << i << "," << j << endl;
        highest = false;
        }
    }
    //cout << highest <<endl;
    if(highest)ans++;
  }
*/

Error: TLE

Fixed submission:

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

using ll = long long;

int main() {
  int N, M;
  cin >> N >> M;
  // vector<int> H(N+1,0);
  long long int H[N + 1];
  rep(i, N) { cin >> H[i + 1]; }

  vector<vector<bool>> Road(N + 1, vector<bool>(N + 1, false));
  // vector<vector<要素の型>> 変数名(要素数1, vector<要素の型>(要素数2, 初期値))
  // rep(a,N+1)rep(b,N+1){Road[a][b]=false;}
  int a, b;
  rep(i, M) {
    cin >> a >> b;
    Road[a][b] = true;
    Road[b][a] = true;
  }

  int ans = 0;
  bool highest = true;

  for (int i = 1; i <= N; i++) {
    highest = true;
    for (int j = 1; j <= N; j++) {
      if ((Road[i][j]) && (H[i] <= H[j])) {
        // cout << i << "," << j << endl;
        highest = false;
      }
    }
    // cout << highest <<endl;
    if (highest)
      ans++;
  }

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

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

typedef long long ll;

#define Canuc80k                                                               \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define I_am ios_base::sync_with_stdio(false);
#define REP(i, a, b) for (int i = a; i < b; i++)
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = a; i >= b; i--)

const int N = 1e6 + 1;
const int M = 1e9 + 7;

string str;
pair<int, int> a[N];
int n, m, h[N], cnt = 0;
bool pp[N];

int main() {
  I_am Canuc80k;

  cin >> n >> m;
  FOR(i, 1, n) {
    cin >> h[i];
    pp[i] = true;
  }

  FOR(i, 1, m)
  cin >> a[i].first >> a[i].second;

  sort(a + 1, a + m + 1);

  FOR(j, 1, m) {
    if (h[a[j].second] >= h[a[j].first])
      pp[a[j].first] = false;
    if (h[a[j].second] <= h[a[j].first])
      pp[a[j].second] = false;
  }

  FOR(i, 1, n)
  if (pp[i])
    cnt++;

  cout << cnt;
}

Error: TLE

Fixed submission:

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

typedef long long ll;

#define Canuc80k                                                               \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define I_am ios_base::sync_with_stdio(false);
#define REP(i, a, b) for (int i = a; i < b; i++)
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = a; i >= b; i--)

const int N = 1e6 + 1;
const int M = 1e9 + 7;

string str;
pair<int, int> a[N];
int n, m, h[N], cnt = 0;
bool pp[N];

int main() {
  I_am Canuc80k;

  cin >> n >> m;
  FOR(i, 1, n) {
    cin >> h[i];
    pp[i] = true;
  }

  FOR(i, 1, m)
  cin >> a[i].first >> a[i].second;

  sort(a + 1, a + m + 1);

  FOR(i, 1, m) {
    int now = h[a[i].first];
    bool ok = false;

    FOR(j, i, m) {
      if (a[j].first != a[i].first || j == m) {
        if (h[a[j].second] >= now)
          pp[a[i].second] = false;
        if (h[a[j].second] <= now)
          pp[a[j].second] = false;
        i = j - 1;
        break;
      } else {
        if (h[a[j].second] >= now)
          pp[a[i].second] = false;
        if (h[a[j].second] <= now)
          pp[a[j].second] = false;
      }
    }
  }

  FOR(i, 1, n)
  if (pp[i])
    cnt++;

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

#include <iostream>
#include <vector>
using ln = long long;
#define rep(i, n)                                                              \\
  for (int i = 1; i <= (int)(n); i++) // rep(i,n)=(int i=0; i < (int)(n) ; i++)
using namespace std;

int main() {
  ln n, m;
  cin >> n >> m;
  ln h[n + 1];
  ln a[m + 1], b[m + 1];
  ln check[n + 1] = {0};

  rep(i, n) { cin >> h[i]; }

  int a_tn, b_tn;
  rep(i, m) {
    cin >> a[i] >> b[i];
    a_tn = a[i];
    b_tn = b[i];

    if (h[a_tn] > h[b_tn]) {
      check[b_tn] = 1;
    } else if (h[a_tn] < h[b_tn]) {
      check[a_tn] = 1;
    } else {
      check[b_tn] = 1;
      check[a_tn] = 1;
    }
  }

  int count = 0;
  rep(i, n) {
    if (check[i] == 0) {
      count++;
    }
  }

  cout << count << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  long long n, m; // 展望台n個,道m個
  cin >> n >> m;
  long long h[n + 100];
  long long a[m + 100], b[m + 100]; // 結ばれている展望台
  int high_check[n + 100];          // 1ならhighst

  for (int i = 0; i < n + 101; i++) {
    high_check[i] = 1;
  }
  int id = 0;

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

  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      if (high_check[i] == 0) {
        break;
      } else {
        if (i == a[j]) {
          id = b[j];
          if (h[i] > h[id]) {
            high_check[id] = 0;
          } else if (h[i] == h[id]) {
            high_check[i] = 0;
            high_check[id] = 0;
          } else {
            high_check[i] = 0;
          }
        } else if (i == b[j]) {
          id = a[j];
          if (h[i] > h[id]) {
            high_check[id] = 0;
          } else if (h[i] == h[id]) {
            high_check[i] = 0;
            high_check[id] = 0;
          } else {
            high_check[i] = 0;
          }
        }
      }
    }
  }

  int cnt = 0;
  for (int i = 1; i < n + 1; i++) {
    if (high_check[i] == 1) {
      cnt++;
    }
  }

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

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
const int N = 2e5 + 10;
int n, m, a[N], ans, vis[N];
vector<int> G[N];
void dfs(int u, int fa) {
  vis[u] = 1;
  int flag = 1;
  for (int v : G[u]) {
    if (a[v] >= a[u])
      flag = 0;
    if (vis[v])
      continue;
    dfs(v, u);
  }
  if (flag)
    ans++;
}
int main() {
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, m) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  rep(i, 1, n) {
    if (vis[i])
      continue;
    dfs(i, -1);
  }

  cout << ans << endl;
}
/*
3 2
1 2 3
1 2
1 2
*/


Error: 0

Fixed submission:

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
const int N = 2e5 + 10;
int n, m, a[N], ans, vis[N];
vector<int> G[N];
void dfs(int u, int fa) {
  vis[u] = 1;
  int flag = 1;
  for (int v : G[u]) {
    if (a[v] >= a[u])
      flag = 0;
    if (v == fa)
      continue;
    dfs(v, u);
  }
  if (flag)
    ans++;
}
int main() {
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, m) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  rep(i, 1, n) {
    if (vis[i])
      continue;
    dfs(i, -1);
  }

  cout << ans << endl;
}