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

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

vector<int> adj_list[200005];

void dfs(int u, vector<int> &flag, int *kitna) {
  *kitna = *kitna + 1;
  flag[u] = 1;
  for (auto v : adj_list[u]) {
    if (flag[v] == -1) {
      dfs(v, flag, kitna);
    }
  }
}

int32_t main() {
  vector<int> arr;
  int n;
  int m;
  cin >> n >> m;
  vector<int> flag(n + 1, -1);
  for (int i = 1; i <= m; i++) {
    int u;
    int v;
    cin >> u >> v;
    adj_list[u].push_back(v);
    adj_list[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    if (flag[i] == -1) {
      int kitna = 0;
      dfs(i, flag, &kitna);
      arr.push_back(kitna);
    }
  }
  int ans = *max_element(arr.begin(), arr.end());
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

vector<int> adj_list[100005];

void dfs(int u, vector<int> &flag, int *kitna) {
  *kitna = *kitna + 1;
  flag[u] = 1;
  for (auto v : adj_list[u]) {
    if (flag[v] == -1) {
      dfs(v, flag, kitna);
    }
  }
}

int32_t main() {
  vector<int> arr;
  int n;
  int m;
  cin >> n >> m;
  vector<int> flag(n + 1, -1);
  for (int i = 1; i <= m; i++) {
    int u;
    int v;
    cin >> u >> v;
    adj_list[u].push_back(v);
    adj_list[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    if (flag[i] == -1) {
      int kitna = 0;
      dfs(i, flag, &kitna);
      arr.push_back(kitna);
    }
  }
  int ans = *max_element(arr.begin(), arr.end());
  cout << ans << endl;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

const int N = (int)2e5 + 7;

int n, m;
vector<int> g[N];
bool used[N];

int dfs(int v) {
  used[v] = 1;
  int q = 1;
  for (int i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    if (!used[to]) {
      q += dfs(to);
    }
  }
  return q;
}

int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  int ans = -1;
  for (int i = 1; i <= n; ++i) {
    if (!used[i]) {
      ans = max(ans, dfs(i));
    }
  }
  cout << ans;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

const int N = (int)1e5 + 7;

int n, m;
vector<int> g[N];
bool used[N];

int dfs(int v) {
  used[v] = 1;
  int q = 1;
  for (int i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    if (!used[to]) {
      q += dfs(to);
    }
  }
  return q;
}

int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  int ans = -1;
  for (int i = 1; i <= n; ++i) {
    if (!used[i]) {
      ans = max(ans, dfs(i));
    }
  }
  cout << ans;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
#define _USE_MATH_DEFINES
#define M_PI 3.14159265358979323846
#define MOD 1000000007
#define ll long long int
#define pii pair<ll, ll>
#define pb push_back
#define MIN -9, 223, 372, 036, 854, 775
#define N 100005
#define all(v) v.begin(), v.end()

ll help(vector<set<ll>> &g, vector<ll> &vis, ll x) {
  queue<ll> q;
  ll ans = 0;
  q.push(x);
  vis[x] = (ll)1;

  while (!q.empty()) {
    x = q.front();
    q.pop();
    ans++;
    set<ll> cur = g[x];
    for (auto it : cur) {
      if (vis[it] == 0) {
        q.push(it);
        vis[it] = (ll)1;
      }
    }
  }
  return ans;
}

void solve() {
  ll i, n, ans = 1, m, x, y;
  cin >> n >> m;
  vector<set<ll>> g(n + 1);
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    g[x].insert(y);
    g[y].insert(x);
  }
  vector<ll> vis(n + 1);
  for (i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      ll c = help(g, vis, i);
      ans = max(ans, c);
    }
  }
  cout << ans;
}

int main() {
  ll t = 1;
  // cin>>t;
  while (t--) {
    solve();
    cout << "\\n";
  }
  return 0;
}


Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
#define _USE_MATH_DEFINES
#define M_PI 3.14159265358979323846
#define MOD 1000000007
#define ll long long int
#define pii pair<ll, ll>
#define pb push_back
#define MIN -9, 223, 372, 036, 854, 775
#define N 100005
#define all(v) v.begin(), v.end()

ll vis[N] = {0};
ll help(vector<set<ll>> &g, ll x) {
  queue<ll> q;
  ll ans = 0;
  q.push(x);
  vis[x] = (ll)1;
  while (!q.empty()) {
    x = q.front();
    q.pop();
    ans++;
    set<ll> cur = g[x];
    for (auto it : cur) {
      if (vis[it] == 0) {
        q.push(it);
        vis[it] = 1;
      }
    }
  }
  return ans;
}

void solve() {
  ll i, n, ans = 1, m, x, y;
  cin >> n >> m;
  vector<set<ll>> g(n + 1);
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    g[x].insert(y);
    g[y].insert(x);
  }

  for (i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      ll c = help(g, i);
      ans = max(ans, c);
    }
  }
  cout << ans;
}

