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

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

#define F first
#define S second
#define pb push_back
#define mp make_pair

ll gcd(ll a, ll b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}

ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

ll n, m;

vector<ll> a[200003];

ll vis[200003];
ll cnt;

ll dfs(ll s) {
  vis[s] = 1;
  cnt++;

  ll len = a[s].size();
  for (ll i = 0; i < len; i++) {
    if (vis[a[s][i]] == 0)
      dfs(a[s][i]);
  }

  return 0;
}

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

  ll i;
  cin >> n >> m;

  map<pair<ll, ll>, ll> ma;

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

    pair<ll, ll> z, z1;

    z = mp(x, y);
    z1 = mp(y, x);

    if (ma.find(z) == ma.end() && ma.find(z1) == ma.end()) {
      ma.insert(mp(z, 1));
      a[x].pb(y);
      a[y].pb(x);
    }
  }

  memset(vis, 0, sizeof(vis));
  for (i = 0; i < n; i++) {
    cnt = 0;

    if (vis[i] == 0) {
      dfs(i);
    }

    mas = max(mas, cnt);
  }

  cout << mas << endl;
}

Error: 0

Fixed submission:

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

#define F first
#define S second
#define pb push_back
#define mp make_pair

ll gcd(ll a, ll b) {
  if (a == 0)
    return b;
  return gcd(b % a, a);
}

ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

ll n, m;

vector<ll> a[200003];

ll vis[200003];
ll cnt;

ll dfs(ll s) {
  vis[s] = 1;
  cnt++;

  for (ll i = 0; i < a[s].size(); i++) {
    if (vis[a[s][i]] == 0)
      dfs(a[s][i]);
  }
}

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

  ll i, j;
  cin >> n >> m;

  map<pair<ll, ll>, ll> ma;

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

    pair<ll, ll> z, z1;

    z = mp(x, y);
    z1 = mp(y, x);

    if (ma.find(z) == ma.end() && ma.find(z1) == ma.end()) {
      ma.insert(mp(z, 1));
      a[x].pb(y);
      a[y].pb(x);
    }
  }

  memset(vis, 0, sizeof(vis));
  for (i = 0; i < n; i++) {
    cnt = 0;

    if (vis[i] == 0) {
      dfs(i);
    }

    mas = max(mas, cnt);
  }

  cout << mas << endl;
}
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 < n; i++)

int tmp[200005] = {};

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(int N) : par(N) { // 最初は全てが根であるとして初期化
    for (int i = 0; i < N; i++)
      par[i] = i;
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x);        // xの根をrx
    int ry = root(y);        // yの根をry
    if (rx == ry)
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] =
        ry; // xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

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

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int r = uf.root(i);
    tmp[r]++;
    ans = max(ans, tmp[r]);
  }

  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 < n; i++)

int tmp[200005] = {};

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(int N) : par(N) { // 最初は全てが根であるとして初期化
    for (int i = 0; i < N; i++)
      par[i] = i;
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x);        // xの根をrx
    int ry = root(y);        // yの根をry
    if (rx == ry)
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] =
        ry; // xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  ;
  int a, b;
  UnionFind uf = UnionFind(n);
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    uf.unite(a, b);
  }

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int r = uf.root(i);
    tmp[r]++;
    ans = max(ans, tmp[r]);
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
ll nodes = 0;
bool vis[N];
vector<ll> graph[N];

void dfs(int n) {
  vis[n] = true;
  ++nodes;
  for (auto i : graph[n]) {
    if (!vis[i])
      dfs(i);
  }
}

int main() {
  fast;
  ll n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    ll u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  ll mx = 0;
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      dfs(i);
      mx = max(mx, nodes);
      nodes = 0;
    }
  }
  cout << mx;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
vector<ll> frien[N];
bool vis[N];
ll mx = 0;

ll dfs(ll source, ll dpt) {
  vis[source] = true;
  mx++;
  for (auto edge : frien[source]) {
    if (!vis[edge])
      dfs(edge, dpt + 1);
  }
}

int main() {
  fast;
  ll n, m;
  cin >> n >> m;
  while (m--) {
    int u, v;
    cin >> u >> v;
    frien[u].push_back(v);
    frien[v].push_back(u);
  }
  ll mxx = 0;
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      dfs(i, 1);
      mxx = max(mxx, mx);
      mx = 0;
    }
  }
  cout << mxx;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define rep(a, c) for (int(a) = 0; (a) < (c); (a)++)
