alexjercan/bugnet huggingface dataset:
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++)

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

  rep(i, m) {
    cin >> a[i];
    cin >> b[i];
  }

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

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

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

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

  rep(i, m) {
    cin >> a[i];
    cin >> b[i];
  }

  int count = 0;
  rep(i, n) {
    bool good = true;
    rep(j, m) {
      if (a[j] == i + 1) {
        if (h[b[j] - 1] >= h[i]) {
          good = false;
          break;
        }
      }
      if (b[j] == i + 1) {
        if (h[a[j] - 1] >= h[i]) {
          good = false;
          break;
        }
      }
    }
    if (good) {
      count++;
    }
  }

  cout << count << endl;

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

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

int main() {
  cin >> N >> M;
  vector<int> H(N);
  rep(i, N) cin >> H[i];
  rep(i, M) {
    int A, B;
    cin >> A >> B;
    --A;
    --B;
    to[A].push_back(B);
    to[B].push_back(A);
  }
  int count = 0;
  rep(i, N) {
    int d = to[i].size();
    if (d == 0)
      count++;
    else {
      bool highest = true;
      for (int u : to[i]) {
        if (H[i] <= H[u])
          highest = false;
      }
      if (highest == true)
        count++;
    }
  }
  cout << count << endl;
  return 0;
}

Error: -11

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int N, M;
vector<int> to[100005];
vector<int> H(N);

int main() {
  cin >> N >> M;
  rep(i, N) cin >> H[i];
  rep(i, M) {
    int A, B;
    cin >> A >> B;
    --A;
    --B;
    to[A].push_back(B);
    to[B].push_back(A);
  }
  int count = 0;
  rep(i, N) {
    int d = to[i].size();
    if (d == 0)
      count++;
    else {
      bool highest = true;
      for (int u : to[i]) {
        if (H[i] <= H[u])
          highest = false;
      }
      if (highest == true)
        count++;
    }
  }
  cout << count << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int obs[100100], ans[100100] = {0}, a[100100] = {0};
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> obs[i];
  }
  while (m--) {
    int x, y;
    cin >> x >> y;
    if (obs[x] < obs[y])
      ans[x] = -1;
    else if (obs[y] < obs[x])
      ans[y] = -1;
    else if (obs[x] == obs[y]) {
      ans[x] = -1;
      ans[y] = -1;
    }
    if (obs[x] > obs[y] && ans[x] != -1)
      ans[x] = 1;
    else if (obs[y] > obs[x] && ans[y] != -1)
      ans[y] = 1;
    a[x] = y;
    a[y] = x;
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (ans[i] == 1)
      cnt += 1;
    if (a[i] == 0)
      cnt += 1;
  }
  cout << cnt;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int obs[10010], ans[10010] = {0}, a[10010] = {0};
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> obs[i];
  }
  while (m--) {
    int x, y;
    cin >> x >> y;
    if (obs[x] <= obs[y])
      ans[x] = -1;
    else if (obs[y] <= obs[x])
      ans[y] = -1;
    if (obs[x] > obs[y] && ans[x] != -1)
      ans[x] = 1;
    else if (obs[y] > obs[x] && ans[y] != -1)
      ans[y] = 1;
    a[x] = y;
    a[y] = x;
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (ans[i] == 1)
      cnt += 1;
    if (a[i] == 0)
      cnt += 1;
  }
  cout << cnt;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  int n, m;

  cin >> n >> m;
  int heights[n];
  vector<set<int>> arr(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> heights[i];
  }
  for (int i = 0; i < m; i++) {
    int s, f;
    cin >> s >> f;
    arr[s].insert(f);
    arr[f].insert(s);
  }
  //	cout<<"elements"<<endl;
  //	for(int i = 1; i <= n; i++){
  ////		if(arr[i].size() > 0) {
  //		cout<<i<<" ";
  //			for(auto el: arr[i]){
  //				cout <<" " << el;
  //			}
  //			cout<<endl;
  ////		}
  //	}
  //	cout<<"hello";
  int count = 0;
  for (int i = 1; i <= n; i++) {
    int currheight = heights[i - 1];
    bool isgood = true;
    for (auto el : arr[i]) {
      if (heights[el - 1] >= currheight) {
        isgood = false;
        break;
      }
    }
    if (isgood)
      count++;
  }
  cout << count;
  return 0;
}

Error: -11

Fixed submission:

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

