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

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

struct UnionFind {
  vector<int> r;

  UnionFind(int N) { r = vector<int>(N, -1); }

  int root(int x) {
    if (r[x] < 0)
      return x;
    return r[x] = root(r[x]);
  }

  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x > y)
      swap(x, y);
    if (x == y)
      return false;
    r[x] += r[y];
    r[y] = x;
    return true;
  }

  int size(int x) { return -r[root(x)]; }
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind UF(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    UF.unite(--a, --b);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, UF.size(i));
  }
  cout << ans;
}


Error: TLE

Fixed submission:

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

struct UnionFind {
  vector<int> r;

  UnionFind(int N) { r = vector<int>(N, -1); }

  int root(int x) {
    if (r[x] < 0)
      return x;
    return root(r[x]);
  }

  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x > y)
      swap(x, y);
    if (x == y)
      return false;
    r[x] += r[y];
    r[y] = x;
    return true;
  }

  int size(int x) { return -r[root(x)]; }
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind UF(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    UF.unite(--a, --b);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, UF.size(i));
  }
  cout << ans;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
typedef pair<int, int> pii;
const int mod = (int)1000000007;
const int inf = (int)2e18;
int par[200010], Rank[200010];

int find(int a) {
  if (par[a] < 0)
    return a;
  int x = find(par[a]);
  par[a] = x;
  return x;
}