#define ll long long
#define vi vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define pb push_back
#define str string
#define mod 998244353
#define pi 3.14159265
using namespace std;
void dfs(vi edge[], ll vis[], ll &value, int i) {
  if (!vis[i]) {
    value++;
    vis[i] = 1;
    for (int j = 0; j < edge[i].size(); j++) {
      if (!vis[edge[i][j]])
        dfs(edge, vis, value, edge[i][j]);
    }
  }
}
int main() {
  FASTIO;
  ll n, m, ans;
  cin >> n >> m;
  ll a[m + 1], b[m + 1];
  rep(i, m) { cin >> a[i] >> b[i]; }
  vi edge[n + 1];
  ll vis[n + 1];
  rep(i, m) {
    edge[a[i]].pb(b[i]);
    edge[b[i]].pb(a[i]);
  }
  ans = -1;
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    if (vis[i])
      continue;
    ll value = 0;
    dfs(edge, vis, value, i);
    ans = max(ans, value);
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define rep(a, c) for (int(a) = 0; (a) < (c); (a)++)
#define ll long long
#define vi vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define pb push_back
#define str string
#define mod 998244353
#define pi 3.14159265
using namespace std;
void dfs(vi edge[], ll vis[], ll &value, int i) {
  if (!vis[i]) {
    value++;
    vis[i] = 1;
    for (int j = 0; j < edge[i].size(); j++) {
      if (!vis[edge[i][j]])
        dfs(edge, vis, value, edge[i][j]);
    }
  }
}
int main() {
  FASTIO;
  ll n, m, ans;
  cin >> n >> m;
  ll a[m + 1], b[m + 1];
  rep(i, m) { cin >> a[i] >> b[i]; }
  vi edge[n + 1];
  ll vis[n + 1];
  rep(i, m) {
    edge[a[i]].pb(b[i]);
    edge[b[i]].pb(a[i]);
  }
  ans = -1;
  for (int i = 1; i <= n; i++) {
    memset(vis, 0, sizeof(vis));
    ll value = 0;
    dfs(edge, vis, value, i);
    ans = max(ans, value);
  }
  cout << ans << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> g(n, -1); // グループ番号を格納
  int g_num = 0;

  vector<pair<int, int>> f(m);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    f[i].first = a;
    f[i].second = b;
  }

  sort(f.begin(), f.end());

  vector<vector<int>> to(n);
  rep(i, m) {
    if (i > 0)
      if (f[i].first == f[i - 1].first && f[i].second == f[i - 1].second)
        continue;
    int a = f[i].first;
    int b = f[i].second;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  int ans = 1;
  vector<bool> visited(n, false);
  rep(i, n) {
    if (!visited[i]) {
      visited[i] = true;
      int cnt = 0;
      queue<int> q;
      q.push(i);
      while (!q.empty()) {
        int v = q.front();
        q.pop();
        cnt++;
        for (int nv : to[v]) {
          if (!visited[nv]) {
            visited[nv] = true;
            q.push(nv);
          }
        }
      }
      ans = max(cnt, ans);
    }
  }

  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> g(n, -1); // グループ番号を格納
  int g_num = 0;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    if (g[a] == -1 && g[b] == -1) {
      g[a] = g_num, g[b] = g_num;
      g_num++;
    } else {
      g[a] = max(g[a], g[b]);
      g[b] = max(g[a], g[b]);
    }
  }
  vector<int> cnt_g(n, 0); // グループの人数
  rep(i, n) cnt_g[g[i]]++;
  int ans = 1;
  rep(i, n) ans = max(ans, cnt_g[i]);
  cout << ans << endl;

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

#include <bits/stdc++.h>

#define int long long

#define F first
#define S second
#define all(x) (x).begin(), (x).end()

using namespace std;

vector<vector<int>> g(200005);
int u[200005];

void dfs(int v, int &cnt) {
  u[v] = 1, cnt++;
  for (int to : g[v])
    if (!u[to])
      dfs(to, cnt);
}

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  //  freopen("input.txt", "r", stdin);
  //  freopen("output.txt", "w", stdout);

  int n, m, ans = 0;
  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);
  }

  for (int i = 1; i <= n; i++) {
    if (!u[i]) {
      int cnt = 0;
      dfs(i, cnt);
      ans = max(ans, cnt);
    }
  }

  cout << ans;

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