int main() {

  int n, m;
  int heights[n];
  cin >> n >> m;
  vector<vector<int>> arr(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> heights[i];
  }
  for (int i = 0; i < m; i++) {
    int s, f;
    cin >> s >> f;
    arr[s].push_back(f);
    arr[f].push_back(s);
  }
  for (int i = 1; i <= n; i++) {
    //		if(arr[i].size() > 0) {
    for (auto el : arr[i]) {
      cout << i << " " << el << endl;
    }
    //		}
  }
  //	cout<<"hello";
  int count = 0;
  for (int i = 1; i <= n; i++) {
    int currheight = heights[i - 1];
    bool isgood = true;
    for (auto el : arr[i]) {
      if (heights[el] > currheight) {
        isgood = false;
        break;
      }
    }
    if (isgood)
      count++;
  }
  cout << count << endl;
  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;

int n, m, q;
vector<int> a, b, c, d;
int ans;

template <typename T> void printVec(vector<T> &vec) {
  cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    cout << *it << " ";
  }
  cout << endl;
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<vector<int>> data(m, vector<int>(2));
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    data.at(i).at(0) = a;
    data.at(i).at(1) = b;
  }
  int ans_count = 0;
  vector<bool> ans(n, true);
  for (int i = 0; i < m; i++) {
    if (h[data[i][0] - 1] <= h[data[i][1] - 1]) {
      ans[data[i][0] - 1] = false;
    }
    if (h[data[i][1] - 1] <= h[data[i][0] - 1]) {
      ans[data[i][1] - 1] = false;
    }
  }
  for (int i = 0; i < n; i++) {
    if (ans[i] == true) {
      ans_count = ans_count + 1;
    }
  }
  cout << ans_count << endl;
  return 0;
}


Error: 0

Fixed submission:

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

int n, m, q;
vector<int> a, b, c, d;
int ans;

template <typename T> void printVec(vector<T> &vec) {
  cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    cout << *it << " ";
  }
  cout << endl;
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  // int a[m][m];
  vector<vector<int>> data(n, vector<int>(2));
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    data.at(i).at(0) = a;
    data.at(i).at(1) = b;
  }
  int ans_count = 0;
  vector<bool> ans(n, true);
  for (int i = 0; i < m; i++) {
    if (h[data[i][0] - 1] <= h[data[i][1] - 1]) {
      ans[data[i][0] - 1] = false;
    }
    if (h[data[i][1] - 1] <= h[data[i][0] - 1]) {
      ans[data[i][1] - 1] = false;
    }
  }
  for (int i = 0; i < n; i++) {
    if (ans[i] == true) {
      ans_count = ans_count + 1;
    }
  }
  cout << ans_count << endl;

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

#include <bits/stdc++.h>
#define rep(x, to) for (int(x) = 0; (x) < (to); (x)++)
#define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++)
#define sz(v) (int)(v).size()
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  ll N, M;
  cin >> N >> M;
  vector<ll> height(N);
  vector<int> flag(N, 1);
  vector<P> load(M);
  int ans = 0;
  rep(i, N) { cin >> height[i]; }
  rep(i, M) {
    cin >> load[i].first;
    cin >> load[i].second;
    if (!(height[load[i].first - 1] > height[load[i].second - 1])) {
      flag[load[i].first - 1] = 0;
    }
    if (!(height[load[i].second - 1] > height[load[i].first - 1])) {
      flag[load[i].second - 1] = 0;
    }
  }
  rep(i, N) if (flag[i] == 1) ans++;
  cout << ans << '\\n';
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(x, to) for (int(x) = 0; (x) < (to); (x)++)
#define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++)
#define sz(v) (int)(v).size()
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  ll N, M;
  cin >> N >> M;
  vector<ll> height(N);
  vector<P> load(M);
  int ans = 0;
  rep(i, N) { cin >> height[i]; }
  rep(i, M) {
    cin >> load[i].first;
    cin >> load[i].second;
  }
  rep(i, N) // 展望台を最初から調べていく
  {
    int flag = 1; // もし条件を満たさない時はflagを折る
    rep(j, M)     // それぞれ道を確認する
    {
      if (load[j].first - 1 == i) // 調べたい展望台に道があった時
      {
        if (!(height[i] >
              height[load[j].second -
                     1])) // もし調べたい展望台とつながっている展望台との比較
        {
          flag = 0;
          break;
        }
      } else if (load[j].second - 1 == i) {
        if (!(height[i] > height[load[j].first - 1])) {
          flag = 0;
          break;
        }
      }
    }
    if (flag)
      ans++;
  }
  cout << ans << '\\n';
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