int main() {
  ll t = 1;
  // cin>>t;
  while (t--) {
    solve();
    cout << "\\n";
  }
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// #define int long long
set<int> adj[mx];
vector<bool> vis;
int nodes;

void dfs(int u) {
  vis[u] = 1;
  nodes += 1;
  for (auto i : adj[u]) {
    if (!vis[i])
      dfs(i);
  }
}

void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i <= n; i++)
    vis.push_back(0);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    if (adj[u].find(v) == adj[u].end())
      adj[u].insert(v);
    if (adj[v].find(u) == adj[v].end())
      adj[v].insert(u);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      nodes = 0;
      dfs(i);
      ans = max(ans, nodes);
    }
  }
  cout << ans << endl;
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int t;
  solve();
}

Error: TLE

Fixed submission:

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

// #define int long long
vector<int> adj[mx];
vector<bool> vis(mx, 0);
int nodes;

void dfs(int u) {
  vis[u] = 1;
  nodes += 1;
  for (int i : adj[u]) {
    if (!vis[i])
      dfs(i);
  }
}

void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    if (find(adj[u].begin(), adj[u].end(), v) == adj[u].end())
      adj[u].push_back(v);
    if (find(adj[v].begin(), adj[v].end(), u) == adj[v].end())
      adj[v].push_back(u);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      nodes = 0;
      dfs(i);
      ans = max(ans, nodes);
    }
  }
  cout << ans << endl;
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int t;
  solve();
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define pb push_back
#define flash                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define lb lower_bound
#define ub upper_bound
#define endl '\\n';
vector<ll> g[1000001];
ll vis[1000005] = {0};
ll ct = 0;
map<ll, ll> mapsy;
ll dfs(ll curr) {
  vis[curr] = 1;
  for (ll i = 0; i < g[curr].size(); i++) {
    ll child = g[curr][i];
    if (vis[child] == 0) {
      ct++;
      dfs(child);
    }
  }
  return ct;
}

int main() {
  ll t;
  t = 1;
  while (t--) {
    ll n, e;
    cin >> n >> e;
    while (e--) {
      ll u, v;
      cin >> u >> v;
      if (mapsy[u] != v) {
        g[u].pb(v);
        g[v].pb(u);
        mapsy[u] = v;
      }
    }
    vector<ll> v;
    ll c = 0;
    for (ll i = 0; i <= n; i++) {
      if (vis[i] == 0) {
        v.pb(dfs(i) + 1);
        ct = 0;
        c++;
      }
    }
    if (c == 1)
      cout << n << " ";
    else {
      sort(v.begin(), v.end());
      cout << v[0] + (v[v.size() - 1] - v[0]);
    }
  }
}


Error: WA

Fixed submission:


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define pb push_back
#define flash                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define lb lower_bound
#define ub upper_bound
#define endl '\\n';
vector<ll> g[100005];
ll vis[100005];
ll ct = 0;
map<ll, ll> mapsy;
ll dfs(ll curr) {
  vis[curr] = 1;
  for (auto x : g[curr]) {
    ll child = x;
    if (vis[child] == 0) {
      ct++;
      dfs(child);
    }
  }
  return ct;
}