#define int long long

#define F first
#define S second
#define all(x) (x).begin(), (x).end()

using namespace std;

vector<vector<int>> g(100005);
int u[100005];

void dfs(int v, int &cnt) {
  u[v] = 1, cnt++;
  for (int to : g[v])
    if (!u[to])
      dfs(to, cnt);
}

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  //  freopen("input.txt", "r", stdin);
  //  freopen("output.txt", "w", stdout);

  int n, m, ans = 0;
  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);
  }

  for (int i = 1; i <= n; i++) {
    if (!u[i]) {
      int cnt = 0;
      dfs(i, cnt);
      ans = max(ans, cnt);
    }
  }

  cout << ans;

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

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

#define ll long long
#define print(r) cout << r << endl
#define prints(r) cout << r << " "
#define printline cout << endl

vector<ll> desc(2e5, 1);
vector<vector<ll>> tree(2e5);
vector<ll> visited(2e5, 0);

ll dfs(ll n) {
  if (visited[n])
    return 0;
  visited[n] = 1;
  ll nc = 1;
  for (ll i = 0; i < (ll)tree[n].size(); i++)
    nc += dfs(tree[n][i]);
  return nc;
}

int main() {
  std::ios_base::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  for (ll i = 0; i < m; i++) {
    ll u, v;
    cin >> u >> v;
    u--;
    v--;
    tree[u].push_back(v);
    tree[v].push_back(u);
  }

  for (ll i = 0; i < 2e5; i++)
    desc[i] = max(desc[i], dfs(i));

  // for (ll i = 0; i < n; i++)
  // {
  //     prints(desc[i]);
  // }

  sort(desc.begin(), desc.end());
  ll ans = 0;
  for (ll i = 1; i < 2e5; i++) {
    ans += desc[i] - desc[i - 1];
  }
  print(ans + 1);

  return 0;
}

Error: 0

Fixed submission:

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

#define ll long long
#define print(r) cout << r << endl
#define prints(r) cout << r << " "
#define printline cout << endl

ll ans = LONG_LONG_MAX;

vector<ll> par(1e5, -1);

ll resolve_parent(ll n) {
  if (par[n] == n)
    return n;
  return resolve_parent(par[n]);
}

int main() {
  std::ios_base::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  for (ll i = 0; i < n; i++)
    par[i] = i;

  for (ll i = 0; i < m; i++) {
    ll u, v;
    cin >> u >> v;
    u--;
    v--;
    if (min(u, v) == u)
      par[v] = u;
    else
      par[u] = v;
  }

  for (ll i = 0; i < n; i++) {
    par[i] = resolve_parent(i);
  }
  vector<ll> cc(n, 0);
  for (ll i = 0; i < n; i++) {
    cc[par[i]]++;
  }
  sort(cc.begin(), cc.end());
  ll ans = 0;
  for (ll i = 1; i < n; i++) {
    ans += cc[i] - cc[i - 1];
  }
  print(ans);

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

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i, r) for (int i = 0; i < (r); i++)
#define pb push_back
#define all(a) a.begin(), a.end()
#define fastio                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define int long long
#define uint unsigned long long
#define endl '\\n'
using namespace std;

struct UnionFind {

  vector<int> id;
  vector<int> Size;

  UnionFind(int n) {
    id.resize(n);
    Size.resize(n, 1);
    for (int i = 0; i < n; i++)
      id[i] = i;
  }

  int find(int u) { return (id[u] == u) ? u : id[u] = find(id[u]); }

  bool uni(int u, int v) {
    u = find(u);
    v = find(v);
    if (u == v)
      return false;
    id[v] = u;
    Size[u] += Size[v];
    return true;
  }

  int size(int u) {
    u = find(u);
    return Size[u];
  }
};

int n, m;

signed main() {
  fastio;
  cin >> n >> m;
  UnionFind dsu(n);
  int res = 1;
  rep(i, m) {
    int ai, bi;
    cin >> ai >> bi;
    ai--, bi--;
    dsu.uni(ai, bi);
    res = max(res, dsu.size(ai));
  }
  cout << res << endl;
}