void merge(int a, int b) {
  a = find(a);
  b = find(b);
  if (a == b)
    return;
  if (Rank[a] > Rank[b]) {
    par[b] = a;
    Rank[a] += Rank[b];
  } else {
    par[a] = b;
    Rank[b] += Rank[a];
  }
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(9);
#ifdef LOCAL_DEFINE
  freopen("in.txt", "rt", stdin);
#endif
  int n, m, x, y, r = 0, mr;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    par[i] = -1, Rank[i] = 1;
  vector<bool> flag(n + 1, false);
  while (m--) {
    cin >> x >> y;
    merge(x, y);
    flag[x] = true;
    flag[y] = true;
  }
  vector<int> v;
  for (int i = 1; i <= n; i++) {
    if (par[i] < 0 && flag[i]) {
      v.push_back(Rank[i]);
    }
  }
  if (v.size() > 0) {
    while (v.size()) {
      sort(v.begin(), v.end());
      mr = v[0];
      for (int i = 0; i < v.size(); i++) {
        v[i] -= mr;
        if (v[i] == 0) {
          v.erase(v.begin() + i);
          i--;
        }
      }
      r += mr;
    }
    cout << r << "\\n";
  } else {
    cout << 1 << "\\n";
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
typedef pair<int, int> pii;
const int mod = (int)1000000007;
const int inf = (int)2e18;
int par[200010], Rank[200010];

int find(int a) {
  if (par[a] < 0)
    return a;
  int x = find(par[a]);
  par[a] = x;
  return x;
}

void merge(int a, int b) {
  a = find(a);
  b = find(b);
  if (a == b)
    return;
  if (Rank[a] > Rank[b]) {
    par[b] = a;
    Rank[a] += Rank[b];
  } else {
    par[a] = b;
    Rank[b] += Rank[a];
  }
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(9);
#ifdef LOCAL_DEFINE
  freopen("in.txt", "rt", stdin);
#endif
  int n, m, x, y;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    par[i] = -1, Rank[i] = 1;
  vector<bool> flag(n + 1, false);
  set<pii> vis;
  while (m--) {
    cin >> x >> y;
    pii p1 = {x, y};
    pii p2 = {y, x};
    if ((vis.find(p1) == vis.end()) && (vis.find(p2) == vis.end())) {
      merge(x, y);
      flag[x] = true;
      flag[y] = true;
    }
    vis.insert(p1);
    vis.insert(p2);
  }
  vector<int> v;
  for (int i = 1; i <= n; i++) {
    if (par[i] < 0 && flag[i])
      v.push_back(Rank[i]);
  }
  sort(v.begin(), v.end());
  int r = v[0], mr = v[0];
  for (int i = 1; i < v.size(); i++) {
    r += (v[i] - mr);
  }
  cout << r << "\\n";
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define read freopen("in.txt", "r", stdin)
#define write freopen("out.txt", "w", stdout)
#define mem(x, n) memset(x, n, sizeof(x))
#define all(x) x.begin(), x.end()
#define endl "\\n"

bool vis[int(1e6) + 5];
vector<int> g[int(1e6) + 5];

int main() {
  faster;

  ll n, m;
  cin >> n >> m;

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

  int mxn = 1;

  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      stack<int> q;
      int temp = 1;
      q.push(i);
      vis[i] = true;
      while (!q.empty()) {
        int curr = q.top();
        q.pop();
        for (auto x : g[curr]) {
          if (!vis[x]) {
            vis[x] = true;
            q.push(x);
            temp++;
            mxn = max(mxn, temp);
          }
        }
      }
    }
  }

  cout << mxn << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define read freopen("in.txt", "r", stdin)
#define write freopen("out.txt", "w", stdout)
#define mem(x, n) memset(x, n, sizeof(x))
#define all(x) x.begin(), x.end()
#define endl "\\n"

bool vis[int(1e5) + 5];
vector<int> g[int(1e5) + 5];

int main() {
  faster;

  ll n, m;
  cin >> n >> m;

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

  int mxn = 1;

  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      stack<int> q;
      int temp = 1;
      q.push(i);
      vis[i] = true;
      while (!q.empty()) {
        int curr = q.top();
        q.pop();
        for (auto x : g[curr]) {
          if (!vis[x]) {
            vis[x] = true;
            q.push(curr);
            temp++;
            mxn = max(mxn, temp);
          }
        }
      }
    }
  }

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

// Ace
#include <bits/stdc++.h>
using namespace std;
using in = long long;
using str = string;
using pi = pair<in, in>;
using vi = vector<in>;
#define F first
#define S second
#define pb push_back
#define rep(i, k, n) for (in i = k; i < n; ++i)
#define repr(i, k, n) for (in i = k; i >= n; --i)
#define sz(x) (in) x.size()
#define all(x) begin(x), end(x)
const in MOD = 1e9 + 7;
const in N = 2e5 + 1;

in parent[N];
in bag[N];

void make_set(int v) {
  parent[v] = v;
  bag[v] = 1;
}

int find_set(int v) {
  if (v == parent[v])
    return v;
  return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (bag[a] < bag[b])
      swap(a, b);
    parent[b] = a;
    bag[a] += bag[b];
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  in n, m;
  cin >> n >> m;

  rep(i, 0, n) make_set(i);

  rep(i, 0, m) {
    in x, y;
    cin >> x >> y;
    x--;
    y--;
    union_sets(x, y);
  }

  in ans = 0;
  rep(i, 0, n) ans = max(ans, bag[i]);
  cout << ans;

  return 0;
}

Error: TLE

Fixed submission:

// Ace
#include <bits/stdc++.h>
using namespace std;
using in = long long;
using str = string;
using pi = pair<in, in>;
using vi = vector<in>;
#define F first
#define S second
#define pb push_back
#define rep(i, k, n) for (in i = k; i < n; ++i)
#define repr(i, k, n) for (in i = k; i >= n; --i)
#define sz(x) (in) x.size()
#define all(x) begin(x), end(x)
const in MOD = 1e9 + 7;
const in N = 2e5 + 1;

vector<vi> g(N);
map<in, in> vis;

void dfs(in node) {
  vis[node] = 1;
  rep(i, 0, sz(g[node])) {
    in nn = g[node][i];
    if (vis[nn] == 0) {
      dfs(nn);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  in n, m;
  cin >> n >> m;

  map<pi, in> viss;

  rep(i, 0, m) {
    in x, y;
    cin >> x >> y;
    x--;
    y--;
    if (viss[{x, y}] == 0) {
      g[x].pb(y);
      g[y].pb(x);
      viss[{x, y}] = 1;
      viss[{y, x}] = 1;
    }
  }

  in ans = 0;
  while (sz(vis) < n) {
    in prev = sz(vis);
    in nonvis = -1;
    rep(i, 0, n) {
      if (vis[i] == 0) {
        nonvis = i;
        break;
      }
    }
    if (nonvis != -1) {
      dfs(nonvis);
    } else
      break;
    ans = max(ans, sz(vis) - prev);
  }
  cout << ans;

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

#include <bits/stdc++.h>
using namespace std;
int p[200010], sum[200010];
inline int dsu(int x) { return p[x] == x ? x : p[x] = dsu(p[x]); }
int main(void) {
  int n, m, mx = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    p[i] = i;
    sum[i] = 1;
  }
  while (m--) {
    int u, v;
    scanf("%d%d", &u, &v);
    int x = dsu(u);
    int y = dsu(v);
    if (x != y) {
      p[x] = y;
      sum[y] += sum[x];
    }
  }
  for (int i = 1; i <= n; i++) {
    if (p[i] == i) {
      mx = max(mx, sum[i]);
    }
  }
  printf("%d\\n", mx);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int p[200010], sum[200010];
int dsu(int x) {
  if (p[x] == x) {
    return p[x];
  } else {
    return dsu(p[x]);
  }
}
int main() {
  int n, m, mx = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    p[i] = i;
    sum[i] = 1;
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x = dsu(x);
    y = dsu(y);
    if (x != y) {
      p[x] = y;
      sum[y] += sum[x];
    }
  }
  for (int i = 1; i <= n; i++) {
    if (p[i] == i) {
      mx = max(mx, sum[i]);
    }
  }
  printf("%d\\n", mx);
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;

int f[maxn];
int sum[maxn];
int n, m;
int Find(int x) { return f[x] == x ? x : f[x] = Find(f[x]); }
void merge(int u, int v) {
  int x = Find(u);
  int y = Find(v);
  if (x != y) {
    f[x] = y;
    sum[y] += sum[x];
  }
}
void Init() {
  for (int i = 1; i <= n; i++) {
    f[i] = i;
    sum[i] = 1;
  }
}
int main(void) {
  cin >> n >> m;
  Init();
  while (m--) {
    int u, v;
    cin >> u >> v;
    merge(u, v);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (f[i] == i) {
      ans = max(ans, sum[i]);
    }
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int p[200010], sum[200010];
int dsu(int x) {
  if (p[x] == x) {
    return p[x];
  } else {
    return dsu(p[x]);
  }
}
int main() {
  int n, m, mx = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    p[i] = i;
    sum[i] = 1;
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x = dsu(x);
    y = dsu(y);
    if (x != y) {
      p[x] = p[y];
      sum[y] += sum[x];
    }
  }
  for (int i = 1; i <= n; i++) {
    if (p[i] == i) {
      mx = max(mx, sum[i]);
    }
  }
  printf("%d\\n", mx);
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

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

struct union_find {
  vector<int> r;
  union_find(int n) { r = vector<int>(n, -1); }
  int root(int x) {
    if (r[x] < 0) {
      return x;
    } else {
      return root(r[x]);
    }
  }
  bool unite(int a, int b) {
    a = root(a);
    b = root(b);
    if (a == b) {
      return false;
    } else {
      if (r[a] > r[b]) {
        swap(a, b);
      }
      r[a] += r[b];
      r[b] = a;
      return true;
    }
  }
  int size(int x) { return -r[root(x)]; }
};

int main() {
  int n, m;
  cin >> n >> m;
  int a, b;
  union_find u(n);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;
    u.unite(a, b);
  }
  int M = 1;
  for (int i = 0; i < n; i++) {
    M = max(u.size(i), M);
  }
  cout << M << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> info(m, vector<int>(2));
  vector<int> index(m);
  for (int i = 0; i < m; i++) {
    cin >> info.at(i).at(0) >> info.at(i).at(1);
    index.at(i) = i;
  }
  set<int> friends;
  bool next;
  int M = 1;
  int sum = 0;
  while (index.size() > 0) {
    next = false;
    friends = {info.at(index.at(0)).at(0), info.at(index.at(0)).at(1)};
    index.erase(index.begin());
    while (!next) {
      next = true;
      for (int i = (int)index.size() - 1; i >= 0; i--) {
        if (friends.count(info.at(index.at(i)).at(0))) {
          friends.insert(info.at(index.at(i)).at(1));
          index.erase(index.begin() + i);
          next = false;
        } else if (friends.count(info.at(index.at(i)).at(1))) {
          friends.insert(info.at(index.at(i)).at(0));
          index.erase(index.begin() + i);
          next = false;
        }
      }
      /*
      for(int i=0;i<(int)index.size();i++){
        if(friends.count(info.at(index.at(i)).at(0))){
          friends.insert(info.at(index.at(i)).at(1));
          index.erase(index.begin()+i);
          i--;
          next=false;
        }else if(friends.count(info.at(index.at(i)).at(1))){
          friends.insert(info.at(index.at(i)).at(0));
          index.erase(index.begin()+i);
          i--;
          next=false;
        }
      }
      */
    }
    sum += friends.size();
    M = max(M, (int)friends.size());
    if (n - sum <= M) {
      break;
    }
  }
  cout << M << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n, t, x, y, m, q;
ll parent[200001] = {0};
ll find(ll x) {
  if (parent[x] == x)
    return x;
  return parent[x] = find(parent[x]);
}
void unian(ll x, ll y) {
  ll xset = find(parent[x]);
  ll yset = find(parent[y]);
  if (yset != xset)
    parent[xset] = yset;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  map<ll, ll> ma;
  for (int i = 0; i < n + 1; i++) {
    parent[i] = i;
  }
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    unian(x, y);
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ma[find(i)]++;
    ans = max(ans, ma[find(i)]);
  }
  cout << ans;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n, t, x, y, m, q;
ll parent[100001] = {0};
ll find(ll x) {
  if (parent[x] == x)
    return x;
  return parent[x] = find(parent[x]);
}
void unian(ll x, ll y) {
  ll xset = find(parent[x]);
  ll yset = find(parent[y]);
  if (yset != xset)
    parent[xset] = yset;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  map<ll, ll> ma;
  for (int i = 0; i < n + 1; i++) {
    parent[i] = i;
  }
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    unian(x, y);
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ma[find(i)]++;
    ans = max(ans, find(i));
  }
  cout << ans;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(), v.end()

int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};

ll gcd(ll a, ll b) {
  if (b > a)
    swap(a, b);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}
ll rep_jijo(ll n, ll x) {
  if (x == 0)
    return 1;
  if (x % 2 == 0) {
    ll t = rep_jijo(n, x / 2);
    return t * t % mod;
  }
  return n * rep_jijo(n, x - 1) % mod;
}

struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {}
  int find(int x) {
    if (d[x] < 0)
      return x;
    return d[x] = find(d[x]);
  }

  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (d[x] > d[y])
      swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};

int main() {

  int n, m;
  cin >> n >> m;
  UnionFind uf(n + 1);

  int ans = 0;

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    uf.unite(a, b);
  }

  for (int i = 1; i <= n; i++) {
    int num = uf.size(i);
    ans = max(ans, num);
    // cout << uf.size(i) <<endl;
  }
  cout << ans << endl;
  return 0;
}


Error: 0

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 inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(), v.end()

int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};

ll gcd(ll a, ll b) {
  if (b > a)
    swap(a, b);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}
ll rep_jijo(ll n, ll x) {
  if (x == 0)
    return 1;
  if (x % 2 == 0) {
    ll t = rep_jijo(n, x / 2);
    return t * t % mod;
  }
  return n * rep_jijo(n, x - 1) % mod;
}

struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {}
  int find(int x) {
    if (d[x] < 0)
      return x;
    return d[x] = find(d[x]);
  }

  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (d[x] > d[y])
      swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};

int main() {

  int n, m;
  cin >> n >> m;
  UnionFind uf(n);

  int ans = 0;

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    uf.unite(a, b);
  }

  for (int i = 1; i <= n; i++) {
    int num = uf.size(i);
    ans = max(ans, num);
    // cout << uf.size(i) <<endl;
  }
  cout << ans << endl;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;

struct UnionFind {
  // 自身が親であれば、その集合に属する頂点数に-1を掛けたもの
  // そうでなければ親のid
  vector<int> r;

  UnionFind(int N) { r = vector<int>(N, -1); }

  int root(int x) {
    if (r[x] < 0)
      return x;
    return r[x] = root(r[x]);
  }

  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (r[x] > r[y])
      swap(x, y);
    r[x] += r[y];
    r[y] = x;
    return true;
  }

  int size(int x) { return -r[root(x)]; }
};

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

  // 友達集合を作る
  UnionFind UF(N);
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    A -= 1;
    B -= 1;
    UF.unite(A, B);
  }

  // 最大の友達集合を求める
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans = max(ans, UF.size(i));
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<vector<ll>> R(N, vector<ll>(N, 0));
  vector<ll> ans(N, 0);
  rep(i, M) {
    ll tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    tmp1--;
    tmp2--;
    if (tmp1 > tmp2) {
      swap(tmp1, tmp2);
    }

    if (R[tmp1][tmp2] != 1) {
      R[tmp1][tmp2] = 1;
      ans[tmp1]++;
    }
  }
  ll max_num = 1;
  rep(i, N) max_num = max(ans[i] + 1, max_num);

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

#include <iostream>
#include <queue>
#include <vector>
using namespace std;
bool t[200010];
vector<int> e[200010];
int dfs(int v) {
  int y = 1;
  t[v] = true;
  for (int i = 0; i < e[v].size(); i++) {
    int u = e[v][i];
    if (!t[u]) {
      y += dfs(u);
    }
  }
  return y;
}
int main() {
  int n;
  int m;
  cin >> n;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int a;
    int b;
    cin >> a;
    cin >> b;
    a--;
    b--;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (!t[i]) {
      int x = dfs(i);
      ans = max(ans, x);
    }
  }
  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
#include <queue>
#include <vector>
using namespace std;
bool t[100];
vector<int> e[100];
int dfs(int v) {
  int y = 1;
  t[v] = true;
  for (int i = 0; i < e[v].size(); i++) {
    int u = e[v][i];
    if (!t[u]) {
      y += dfs(u);
    }
  }
  return y;
}
int main() {
  int n;
  int m;
  cin >> n;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int a;
    int b;
    cin >> a;
    cin >> b;
    a--;
    b--;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (!t[i]) {
      int x = dfs(i);
      ans = max(ans, x);
    }
  }
  cout << ans;
  return 0;
}