int main() {
  ll t;
  t = 1;
  while (t--) {
    ll n, e;
    cin >> n >> e;
    while (e--) {
      ll u, v;
      cin >> u >> v;
      if (mapsy[u] != v) {
        g[u].pb(v);
        g[v].pb(u);
        mapsy[u] = v;
      }
    }
    vector<ll> v;
    ll c = 0;
    for (ll i = 0; i <= n; i++) {
      if (vis[i] == 0) {
        v.pb(dfs(i) + 1);
        ct = 0;
        c++;
      }
    }
    if (c == 1)
      cout << n << " ";
    else {
      sort(v.begin(), v.end());
      cout << v[0] + (v[v.size() - 1] - v[0]);
    }
  }
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
ll M = 1e9 + 7;

class DS {
public:
  vector<ll> parent;
  vector<ll> nodes;
  DS(ll n) {
    parent.resize(n + 1);
    nodes.resize(n + 1);
    for (ll i = 0; i <= n; i++) {
      parent[i] = i;
      nodes[i] = 1;
    }
  }
  void join(ll a, ll b) {
    ll x = findparent(a), y = findparent(b);
    if (x == y)
      return;
    parent[x] = y;
    nodes[y] += nodes[x];
  }
  ll findparent(ll a) {
    if (a == parent[a])
      return a;
    parent[a] = findparent(parent[a]);
    return parent[a];
  }
};

int main() {
  ll n, m;
  cin >> n >> m;
  map<pair<ll, ll>, ll> map1;
  DS ds(n);
  for (ll i = 1; i <= m; i++) {
    ll a, b;
    cin >> a >> b;
    if (a > b)
      swap(a, b);
    if (map1.find({a, b}) == map1.end()) {
      ds.join(a, b);
    }
    map1[{a, b}] = 1;
  }

  ll ans = 1;
  for (ll i = 1; i <= n; i++) {
    ans = max(ans, ds.nodes[i]);
  }
  cout << ans << endl;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
ll M = 1e9 + 7;

#define MAXN 10000005
ll spf[MAXN];
ll hash1[MAXN] = {0};
void sieve() {
  spf[1] = 1;
  for (ll i = 2; i < MAXN; i++)
    spf[i] = i;
  for (ll i = 4; i < MAXN; i += 2)
    spf[i] = 2;
  for (ll i = 3; i * i < MAXN; i++) {
    if (spf[i] == i) {
      for (ll j = i * i; j < MAXN; j += i)
        if (spf[j] == j)
          spf[j] = i;
    }
  }
}

void getFactorization(ll x) {
  ll temp;
  while (x != 1) {
    temp = spf[x];

    if (x % temp == 0) {
      hash1[spf[x]]++;

      x = x / spf[x];
    }
    while (x % temp == 0)
      x = x / temp;
  }
}

bool check(ll x) {
  ll temp;
  while (x != 1) {
    temp = spf[x];
    if (x % temp == 0 && hash1[temp] > 1)
      return false;
    while (x % temp == 0)
      x = x / temp;
  }
  return true;
}

int main() {
  ll n;
  cin >> n;
  sieve();
  vector<ll> vec(n + 1, 0);
  bool bb = 1;
  for (ll i = 1; i <= n; i++) {
    cin >> vec[i];
    getFactorization(vec[i]);
  }

  for (ll i = 1; i <= n; i++) {
    if (check(vec[i]) == 0) {
      bb = 0;
      break;
    }
  }

  if (bb == 1) {
    cout << "pairwise coprime" << endl;
  } else {
    ll g = vec[1];
    for (ll i = 2; i <= n; i++) {
      g = __gcd(g, vec[i]);
    }
    if (g == 1) {
      cout << "setwise coprime" << endl;
    } else {
      cout << "not coprime" << endl;
    }
  }
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int f[N], sum[N];
int get(int x) {
  if (f[x] != x) {
    f[x] = get(f[x]);
    sum[x] = sum[f[x]];
  }
  return f[x];
}
int main() {
  int n, m, a, b;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    f[i] = i, sum[i] = 1;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    int f1 = get(a), f2 = get(b);
    if (f1 != f2) {
      f[f1] = f2;
      sum[f2] += sum[f1];
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, sum[i]);
  }
  cout << ans;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int f[N], sum[N];
int get(int x) {
  if (f[x] != x) {
    f[x] = get(f[x]);
    sum[x] = sum[f[x]];
  }
  return f[x];
}
int main() {
  int n, m, a, b;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    f[i] = i, sum[i] = 1;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    int f1 = get(a), f2 = get(b);
    if (f1 != f2) {
      f[f1] = f2;
      sum[f2] += sum[f1];
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, sum[i]);
  }
  cout << ans;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 100;

int n, m, fa[N], Size[N], ans = 1;
inline int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); }
inline void Union(int x, int y) {
  x = Find(x);
  y = Find(y);
  if (x == y)
    return;
  fa[x] = y;
  Size[y] += Size[x];
  ans = max(ans, Size[y]);
}

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i)
    fa[i] = i, Size[i] = 1;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    Union(u, v);
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 100;