Error: -6
free(): invalid pointer


Fixed submission:

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i, r) for (int i = 0; i < (r); i++)
#define pb push_back
#define all(a) a.begin(), a.end()
#define fastio                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define int long long
#define uint unsigned long long
#define endl '\\n'
using namespace std;

struct UnionFind {

  vector<int> id;
  vector<int> Size;

  UnionFind(int n) {
    id.resize(n);
    Size.resize(n, 1);
    for (int i = 0; i < n; i++)
      id[i] = i;
  }

  int find(int u) { return (id[u] == u) ? u : id[u] = find(id[u]); }

  bool uni(int u, int v) {
    u = find(u);
    v = find(v);
    if (u == v)
      return false;
    id[v] = u;
    Size[u] += Size[v];
    return true;
  }

  int size(int u) {
    u = find(u);
    return Size[u];
  }
};

int n, m;

signed main() {
  fastio;
  cin >> n >> m;

  UnionFind dsu(n);
  int res = 1;
  rep(i, m) {
    int ai, bi;
    cin >> ai >> bi;
    dsu.uni(ai, bi);
    res = max(res, dsu.size(ai));
  }
  cout << res << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int tt;

void dfs(vector<int> &visited, vector<set<int>> &adj, int i, int n) {
  visited[i] = n;
  for (auto v : adj[i]) {
    if (!visited[v]) {
      tt++;
      dfs(visited, adj, v, n);
    }
  }
}

int main(int argc, char const *argv[]) {
  int V, E;
  cin >> V >> E;
  vector<set<int>> adj(V);
  int u, v;
  for (int i = 0; i < E; ++i) {
    cin >> u >> v;
    u--;
    v--;
    adj[u].insert(v);
    adj[v].insert(u);
  }
  int ans = 0;
  int count = 0;
  vector<int> visited(V, 0);
  for (int i = 0; i < V; ++i) {
    tt = 0;
    if (!visited[i]) {
      count++;
      tt++;
      dfs(visited, adj, i, count);
    }
    ans = max(ans, tt);
  }
  cout << ans << "\\n";
}

Error: TLE

Fixed submission:

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

void dfs(vector<int> &visited, vector<set<int>> &adj, int i, int n) {
  visited[i] = n;
  for (auto v : adj[i]) {
    if (!visited[v])
      dfs(visited, adj, v, n);
  }
}

int main(int argc, char const *argv[]) {
  int V, E;
  cin >> V >> E;
  vector<set<int>> adj(V);
  int u, v;
  for (int i = 0; i < E; ++i) {
    cin >> u >> v;
    u--;
    v--;
    adj[u].insert(v);
    adj[v].insert(u);
  }
  int count = 0;
  vector<int> visited(V, 0);
  for (int i = 0; i < V; ++i) {
    if (!visited[i]) {
      count++;
      dfs(visited, adj, i, count);
    }
  }
  int ans = 0;
  for (int i = 1; i <= count; ++i) {
    int tmp = 0;
    for (int j = 0; j < V; ++j) {
      if (visited[j] == i)
        tmp++;
    }
    ans = max(ans, tmp);
  }
  cout << ans << "\\n";
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

/*
 * @Author: dnhirapara
 * @Problem: abc177_d
 * @Time: 11-September-2020 : ( 16:17:57 )
 */
#include <bits/stdc++.h>

using namespace std;

/************defination************/

#define endl "\\n"
#define logger(x) cout << __LINE__ << ": " << #x << " -> " << (x) << endl;
#define ll long long int
#define ull unsigned long long int

vector<ll> g[200005];
vector<bool> vis(200005, 0);

ll max_len = 0;

void dfs(ll node, ll lvl) {
  vis[node] = true;
  for (auto i : g[node]) {
    // logger(i);
    if (!vis[i]) {
      dfs(i, lvl + 1);
      max_len++;
    }
  }
  // max_len = max(lvl, max_len);
}

//@time comp :
//@space comp :
int main() {
  // ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  // cin.ignore(); must be there when using getline(cin, s)
  ll tc = 1;
  // cin >> tc;
  while (tc--) {
    ll n, m;
    cin >> n >> m;
    // logger(n);
    ll u, v;
    for (int i = 0; i <= n; i++) {
      vis[i] = false;
    }
    for (ll i = 0; i < m; i++) {
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    ll maxi = LLONG_MIN;
    for (ll i = 1; i <= n; i++) {
      if (!vis[i]) {
        max_len = 0;
        dfs(i, 0);
        // logger(max_len);
        maxi = max(max_len, maxi);
      }
    }
    cout << maxi + 1 << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

/*
 * @Author: dnhirapara
 * @Problem: abc177_d
 * @Time: 11-September-2020 : ( 16:17:57 )
 */
#include <bits/stdc++.h>

using namespace std;

/************defination************/

#define endl "\\n"
#define logger(x) cout << __LINE__ << ": " << #x << " -> " << (x) << endl;
#define ll long long int
#define ull unsigned long long int

vector<ll> g[100005];
vector<bool> vis(100005, 0);

ll max_len = 0;

void dfs(ll node, ll lvl) {
  vis[node] = true;
  for (auto i : g[node]) {
    // logger(i);
    if (!vis[i]) {
      dfs(i, lvl + 1);
      max_len++;
    }
  }
  // max_len = max(lvl, max_len);
}

//@time comp :
//@space comp :
int main() {
  // ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  // cin.ignore(); must be there when using getline(cin, s)
  ll tc = 1;
  // cin >> tc;
  while (tc--) {
    ll n, m;
    cin >> n >> m;
    // logger(n);
    ll u, v;
    for (int i = 0; i <= n; i++) {
      vis[i] = false;
    }
    for (ll i = 0; i < m; i++) {
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    ll maxi = LLONG_MIN;
    for (ll i = 1; i <= n; i++) {
      if (!vis[i]) {
        max_len = 0;
        dfs(i, 0);
        // logger(max_len);
        maxi = max(max_len, maxi);
      }
    }
    cout << maxi + 1 << endl;
  }
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<LL> vl;
typedef vector<vector<LL>> vvl;
typedef vector<vector<vector<LL>>> vvvl;

const int inf = 1e9 + 7;
const LL INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int mxN = 1e5 + 5;
const int mxM = 1e5 + 5;

int vis[mxN * 2];
vi adj[mxN * 2];

void dfs(int s, int &c) {
  if (vis[s])
    return;
  vis[s] = true;
  for (auto i : adj[s]) {
    if (!vis[i]) {
      c = c + 1;
      dfs(i, c);
    }
  }
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("E:\\\\Coding\\\\Programming\\\\input.txt", "r", stdin);
  freopen("E:\\\\Coding\\\\Programming\\\\output.txt", "w", stdout);
#endif
  int n, m;
  cin >> n >> m;

  memset(vis, false, sizeof vis);
  memset(adj, {}, sizeof adj);
  map<pair<int, int>, int> exist;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    if (exist.find({u, v}) == exist.end()) {
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    exist[{u, v}] = 1;
    exist[{v, u}] = 1;
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      int x = 1;
      dfs(i, x);
      ans = max(ans, x);
    }
  }
  cout << ans << endl;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<LL> vl;
typedef vector<vector<LL>> vvl;
typedef vector<vector<vector<LL>>> vvvl;

const int inf = 1e9 + 7;
const LL INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int mxN = 1e5 + 5;
const int mxM = 1e5 + 5;

int vis[mxN * 2];
vi adj[mxN];

void dfs(int s, int &c) {
  if (vis[s])
    return;
  vis[s] = true;
  for (auto i : adj[s]) {
    if (!vis[i]) {
      c = c + 1;
      dfs(i, c);
    }
  }
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("E:\\\\Coding\\\\Programming\\\\input.txt", "r", stdin);
  freopen("E:\\\\Coding\\\\Programming\\\\output.txt", "w", stdout);
#endif
  int n, m;
  cin >> n >> m;

  memset(vis, false, sizeof vis);
  memset(adj, {}, sizeof adj);
  map<pair<int, int>, int> exist;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    if (exist.find({u, v}) == exist.end()) {
      u--;
      v--;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    exist[{u, v}] = 1;
    exist[{v, u}] = 1;
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      int x = 1;
      dfs(i, x);
      ans = max(ans, x);
    }
  }
  cout << ans << endl;
}