int main() {
  int n;
  std::cin >> n;

  int m;
  std::cin >> m;

  std::vector<int> h(n);
  for (int i = 0; i < n; ++i) {
    int v;
    std::cin >> v;
    h[i] = v;
  }

  std::vector<int> r(n);

  for (int i = 0; i < m; ++i) {
    int a;
    std::cin >> a;
    --a;

    int b;
    std::cin >> b;
    --b;

    if (h[a] <= h[b]) {
      ++r[a];
    }

    if (h[a] >= h[b]) {
      ++r[b];
    }
  }

  int x = 0;
  for (int i = 0; i < n; ++i) {
    // std::cout << r[i] << std::endl;
    if (!r[i]) {
      ++x;
    }
  }

  std::cout << x << std::endl;
}


Error: 0

Fixed submission:

#include <iostream>
#include <vector>

int main() {
  int n;
  std::cin >> n;

  int m;
  std::cin >> m;
  ++m;

  std::vector<int> h(n);
  for (int i = 0; i < n; ++i) {
    int v;
    std::cin >> v;
    h[i] = v;
  }

  std::vector<int> r(n);

  for (int i = 0; i < m; ++i) {
    int a;
    std::cin >> a;
    --a;

    int b;
    std::cin >> b;
    --b;

    if (h[a] < h[b]) {
      ++r[a];
    }

    if (h[a] > h[b]) {
      ++r[b];
    }
  }

  int x = 0;
  for (int i = 0; i < n; ++i) {
    // std::cout << r[i] << std::endl;
    if (!r[i]) {
      ++x;
    }
  }

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

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

typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

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

  vector<int> connected[n];
  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    connected[a - 1].push_back(h[b - 1]);
    connected[b - 1].push_back(h[a - 1]);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int toAdd = 1;
    for (int x : connected[i]) {
      if (x >= h[i]) {
        toAdd = 0;
        break;
      }
    }
    ans += toAdd;
  }

  cout << ans;

  return 0;
}

Error: TLE

Fixed submission:

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

typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;
  int h[n];
  for (int i = 0; i < n; i++)
    cin >> h[i];
  pair<int, int> roads[m];
  for (int i = 0; i < m; i++) {
    cin >> roads[i].first;
    cin >> roads[i].second;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int maxConnectedHeight = -1;
    for (int j = 0; j < m; j++) {
      if (roads[j].first == i + 1)
        maxConnectedHeight = max(maxConnectedHeight, h[roads[j].second - 1]);
      if (roads[j].second == i + 1)
        maxConnectedHeight = max(maxConnectedHeight, h[roads[j].first - 1]);
    }
    if (maxConnectedHeight < h[i])
      ans++;
  }
  cout << ans;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int N, M, A, B;
  int ans = 0;
  cin >> N >> M;
  long long H[100100];
  int Ten[100100] = {0};
  rep(i, N) { cin >> H[i]; }
  rep(i, M) {
    cin >> A >> B;
    if (H[A - 1] > H[B - 1]) {
      Ten[B - 1] = 1;
    } else if (H[A - 1] < H[B - 1]) {
      Ten[A - 1] = 1;
    } else {
      Ten[A - 1] = 1;
      Ten[B - 1] = 1;
    }
  }

  rep(i, N) {
    if (Ten[i] == 0)
      ans++;
  }

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int N, M, A, B;
  int ans = 0;
  cin >> N >> M;
  long long H[10010];
  int Ten[10010] = {0};
  rep(i, N) { cin >> H[i]; }
  rep(i, M) {
    cin >> A >> B;
    if (H[A - 1] > H[B - 1]) {
      Ten[B - 1] = 1;
    } else if (H[A - 1] < H[B - 1]) {
      Ten[A - 1] = 1;
    } else {
      Ten[A - 1] = 1;
      Ten[B - 1] = 1;
    }
  }

  rep(i, N) {
    if (Ten[i] == 0)
      ans++;
  }

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

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int i, n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (i = 0; i < n; ++i)
    cin >> h[i];
  vector<int> a(m), b(m);
  for (i = 0; i < m; ++i)
    cin >> a[i] >> b[i];

  vector<int> t(n, 0);
  for (i = 0; i < m; ++i) {
    t[a[i] - 1] |= h[a[i] - 1] - h[b[i] - 1] - 1;
    t[b[i] - 1] |= h[b[i] - 1] - h[a[i] - 1] - 1;
  }
  int cnt = 0;
  for (i = 0; i < n; ++i)
    if (t[i] >= 0)
      ++cnt;
  cout << cnt << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int i, n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (i = 0; i < n; ++i)
    cin >> h[i];
  vector<int> a(m), b(m);
  for (i = 0; i < n; ++i)
    cin >> a[i] >> b[i];

  vector<int> t(n, 0);
  for (i = 0; i < n; ++i) {
    t[a[i] - 1] |= h[a[i] - 1] - h[b[i] - 1];
    t[b[i] - 1] |= h[b[i] - 1] - h[a[i] - 1];
  }
  for (i = 0; t[i] < 0; ++i)
    ;
  cout << i << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int main() {
  int n, m, h[100005], i, a, b;
  cin >> n >> m;
  vector<int> g[100001];
  for (i = 1; i <= n; i++) {
    cin >> h[i];
  }
  for (i = 1; i <= m; i++) {
    cin >> a >> b;
    g[a].pb(b);
    g[b].pb(a);
  }
  int cnt, ans = 0;
  for (i = 1; i <= n; i++) {
    cnt = 0;
    for (int j = 0; j < g[i].size(); j++) {
      int k = g[i][j];
      if (h[k] < h[i]) {
        cnt++;
      }
    }
    if (cnt == g[i].size()) {
      ans++;
    }
  }
  cout << ans << '\\n';
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int main() {
  int n, m, h[100005], i, a, b;
  cin >> n >> m;
  vector<int> g[10000];
  for (i = 1; i <= n; i++) {
    cin >> h[i];
  }
  for (i = 1; i <= m; i++) {
    cin >> a >> b;
    g[a].pb(b);
    g[b].pb(a);
  }
  int cnt, ans = 0;
  for (i = 1; i <= n; i++) {
    cnt = 0;
    for (auto j : g[i]) {
      if (h[j] < h[i]) {
        cnt++;
      }
    }
    if (cnt == g[i].size()) {
      ans++;
    }
  }
  cout << ans << '\\n';
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

/* LETS SEE IF U CAN PULL IT UP THIS TIME OR NOT */
/* WORK HARD MAN ! IT DEFINETELY AIN'T EASY FOR THE PRIZE IT HOLDS .... */
/* GET YOUR ASS TO WORK ALREADY*/
#include <bits/stdc++.h>

#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr);                                                            \\
  cin.tie(nullptr);
#define int long long
#define pb emplace_back
#define ran(v) v.begin(), v.end()
#define mod 1000000007
#define inf 1e15
#define pii pair<int, int>
#define ff first
#define ss second
// #define N --

using namespace std;

int n, m;
vector<list<int>> adjList;
vector<int> val;
vector<int> dp;
bitset<100005> vis;

void dfs(int node) {
  vis[node] = true;

  for (int child : adjList[node]) {
    if (!vis[child])
      dfs(child);
    dp[node] = max(dp[node], val[child]);
    dp[child] = max(dp[child], val[node]);
  }
}

int32_t main() {
  fast cin >> n >> m;
  adjList.resize(n + 1), val.resize(n + 1), dp.resize(n + 1, -inf);
  for (int i = 1; i <= n; i++)
    cin >> val[i];
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    adjList[b].pb(a);
    adjList[a].pb(b);
  }

  for (int i = 1; i <= n; i++)
    if (!vis[i])
      dfs(i);

  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (val[i] > dp[i])
      cnt++;

  cout << cnt << endl;
}

Error: WA

Fixed submission:

/* LETS SEE IF U CAN PULL IT UP THIS TIME OR NOT */
/* WORK HARD MAN ! IT DEFINETELY AIN'T EASY FOR THE PRIZE IT HOLDS .... */
/* GET YOUR ASS TO WORK ALREADY*/
#include <bits/stdc++.h>

#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(nullptr);                                                            \\
  cin.tie(nullptr);
#define int long long
#define pb emplace_back
#define ran(v) v.begin(), v.end()
#define mod 1000000007
#define inf 1e15
#define pii pair<int, int>
#define ff first
#define ss second
// #define N --

using namespace std;

int n, m;
vector<list<int>> adjList;
vector<int> val;
vector<int> kh, ch;
bitset<10005> vis;

void dfs(int node) {
  vis[node] = true;
  kh[node] = val[node];
  for (int child : adjList[node]) {
    if (!vis[child])
      dfs(child);
    kh[node] = max(kh[node], val[child]);
    ch[node] = max(ch[node], val[child]);
    kh[child] = max(kh[child], val[child]);
    ch[child] = max(ch[child], val[node]);
  }
}

int32_t main() {
  fast cin >> n >> m;
  adjList.resize(n + 1), val.resize(n + 1), kh.resize(n + 1),
      ch.resize(n + 1, -inf);
  for (int i = 1; i <= n; i++)
    cin >> val[i];
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    adjList[b].pb(a);
    adjList[a].pb(b);
  }

  for (int i = 1; i <= n; i++)
    if (!vis[i])
      dfs(i);
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (kh[i] == val[i] and ch[i] != val[i]) {
      cout << i << " ";
      cnt++;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define MAXN 100005
int hill[MAXN];
int fir[MAXN];
int n, m, ecnt, ans;
struct edge {
  int v, nxt;
} eds[MAXN << 1];
void adde(int a, int b) {
  eds[++ecnt].v = b, eds[ecnt].nxt = fir[a], fir[a] = ecnt;
  eds[++ecnt].v = a, eds[ecnt].nxt = fir[b], fir[b] = ecnt;
}
int main() {
  int a, b;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d", &hill[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a, &b);
    adde(a, b);
  }
  for (int i = 1; i <= n; i++) {
    bool flg = 0;
    for (int j = fir[i]; j; j = eds[j].nxt) {
      int v = eds[j].v;
      if (hill[v] >= hill[i])
        flg = 1;
    }
    if (flg == 0)
      ans++;
  }
  printf("%d\\n", ans);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define MAXN 100005
int hill[MAXN];
int fir[MAXN];
int n, m, ecnt, ans;
struct edge {
  int v, nxt;
} eds[MAXN];
void adde(int a, int b) {
  eds[++ecnt].v = b, eds[ecnt].nxt = fir[a], fir[a] = ecnt;
  eds[++ecnt].v = a, eds[ecnt].nxt = fir[b], fir[b] = ecnt;
}
int main() {
  int a, b;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d", &hill[i]);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a, &b);
    adde(a, b);
  }
  for (int i = 1; i <= n; i++) {
    bool flg = 0;
    for (int j = fir[i]; j; j = eds[j].nxt) {
      int v = eds[j].v;
      if (hill[v] >= hill[i])
        flg = 1;
    }
    if (flg == 0)
      ans++;
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

// #define _CRT_SECURE_NO_WARNINGS
// #include <bits/stdc++.h>
#include "bits/stdc++.h"

#define rep(i, n) for (ll(i) = 0; (i) < (ll)(n); (i)++)
#define all(x) (x).begin(), (x).end()

#define MOD 1000000007LL
#define INF (1LL << 60LL)
#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> v(n, true);
  rep(i, n) cin >> h[i];
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (h[a] < h[b]) {
      v[a] = false;
    } else {
      v[b] = false;
      if (h[a] == h[b])
        v[a] = false;
    }
  }
  int ans = 0;
  rep(i, n) if (v[i]) ans++;
  cout << ans << endl;
}


Error: 0

Fixed submission:

// #define _CRT_SECURE_NO_WARNINGS
// #include <bits/stdc++.h>
#include "bits/stdc++.h"

#define rep(i, n) for (ll(i) = 0; (i) < (ll)(n); (i)++)
#define all(x) (x).begin(), (x).end()

#define MOD 1000000007LL
#define INF (1LL << 60LL)
#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;

int par[MAX_N], my_rank[MAX_N];
void init(int n) {
  rep(i, MAX_N) {
    par[i] = i;
    my_rank[i] = 0;
  }
}
int root(int x) {
  if (par[x] == x)
    return x;
  else
    return par[x] = root(par[x]);
}

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y)
    return;
  if (my_rank[x] < my_rank[y]) {
    par[x] = y;
  } else {
    par[y] = par[x];
    if (my_rank[x] == my_rank[y])
      my_rank[x]++;
  }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  init(MAX_N);
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    unite(a, b);
  }
  vector<int> v(n, 0);
  vector<bool> v2(n, false);
  rep(i, n) {
    if (v[root(i)] > h[i])
      continue;
    else if (v[root(i)] == h[i])
      v2[root(i)] = false;
    else {
      v[root(i)] = h[i];
      v2[root(i)] = true;
    }
  }
  int ans = 0;
  rep(i, n) if (v2[i]) ans++;
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> h;
  vector<ll> ma(n + 1, 0);
  rep(i, n) {
    int h_y;
    cin >> h_y;
    h.push_back(h_y);
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    ma[a] = max(ma[a], h[b - 1]);
    ma[b] = max(ma[b], h[a - 1]);
  }
  int ans = 0;
  rep(i, n) {
    if (h[i - 1] > ma[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> h;
  vector<ll> ma(n, 0);
  rep(i, n) { cin >> h[i]; }
  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;
  rep(i, n) {
    if (h[i] > ma[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}