int n, m, fa[N], Size[N], ans = 1;
inline int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); }
inline int Union(int x, int y) {
  x = Find(x);
  y = Find(y);
  if (x == y)
    return 0;
  fa[x] = y;
  Size[y] += Size[x];
  ans = max(ans, Size[y]);
}

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i)
    fa[i] = i, Size[i] = 1;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    Union(u, v);
  }
  cout << ans << endl;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

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

void dfs(int s, int e, int &ans, set<int> *adj, bool *visited) {
  ans++;
  visited[s] = 1;
  for (auto u : adj[s]) {
    if (u == e)
      continue;
    if (!visited[u]) {
      dfs(u, s, ans, adj, visited);
    }
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  set<int> adj[n];
  while (m--) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    adj[a].insert(b);
    adj[b].insert(a);
  }
  bool visited[n];
  memset(visited, 0, sizeof visited);
  int maxm = INT_MIN;
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      int ans = 0;
      dfs(i, -1, ans, adj, visited);
      maxm = max(maxm, ans);
    }
  }
  cout << maxm << "\\n";
}

Error: 0

Fixed submission:

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

int compress(int *val, int n, int *originals) {
  int maxVal = INT_MIN;
  int d[n];
  for (int i = 0; i < n; i++)
    d[i] = val[i];
  sort(d, d + n);
  int k = unique(d, d + n) - d;
  FOR(i, 0, n, 1) {
    int temp = lower_bound(d, d + k, val[i]) - d;
    originals[val[i]] = temp;
    val[i] = temp;
    maxVal = max(maxVal, temp);
  }
  return maxVal;
}

void dfs(int s, int e, int &ans, vector<int> *adj1, bool *visited) {
  ans++;
  visited[s] = 1;
  for (auto u : adj1[s]) {
    if (u == e)
      continue;
    if (!visited[u]) {
      dfs(u, s, ans, adj1, visited);
    }
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  int ar[2 * m];
  int i = 0;
  set<int> adj[n];
  while (m--) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    adj[a].insert(b);
    adj[b].insert(a);
    ar[i] = a;
    ar[i + 1] = b;
    i += 2;
  }
  int k = i;
  int originals[n];
  k = compress(ar, i, originals);
  k++;
  vector<int> adj1[k];
  for (int i = 0; i < n; i++) {
    if (adj[i].size()) {
      for (auto u : adj[i])
        adj1[originals[i]].emplace_back(originals[u]);
    }
  }
  // exit(0);
  bool visited[k];
  memset(visited, 0, sizeof visited);
  int maxm = INT_MIN;
  for (int i = 0; i < k; i++) {
    if (!visited[i]) {
      int ans = 0;
      dfs(i, -1, ans, adj1, visited);
      maxm = max(maxm, ans);
    }
  }
  cout << maxm << "\\n";
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

const int N = 2e5 + 7;

int used[N];
vector<int> g[N];

void dfs(int cur, int &c) {
  c++;
  used[cur] = 1;
  for (auto t : g[cur]) {
    if (!used[t]) {
      dfs(t, c);
    }
  }
}

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

  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      int c = 0;
      dfs(i, c);
      ans = max(ans, c);
    }
  }
  cout << ans << '\\n';
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

const int N = 1e5 + 7;

int used[N];
vector<int> g[N];

void dfs(int cur, int &c) {
  c++;
  used[cur] = 1;
  for (auto t : g[cur]) {
    if (!used[t]) {
      dfs(t, c);
    }
  }
}

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

  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      int c = 0;
      dfs(i, c);
      ans = max(ans, c);
    }
  }
  cout << ans << '\\n';
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

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

using ll = long long;
using pi = pair<int, int>;

const int maxn = 2e5 + 5;
int n;
vector<int> adj[maxn];
int vis[maxn];

int dfs(int node) {
  vis[node] = 1;
  int res = 1;
  for (int nei : adj[node]) {
    if (vis[nei])
      continue;
    res += dfs(nei);
  }
  return res;
}

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

  int m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u - 1].push_back(v - 1);
    adj[v - 1].push_back(u - 1);
  }
  for (int i = 0; i < n; i++)
    vis[i] = 0;

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

  return 0;
}

Error: 0

Fixed submission:

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

using ll = long long;
using pi = pair<int, int>;

const int maxn = 1e5 + 5;
int n;
vector<int> adj[maxn];
int vis[maxn];

int dfs(int node) {
  vis[node] = 1;
  int res = 1;
  for (int nei : adj[node]) {
    if (vis[nei])
      continue;
    res += dfs(nei);
  }
  return res;
}

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

  int m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u - 1].push_back(v - 1);
    adj[v - 1].push_back(u - 1);
  }
  for (int i = 0; i < n; i++)
    vis[i] = 0;

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

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

// atcoder
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll dfs(vector<vector<ll>> &adj, ll root, ll &count, vector<bool> &vis) {
  vis[root] = true;
  count++;
  for (int i = 0; i < adj[root].size(); i++) {
    if (vis[adj[root][i]] == false)
      dfs(adj, adj[root][i], count, vis);
  }
  return count;
}
int main() {
  ll n, m, u, v, ans = INT_MIN, count;
  cin >> n >> m;
  vector<vector<ll>> adj(n + 1);
  vector<bool> vis(n + 1, false);
  while (m > 0) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
    m--;
  }
  for (ll i = 1; i < n + 1; i++) {
    count = 0;
    if (vis[i] == false) {
      ans = max(ans, dfs(adj, i, count, vis));
    }
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

// atcoder
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll dfs(vector<vector<ll>> adj, ll root, ll &count, vector<bool> &vis) {
  vis[root] = true;
  count++;
  for (int i = 0; i < adj[root].size(); i++) {
    if (vis[adj[root][i]] == false)
      dfs(adj, adj[root][i], count, vis);
  }
  return count;
}
int main() {
  ll n, m, u, v, ans = INT_MIN, count;
  cin >> n >> m;
  vector<vector<ll>> adj(n + 1);
  vector<bool> vis(n + 1, false);
  while (m > 0) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
    m--;
  }
  for (ll i = 1; i < n + 1; i++) {
    count = 0;
    if (vis[i] == false) {
      ans = max(ans, dfs(adj, i, count, vis));
    }
  }
  cout << ans;
  return 0;
}
Problem p02573 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 1e15
vector<ll> ad[400009];
map<pair<ll, ll>, ll> mp;
bool vis[400009];
ll A;
void dfs(ll a) {
  vis[a] = true;
  A++;
  ll i, b, l = ad[a].size();
  for (i = 0; i < l; i++) {
    b = ad[a][i];
    if (!vis[b]) {
      dfs(b);
    }
  }
}
int main() {
  ll a, b, c, d, e, i, j, k, l, n, m, x, y, t, p;
  cin >> n >> m;
  for (i = 0; i <= n; i++) {
    vis[i] = false;
  }
  for (i = 1; i <= m; i++) {
    cin >> a >> b;
    if (mp[make_pair(a, b)] == 0) {
      mp[make_pair(a, b)] = 1;
      mp[make_pair(b, a)] = 1;
    } else {
      continue;
    }
    ad[a].push_back(b);
    ad[b].push_back(a);
  }

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


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 1e15
vector<ll> ad[400009];
map<pair<ll, ll>, ll> mp;
bool vis[400009];
ll A;
ll dfs(ll a) {
  vis[a] = true;
  A++;
  ll i, b, l = ad[a].size();
  for (i = 0; i < l; i++) {
    b = ad[a][i];
    if (!vis[b]) {
      dfs(b);
    }
  }
}
int main() {
  ll a, b, c, d, e, i, j, k, l, n, m, x, y, t, p;
  cin >> n >> m;
  for (i = 0; i <= n; i++) {
    vis[i] = false;
  }
  for (i = 1; i <= m; i++) {
    cin >> a >> b;
    if (mp[make_pair(a, b)] == 0) {
      mp[make_pair(a, b)] = 1;
      mp[make_pair(b, a)] = 1;
    } else {
      continue;
    }
    ad[a].push_back(b);
    ad[b].push_back(a);
  }

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