problem_id
stringlengths
6
6
language
stringclasses
2 values
original_status
stringclasses
3 values
original_src
stringlengths
19
243k
changed_src
stringlengths
19
243k
change
stringclasses
3 values
i1
int64
0
8.44k
i2
int64
0
8.44k
j1
int64
0
8.44k
j2
int64
0
8.44k
error
stringclasses
270 values
stderr
stringlengths
0
226k
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<pair<int, int>> vpii; #define F first #define S second #define PU push #define PUF push_front #define PUB push_back #define PO pop #define POF pop_front #define POB pop_back #define REP(i, a, b) for (int i = a; i <= b; i++) void dfs(vector<vector<int>> &arr, vector<int> &vis, int curr, int col) { queue<int> q; q.push(curr); while (!q.empty()) { int now = q.front(); q.pop(); if (vis[now] != 0) continue; vis[now] = col; for (auto i : arr[now]) { if (vis[i] == 0) q.push(i); // cerr<<i<<" "; } // cerr<<endl; } } void solve(int test_case) { int n, m; cin >> n >> m; if (m == 0) { cout << 1; return; } vector<vector<int>> arr(n, vector<int>(10000)); while (m--) { int f, t; cin >> f >> t; f--, t--; arr[f].PUB(t); arr[t].PUB(f); } vector<int> vis(n, 0); int col = 1; for (int i = 0; i < n; i++) if (vis[i] == 0) dfs(arr, vis, i, col++); vector<int> cols(col, 0); int ans = 0; for (int i : vis) { if (i != 0) cols[i]++, ans = max(ans, cols[i]); } // for(int i:cols)cerr<<i<<" "; cout << ans; } int main() { ////// FILE BASED IO//// // freopen("in", "r", stdin); // freopen("out", "w", stdout); /////////////// ios::sync_with_stdio(0); cin.tie(0); int t = 1; // cin>>t; REP(i, 1, t) { solve(i); } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<pair<int, int>> vpii; #define F first #define S second #define PU push #define PUF push_front #define PUB push_back #define PO pop #define POF pop_front #define POB pop_back #define REP(i, a, b) for (int i = a; i <= b; i++) void dfs(vector<vector<int>> &arr, vector<int> &vis, int curr, int col) { queue<int> q; q.push(curr); while (!q.empty()) { int now = q.front(); q.pop(); if (vis[now] != 0) continue; vis[now] = col; for (auto i : arr[now]) { if (vis[i] == 0) q.push(i); // cerr<<i<<" "; } // cerr<<endl; } } void solve(int test_case) { int n, m; cin >> n >> m; if (m == 0) { cout << 1; return; } vector<vector<int>> arr(n, vector<int>()); while (m--) { int f, t; cin >> f >> t; f--, t--; arr[f].PUB(t); arr[t].PUB(f); } vector<int> vis(n, 0); int col = 1; for (int i = 0; i < n; i++) if (vis[i] == 0) dfs(arr, vis, i, col++); vector<int> cols(col, 0); int ans = 0; for (int i : vis) { if (i != 0) cols[i]++, ans = max(ans, cols[i]); } // for(int i:cols)cerr<<i<<" "; cout << ans; } int main() { ////// FILE BASED IO//// // freopen("in", "r", stdin); // freopen("out", "w", stdout); /////////////// ios::sync_with_stdio(0); cin.tie(0); int t = 1; // cin>>t; REP(i, 1, t) { solve(i); } }
replace
45
46
45
46
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long using namespace std; typedef pair<int, int> P; typedef pair<ll, ll> LP; // 定数 // 円周率 const double pi = 3.141592653589793238462643383279; // 天井 const int INF = 1000000000; // = 10^9 const ll LINF = 100000000000000000; // = 10^17 // ABC文字列 const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC"; const string abc = "abcdefghijklmnopqrstuvwxyzabc"; // よくあるmodくん const ll MOD = 1000000007; // = 10^9 + 7 // 前処理テーブルの大きさ指定 const int MAX = 1200000; // = 10^6 + 2*(10^5) // ちなみに、1024MBで持てる最大長の配列は2*(10^8)程度 // データ構造 // 隣接リスト用構造体(有向グラフ向け) struct edge { ll to; // E.toでその辺の終点へアクセスできる。 ll cost; // e.costでその辺の重みにアクセスできる。 }; // Union_Find木 struct UnionFind { vector<int> UF; // UF.at(i) : iの親の番号 vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数 UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化 for (int i = 0; i < N; i++) { UF.at(i) = i; } } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (UF.at(x) == x) { return x; } return UF.at(x) = root(UF.at(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の根が同じ(=同じ木にある)時はそのまま } // xとyの根が同じでない(=同じ木にない)時:小さい方の根を大きい方の根につける。 if (SIZE.at(rx) < SIZE.at(ry)) { UF.at(rx) = ry; SIZE.at(ry) += SIZE.at(rx); SIZE.at(rx) = 0; } else { UF.at(ry) = rx; SIZE.at(rx) += SIZE.at(ry); SIZE.at(ry) = 0; } } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す。 int rx = root(x); int ry = root(y); return rx == ry; } int size(int x) { // xと連結されてる要素の数を返す。 return SIZE.at(root(x)); } }; // 関数 (計算量) // ctoi (O(1)) int ctoi(char c) { if (c == '0') return 0; if (c == '1') return 1; if (c == '2') return 2; if (c == '3') return 3; if (c == '4') return 4; if (c == '5') return 5; if (c == '6') return 6; if (c == '7') return 7; if (c == '8') return 8; if (c == '9') return 9; return -1; } // to_char (O(1)) char to_char(int i) { if (i == 0) return '0'; if (i == 1) return '1'; if (i == 2) return '2'; if (i == 3) return '3'; if (i == 4) return '4'; if (i == 5) return '5'; if (i == 6) return '6'; if (i == 7) return '7'; if (i == 8) return '8'; if (i == 9) return '9'; return ' '; } // 二分探索(その要素があるかないか判定するだけならsetとか二分木使う。) // (0(NlogN)) ll BS(vector<int> V, int Q) { sort(V.begin(), V.end()); // こことれば(O(logN)) int L = -1; // Q未満の最大の要素 int R = V.size(); // Q以上の最小の要素 while (R - L > 1) { int M = (L + R) / 2; if (V.at(M) < Q) L = M; else R = M; } if (R == int(V.size())) return INF; // Qより大きい要素がない時はINFを返す。 return V.at(R); // Lを返すとQ未満の最大の要素が出てくる。 } // 素数判定 // 一つ一つの判定ではこっちの方が速い。(一つ当たりO(√N)) // 一方100までに何個あるかなどはEratosthenesの篩の方が良い。O(NlogN)) bool PN(int x) { if (x <= 1) return false; // 1や0,-1は素数ではない。 if (x == 2) return true; // √2 + 1 > 2 なので下でやると 2 % 2 = 0 となり判定できない。 for (int i = 2; i < sqrt(x) + 1; i++) { if (x % i == 0) return false; // 割れたら素数じゃない。 } return true; } // A^N mod M を計算する。modしたくなかったらM = LINFとかにすればよい。(O(√N)) ll modpow(ll A, ll N, ll M) { ll ans = 1; while (N > 0) { if (N & 1) ans = ans * A % M; A = A * A % M; N >>= 1; } return ans; } // 逆元を求める。(O(logm)) ll modinv(ll a, ll m) { // 'a'の"mod m"においての逆元 ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // テーブルを作る前処理(O(MAX)?) ll fac[MAX], finv[MAX], inv[MAX]; void COMset() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算(nCk) ちなみに "nHk" = "(n+k-1)C(n-1)" となる。 ll COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // ライブラリ終了 // メイン処理 int main() { cout << fixed << setprecision(16); // 精度向上 // ここまでテンプレ int N, M; cin >> N >> M; UnionFind F(N); for (int i = 0; i < N; i++) { int A, B; cin >> A >> B; F.unite(A - 1, B - 1); } int ans = 0; for (int i = 0; i < N; i++) { ans = max(ans, F.size(i)); } cout << ans << endl; }
#include <bits/stdc++.h> #define ll long long using namespace std; typedef pair<int, int> P; typedef pair<ll, ll> LP; // 定数 // 円周率 const double pi = 3.141592653589793238462643383279; // 天井 const int INF = 1000000000; // = 10^9 const ll LINF = 100000000000000000; // = 10^17 // ABC文字列 const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC"; const string abc = "abcdefghijklmnopqrstuvwxyzabc"; // よくあるmodくん const ll MOD = 1000000007; // = 10^9 + 7 // 前処理テーブルの大きさ指定 const int MAX = 1200000; // = 10^6 + 2*(10^5) // ちなみに、1024MBで持てる最大長の配列は2*(10^8)程度 // データ構造 // 隣接リスト用構造体(有向グラフ向け) struct edge { ll to; // E.toでその辺の終点へアクセスできる。 ll cost; // e.costでその辺の重みにアクセスできる。 }; // Union_Find木 struct UnionFind { vector<int> UF; // UF.at(i) : iの親の番号 vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数 UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化 for (int i = 0; i < N; i++) { UF.at(i) = i; } } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (UF.at(x) == x) { return x; } return UF.at(x) = root(UF.at(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の根が同じ(=同じ木にある)時はそのまま } // xとyの根が同じでない(=同じ木にない)時:小さい方の根を大きい方の根につける。 if (SIZE.at(rx) < SIZE.at(ry)) { UF.at(rx) = ry; SIZE.at(ry) += SIZE.at(rx); SIZE.at(rx) = 0; } else { UF.at(ry) = rx; SIZE.at(rx) += SIZE.at(ry); SIZE.at(ry) = 0; } } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す。 int rx = root(x); int ry = root(y); return rx == ry; } int size(int x) { // xと連結されてる要素の数を返す。 return SIZE.at(root(x)); } }; // 関数 (計算量) // ctoi (O(1)) int ctoi(char c) { if (c == '0') return 0; if (c == '1') return 1; if (c == '2') return 2; if (c == '3') return 3; if (c == '4') return 4; if (c == '5') return 5; if (c == '6') return 6; if (c == '7') return 7; if (c == '8') return 8; if (c == '9') return 9; return -1; } // to_char (O(1)) char to_char(int i) { if (i == 0) return '0'; if (i == 1) return '1'; if (i == 2) return '2'; if (i == 3) return '3'; if (i == 4) return '4'; if (i == 5) return '5'; if (i == 6) return '6'; if (i == 7) return '7'; if (i == 8) return '8'; if (i == 9) return '9'; return ' '; } // 二分探索(その要素があるかないか判定するだけならsetとか二分木使う。) // (0(NlogN)) ll BS(vector<int> V, int Q) { sort(V.begin(), V.end()); // こことれば(O(logN)) int L = -1; // Q未満の最大の要素 int R = V.size(); // Q以上の最小の要素 while (R - L > 1) { int M = (L + R) / 2; if (V.at(M) < Q) L = M; else R = M; } if (R == int(V.size())) return INF; // Qより大きい要素がない時はINFを返す。 return V.at(R); // Lを返すとQ未満の最大の要素が出てくる。 } // 素数判定 // 一つ一つの判定ではこっちの方が速い。(一つ当たりO(√N)) // 一方100までに何個あるかなどはEratosthenesの篩の方が良い。O(NlogN)) bool PN(int x) { if (x <= 1) return false; // 1や0,-1は素数ではない。 if (x == 2) return true; // √2 + 1 > 2 なので下でやると 2 % 2 = 0 となり判定できない。 for (int i = 2; i < sqrt(x) + 1; i++) { if (x % i == 0) return false; // 割れたら素数じゃない。 } return true; } // A^N mod M を計算する。modしたくなかったらM = LINFとかにすればよい。(O(√N)) ll modpow(ll A, ll N, ll M) { ll ans = 1; while (N > 0) { if (N & 1) ans = ans * A % M; A = A * A % M; N >>= 1; } return ans; } // 逆元を求める。(O(logm)) ll modinv(ll a, ll m) { // 'a'の"mod m"においての逆元 ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // テーブルを作る前処理(O(MAX)?) ll fac[MAX], finv[MAX], inv[MAX]; void COMset() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算(nCk) ちなみに "nHk" = "(n+k-1)C(n-1)" となる。 ll COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // ライブラリ終了 // メイン処理 int main() { cout << fixed << setprecision(16); // 精度向上 // ここまでテンプレ int N, M; cin >> N >> M; UnionFind F(N); for (int i = 0; i < M; i++) { int A, B; cin >> A >> B; F.unite(A - 1, B - 1); } int ans = 0; for (int i = 0; i < N; i++) { ans = max(ans, F.size(i)); } cout << ans << endl; }
replace
212
213
212
213
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> #include <stdio.h> using namespace std; typedef long long ll; typedef vector<ll> vll; #define fr(n, x) for (ll n = 0; n < x; n++) #define pf(x) cout << x << '\n' const ll mx = 1e5 + 4; const ll mod = 1e9 + 7; #pragma GCC optimize("O3") vll graph[mx]; bool vis[mx] = {0}; ll res = 0; void dfs(ll node) { vis[node] = 1; queue<ll> bfs; bfs.push(node); while (!bfs.empty()) { ll top = bfs.front(); bfs.pop(); res++; for (auto j : graph[top]) { if (!vis[j]) { bfs.push(j); vis[j] = 1; } } } } int main() { ll x, y; cin >> x >> y; set<pair<ll, ll>> edg; fr(n, y) { ll a, b; cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); } ll mx = 0; for (ll n = 1; n <= x; n++) { if (!vis[n]) { res = 0; dfs(n); mx = max(mx, res); // cout << res << ' ' << n << '\n'; } } cout << mx; }
#include <bits/stdc++.h> #include <stdio.h> using namespace std; typedef long long ll; typedef vector<ll> vll; #define fr(n, x) for (ll n = 0; n < x; n++) #define pf(x) cout << x << '\n' const ll mx = 3e5 + 4; const ll mod = 1e9 + 7; #pragma GCC optimize("O3") vll graph[mx]; bool vis[mx] = {0}; ll res = 0; void dfs(ll node) { vis[node] = 1; queue<ll> bfs; bfs.push(node); while (!bfs.empty()) { ll top = bfs.front(); bfs.pop(); res++; for (auto j : graph[top]) { if (!vis[j]) { bfs.push(j); vis[j] = 1; } } } } int main() { ll x, y; cin >> x >> y; set<pair<ll, ll>> edg; fr(n, y) { ll a, b; cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); } ll mx = 0; for (ll n = 1; n <= x; n++) { if (!vis[n]) { res = 0; dfs(n); mx = max(mx, res); // cout << res << ' ' << n << '\n'; } } cout << mx; }
replace
7
8
7
8
0
p02573
C++
Runtime Error
//----AUTHOR:kkdrummer----/ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // #include <boost/multiprecision/cpp_int.hpp> // using namespace boost::multiprecision; using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef long double ld; typedef unordered_set<ll> usll; typedef unordered_multiset<ll> umsll; typedef multiset<ll> msll; typedef set<ll> sll; typedef vector<ll> vll; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef priority_queue<ll> pqll; typedef vector<int> vi; typedef set<int> si; typedef multiset<int> msi; typedef unordered_multiset<int> umsi; typedef unordered_set<int> usi; typedef pair<int, int> pi; typedef vector<pi> vpi; typedef priority_queue<int> pqi; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ind_si; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ind_sll; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ind_msi; typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ind_msll; #define in insert #define fi first #define se second #define pb push_back #define mp make_pair #define be begin #define en end #define itr iterator #define io \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define mo 1000000007 #define inf 8222372026854775807 #define ninf -inf #define ima 1147483647 #define imi -ima #define oncnt __builtin_popcount #define zerobegin __builtin_clz #define zeroend __builtin_ctz #define parity __builtin_parity #define all(x) x.be(), x.en() #define eps 1e-9 #define coutd cout << setprecision(15) << fixed #define mems(dp, x) memset(dp, x, sizeof(dp)) #define fbo find_by_order #define ook order_of_key #define upb upper_bound #define lowb lower_bound #define lte(v, x) (upb(all(v), x) - v.be()) #define gte(v, x) (v.end() - lowb(all(v), x)) #define gt(v, x) (v.en() - upb(all(v), x)) #define lt(v, x) (lowb(all(v), x) - v.be()) const ld PI = 3.1415926535897932384626433832792884197169399375105820974944; inline ll modpow(ll x, ll n) { if (n == 0) return 1; if (x == 0) return 0; if (n == 1) return (x % mo); ll u = (modpow(x, n / 2)); u = (u * u) % mo; if (n % 2 != 0) u = (u * x % mo) % mo; return u; } inline ll modinv(ll x) { return modpow(x, mo - 2); } inline ll mmul(ll a, ll b) { if (a >= mo) a = a % mo; if (b >= mo) b = b % mo; if (a * b >= mo) return (a * b) % mo; return (a * b); } inline ll madd(ll a, ll b) { if (a >= mo) a = a % mo; if (b >= mo) b = b % mo; if (a + b >= mo) return (a + b) % mo; return (a + b); } inline ll msub(ll a, ll b) { if (a >= mo) a = a % mo; if (b >= mo) b = b % mo; return (((a - b) % mo + mo) % mo); } inline ll mdiv(ll a, ll bb) { if (a >= mo) a = a % mo; ll b = modinv(bb); if (b >= mo) b = b % mo; if (a * b >= mo) return (a * b) % mo; return (a * b); } inline ll gcd(ll a, ll b) { return __gcd(a, b); } inline ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } vi ad[100001]; vi adjr[100001]; bool visited[100001] = {false}; int n, m; void dfsfillorder(stack<int> &s, int u) { if (visited[u]) return; visited[u] = true; for (int i = 0; i < ad[u].size(); i++) dfsfillorder(s, ad[u][i]); s.push(u); } void rev() { for (int i = 1; i <= n; i++) for (int j = 0; j < ad[i].size(); j++) adjr[ad[i][j]].pb(i); } void dfsutil(int x, vi &vx) { if (visited[x]) return; vx.pb(x); visited[x] = true; for (int i = 0; i < adjr[x].size(); i++) dfsutil(adjr[x][i], vx); } vector<vector<int>> getSCC(int v) { vector<vector<int>> cc; stack<int> s; for (int i = 1; i <= v; i++) dfsfillorder(s, i); rev(); for (int i = 1; i <= v; i++) visited[i] = false; while (!s.empty()) { int x = s.top(); s.pop(); if (!visited[x]) { vi vx; dfsutil(x, vx); cc.pb(vx); } } return cc; } int main() { io int testcases = 1; // cin>>testcases; while (testcases--) { cin >> n >> m; int a, b; set<pi> s; for (int i = 1; i <= m; i++) { cin >> a >> b; if (a > b) swap(a, b); pi p = mp(a, b); if (s.find(p) != s.end()) continue; s.in(p); ad[a].pb(b); ad[b].pb(a); } vector<vector<int>> cc = getSCC(n); int ma = 0; for (int i = 0; i < cc.size(); i++) { ma = max(ma, (int)cc[i].size()); } cout << ma; } return 0; }
//----AUTHOR:kkdrummer----/ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // #include <boost/multiprecision/cpp_int.hpp> // using namespace boost::multiprecision; using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef long double ld; typedef unordered_set<ll> usll; typedef unordered_multiset<ll> umsll; typedef multiset<ll> msll; typedef set<ll> sll; typedef vector<ll> vll; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef priority_queue<ll> pqll; typedef vector<int> vi; typedef set<int> si; typedef multiset<int> msi; typedef unordered_multiset<int> umsi; typedef unordered_set<int> usi; typedef pair<int, int> pi; typedef vector<pi> vpi; typedef priority_queue<int> pqi; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ind_si; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ind_sll; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ind_msi; typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ind_msll; #define in insert #define fi first #define se second #define pb push_back #define mp make_pair #define be begin #define en end #define itr iterator #define io \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define mo 1000000007 #define inf 8222372026854775807 #define ninf -inf #define ima 1147483647 #define imi -ima #define oncnt __builtin_popcount #define zerobegin __builtin_clz #define zeroend __builtin_ctz #define parity __builtin_parity #define all(x) x.be(), x.en() #define eps 1e-9 #define coutd cout << setprecision(15) << fixed #define mems(dp, x) memset(dp, x, sizeof(dp)) #define fbo find_by_order #define ook order_of_key #define upb upper_bound #define lowb lower_bound #define lte(v, x) (upb(all(v), x) - v.be()) #define gte(v, x) (v.end() - lowb(all(v), x)) #define gt(v, x) (v.en() - upb(all(v), x)) #define lt(v, x) (lowb(all(v), x) - v.be()) const ld PI = 3.1415926535897932384626433832792884197169399375105820974944; inline ll modpow(ll x, ll n) { if (n == 0) return 1; if (x == 0) return 0; if (n == 1) return (x % mo); ll u = (modpow(x, n / 2)); u = (u * u) % mo; if (n % 2 != 0) u = (u * x % mo) % mo; return u; } inline ll modinv(ll x) { return modpow(x, mo - 2); } inline ll mmul(ll a, ll b) { if (a >= mo) a = a % mo; if (b >= mo) b = b % mo; if (a * b >= mo) return (a * b) % mo; return (a * b); } inline ll madd(ll a, ll b) { if (a >= mo) a = a % mo; if (b >= mo) b = b % mo; if (a + b >= mo) return (a + b) % mo; return (a + b); } inline ll msub(ll a, ll b) { if (a >= mo) a = a % mo; if (b >= mo) b = b % mo; return (((a - b) % mo + mo) % mo); } inline ll mdiv(ll a, ll bb) { if (a >= mo) a = a % mo; ll b = modinv(bb); if (b >= mo) b = b % mo; if (a * b >= mo) return (a * b) % mo; return (a * b); } inline ll gcd(ll a, ll b) { return __gcd(a, b); } inline ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } vi ad[200001]; vi adjr[200001]; bool visited[200001] = {false}; int n, m; void dfsfillorder(stack<int> &s, int u) { if (visited[u]) return; visited[u] = true; for (int i = 0; i < ad[u].size(); i++) dfsfillorder(s, ad[u][i]); s.push(u); } void rev() { for (int i = 1; i <= n; i++) for (int j = 0; j < ad[i].size(); j++) adjr[ad[i][j]].pb(i); } void dfsutil(int x, vi &vx) { if (visited[x]) return; vx.pb(x); visited[x] = true; for (int i = 0; i < adjr[x].size(); i++) dfsutil(adjr[x][i], vx); } vector<vector<int>> getSCC(int v) { vector<vector<int>> cc; stack<int> s; for (int i = 1; i <= v; i++) dfsfillorder(s, i); rev(); for (int i = 1; i <= v; i++) visited[i] = false; while (!s.empty()) { int x = s.top(); s.pop(); if (!visited[x]) { vi vx; dfsutil(x, vx); cc.pb(vx); } } return cc; } int main() { io int testcases = 1; // cin>>testcases; while (testcases--) { cin >> n >> m; int a, b; set<pi> s; for (int i = 1; i <= m; i++) { cin >> a >> b; if (a > b) swap(a, b); pi p = mp(a, b); if (s.find(p) != s.end()) continue; s.in(p); ad[a].pb(b); ad[b].pb(a); } vector<vector<int>> cc = getSCC(n); int ma = 0; for (int i = 0; i < cc.size(); i++) { ma = max(ma, (int)cc[i].size()); } cout << ma; } return 0; }
replace
123
126
123
126
0
p02573
C++
Runtime Error
#include <cmath> #include <iostream> #include <vector> using namespace std; const int N = 1e5 + 5; typedef long long ll; int father[N]; int height[N]; int people[N]; int find(int x) { if (x != father[x]) father[x] = find(father[x]); return father[x]; } // 合并并返回合并后的祖先序号 void Union(int x, int y) { x = find(x); y = find(y); if (height[x] > height[y]) { father[y] = x; // 两者祖先相同时,实际没发生合并,只考虑祖先不同的情况 if (x != y) people[x] += people[y]; } else { father[x] = y; // 两者祖先相同时,实际没发生合并,只考虑祖先不同的情况 if (x != y) people[y] += people[x]; if (height[x] == height[y]) // 树高相同时让父节点的树高值加一 height[y] += 1; } } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { father[i] = i; height[i] = 0; people[i] = 1; } for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; Union(a, b); } int cnt = 1; for (int i = 1; i <= n; i++) if (people[i] > cnt) cnt = people[i]; cout << cnt; }
#include <cmath> #include <iostream> #include <vector> using namespace std; const int N = 2e5 + 5; typedef long long ll; int father[N]; int height[N]; int people[N]; int find(int x) { if (x != father[x]) father[x] = find(father[x]); return father[x]; } // 合并并返回合并后的祖先序号 void Union(int x, int y) { x = find(x); y = find(y); if (height[x] > height[y]) { father[y] = x; // 两者祖先相同时,实际没发生合并,只考虑祖先不同的情况 if (x != y) people[x] += people[y]; } else { father[x] = y; // 两者祖先相同时,实际没发生合并,只考虑祖先不同的情况 if (x != y) people[y] += people[x]; if (height[x] == height[y]) // 树高相同时让父节点的树高值加一 height[y] += 1; } } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { father[i] = i; height[i] = 0; people[i] = 1; } for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; Union(a, b); } int cnt = 1; for (int i = 1; i <= n; i++) if (people[i] > cnt) cnt = people[i]; cout << cnt; }
replace
4
5
4
5
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> using namespace std; #define int long long int #define pb push_back #define fi(n) for (int i = 0; i < n; i++) #define fi1(n) for (int i = 1; i < n; i++) #define fj(n) for (int j = 0; j < n; j++) #define clr(x) memset(x, 0, sizeof(x)) #define print(x) \ for (auto a : x) \ cout << a << " "; \ cout << "\n" #define nl "\n" #define vi vector<int> #define si set<int> #define mp make_pair #define pairi pair<int, int> #define vpairi vector<pair<int, int>> #define ff first #define ss second #define inf 1e9 + 10 #define input \ "C://Users//Piyush Aggarwal//Documents//Cpp files//input-output//input.txt" #define output \ "C://Users//Piyush Aggarwal//Documents//Cpp files//input-output//output.txt" #define error \ "C://Users//Piyush Aggarwal//Documents//Cpp files//input-output//error.txt" int ctoi(char a) { int x = a - 48 - 49; return x; } string itos(int a) { string out_string; stringstream ss; ss << a; out_string = ss.str(); return out_string; } char itoc(int a) { return itos(a)[0]; } int pow(int e, int x) { int ans = 1; while (x > 0) { if (x & 1) ans *= e; e *= e; x >>= 1; } return ans; } string bin(int x) { bitset<sizeof(1) * CHAR_BIT> bits(x); string b = bits.to_string(); return b; } vi a(100005); vi parent(100005); int find(int x) { if (parent[x] == -1) return x; else return parent[x] = find(parent[x]); } void union1(int x, int y) { int a1 = find(x); int b = find(y); if (a1 != b) { parent[a1] = b; a[b] += a[a1]; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen(input, "r", stdin); freopen(output, "w", stdout); freopen(error, "w", stderr); #endif int T = 1; // cin>>T; while (T--) { int n, k, m, x, y, z; cin >> n >> m; // vi a(n); // fi(n) cin>>a[i]; // vi a(n); // vi parent(n); fi(n) { parent[i] = -1; a[i] = 1; } fi(m) { cin >> x >> y; union1(x - 1, y - 1); // print(a); } int ans = -1; fi(n) { ans = max(ans, a[i]); } cout << ans << nl; } return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; #define int long long int #define pb push_back #define fi(n) for (int i = 0; i < n; i++) #define fi1(n) for (int i = 1; i < n; i++) #define fj(n) for (int j = 0; j < n; j++) #define clr(x) memset(x, 0, sizeof(x)) #define print(x) \ for (auto a : x) \ cout << a << " "; \ cout << "\n" #define nl "\n" #define vi vector<int> #define si set<int> #define mp make_pair #define pairi pair<int, int> #define vpairi vector<pair<int, int>> #define ff first #define ss second #define inf 1e9 + 10 #define input \ "C://Users//Piyush Aggarwal//Documents//Cpp files//input-output//input.txt" #define output \ "C://Users//Piyush Aggarwal//Documents//Cpp files//input-output//output.txt" #define error \ "C://Users//Piyush Aggarwal//Documents//Cpp files//input-output//error.txt" int ctoi(char a) { int x = a - 48 - 49; return x; } string itos(int a) { string out_string; stringstream ss; ss << a; out_string = ss.str(); return out_string; } char itoc(int a) { return itos(a)[0]; } int pow(int e, int x) { int ans = 1; while (x > 0) { if (x & 1) ans *= e; e *= e; x >>= 1; } return ans; } string bin(int x) { bitset<sizeof(1) * CHAR_BIT> bits(x); string b = bits.to_string(); return b; } vi a(200005); vi parent(200005); int find(int x) { if (parent[x] == -1) return x; else return parent[x] = find(parent[x]); } void union1(int x, int y) { int a1 = find(x); int b = find(y); if (a1 != b) { parent[a1] = b; a[b] += a[a1]; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen(input, "r", stdin); freopen(output, "w", stdout); freopen(error, "w", stderr); #endif int T = 1; // cin>>T; while (T--) { int n, k, m, x, y, z; cin >> n >> m; // vi a(n); // fi(n) cin>>a[i]; // vi a(n); // vi parent(n); fi(n) { parent[i] = -1; a[i] = 1; } fi(m) { cin >> x >> y; union1(x - 1, y - 1); // print(a); } int ans = -1; fi(n) { ans = max(ans, a[i]); } cout << ans << nl; } return 0; }
replace
57
59
57
59
-11
p02573
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int #define ull unsigned long long int #define ld long double #define mod 1000000007 #define FT() \ int t; \ scanf("%d", &t); \ while (t--) #define pb push_back #define nl printf("\n") #define fi(i, start, end) for (int i = start; i < (int)end; ++i) #define ip(n) scanf("%d", &n) #define mz(a) memset(a, 0, sizeof(a)) #define inpArr(A, n) fi(i, 0, n) ip(A[i]); #define print(a) \ for (auto i : a) \ cout << i << " "; \ nl; #define Fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); using namespace std; ll max(ll a, ll b) { return a > b ? a : b; } ll min(ll a, ll b) { return a < b ? a : b; } const int N = 1e5 + 1; vector<int> adj[N]; vector<int> vis(N); void dfs(int root, int val) { vis[root] = val; for (auto i : adj[root]) if (!vis[i]) dfs(i, val); } int main() { #ifndef ONLINE_JUDGE freopen("D:/Sublime/Rough/input.txt", "r", stdin); // freopen("output.txt","w",stdout); #endif // std::cout << std::fixed; // std::cout << std::setprecision(6); Fastio; int n, m; cin >> n >> m; while (m--) { int u, v; cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } int val = 0; for (int i = 1; i <= n; i++) { if (!vis[i]) dfs(i, ++val); } int a[val + 1]; mz(a); int mx = 0; for (auto i : vis) a[i]++; for (int i = 1; i <= val; i++) mx = max(mx, a[i]); // print(a); cout << mx; #ifndef ONLINE_JUDGE cout << "\nTime Elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " s"; #endif return 0; }
#include <bits/stdc++.h> #define ll long long int #define ull unsigned long long int #define ld long double #define mod 1000000007 #define FT() \ int t; \ scanf("%d", &t); \ while (t--) #define pb push_back #define nl printf("\n") #define fi(i, start, end) for (int i = start; i < (int)end; ++i) #define ip(n) scanf("%d", &n) #define mz(a) memset(a, 0, sizeof(a)) #define inpArr(A, n) fi(i, 0, n) ip(A[i]); #define print(a) \ for (auto i : a) \ cout << i << " "; \ nl; #define Fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); using namespace std; ll max(ll a, ll b) { return a > b ? a : b; } ll min(ll a, ll b) { return a < b ? a : b; } const int N = 2e5 + 1; vector<int> adj[N]; vector<int> vis(N); void dfs(int root, int val) { vis[root] = val; for (auto i : adj[root]) if (!vis[i]) dfs(i, val); } int main() { #ifndef ONLINE_JUDGE freopen("D:/Sublime/Rough/input.txt", "r", stdin); // freopen("output.txt","w",stdout); #endif // std::cout << std::fixed; // std::cout << std::setprecision(6); Fastio; int n, m; cin >> n >> m; while (m--) { int u, v; cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } int val = 0; for (int i = 1; i <= n; i++) { if (!vis[i]) dfs(i, ++val); } int a[val + 1]; mz(a); int mx = 0; for (auto i : vis) a[i]++; for (int i = 1; i <= val; i++) mx = max(mx, a[i]); // print(a); cout << mx; #ifndef ONLINE_JUDGE cout << "\nTime Elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " s"; #endif return 0; }
replace
25
26
25
26
-11
p02573
C++
Runtime Error
/*created by tanishk gupta*/ #include <bits/stdc++.h> using namespace std; #define rep(i, a, n) for (int i = a; i < n; i++) #define per(i, a, n) for (int i = n - 1; i >= a; i--) #define repl(i, a, n) for (long long int i = a; i < n; i++) #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define fi first #define se second #define SZ(x) ((int)(x).size()) #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); typedef vector<int> VI; typedef long long int ll; typedef unsigned long long ull; // typedef pair<int,int> PII; typedef double db; mt19937 mrand(random_device{}()); const ll MOD = 1e9 + 7; const ll mod = 1e9 + 7; // const llint MOD; const ll N = (ll)(1e6 + 1); int rnd(int x) { return mrand() % x; } ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll add(ll a, ll b) { return ((a % MOD) + (b % MOD)) % MOD; } ll mul(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; } ll sub(ll a, ll b) { return ((a % MOD) - (b % MOD) + MOD) % MOD; } ll binpow(ll x, ll y) { ll z = 1; while (y) { if (y & 1) z = mul(z, x); x = mul(x, x); y >>= 1; } return z; } ll inv(int x) { return binpow(x, MOD - 2); } ll divide(ll x, ll y) { return mul(x, inv(y)); } ll fact[N]; void precalc() { fact[0] = 1; for (ll i = 1; i < N; i++) fact[i] = mul(fact[i - 1], i); } ll C(ll n, ll k) { return divide(fact[n], mul(fact[k], fact[n - k])); } // bool prime[N]; // void sieve() {for(int i=2;i<N;i++) {prime[i]=true;}for (int p=2; p*p<=N; // p++){if (prime[p] == true){for (int i=p*p; i<=N; i += p)prime[i] = false;}}} ll legendpow(ll n, ll p) { ll total = 0; while (n) { n /= p; total += n; } return total; } // head================================================================================== VI adj[100005]; int vis[100005]; int tot = 0; void dfs(int node) { tot++; vis[node] = 1; for (auto x : adj[node]) { if (vis[x] == 0) { dfs(x); } } } int main() { // #ifdef _DEBUG // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif IOS; int n, m; cin >> n >> m; int maxa = 0; while (m--) { int u, v; cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } rep(i, 1, n + 1) { if (vis[i] == 0) { dfs(i); maxa = max(tot, maxa); tot = 0; } } cout << maxa << endl; }
/*created by tanishk gupta*/ #include <bits/stdc++.h> using namespace std; #define rep(i, a, n) for (int i = a; i < n; i++) #define per(i, a, n) for (int i = n - 1; i >= a; i--) #define repl(i, a, n) for (long long int i = a; i < n; i++) #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define fi first #define se second #define SZ(x) ((int)(x).size()) #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); typedef vector<int> VI; typedef long long int ll; typedef unsigned long long ull; // typedef pair<int,int> PII; typedef double db; mt19937 mrand(random_device{}()); const ll MOD = 1e9 + 7; const ll mod = 1e9 + 7; // const llint MOD; const ll N = (ll)(1e6 + 1); int rnd(int x) { return mrand() % x; } ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll add(ll a, ll b) { return ((a % MOD) + (b % MOD)) % MOD; } ll mul(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; } ll sub(ll a, ll b) { return ((a % MOD) - (b % MOD) + MOD) % MOD; } ll binpow(ll x, ll y) { ll z = 1; while (y) { if (y & 1) z = mul(z, x); x = mul(x, x); y >>= 1; } return z; } ll inv(int x) { return binpow(x, MOD - 2); } ll divide(ll x, ll y) { return mul(x, inv(y)); } ll fact[N]; void precalc() { fact[0] = 1; for (ll i = 1; i < N; i++) fact[i] = mul(fact[i - 1], i); } ll C(ll n, ll k) { return divide(fact[n], mul(fact[k], fact[n - k])); } // bool prime[N]; // void sieve() {for(int i=2;i<N;i++) {prime[i]=true;}for (int p=2; p*p<=N; // p++){if (prime[p] == true){for (int i=p*p; i<=N; i += p)prime[i] = false;}}} ll legendpow(ll n, ll p) { ll total = 0; while (n) { n /= p; total += n; } return total; } // head================================================================================== VI adj[200005]; int vis[200005]; int tot = 0; void dfs(int node) { tot++; vis[node] = 1; for (auto x : adj[node]) { if (vis[x] == 0) { dfs(x); } } } int main() { // #ifdef _DEBUG // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif IOS; int n, m; cin >> n >> m; int maxa = 0; while (m--) { int u, v; cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } rep(i, 1, n + 1) { if (vis[i] == 0) { dfs(i); maxa = max(tot, maxa); tot = 0; } } cout << maxa << endl; }
replace
74
76
74
76
0
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> // For policy based data structure /*#include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> */ using namespace std; /*using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;*/ #define MD 1000000007 #define X first #define Y second #define pb push_back #define debug(val, ch) cout << val << ch typedef long long int ll; typedef unsigned int ui; typedef unsigned long long ull; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef pair<int, int> pii; typedef pair<int, bool> pib; typedef pair<bool, int> pbi; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; #define fast() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) int find(vector<int> &par, int a) { if (par[a] == a) { return a; } return find(par, par[a]); } /*********************************************************************/ void test(int r) { int n, m; cin >> n >> m; vector<int> par(n + 1, 0), cn(n + 1, 0); int i, j; for (i = 1; i <= n; i++) { par[i] = i; cn[i] = 1; } for (i = 1; i <= m; i++) { int a, b; cin >> a >> b; int p1, p2; p1 = find(par, a); p2 = find(par, b); if (p1 != p2) { par[p1] = p2; cn[p2] += cn[p1]; } } int mx = 0; for (i = 1; i <= n; i++) mx = max(mx, cn[i]); cout << mx << endl; } /***********************************************************************/ int main() { fast(); int t = 1, r; // cin>>t; for (r = 1; r <= t; r++) test(r); return 0; }
#include <bits/stdc++.h> // For policy based data structure /*#include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> */ using namespace std; /*using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;*/ #define MD 1000000007 #define X first #define Y second #define pb push_back #define debug(val, ch) cout << val << ch typedef long long int ll; typedef unsigned int ui; typedef unsigned long long ull; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef pair<int, int> pii; typedef pair<int, bool> pib; typedef pair<bool, int> pbi; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; #define fast() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) int find(vector<int> &par, int a) { if (par[a] == a) { return a; } par[a] = find(par, par[a]); return par[a]; } /*********************************************************************/ void test(int r) { int n, m; cin >> n >> m; vector<int> par(n + 1, 0), cn(n + 1, 0); int i, j; for (i = 1; i <= n; i++) { par[i] = i; cn[i] = 1; } for (i = 1; i <= m; i++) { int a, b; cin >> a >> b; int p1, p2; p1 = find(par, a); p2 = find(par, b); if (p1 != p2) { par[p1] = p2; cn[p2] += cn[p1]; } } int mx = 0; for (i = 1; i <= n; i++) mx = max(mx, cn[i]); cout << mx << endl; } /***********************************************************************/ int main() { fast(); int t = 1, r; // cin>>t; for (r = 1; r <= t; r++) test(r); return 0; }
replace
38
39
38
40
TLE
p02573
C++
Runtime Error
#include <bits/stdc++.h> // #define M_PI 3.14159265358979323846 using namespace std; #define rep(i, a, b) for (int i = a; i < b; ++i) #define repb(i, a, b) for (int i = a; i >= b; --i) #define vi vector<int> #define vb vector<bool> #define vs vector<string> #define vl vector<long long int> #define vc vector<char> #define vld vector<ld> #define vvi vector<vector<int>> #define vvl vector<vector<long long>> #define vvld vector<vector<ld>> #define vpii vector<pii> #define vpll vector<pll> #define ld long double #define ll long long #define sz(a) (ll) a.size() #define ssortA(arr) stable_sort(arr.begin(), arr.end()) #define ssortB(arr) stable_sort(arr.begin(), arr.end(), greater<ll>()); #define pii pair<int, int> #define pll pair<long long, long long> #define ff first #define ss second #define search(arr, c) binary_search(arr.begin(), arr.end(), c) #define pb push_back #define pf push_front #define mp make_pair #define lb lower_bound #define ub upper_bound #define endl "\n" #define PI acos(-1.0) #define GCD(a, b) __gcd(a, b) #define popcount(x) __builtin_popcountll(x) #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define r1(x) cin >> x #define r2(x, y) cin >> x >> y #define r3(x, y, z) cin >> x >> y >> z #define r4(a, b, c, d) cin >> a >> b >> c >> d #define d1(x) cout << (x) << endl #define d2(x, y) cout << (x) << " " << (y) << endl #define d3(x, y, z) cout << (x) << " " << (y) << " " << (z) << endl #define d4(a, b, c, d) \ cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl #define fix(f, n) fixed << setprecision(n) << f << endl #define check(ds, a) (ds.find(a) != ds.end() ? 1 : 0) #define mem(arr) memset(arr, 0, sizeof(arr)) const int M = (int)1e9 + 7; int c = 0; vi adj[200005]; vb visited(20005, false); void dfs(int a) { visited[a] = true; ++c; for (auto it : adj[a]) { if (!visited[it]) { dfs(it); } } } int main() { int n, m; cin >> n >> m; rep(i, 0, m) { int u, v; cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } int maxi = 0; rep(i, 1, n + 1) { c = 0; if (!visited[i]) { dfs(i); } maxi = max(maxi, c); } cout << maxi << endl; }
#include <bits/stdc++.h> // #define M_PI 3.14159265358979323846 using namespace std; #define rep(i, a, b) for (int i = a; i < b; ++i) #define repb(i, a, b) for (int i = a; i >= b; --i) #define vi vector<int> #define vb vector<bool> #define vs vector<string> #define vl vector<long long int> #define vc vector<char> #define vld vector<ld> #define vvi vector<vector<int>> #define vvl vector<vector<long long>> #define vvld vector<vector<ld>> #define vpii vector<pii> #define vpll vector<pll> #define ld long double #define ll long long #define sz(a) (ll) a.size() #define ssortA(arr) stable_sort(arr.begin(), arr.end()) #define ssortB(arr) stable_sort(arr.begin(), arr.end(), greater<ll>()); #define pii pair<int, int> #define pll pair<long long, long long> #define ff first #define ss second #define search(arr, c) binary_search(arr.begin(), arr.end(), c) #define pb push_back #define pf push_front #define mp make_pair #define lb lower_bound #define ub upper_bound #define endl "\n" #define PI acos(-1.0) #define GCD(a, b) __gcd(a, b) #define popcount(x) __builtin_popcountll(x) #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define r1(x) cin >> x #define r2(x, y) cin >> x >> y #define r3(x, y, z) cin >> x >> y >> z #define r4(a, b, c, d) cin >> a >> b >> c >> d #define d1(x) cout << (x) << endl #define d2(x, y) cout << (x) << " " << (y) << endl #define d3(x, y, z) cout << (x) << " " << (y) << " " << (z) << endl #define d4(a, b, c, d) \ cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl #define fix(f, n) fixed << setprecision(n) << f << endl #define check(ds, a) (ds.find(a) != ds.end() ? 1 : 0) #define mem(arr) memset(arr, 0, sizeof(arr)) const int M = (int)1e9 + 7; int c = 0; vi adj[200005]; vb visited(200005, false); void dfs(int a) { visited[a] = true; ++c; for (auto it : adj[a]) { if (!visited[it]) { dfs(it); } } } int main() { int n, m; cin >> n >> m; rep(i, 0, m) { int u, v; cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } int maxi = 0; rep(i, 1, n + 1) { c = 0; if (!visited[i]) { dfs(i); } maxi = max(maxi, c); } cout << maxi << endl; }
replace
58
59
58
59
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; int back(int tree[], int start) { int root; if (tree[start] == -1) return start; root = back(tree, tree[start]); tree[start] = root; return root; } int main() { int n, m; cin >> n >> m; int h1[n], h2[n]; rep(i, n) { h1[i] = -1; h2[i] = 0; } int a, b, aroot, broot; rep(i, m) { cin >> a >> b; aroot = back(h1, a); broot = back(h1, b); if (aroot != broot) h1[aroot] = broot; } rep(i, n) h2[back(h1, i)]++; int mm = 0; rep(i, n) mm = max(mm, h2[i]); cout << mm; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; int back(int tree[], int start) { int root; if (tree[start] == -1) return start; root = back(tree, tree[start]); tree[start] = root; return root; } int main() { int n, m; cin >> n >> m; int h1[n], h2[n]; rep(i, n) { h1[i] = -1; h2[i] = 0; } int a, b, aroot, broot; rep(i, m) { cin >> a >> b; a--; b--; aroot = back(h1, a); broot = back(h1, b); if (aroot != broot) h1[aroot] = broot; } rep(i, n) h2[back(h1, i)]++; int mm = 0; rep(i, n) mm = max(mm, h2[i]); cout << mm; return 0; }
insert
23
23
23
25
-11
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define V vector typedef long long ll; typedef unsigned long long ull; typedef V<int> vi; typedef V<ll> vll; typedef V<string> vs; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define f(i, a) for (int i = 0; i < a; i++) #define fll(i, a) for (ll i = 0; i < a; i++) #define forab(i, a, b) for (int i = a; i < b; i++) #define prec(x) cout << fixed << setprecision(x) #define ff first #define ss second #define pb push_back #define mp make_pair #define numberofdigits(x) floor(log10(x)) + 1 const ll mod = 1e9 + 7; ll binpow(ll a, long long b) { ll res = 1; while (b > 0) { if (b & 1) res = (res * a); a = (a * a); b >>= 1; } return res; } vector<vector<int>> a; vector<int> vis; int dfs(int node) { vis[node] = 1; int ans = 1; for (auto child : a[node]) { if (vis[child] == 1) continue; ans += dfs(child); } return ans; } void solve() { int n, m; cin >> n >> m; a = vector<vector<int>>(n + 1); vis = vector<int>(n + 1, 0); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; a[u].pb(v), a[v].pb(u); } int cc = 0; vector<int> cntnodes; for (int i = 1; i <= n; i++) { if (vis[i] == 0) { int c = dfs(i); cntnodes.pb(c); } } sort(cntnodes.begin(), cntnodes.end()); /*for (auto c : cntnodes) cout << c << " "; cout << "\n";*/ int sz = cntnodes.size(), i = 0; while (i < sz) { if (cntnodes[i] == 0) { i++; continue; } int e = cntnodes[i]; int j = i; while (j < n) { cntnodes[j] -= e; if (cntnodes[j] == 0) i++; j++; } cc += e; if (cntnodes[sz - 1] == 0) break; } cout << cc << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define V vector typedef long long ll; typedef unsigned long long ull; typedef V<int> vi; typedef V<ll> vll; typedef V<string> vs; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define f(i, a) for (int i = 0; i < a; i++) #define fll(i, a) for (ll i = 0; i < a; i++) #define forab(i, a, b) for (int i = a; i < b; i++) #define prec(x) cout << fixed << setprecision(x) #define ff first #define ss second #define pb push_back #define mp make_pair #define numberofdigits(x) floor(log10(x)) + 1 const ll mod = 1e9 + 7; ll binpow(ll a, long long b) { ll res = 1; while (b > 0) { if (b & 1) res = (res * a); a = (a * a); b >>= 1; } return res; } vector<vector<int>> a; vector<int> vis; int dfs(int node) { vis[node] = 1; int ans = 1; for (auto child : a[node]) { if (vis[child] == 1) continue; ans += dfs(child); } return ans; } void solve() { int n, m; cin >> n >> m; a = vector<vector<int>>(n + 1); vis = vector<int>(n + 1, 0); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; a[u].pb(v), a[v].pb(u); } int cc = 0; vector<int> cntnodes; for (int i = 1; i <= n; i++) { if (vis[i] == 0) { int c = dfs(i); cntnodes.pb(c); } } sort(cntnodes.begin(), cntnodes.end()); /*for (auto c : cntnodes) cout << c << " "; cout << "\n";*/ int sz = cntnodes.size(), i = 0; while (i < sz) { if (cntnodes[i] == 0) { i++; continue; } int e = cntnodes[i]; int j = i; while (j < sz) { cntnodes[j] -= e; if (cntnodes[j] == 0) i++; j++; } cc += e; if (cntnodes[sz - 1] == 0) break; } cout << cc << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin >> t; while (t--) solve(); return 0; }
replace
94
95
94
95
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define M 1000000007 vector<ll> adj[20000]; ll vis[20000]; void dfs(ll node, vector<ll> &v) { vis[node] = 1; v.push_back(node); for (ll child : adj[node]) { if (vis[child] == 0) dfs(child, v); } } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio; ll n, m, u, v; cin >> n >> m; for (int i = 1; i <= n; ++i) { vis[i] = 0; adj[i].clear(); } while (m--) { cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } ll res = INT_MIN; for (int i = 1; i <= n; ++i) { if (vis[i] == 0) { vector<ll> v; dfs(i, v); res = max(res, (ll)v.size()); v.clear(); } } cout << res; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define M 1000000007 vector<ll> adj[200006]; ll vis[200006]; void dfs(ll node, vector<ll> &v) { vis[node] = 1; v.push_back(node); for (ll child : adj[node]) { if (vis[child] == 0) dfs(child, v); } } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio; ll n, m, u, v; cin >> n >> m; for (int i = 1; i <= n; ++i) { vis[i] = 0; adj[i].clear(); } while (m--) { cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } ll res = INT_MIN; for (int i = 1; i <= n; ++i) { if (vis[i] == 0) { vector<ll> v; dfs(i, v); res = max(res, (ll)v.size()); v.clear(); } } cout << res; return 0; }
replace
7
9
7
9
-11
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll LINF = 1e18; const int INF = 1e9; #define rep(i, n) for (int i = 0; i < (int)(n); i++) struct UnionFind { vector<int> par; UnionFind(int N) : par(N) { rep(i, N) par[i] = i; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { if (root(x) == root(y)) return; par[root(x)] = root(y); } bool same(int x, int y) { return root(x) == root(y); } }; int main() { int N, M; cin >> N >> M; UnionFind tree(N); rep(i, M) { int a, b; cin >> a >> b; tree.unite(a - 1, b - 1); } int ROOT[N]; rep(i, N) ROOT[i] = 0; rep(i, N) { int r = tree.root(i + 1); ROOT[r]++; } sort(ROOT, ROOT + N); cout << ROOT[N - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll LINF = 1e18; const int INF = 1e9; #define rep(i, n) for (int i = 0; i < (int)(n); i++) struct UnionFind { vector<int> par; UnionFind(int N) : par(N) { rep(i, N) par[i] = i; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { if (root(x) == root(y)) return; par[root(x)] = root(y); } bool same(int x, int y) { return root(x) == root(y); } }; int main() { int N, M; cin >> N >> M; UnionFind tree(N); rep(i, M) { int a, b; cin >> a >> b; tree.unite(a - 1, b - 1); } int ROOT[N]; rep(i, N) ROOT[i] = 0; rep(i, N) { int r = tree.root(i); ROOT[r]++; } sort(ROOT, ROOT + N); cout << ROOT[N - 1] << endl; return 0; }
replace
39
40
39
40
0
p02573
C++
Runtime Error
/* []__________[][][][]____[][][][][]__{}__[][][][]____[][][][][]__[][][][] []__________[]______________[]__________[]__________[]__________[]____[] []__________[][][][]________[]__________[][][][]____[]__________[]____[] []__________[]______________[]________________[]____[]__[][][]__[]____[] []__________[]______________[]________________[]____[]______[]__[]____[] [][][][]____[][][][]________[]__________[][][][]____[][][][][]__[][][][] */ #include <bits/stdc++.h> #define ll long long int #define mod 1000000007 #define endl '\n' using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #define decimal(x) cout << fixed << setprecision(x); vector<int> adj[100005]; bool vis[100005]; int n; vector<int> temp; int c; void dfs(int x) { vis[x] = true; c++; for (auto i : adj[x]) { if (!vis[i]) dfs(i); } } void helper() { int ans = 0; for (int i = 1; i <= n; i++) { if (vis[i] == false) { dfs(i); ans = max(ans, c); c = 0; } } cout << ans << endl; } void solve() { int m; cin >> n >> m; while (m--) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } helper(); } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin>>t; while (t--) { solve(); } }
/* []__________[][][][]____[][][][][]__{}__[][][][]____[][][][][]__[][][][] []__________[]______________[]__________[]__________[]__________[]____[] []__________[][][][]________[]__________[][][][]____[]__________[]____[] []__________[]______________[]________________[]____[]__[][][]__[]____[] []__________[]______________[]________________[]____[]______[]__[]____[] [][][][]____[][][][]________[]__________[][][][]____[][][][][]__[][][][] */ #include <bits/stdc++.h> #define ll long long int #define mod 1000000007 #define endl '\n' using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #define decimal(x) cout << fixed << setprecision(x); vector<int> adj[200005]; bool vis[200005]; int n; vector<int> temp; int c; void dfs(int x) { vis[x] = true; c++; for (auto i : adj[x]) { if (!vis[i]) dfs(i); } } void helper() { int ans = 0; for (int i = 1; i <= n; i++) { if (vis[i] == false) { dfs(i); ans = max(ans, c); c = 0; } } cout << ans << endl; } void solve() { int m; cin >> n >> m; while (m--) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } helper(); } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin>>t; while (t--) { solve(); } }
replace
15
17
15
17
-11
p02573
C++
Runtime Error
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */ // codeforces #include <bits/stdc++.h> // #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define mp make_pair #define pb push_back #define sz(v) ((int)v.size()) #define all(v) v.begin(), v.end() void parseArray(ll *A, ll n) { for (ll K = 0; K < n; K++) { cin >> A[K]; } } ll modInverse(ll a, ll b) { return 1 < a ? b - modInverse(b % a, a) * b / a : 1; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } ld dist(ld x, ld y, ld a, ld b) { return sqrt((x - a) * (x - a) + (y - b) * (y - b)); } void debug(ll *a, ll n) { for (ll k = 0; k < n; k++) { cerr << a[k] << " "; } cout << "\n"; } #define PI 3.14159265358979323846 #define FF first #define SS second #define M 2222 ll sze, numComp; ll sz[M], id[M]; void build(ll N) { sze = numComp = N; for (ll k = 0; k < N; k++) { sz[k] = 1; id[k] = k; } } ll find(ll p) { ll root = p; while (root != id[root]) { root = id[root]; } while (p != root) { ll temp = id[p]; id[p] = root; p = temp; } return root; } bool connected(ll p, ll q) { return find(p) == find(q); } ll componentSize(ll p) { return sz[find(p)]; } void unify(ll p, ll q) { ll root1 = find(p); ll root2 = find(q); if (root1 == root2) return; if (sz[root1] < sz[root2]) { sz[root2] += sz[root1]; id[root1] = root2; } else { sz[root1] += sz[root2]; id[root2] = root1; } numComp--; } int main() { FASTIO; ll n, m; cin >> n >> m; build(n + 1); for (int k = 0; k < m; k++) { ll x, y; cin >> x >> y; unify(x, y); } ll ans = 0; for (int k = 0; k <= n; k++) { ans = max(ans, componentSize(k)); } cout << ans << endl; return 0; }
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */ // codeforces #include <bits/stdc++.h> // #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define mp make_pair #define pb push_back #define sz(v) ((int)v.size()) #define all(v) v.begin(), v.end() void parseArray(ll *A, ll n) { for (ll K = 0; K < n; K++) { cin >> A[K]; } } ll modInverse(ll a, ll b) { return 1 < a ? b - modInverse(b % a, a) * b / a : 1; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } ld dist(ld x, ld y, ld a, ld b) { return sqrt((x - a) * (x - a) + (y - b) * (y - b)); } void debug(ll *a, ll n) { for (ll k = 0; k < n; k++) { cerr << a[k] << " "; } cout << "\n"; } #define PI 3.14159265358979323846 #define FF first #define SS second #define M 222222 ll sze, numComp; ll sz[M], id[M]; void build(ll N) { sze = numComp = N; for (ll k = 0; k < N; k++) { sz[k] = 1; id[k] = k; } } ll find(ll p) { ll root = p; while (root != id[root]) { root = id[root]; } while (p != root) { ll temp = id[p]; id[p] = root; p = temp; } return root; } bool connected(ll p, ll q) { return find(p) == find(q); } ll componentSize(ll p) { return sz[find(p)]; } void unify(ll p, ll q) { ll root1 = find(p); ll root2 = find(q); if (root1 == root2) return; if (sz[root1] < sz[root2]) { sz[root2] += sz[root1]; id[root1] = root2; } else { sz[root1] += sz[root2]; id[root2] = root1; } numComp--; } int main() { FASTIO; ll n, m; cin >> n >> m; build(n + 1); for (int k = 0; k < m; k++) { ll x, y; cin >> x >> y; unify(x, y); } ll ans = 0; for (int k = 0; k <= n; k++) { ans = max(ans, componentSize(k)); } cout << ans << endl; return 0; }
replace
38
39
38
39
0
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define min3(a, b, c) min(a, min(b, c)) #define max3(a, b, c) max(a, max(b, c)) typedef long long ll; typedef unsigned long long ull; 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 a, int b) { int x = root(a); int y = root(b); if (x == y) return false; if (x > y) swap(x, y); r[x] += r[y]; r[y] = x; return true; } int size(int x) { return -r[root(x)]; } }; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 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 res = 1; for (int i = 0; i < n; i++) { res = max(res, UF.size(i)); } cout << res << endl; }
#include <bits/stdc++.h> #define min3(a, b, c) min(a, min(b, c)) #define max3(a, b, c) max(a, max(b, c)) typedef long long ll; typedef unsigned long long ull; 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; r[x] = root(r[x]); return r[x]; } bool unite(int a, int b) { int x = root(a); int y = root(b); if (x == y) return false; if (x > y) swap(x, y); r[x] += r[y]; r[y] = x; return true; } int size(int x) { return -r[root(x)]; } }; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 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 res = 1; for (int i = 0; i < n; i++) { res = max(res, UF.size(i)); } cout << res << endl; }
replace
12
13
12
14
TLE
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long vector<int> adj[100001]; bool visited[100001]; int groupsize = 0; int maxsize = 0; void dfs(int s) { visited[s] = true; groupsize += 1; for (int i = 0; i < adj[s].size(); ++i) { if (visited[adj[s][i]] == false) dfs(adj[s][i]); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n, m; cin >> n >> m; for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; // cout << a << ' ' << b << '\n'; adj[a].push_back(b); adj[b].push_back(a); } for (int i = 1; i <= n; ++i) { groupsize = 0; if (!visited[i]) { dfs(i); if (groupsize > maxsize) { maxsize = groupsize; } } } cout << maxsize; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long vector<int> adj[1000001]; bool visited[1000001]; int groupsize = 0; int maxsize = 0; void dfs(int s) { visited[s] = true; groupsize += 1; for (int i = 0; i < adj[s].size(); ++i) { if (visited[adj[s][i]] == false) dfs(adj[s][i]); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n, m; cin >> n >> m; for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; // cout << a << ' ' << b << '\n'; adj[a].push_back(b); adj[b].push_back(a); } for (int i = 1; i <= n; ++i) { groupsize = 0; if (!visited[i]) { dfs(i); if (groupsize > maxsize) { maxsize = groupsize; } } } cout << maxsize; }
replace
4
6
4
6
-11
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll INF = 100000000; #define rep1(i, n) for (ll i = 0; i < (n); i++) #define rep2(i, k, n) for (ll i = k; i < (n); i++) template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } struct UnionFind { vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(ll N) : par(N) { // 最初は全てが根であるとして初期化 for (ll i = 0; i < N; i++) par[i] = i; } ll root(ll x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(ll x, ll y) { // xとyの木を併合 ll rx = root(x); // xの根をrx ll ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す ll rx = root(x); ll ry = root(y); return rx == ry; } }; int main() { ll n, m, a, b; cin >> n >> m; map<P, ll> p; rep1(i, m) { cin >> a >> b; p[make_pair(min(a, b), max(a, b))] = 1; } UnionFind tree(n); for (auto xy : p) { tree.unite(xy.first.first, xy.first.second); } vector<ll> count(n); rep1(i, n) { ll cnt = tree.root(i); count[cnt]++; } ll ans = 0; rep1(i, n) ans = max(ans, count[i]); cout << ans << endl; // printf("%.12f", ans); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll INF = 100000000; #define rep1(i, n) for (ll i = 0; i < (n); i++) #define rep2(i, k, n) for (ll i = k; i < (n); i++) template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } struct UnionFind { vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(ll N) : par(N) { // 最初は全てが根であるとして初期化 for (ll i = 0; i < N; i++) par[i] = i; } ll root(ll x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(ll x, ll y) { // xとyの木を併合 ll rx = root(x); // xの根をrx ll ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す ll rx = root(x); ll ry = root(y); return rx == ry; } }; int main() { ll n, m, a, b; cin >> n >> m; map<P, ll> p; rep1(i, m) { cin >> a >> b; a--, b--; p[make_pair(min(a, b), max(a, b))] = 1; } UnionFind tree(n); for (auto xy : p) { tree.unite(xy.first.first, xy.first.second); } vector<ll> count(n); rep1(i, n) { ll cnt = tree.root(i); count[cnt]++; } ll ans = 0; rep1(i, n) ans = max(ans, count[i]); cout << ans << endl; // printf("%.12f", ans); }
insert
58
58
58
59
-11
p02573
Python
Runtime Error
n, m = map(int, input().split()) grid = [set() for i in range(n)] for i in range(m): u, v = map(int, input().split()) u -= 1 v -= 1 grid[u].add(v) grid[v].add(u) cnt = 0 best = 0 visited = set() def dfs(x): global cnt if x in visited: return cnt += 1 visited.add(x) for i in grid[x]: dfs(i) for i in range(n): cnt = 0 dfs(i) best = max(best, cnt) print(best)
n, m = map(int, input().split()) grid = [set() for i in range(n)] for i in range(m): u, v = map(int, input().split()) u -= 1 v -= 1 grid[u].add(v) grid[v].add(u) cnt = 0 best = 0 visited = set() import sys sys.setrecursionlimit(1000000) def dfs(x): global cnt if x in visited: return cnt += 1 visited.add(x) for i in grid[x]: dfs(i) for i in range(n): cnt = 0 dfs(i) best = max(best, cnt) print(best)
insert
12
12
12
16
0
p02573
Python
Runtime Error
N, M = list(map(int, input().split())) d = {i: [] for i in range(1, N + 1)} for _ in range(M): a, b = list(map(int, input().split())) d[a].append(b) d[b].append(a) visited = [False for _ in range(N + 1)] def visit(x): if visited[x]: return 0 visited[x] = True z = 1 for y in d[x]: z += visit(y) return z m = 1 for i in range(1, N + 1): r = visit(i) if m < r: m = r print(m)
import sys sys.setrecursionlimit(10000000) N, M = list(map(int, input().split())) d = {i: [] for i in range(1, N + 1)} for _ in range(M): a, b = list(map(int, input().split())) d[a].append(b) d[b].append(a) visited = [False for _ in range(N + 1)] def visit(x): if visited[x]: return 0 visited[x] = True z = 1 for y in d[x]: z += visit(y) return z m = 1 for i in range(1, N + 1): r = visit(i) if m < r: m = r print(m)
insert
0
0
0
4
0
p02573
Python
Runtime Error
from collections import Counter N, M = map(int, input().split()) groups = [0] * (N + 1) group_num_list = [[0]] group_num = 1 for _ in range(M): A, B = map(int, input().split()) if groups[A] != 0 and groups[B] != 0: if groups[A] != groups[B]: lower = min(groups[A], groups[B]) higher = max(groups[A], groups[B]) for i in group_num_list[higher]: groups[i] = lower tmp = group_num_list[higher] group_num_list[lower].extend(tmp) # del group_num_list[higher] elif groups[A] != 0: groups[B] = groups[A] group_num_list[groups[A]].append(int(B)) elif groups[B] != 0: groups[A] = groups[B] group_num_list[groups[B]].append(int(A)) else: groups[A] = group_num groups[B] = group_num group_num_list.append([int(A), int(B)]) group_num += 1 counter = Counter(groups) # print(collection) # print(group_num_list) if len(groups) == 1: print(1) elif int(counter.most_common()[0][0]) != 0: print(counter.most_common()[0][1]) else: print(counter.most_common()[1][1])
from collections import Counter N, M = map(int, input().split()) groups = [0] * (N + 1) group_num_list = [[0]] group_num = 1 for _ in range(M): A, B = map(int, input().split()) if groups[A] != 0 and groups[B] != 0: if groups[A] != groups[B]: lower = min(groups[A], groups[B]) higher = max(groups[A], groups[B]) for i in group_num_list[higher]: groups[i] = lower tmp = group_num_list[higher] group_num_list[lower].extend(tmp) # del group_num_list[higher] elif groups[A] != 0: groups[B] = groups[A] group_num_list[groups[A]].append(int(B)) elif groups[B] != 0: groups[A] = groups[B] group_num_list[groups[B]].append(int(A)) else: groups[A] = group_num groups[B] = group_num group_num_list.append([int(A), int(B)]) group_num += 1 counter = Counter(groups) # print(collection) # print(group_num_list) if len(group_num_list) == 1: print(1) elif int(counter.most_common()[0][0]) != 0: print(counter.most_common()[0][1]) else: print(counter.most_common()[1][1])
replace
31
32
31
32
0
p02573
Python
Time Limit Exceeded
class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {root: self.members(root) for root in self.roots()} def __str__(self): return "\n".join(f"{root}: {self.members(root)}" for root in self.roots()) N, M = map(int, input().split()) uf = UnionFind(N) for _ in range(M): a, b = map(int, input().split()) uf.union(a - 1, b - 1) print(max(len(members) for members in uf.all_group_members().values()))
class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {root: self.members(root) for root in self.roots()} def __str__(self): return "\n".join(f"{root}: {self.members(root)}" for root in self.roots()) N, M = map(int, input().split()) uf = UnionFind(N) for _ in range(M): a, b = map(int, input().split()) uf.union(a - 1, b - 1) print(max(uf.size(i) for i in range(N)))
replace
55
56
55
56
TLE
p02573
Python
Runtime Error
N, M = map(int, input().split()) C = [set([]) for i in range(N)] def dfs(n, y): seen[n] = True y += 1 for c in C[n]: if seen[c]: continue else: y = dfs(c, y) return y for i in range(M): a, b = map(int, input().split()) C[a - 1].add(b - 1) C[b - 1].add(a - 1) ans = 0 seen = [False] * N for i in range(N): if seen[i]: continue x = 0 x = dfs(i, x) ans = max(ans, x) print(ans)
import sys sys.setrecursionlimit(1000000) N, M = map(int, input().split()) C = [set([]) for i in range(N)] def dfs(n, y): seen[n] = True y += 1 for c in C[n]: if seen[c]: continue else: y = dfs(c, y) return y for i in range(M): a, b = map(int, input().split()) C[a - 1].add(b - 1) C[b - 1].add(a - 1) ans = 0 seen = [False] * N for i in range(N): if seen[i]: continue x = 0 x = dfs(i, x) ans = max(ans, x) print(ans)
insert
0
0
0
5
0
p02573
Python
Time Limit Exceeded
import sys sys.setrecursionlimit(10**9) n, m = map(int, input().split()) root = [-1] * n def r(x): if root[x] < 0: return x return r(root[x]) def unite(x, y): x = r(x) y = r(y) if x == y: return root[x] += root[y] root[y] = x def size(x): return -1 * root[r(x)] for i in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 unite(a, b) ans = 0 for i in range(n): ans = max(ans, size(i)) print(ans)
import sys sys.setrecursionlimit(10**9) n, m = map(int, input().split()) root = [-1] * n def r(x): if root[x] < 0: return x else: root[x] = r(root[x]) return root[x] def unite(x, y): x = r(x) y = r(y) if x == y: return root[x] += root[y] root[y] = x def size(x): return -1 * root[r(x)] for i in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 unite(a, b) ans = 0 for i in range(n): ans = max(ans, size(i)) print(ans)
replace
12
14
12
15
TLE
p02573
C++
Runtime Error
#include <bits/stdc++.h> #define speed \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define int long long using namespace std; const int N = 1e5 + 7; const int mod = 1e9 + 7; vector<int> adj[N]; int used[N], cnt, mx; void dfs(int v) { used[v] = 1; cnt++; for (auto u : adj[v]) { if (!used[u]) { dfs(u); } } } int32_t main() { speed; int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } for (int i = 1; i <= n; i++) { if (!used[i]) { cnt = 0; dfs(i); mx = max(mx, cnt); } } cout << mx; }
#include <bits/stdc++.h> #define speed \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define int long long using namespace std; const int N = 2e5 + 7; const int mod = 1e9 + 7; vector<int> adj[N]; int used[N], cnt, mx; void dfs(int v) { used[v] = 1; cnt++; for (auto u : adj[v]) { if (!used[u]) { dfs(u); } } } int32_t main() { speed; int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } for (int i = 1; i <= n; i++) { if (!used[i]) { cnt = 0; dfs(i); mx = max(mx, cnt); } } cout << mx; }
replace
12
13
12
13
0
p02573
C++
Runtime Error
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <string> #include <vector> #define PI 3.14159265359 typedef long long ll; const int MOD = 1e9 + 7; const ll LLINF = 7e18; using namespace std; ll par[100001]; ll ran[100001]; ll siz[100001]; void init(int n) { for (int i = 0; i <= n; i++) { par[i] = i; ran[i] = 0; siz[i] = 1; } } int find(int x) { if (par[x] == x) { return x; } else { par[x] = find(par[x]); return par[x]; } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (ran[x] < ran[y]) { par[x] = y; siz[y] += siz[x]; } else { par[y] = x; siz[x] += siz[y]; if (ran[x] == ran[y]) ran[x]++; } } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return siz[find(x)]; } int main() { int n, m; cin >> n >> m; init(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; unite(a, b); } int ans = 0; for (int i = 1; i <= n; i++) { ans = max(ans, size(i)); } cout << ans << endl; return 0; }
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <string> #include <vector> #define PI 3.14159265359 typedef long long ll; const int MOD = 1e9 + 7; const ll LLINF = 7e18; using namespace std; ll par[200001]; ll ran[200001]; ll siz[200001]; void init(int n) { for (int i = 0; i <= n; i++) { par[i] = i; ran[i] = 0; siz[i] = 1; } } int find(int x) { if (par[x] == x) { return x; } else { par[x] = find(par[x]); return par[x]; } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (ran[x] < ran[y]) { par[x] = y; siz[y] += siz[x]; } else { par[y] = x; siz[x] += siz[y]; if (ran[x] == ran[y]) ran[x]++; } } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return siz[find(x)]; } int main() { int n, m; cin >> n >> m; init(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; unite(a, b); } int ans = 0; for (int i = 1; i <= n; i++) { ans = max(ans, size(i)); } cout << ans << endl; return 0; }
replace
16
19
16
19
0
p02573
C++
Time Limit Exceeded
/* #pragma GCC optimize(2) #pragma GCC optimize(3,"Ofast","inline") */ #include <bits/stdc++.h> #define ALL(x) (x).begin(), (x).end() #define ll long long #define db double #define ull unsigned long long #define pii_ pair<int, int> #define mp_ make_pair #define pb push_back #define fi first #define se second #define rep(i, a, b) for (int i = (a); i <= (b); i++) #define per(i, a, b) for (int i = (a); i >= (b); i--) #define show1(a) cout << #a << " = " << a << endl #define show2(a, b) cout << #a << " = " << a << "; " << #b << " = " << b << endl using namespace std; const ll INF = 1LL << 60; const int inf = 1 << 30; const int maxn = 2e5 + 5; inline void fastio() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int father[maxn], cnt[maxn]; int findFather(int x) { return x == father[x] ? x : findFather(father[x]); } int main() { fastio(); int n, m; cin >> n >> m; rep(i, 1, n) father[i] = i; rep(i, 1, m) { int u, v; cin >> u >> v; int fu = findFather(u), fv = findFather(v); if (fu != fv) father[fu] = fv; } int ans = 0; rep(i, 1, n) { int f = findFather(i); cnt[f]++; ans = max(cnt[f], ans); } cout << ans << endl; return 0; }
/* #pragma GCC optimize(2) #pragma GCC optimize(3,"Ofast","inline") */ #include <bits/stdc++.h> #define ALL(x) (x).begin(), (x).end() #define ll long long #define db double #define ull unsigned long long #define pii_ pair<int, int> #define mp_ make_pair #define pb push_back #define fi first #define se second #define rep(i, a, b) for (int i = (a); i <= (b); i++) #define per(i, a, b) for (int i = (a); i >= (b); i--) #define show1(a) cout << #a << " = " << a << endl #define show2(a, b) cout << #a << " = " << a << "; " << #b << " = " << b << endl using namespace std; const ll INF = 1LL << 60; const int inf = 1 << 30; const int maxn = 2e5 + 5; inline void fastio() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int father[maxn], cnt[maxn]; int findFather(int x) { return x == father[x] ? x : father[x] = findFather(father[x]); } int main() { fastio(); int n, m; cin >> n >> m; rep(i, 1, n) father[i] = i; rep(i, 1, m) { int u, v; cin >> u >> v; int fu = findFather(u), fv = findFather(v); if (fu != fv) father[fu] = fv; } int ans = 0; rep(i, 1, n) { int f = findFather(i); cnt[f]++; ans = max(cnt[f], ans); } cout << ans << endl; return 0; }
replace
29
30
29
32
TLE
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define mes(a, b) memset((a), (b), sizeof((a))) #define syio \ std::ios::sync_with_stdio(false); \ std::cin.tie(0); \ std::cout.tie(0); #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 typedef long long ll; typedef long double real; typedef pair<int, int> pii; const int oo = ~0u >> 2; const double pi = acos(-1.0); const double eps = 1e-8; const int mxn = 200033; inline int read() { int x = 0, f = 1; char c = getchar(); while (!isdigit(c)) f = c == '-' ? -1 : 1, c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); return x * f; } int n, m, f[mxn], cnt[mxn]; void init() { for (int i = 1; i <= n; ++i) f[i] = i, cnt[i] = 1; } int find(int x) { return f[x] == x ? x : find(f[x]); } void join(int u, int v) { int fu = find(u), fv = find(v); if (fu != fv) { f[fu] = f[fv]; cnt[fv] += cnt[fu]; } } int main() { syio; cin >> n >> m; init(); int a, b; while (m--) { cin >> a >> b; join(a, b); } int mx = 0; for (int i = 1; i <= n; ++i) if (find(i) == i) mx = max(mx, cnt[i]); cout << mx << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define mes(a, b) memset((a), (b), sizeof((a))) #define syio \ std::ios::sync_with_stdio(false); \ std::cin.tie(0); \ std::cout.tie(0); #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 typedef long long ll; typedef long double real; typedef pair<int, int> pii; const int oo = ~0u >> 2; const double pi = acos(-1.0); const double eps = 1e-8; const int mxn = 200033; inline int read() { int x = 0, f = 1; char c = getchar(); while (!isdigit(c)) f = c == '-' ? -1 : 1, c = getchar(); while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); return x * f; } int n, m, f[mxn], cnt[mxn]; void init() { for (int i = 1; i <= n; ++i) f[i] = i, cnt[i] = 1; } int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); } void join(int u, int v) { int fu = find(u), fv = find(v); if (fu != fv) { f[fu] = f[fv]; cnt[fv] += cnt[fu]; } } int main() { syio; cin >> n >> m; init(); int a, b; while (m--) { cin >> a >> b; join(a, b); } int mx = 0; for (int i = 1; i <= n; ++i) if (find(i) == i) mx = max(mx, cnt[i]); cout << mx << endl; return 0; }
replace
32
33
32
33
TLE
p02573
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) using namespace std; const int MOD = 1000000007; 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 same(int x, int y) { return root(x) == root(y); } }; 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 = 1; i <= N; i++) { ans = max(ans, UF.size(i)); } cout << ans << endl; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) using namespace std; const int MOD = 1000000007; 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 same(int x, int y) { return root(x) == root(y); } }; int main() { int N, M; cin >> N >> M; // 友達集合を作る UnionFind UF(N + 1); 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 = 1; i <= N; i++) { ans = max(ans, UF.size(i)); } cout << ans << endl; }
replace
40
41
40
41
0
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; // syntax sugar: `for (int i = 0; i < N; ++i)` #define rep(i, N) for (int i = 0; i < (int)(N); ++i) #define rep2(i, startValue, N) \ for (int i = (int)(startValue); i < (int)(N); ++i) // syntax sugar: `for (int i = 0; i < N; ++i)` #define REP(type, name, beginValue, endCondValue) \ for (type name = beginValue; name < endCondValue; ++name) // syntax sugar: 多次元vector #define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \ std::vector<std::vector<std::vector<T>>> name( \ d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue))); #define VECTOR_DIM2(T, name, d1, d2, initValue) \ std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue)); #define VECTOR_DIM1(T, name, d1, initValue) std::vector<T> name(d1, initValue); #define ll long long #define ld long double #define DUMP(v) "," #v ":" << v int main() { ll n, m; cin >> n >> m; int nextcircleno = 0; vector<int> circleno(n + 1, 0); // 0番目は空き (index+1 -> circleno) unordered_map<int, unordered_set<int>> circlemap; // circleno -> index+1 int a, b; rep(i, m) { cin >> a >> b; const int cnoA = circleno[a]; const int cnoB = circleno[b]; if (cnoA != 0 && cnoB != 0) { if (cnoA == cnoB) { // 同じサークル同士 } else { // 別々だと思っていたサークルを合体させる const int &fromcircleno = cnoB; const int &tocircleno = cnoA; const auto &fromset = circlemap[fromcircleno]; circlemap[tocircleno].insert(fromset.begin(), fromset.end()); for (const auto &elem : fromset) { circleno[elem] = tocircleno; } circlemap.erase(fromcircleno); } } else if (cnoA == 0 && cnoB != 0) { circleno[a] = cnoB; circlemap[cnoB].emplace(a); } else if (cnoA != 0 && cnoB == 0) { circleno[b] = cnoA; circlemap[cnoA].emplace(b); } else { ++nextcircleno; circleno[a] = nextcircleno; circleno[b] = nextcircleno; circlemap[nextcircleno].emplace(a); circlemap[nextcircleno].emplace(b); } } ll maxmember = 0; if (circlemap.size() == 0) { maxmember = 1; // サークルがないので1つのグループに収める } else { for (const auto &p : circlemap) { const int membernum = p.second.size(); if (maxmember < membernum) { maxmember = membernum; } } } cout << maxmember << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // syntax sugar: `for (int i = 0; i < N; ++i)` #define rep(i, N) for (int i = 0; i < (int)(N); ++i) #define rep2(i, startValue, N) \ for (int i = (int)(startValue); i < (int)(N); ++i) // syntax sugar: `for (int i = 0; i < N; ++i)` #define REP(type, name, beginValue, endCondValue) \ for (type name = beginValue; name < endCondValue; ++name) // syntax sugar: 多次元vector #define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \ std::vector<std::vector<std::vector<T>>> name( \ d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue))); #define VECTOR_DIM2(T, name, d1, d2, initValue) \ std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue)); #define VECTOR_DIM1(T, name, d1, initValue) std::vector<T> name(d1, initValue); #define ll long long #define ld long double #define DUMP(v) "," #v ":" << v int main() { ll n, m; cin >> n >> m; int nextcircleno = 0; vector<int> circleno(n + 1, 0); // 0番目は空き (index+1 -> circleno) unordered_map<int, unordered_set<int>> circlemap; // circleno -> index+1 int a, b; rep(i, m) { cin >> a >> b; const int cnoA = circleno[a]; const int cnoB = circleno[b]; if (cnoA != 0 && cnoB != 0) { if (cnoA == cnoB) { // 同じサークル同士 } else { // 別々だと思っていたサークルを合体させる int fromcircleno = cnoB; int tocircleno = cnoA; if (circlemap[fromcircleno].size() > circlemap[tocircleno].size()) { std::swap(fromcircleno, tocircleno); } const auto &fromset = circlemap[fromcircleno]; circlemap[tocircleno].insert(fromset.begin(), fromset.end()); for (const auto &elem : fromset) { circleno[elem] = tocircleno; } circlemap.erase(fromcircleno); } } else if (cnoA == 0 && cnoB != 0) { circleno[a] = cnoB; circlemap[cnoB].emplace(a); } else if (cnoA != 0 && cnoB == 0) { circleno[b] = cnoA; circlemap[cnoA].emplace(b); } else { ++nextcircleno; circleno[a] = nextcircleno; circleno[b] = nextcircleno; circlemap[nextcircleno].emplace(a); circlemap[nextcircleno].emplace(b); } } ll maxmember = 0; if (circlemap.size() == 0) { maxmember = 1; // サークルがないので1つのグループに収める } else { for (const auto &p : circlemap) { const int membernum = p.second.size(); if (maxmember < membernum) { maxmember = membernum; } } } cout << maxmember << endl; return 0; }
replace
38
40
38
43
TLE
p02573
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef set<int> si; typedef map<int, int> mii; typedef map<ll, ll> mll; typedef vector<pii> vii; typedef vector<pll> vll; typedef pair<ll, pll> plll; typedef vector<pair<int, pii>> viii; #define fi first #define se second #define pi 3.141592653589793 #define mod 1000000007 #define pb push_back #define mp make_pair #define all(v) v.begin(), v.end() #define tc \ int tt; \ cin >> tt; \ while (tt--) #define pqmax priority_queue<int> #define pqmin priority_queue<int, vi, greater<int>> #define fio ios_base::sync_with_stdio(0), cin.tie(NULL) #define tc_g \ int tt; \ cin >> tt; \ for (int ti = 1; ti <= tt; ti++) #define case_g "Case #" << ti << ": " #define RED "\033[31m" #define GREEN "\033[32m" #define RESET "\033[0m" #define sleep for (int i = 1, a; i < 100000000; i++, a = a * a) typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ranked_pairset; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_set; typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_map; const int N = 1e5 + 1; int p[N]; void build(int n) { for (int i = 0; i < n; i++) p[i] = i; } int findset(int a) { return p[a] == a ? a : p[a] = findset(p[a]); } void unionset(int a, int b) { p[findset(a)] = findset(b); } int main() { fio; int n, m; cin >> n >> m; build(n + 1); while (m--) { int u, v; cin >> u >> v; unionset(u, v); } vi ans(n + 1); for (int i = 1; i <= n; i++) ans[findset(i)]++; cout << *max_element(all(ans)) << '\n'; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef set<int> si; typedef map<int, int> mii; typedef map<ll, ll> mll; typedef vector<pii> vii; typedef vector<pll> vll; typedef pair<ll, pll> plll; typedef vector<pair<int, pii>> viii; #define fi first #define se second #define pi 3.141592653589793 #define mod 1000000007 #define pb push_back #define mp make_pair #define all(v) v.begin(), v.end() #define tc \ int tt; \ cin >> tt; \ while (tt--) #define pqmax priority_queue<int> #define pqmin priority_queue<int, vi, greater<int>> #define fio ios_base::sync_with_stdio(0), cin.tie(NULL) #define tc_g \ int tt; \ cin >> tt; \ for (int ti = 1; ti <= tt; ti++) #define case_g "Case #" << ti << ": " #define RED "\033[31m" #define GREEN "\033[32m" #define RESET "\033[0m" #define sleep for (int i = 1, a; i < 100000000; i++, a = a * a) typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ranked_pairset; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_set; typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_map; const int N = 2e5 + 1; int p[N]; void build(int n) { for (int i = 0; i < n; i++) p[i] = i; } int findset(int a) { return p[a] == a ? a : p[a] = findset(p[a]); } void unionset(int a, int b) { p[findset(a)] = findset(b); } int main() { fio; int n, m; cin >> n >> m; build(n + 1); while (m--) { int u, v; cin >> u >> v; unionset(u, v); } vi ans(n + 1); for (int i = 1; i <= n; i++) ans[findset(i)]++; cout << *max_element(all(ans)) << '\n'; }
replace
51
52
51
52
0
p02573
C++
Runtime Error
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Name:- OMHARI Institution:- UNIVERSIT OF CALCUTTA(INFORMATION TECHNOLOGY) Email:- omharicu@gmail.com ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ #include <bits/stdc++.h> using namespace std; #define F first #define S second #define ull unsigned long long #define ll long long #define ul unsigned long #define db double #define ST string #define pb push_back #define mp make_pair #define el "\n" #define vll vector<ll> #define vl vector<long int> #define vi vector<int> #define all(v) (v.begin(), v.end()) #define rall(v) (v.rbegin(), v.rend()) #define is_sort(v) is_sorted all(v) #define max_of(v) *max_element all(v) #define min_of(v) *min_element all(v) #define itos(s) to_string(s) #define cntone(x) __builtin_popcountll(x) #define cntzro(x) __builtin_clz(x) #define For(i, a, b) for (int i = a; i < b; i++) #define Forr(i, a, b) for (int i = a; i >= b; i--) const ll mod = 1e9 + 7; vi arr[100005]; int vis[100005]; int cnt = 0; void dfs(int node) { cnt++; vis[node] = 1; for (int child : arr[node]) if (!vis[child]) dfs(child); } void solve() { int n, m; cin >> n >> m; while (m--) { int x, y; cin >> x >> y; arr[x].pb(y); arr[y].pb(x); } int ans = 0; For(i, 1, n + 1) { cnt = 0; if (!vis[i]) { dfs(i); ans = max(ans, cnt); } } cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif /***************-Code starts from here-***************/ // int t; // cin>>t; // while(t--) solve(); return 0; }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Name:- OMHARI Institution:- UNIVERSIT OF CALCUTTA(INFORMATION TECHNOLOGY) Email:- omharicu@gmail.com ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ #include <bits/stdc++.h> using namespace std; #define F first #define S second #define ull unsigned long long #define ll long long #define ul unsigned long #define db double #define ST string #define pb push_back #define mp make_pair #define el "\n" #define vll vector<ll> #define vl vector<long int> #define vi vector<int> #define all(v) (v.begin(), v.end()) #define rall(v) (v.rbegin(), v.rend()) #define is_sort(v) is_sorted all(v) #define max_of(v) *max_element all(v) #define min_of(v) *min_element all(v) #define itos(s) to_string(s) #define cntone(x) __builtin_popcountll(x) #define cntzro(x) __builtin_clz(x) #define For(i, a, b) for (int i = a; i < b; i++) #define Forr(i, a, b) for (int i = a; i >= b; i--) const ll mod = 1e9 + 7; vi arr[2 * 100005]; int vis[2 * 100005]; int cnt = 0; void dfs(int node) { cnt++; vis[node] = 1; for (int child : arr[node]) if (!vis[child]) dfs(child); } void solve() { int n, m; cin >> n >> m; while (m--) { int x, y; cin >> x >> y; arr[x].pb(y); arr[y].pb(x); } int ans = 0; For(i, 1, n + 1) { cnt = 0; if (!vis[i]) { dfs(i); ans = max(ans, cnt); } } cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif /***************-Code starts from here-***************/ // int t; // cin>>t; // while(t--) solve(); return 0; }
replace
33
35
33
35
-11
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long ll read() { ll x = 0, f = 1; char ch = ' '; while (!isdigit(ch)) { ch = getchar(); if (ch == '-') f = -1; } while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar(); return x * f; } int f[100005], n, m, maxn, cnt[100005]; int find(int x) { if (x == f[x]) return f[x]; return f[x] = find(f[x]); } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) f[i] = i; for (int i = 1; i <= m; i++) { int a = read(), b = read(); int x = find(a), y = find(b); if (x != y) f[x] = y; } for (int i = 1; i <= n; i++) cnt[find(i)]++; for (int i = 1; i <= n; i++) maxn = max(maxn, cnt[i]); cout << maxn; }
#include <bits/stdc++.h> using namespace std; #define ll long long ll read() { ll x = 0, f = 1; char ch = ' '; while (!isdigit(ch)) { ch = getchar(); if (ch == '-') f = -1; } while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar(); return x * f; } int f[500005], n, m, maxn, cnt[500005]; int find(int x) { if (x == f[x]) return f[x]; return f[x] = find(f[x]); } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) f[i] = i; for (int i = 1; i <= m; i++) { int a = read(), b = read(); int x = find(a), y = find(b); if (x != y) f[x] = y; } for (int i = 1; i <= n; i++) cnt[find(i)]++; for (int i = 1; i <= n; i++) maxn = max(maxn, cnt[i]); cout << maxn; }
replace
15
16
15
16
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int p[100005], n, m, g[100005], ans = 0, nc = 0; vector<int> v; int fa(int x) { return (p[x] == x) ? x : (p[x] = fa(p[x])); } void merge(int x, int y) { int fx = fa(x), fy = fa(y); p[fx] = fy; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) p[i] = i; for (int i = 1; i <= m; i++) { int a, b; scanf("%d%d", &a, &b); merge(a, b); } for (int i = 1; i <= n; i++) { g[fa(i)]++; } for (int i = 1; i <= n; i++) if (g[i] != 0) v.push_back(g[i]); sort(v.begin(), v.end()); for (int i = 0; i < v.size(); i++) { if (i != 0 && v[i] == v[i - 1]) continue; ans += (v[i] - nc); nc += (v[i] - nc); // cout<<i<<' '<<ans<<' '<<nc<<endl; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int p[200005], n, m, g[200005], ans = 0, nc = 0; vector<int> v; int fa(int x) { return (p[x] == x) ? x : (p[x] = fa(p[x])); } void merge(int x, int y) { int fx = fa(x), fy = fa(y); p[fx] = fy; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) p[i] = i; for (int i = 1; i <= m; i++) { int a, b; scanf("%d%d", &a, &b); merge(a, b); } for (int i = 1; i <= n; i++) { g[fa(i)]++; } for (int i = 1; i <= n; i++) if (g[i] != 0) v.push_back(g[i]); sort(v.begin(), v.end()); for (int i = 0; i < v.size(); i++) { if (i != 0 && v[i] == v[i - 1]) continue; ans += (v[i] - nc); nc += (v[i] - nc); // cout<<i<<' '<<ans<<' '<<nc<<endl; } cout << ans; return 0; }
replace
2
3
2
3
0
p02573
Python
Time Limit Exceeded
class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return (i for i in range(self.n) if self.find(i) == root) def roots(self): return (i for i, x in enumerate(self.parents) if x < 0) def group_count(self): return len(self.roots()) def all_group_members(self): d = {} for i in range(self.n): p = self.find(i) d[p] = d.get(p, []) + [i] return d def __str__(self): return "\n".join( "{}: {}".format(k, v) for k, v in self.all_group_members().items() ) def resolve(): import sys input = sys.stdin.readline n, m = map(int, input().split()) u = UnionFind(n) for _ in range(m): a, b = map(int, input().split()) u.union(a - 1, b - 1) ans = 0 for v in u.all_group_members().values(): ans = max(len(v), ans) print(ans) if __name__ == "__main__": resolve()
class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return (i for i in range(self.n) if self.find(i) == root) def roots(self): return (i for i, x in enumerate(self.parents) if x < 0) def group_count(self): return len(self.roots()) def all_group_members(self): d = {} for i in range(self.n): p = self.find(i) d[p] = d.get(p, []) + [i] return d def __str__(self): return "\n".join( "{}: {}".format(k, v) for k, v in self.all_group_members().items() ) def resolve(): import sys input = sys.stdin.readline n, m = map(int, input().split()) u = UnionFind(n) for _ in range(m): a, b = map(int, input().split()) u.union(a - 1, b - 1) ans = 0 for i in u.roots(): ans = max(u.size(i), ans) print(ans) if __name__ == "__main__": resolve()
replace
64
66
64
66
TLE
p02573
C++
Runtime Error
#include <bits/stdc++.h> #define repd(i, a, b) for (ll i = (a); i < (b); i++) #define repb(i, n) for (ll i = (n)-1; i >= 0; i--) #define rep(i, n) repd(i, 0, n) using namespace std; using ll = long long; using ul = unsigned long long; using ld = long double; ll mod = 1000000007; class UnionFind { private: ll num; vector<ll> par; vector<ll> sizes; vector<ll> rank; public: UnionFind(ll n) { init(n); } ~UnionFind() {} ll init(ll n) { num = n; par.resize(n); sizes.resize(n); rank.resize(n); for (ll i = 0; i < n; i++) { par[i] = i; sizes[i] = 1; rank[i] = 0; } } ll root(ll x) { if (par[x] == x) { return x; } else { return par[x] = root(par[x]); } } void unite(ll x, ll y) { ll rx = root(x); ll ry = root(y); if (rx == ry) return; if (rank[rx] < rank[ry]) { par[rx] = ry; } else { par[ry] = rx; if (rank[rx] == rank[ry]) { rank[rx]++; } } ll temp = sizes[rx] + sizes[ry]; sizes[rx] = temp; sizes[ry] = temp; } ll get_size(ll x) { return sizes[root(x)]; } bool same(ll x, ll y) { ll rx = root(x); ll ry = root(y); return rx == ry; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, m; cin >> n >> m; UnionFind u(n); rep(i, m) { ll a, b; cin >> a >> b; a--; b--; u.unite(a, b); } ll max_size = 0; rep(i, n) { max_size = max(max_size, u.get_size(i)); } cout << max_size << endl; return 0; }
#include <bits/stdc++.h> #define repd(i, a, b) for (ll i = (a); i < (b); i++) #define repb(i, n) for (ll i = (n)-1; i >= 0; i--) #define rep(i, n) repd(i, 0, n) using namespace std; using ll = long long; using ul = unsigned long long; using ld = long double; ll mod = 1000000007; class UnionFind { private: ll num; vector<ll> par; vector<ll> sizes; vector<ll> rank; public: UnionFind(ll n) { init(n); } ~UnionFind() {} void init(ll n) { num = n; par.resize(n); sizes.resize(n); rank.resize(n); for (ll i = 0; i < n; i++) { par[i] = i; sizes[i] = 1; rank[i] = 0; } } ll root(ll x) { if (par[x] == x) { return x; } else { return par[x] = root(par[x]); } } void unite(ll x, ll y) { ll rx = root(x); ll ry = root(y); if (rx == ry) return; if (rank[rx] < rank[ry]) { par[rx] = ry; } else { par[ry] = rx; if (rank[rx] == rank[ry]) { rank[rx]++; } } ll temp = sizes[rx] + sizes[ry]; sizes[rx] = temp; sizes[ry] = temp; } ll get_size(ll x) { return sizes[root(x)]; } bool same(ll x, ll y) { ll rx = root(x); ll ry = root(y); return rx == ry; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, m; cin >> n >> m; UnionFind u(n); rep(i, m) { ll a, b; cin >> a >> b; a--; b--; u.unite(a, b); } ll max_size = 0; rep(i, n) { max_size = max(max_size, u.get_size(i)); } cout << max_size << endl; return 0; }
replace
25
26
25
26
0
p02573
C++
Runtime Error
#include <algorithm> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <time.h> #include <vector> #define h 200010 #define lli long long int #define pb push_back #define pof pop_front #define lb lower_bound #define ub upper_bound #define mp make_pair using namespace std; vector<lli> par(h); lli func(lli a) { if (par[a] == a) return a; else par[a] = func(par[a]); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); lli n, e, i, x, y, u, v, ans = 0, l = 0, cnt; set<lli> c; cin >> n >> e; for (i = 0; i <= n; i++) par[i] = i; for (i = 0; i < e; i++) { cin >> x >> y; u = func(x); v = func(y); if (u != v) par[u] = v; } for (i = 1; i <= n; i++) u = func(i); sort(par.begin() + 1, par.begin() + n + 1); cnt = 1; for (i = 1; i <= n; i++) { c.insert(par[i]); if (l == c.size()) cnt += 1; else { l += 1; ans = max(ans, cnt); cnt = 1; } } ans = max(ans, cnt); cout << ans << endl; return 0; }
#include <algorithm> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <time.h> #include <vector> #define h 200010 #define lli long long int #define pb push_back #define pof pop_front #define lb lower_bound #define ub upper_bound #define mp make_pair using namespace std; vector<lli> par(h); lli func(lli a) { if (par[a] == a) return a; else return par[a] = func(par[a]); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); lli n, e, i, x, y, u, v, ans = 0, l = 0, cnt; set<lli> c; cin >> n >> e; for (i = 0; i <= n; i++) par[i] = i; for (i = 0; i < e; i++) { cin >> x >> y; u = func(x); v = func(y); if (u != v) par[u] = v; } for (i = 1; i <= n; i++) u = func(i); sort(par.begin() + 1, par.begin() + n + 1); cnt = 1; for (i = 1; i <= n; i++) { c.insert(par[i]); if (l == c.size()) cnt += 1; else { l += 1; ans = max(ans, cnt); cnt = 1; } } ans = max(ans, cnt); cout << ans << endl; return 0; }
replace
25
26
25
26
-11
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; const long double pi = acos(-1); #define x first #define y second #define read(n, a) \ for (int i = 0; i < n; i++) \ cin >> a[i]; #define rep(z, n) for (int i = z; i < n; i++) // pair<int,int> a[200002]={}; // ll b[200003]={}; ll n, m; #define MAXNODES 100000 + 9 #define PB push_back typedef vector<int> vi; vector<vi> edges(MAXNODES); bool visited[MAXNODES]; int dfs(int node) { int ans = 0; visited[node] = true; for (int neighbor : edges[node]) { if (!visited[neighbor]) { ans++; ans += dfs(neighbor); } } return ans; } // vector<set<int> >v(200002); int main() { cin.tie(0); cin.sync_with_stdio(0); /// freopen("ss.txt","r",stdin); /// freopen("out.txt","w",stdout); int t = 1; // cin>>t; while (t--) { cin >> n >> m; rep(0, m) { int u, v; cin >> u >> v; edges[u].PB(v); edges[v].PB(u); } ll ans = 0; rep(1, n + 1) { if (!visited[i]) { ans = max(ans, (ll)dfs(i) + 1); } } cout << ans; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; const long double pi = acos(-1); #define x first #define y second #define read(n, a) \ for (int i = 0; i < n; i++) \ cin >> a[i]; #define rep(z, n) for (int i = z; i < n; i++) // pair<int,int> a[200002]={}; // ll b[200003]={}; ll n, m; #define MAXNODES 200000 + 9 #define PB push_back typedef vector<int> vi; vector<vi> edges(MAXNODES); bool visited[MAXNODES]; int dfs(int node) { int ans = 0; visited[node] = true; for (int neighbor : edges[node]) { if (!visited[neighbor]) { ans++; ans += dfs(neighbor); } } return ans; } // vector<set<int> >v(200002); int main() { cin.tie(0); cin.sync_with_stdio(0); /// freopen("ss.txt","r",stdin); /// freopen("out.txt","w",stdout); int t = 1; // cin>>t; while (t--) { cin >> n >> m; rep(0, m) { int u, v; cin >> u >> v; edges[u].PB(v); edges[v].PB(u); } ll ans = 0; rep(1, n + 1) { if (!visited[i]) { ans = max(ans, (ll)dfs(i) + 1); } } cout << ans; } return 0; }
replace
17
18
17
18
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll llINF = 1LL << 60; const int iINF = 1e9; //---Union Find--- struct UnionFind { // グループのサイズ、要素の親idx、要素から親までのランクの配列 vector<int> gsize, parent, rank; // コンストラクタ 各配列を初期化 UnionFind(int N) { gsize = vector<int>(N, 1); parent = vector<int>(N, -1); rank = vector<int>(N); } // 親を求める int findparent(int x) { if (parent[x] < 0) return x; else return parent[x] = findparent(parent[x]); // rankが小さくなるよう親を再設定 } // 2要素x,yの属するグループを合併 bool unite(int x, int y) { x = findparent(x); y = findparent(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); parent[y] = x; gsize[x] += gsize[y]; gsize[y] = 0; if (rank[x] == rank[y]) rank[x]++; } // 2要素x,yが同じ集合に属するかどうか bool same(int x, int y) { return findparent(x) == findparent(y); } }; //---main--------------------------------------------- int main() { // main int N, M; cin >> N >> M; UnionFind UF(N); int Ai, Bi; rep(mi, M) { cin >> Ai >> Bi; Ai--; Bi--; UF.unite(Ai, Bi); } int ans = 0; for (int gs : UF.gsize) chmax(ans, gs); // rep(i,N) cout << UF.gsize[i] << " " << UF.parent[i] << " " << UF.rank[i] << // endl; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll llINF = 1LL << 60; const int iINF = 1e9; //---Union Find--- struct UnionFind { // グループのサイズ、要素の親idx、要素から親までのランクの配列 vector<int> gsize, parent, rank; // コンストラクタ 各配列を初期化 UnionFind(int N) { gsize = vector<int>(N, 1); parent = vector<int>(N, -1); rank = vector<int>(N); } // 親を求める int findparent(int x) { if (parent[x] < 0) return x; else return parent[x] = findparent(parent[x]); // rankが小さくなるよう親を再設定 } // 2要素x,yの属するグループを合併 bool unite(int x, int y) { x = findparent(x); y = findparent(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); parent[y] = x; gsize[x] += gsize[y]; gsize[y] = 0; if (rank[x] == rank[y]) rank[x]++; return true; } // 2要素x,yが同じ集合に属するかどうか bool same(int x, int y) { return findparent(x) == findparent(y); } }; //---main--------------------------------------------- int main() { // main int N, M; cin >> N >> M; UnionFind UF(N); int Ai, Bi; rep(mi, M) { cin >> Ai >> Bi; Ai--; Bi--; UF.unite(Ai, Bi); } int ans = 0; for (int gs : UF.gsize) chmax(ans, gs); // rep(i,N) cout << UF.gsize[i] << " " << UF.parent[i] << " " << UF.rank[i] << // endl; cout << ans << endl; return 0; }
insert
57
57
57
58
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define mod 1000000007 bool vis[100005]; vector<ll> gr[100005]; ll dfs(ll u) { vis[u] = true; ll ans = 1; for (auto v : gr[u]) { if (!vis[v]) { ans += dfs(v); } } return ans; } int main() { ll n, m; cin >> n >> m; memset(vis, false, sizeof(vis)); ll a, b; map<pair<ll, ll>, ll> ma; while (m--) { cin >> a >> b; if (a > b) swap(a, b); if (!ma[{a, b}]) { gr[a].push_back(b); gr[b].push_back(a); } } ll mx = 0; for (ll i = 1; i <= n; ++i) { if (vis[i] == false) { mx = max(mx, dfs(i)); } } cout << mx << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define mod 1000000007 bool vis[200005]; vector<ll> gr[200005]; ll dfs(ll u) { vis[u] = true; ll ans = 1; for (auto v : gr[u]) { if (!vis[v]) { ans += dfs(v); } } return ans; } int main() { ll n, m; cin >> n >> m; memset(vis, false, sizeof(vis)); ll a, b; map<pair<ll, ll>, ll> ma; while (m--) { cin >> a >> b; if (a > b) swap(a, b); if (!ma[{a, b}]) { gr[a].push_back(b); gr[b].push_back(a); } } ll mx = 0; for (ll i = 1; i <= n; ++i) { if (vis[i] == false) { mx = max(mx, dfs(i)); } } cout << mx << endl; }
replace
4
6
4
6
0
p02573
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, -1, 0, 1}; const int LIT = 1e9 + 7; int n, m; vector<int> Map[20001]; set<pair<int, int>> s; void solve() { cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; if (a > b) swap(a, b); if (s.count({a, b}) == 0) { s.insert({a, b}); Map[a].push_back(b); Map[b].push_back(a); } } vector<bool> bfs_visited(n + 1, false); int ans = 0; for (int i = 1; i <= n; i++) { int cnt = 1; if (!bfs_visited[i]) { queue<int> q; q.push(i); bfs_visited[i] = true; while (!q.empty()) { int cur = q.front(); q.pop(); for (int j = 0; j < Map[cur].size(); j++) { if (!bfs_visited[Map[cur][j]]) { bfs_visited[Map[cur][j]] = true; cnt++; q.push(Map[cur][j]); } } } } ans = max(ans, cnt); } cout << ans; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); solve(); return 0; }
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, -1, 0, 1}; const int LIT = 1e9 + 7; int n, m; vector<int> Map[200001]; set<pair<int, int>> s; void solve() { cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; if (a > b) swap(a, b); if (s.count({a, b}) == 0) { s.insert({a, b}); Map[a].push_back(b); Map[b].push_back(a); } } vector<bool> bfs_visited(n + 1, false); int ans = 0; for (int i = 1; i <= n; i++) { int cnt = 1; if (!bfs_visited[i]) { queue<int> q; q.push(i); bfs_visited[i] = true; while (!q.empty()) { int cur = q.front(); q.pop(); for (int j = 0; j < Map[cur].size(); j++) { if (!bfs_visited[Map[cur][j]]) { bfs_visited[Map[cur][j]] = true; cnt++; q.push(Map[cur][j]); } } } } ans = max(ans, cnt); } cout << ans; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); solve(); return 0; }
replace
14
15
14
15
0
p02573
Python
Time Limit Exceeded
import sys import heapq sys.setrecursionlimit(10**8) input = sys.stdin.readline class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def all_group_memberss(self): return [len(self.members(r)) for r in self.roots()] def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) def main(): N, M = [int(x) for x in input().split()] AB = [[int(x) for x in input().split()] for _ in range(M)] uf = UnionFind(N) for a, b in AB: uf.union(a - 1, b - 1) hq = [] for k in uf.all_group_memberss(): heapq.heappush(hq, k) ans = 0 prev = 0 while hq: c = heapq.heappop(hq) if prev != c: ans += c - prev prev = c print(ans) if __name__ == "__main__": main()
import sys import heapq sys.setrecursionlimit(10**8) input = sys.stdin.readline class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def all_group_memberss(self): return [self.size(r) for r in self.roots()] def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) def main(): N, M = [int(x) for x in input().split()] AB = [[int(x) for x in input().split()] for _ in range(M)] uf = UnionFind(N) for a, b in AB: uf.union(a - 1, b - 1) hq = [] for k in uf.all_group_memberss(): heapq.heappush(hq, k) ans = 0 prev = 0 while hq: c = heapq.heappop(hq) if prev != c: ans += c - prev prev = c print(ans) if __name__ == "__main__": main()
replace
53
54
53
54
TLE
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; struct UnionFind { vector<int> p; UnionFind(int n) { p = vector<int>(n, -1); } int root(int c) { if (p.at(c) < 0) return c; else return root(p.at(c)); } void unite(int a, int b) { int ra = root(a); int rb = root(b); if (ra == rb) return; if (p.at(ra) > p.at(rb)) swap(p.at(ra), p.at(rb)); p.at(ra) += p.at(rb); p.at(rb) = ra; } int size(int c) { return -p.at(root(c)); } }; int main() { int n, m; cin >> n >> m; UnionFind fuf(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; fuf.unite(a - 1, b - 1); } int ans = 0; for (int i = 0; i < n; i++) { ans = max(ans, fuf.size(i)); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; struct UnionFind { vector<int> p; UnionFind(int n) { p = vector<int>(n, -1); } int root(int c) { if (p.at(c) < 0) return c; else return p.at(c) = root(p.at(c)); } void unite(int a, int b) { int ra = root(a); int rb = root(b); if (ra == rb) return; if (p.at(ra) > p.at(rb)) swap(p.at(ra), p.at(rb)); p.at(ra) += p.at(rb); p.at(rb) = ra; } int size(int c) { return -p.at(root(c)); } }; int main() { int n, m; cin >> n >> m; UnionFind fuf(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; fuf.unite(a - 1, b - 1); } int ans = 0; for (int i = 0; i < n; i++) { ans = max(ans, fuf.size(i)); } cout << ans << endl; }
replace
12
13
12
13
TLE
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define pi acos(-1.0) #define pb push_back #define mp make_pair #define ll long long #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define testcase \ ll T; \ cin >> T; \ for (ll tc = 1; tc <= T; tc++) #define M 1000000007 #define MM 998244353 #define eps 1e-8 #define eq(x, y) (fabs((x) - (y)) < eps) #define r2 1.41421356237 ll powmod(ll a, ll b, ll mod) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // testcase { int n, m; cin >> n >> m; vector<int> v(n + 1, -1); while (m--) { int c, d; cin >> c >> d; // if(v[p]==q || v[q]==p) { continue; } while (v[c] > 0) { c = v[c]; } while (v[d] > 0) { d = v[d]; } if (c == d) { continue; } v[c] += v[d]; v[d] = c; } int ans = M; for (int i = 1; i <= n; i++) { ans = min(ans, v[i]); } cout << -ans; //} return 0; }
#include <bits/stdc++.h> using namespace std; #define pi acos(-1.0) #define pb push_back #define mp make_pair #define ll long long #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define testcase \ ll T; \ cin >> T; \ for (ll tc = 1; tc <= T; tc++) #define M 1000000007 #define MM 998244353 #define eps 1e-8 #define eq(x, y) (fabs((x) - (y)) < eps) #define r2 1.41421356237 ll powmod(ll a, ll b, ll mod) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // testcase { int n, m; cin >> n >> m; vector<int> v(n + 1, -1); while (m--) { int c, d; cin >> c >> d; // if(v[p]==q || v[q]==p) { continue; } while (v[c] > 0) { c = v[c]; } while (v[d] > 0) { d = v[d]; } if (c == d) { continue; } if (v[c] < v[d]) { v[c] += v[d]; v[d] = c; } else { v[d] += v[c]; v[c] = d; } } int ans = M; for (int i = 1; i <= n; i++) { ans = min(ans, v[i]); } cout << -ans; //} return 0; }
replace
51
53
51
58
TLE
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; struct bcj { int f[100001]; int size[100001]; int find(int n) { if (f[n] == n) return n; else f[n] = find(f[n]); return f[n]; } int add(int x, int y) { int a = find(x); int b = find(y); if (a == b) return 0; else { f[a] = b; size[b] += size[a]; } return 1; } void clear(int n) { for (int i = 1; i <= n; i++) { f[i] = i; size[i] = 1; } } } S; int n, m, x, y, ans; int main() { scanf("%d %d", &n, &m); S.clear(n); while (m--) { scanf("%d %d", &x, &y); S.add(x, y); } for (int i = 1; i <= n; ++i) { ans = max(ans, S.size[i]); } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; struct bcj { int f[200001]; int size[200001]; int find(int n) { if (f[n] == n) return n; else f[n] = find(f[n]); return f[n]; } int add(int x, int y) { int a = find(x); int b = find(y); if (a == b) return 0; else { f[a] = b; size[b] += size[a]; } return 1; } void clear(int n) { for (int i = 1; i <= n; i++) { f[i] = i; size[i] = 1; } } } S; int n, m, x, y, ans; int main() { scanf("%d %d", &n, &m); S.clear(n); while (m--) { scanf("%d %d", &x, &y); S.add(x, y); } for (int i = 1; i <= n; ++i) { ans = max(ans, S.size[i]); } printf("%d\n", ans); return 0; }
replace
3
5
3
5
0
p02573
C++
Time Limit Exceeded
#include <iostream> typedef std::pair<int, int> Edge; int find(int *par, int x) { if (x == par[x]) return x; else return find(par, par[x]); } void unite(int *par, int x, int y) { par[find(par, x)] = find(par, y); } bool isSame(int *par, int x, int y) { return find(par, x) == find(par, y); } int main() { int N, M; std::cin >> N >> M; Edge *edge_list = new Edge[M]; for (int i = 0; i < M; i++) { int a, b; std::cin >> a >> b; edge_list[i].first = a; edge_list[i].second = b; } int *par = new int[N + 1]; for (int i = 1; i <= N; i++) par[i] = i; for (int i = 0; i < M; i++) { int u, v; u = edge_list[i].first; v = edge_list[i].second; unite(par, u, v); } int *color_cnt = new int[N + 1]; for (int i = 1; i <= N; i++) { color_cnt[i] = 0; } for (int i = 1; i <= N; i++) { color_cnt[find(par, i)]++; } int max_size = 0; for (int i = 1; i <= N; i++) { max_size = std::max(max_size, color_cnt[i]); } std::cout << max_size << std::endl; delete[] edge_list; delete[] par; delete[] color_cnt; }
#include <iostream> typedef std::pair<int, int> Edge; int find(int *par, int x) { if (x == par[x]) return x; else return par[x] = find(par, par[x]); } void unite(int *par, int x, int y) { par[find(par, x)] = find(par, y); } bool isSame(int *par, int x, int y) { return find(par, x) == find(par, y); } int main() { int N, M; std::cin >> N >> M; Edge *edge_list = new Edge[M]; for (int i = 0; i < M; i++) { int a, b; std::cin >> a >> b; edge_list[i].first = a; edge_list[i].second = b; } int *par = new int[N + 1]; for (int i = 1; i <= N; i++) par[i] = i; for (int i = 0; i < M; i++) { int u, v; u = edge_list[i].first; v = edge_list[i].second; unite(par, u, v); } int *color_cnt = new int[N + 1]; for (int i = 1; i <= N; i++) { color_cnt[i] = 0; } for (int i = 1; i <= N; i++) { color_cnt[find(par, i)]++; } int max_size = 0; for (int i = 1; i <= N; i++) { max_size = std::max(max_size, color_cnt[i]); } std::cout << max_size << std::endl; delete[] edge_list; delete[] par; delete[] color_cnt; }
replace
7
8
7
8
TLE
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define F first #define S second #define pl pair<long long, long long> #define pi pair<int, int> #define lb(v, x) lower_bound(v.begin(), v.end(), x) - v.begin() #define ub(v, x) upper_bound(v.begin(), v.end(), x) - v.begin() #define ct(i) cout << i << "\n" #define sv(v) sort(v.begin(), v.end()) #define mod 1000000007 #define M 100005 #define endl "\n" vector<int> adj[M + 1], visited(M); int co = 0; void dfs(int s, int nodes) { visited[s] = true; co++; for (int i = 0; i < adj[s].size(); i++) { if (visited[adj[s][i]] == 0) { dfs(adj[s][i], nodes); } } } void solve() { ll n, x = 0, ans = 0, y, m; // string s,t; cin >> n >> m; set<pair<int, int>> se; for (int i = 0; i < m; i++) { cin >> x >> y; if (x > y) swap(x, y); se.insert({x, y}); } for (auto i : se) { x = i.F, y = i.S; adj[x].pb(y); adj[y].pb(x); } for (int i = 1; i <= n; i++) { if (visited[i] == false) { dfs(i, n); ans = max((ll)co, ans); co = 0; } } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int q; // cin>>q; while(q--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define F first #define S second #define pl pair<long long, long long> #define pi pair<int, int> #define lb(v, x) lower_bound(v.begin(), v.end(), x) - v.begin() #define ub(v, x) upper_bound(v.begin(), v.end(), x) - v.begin() #define ct(i) cout << i << "\n" #define sv(v) sort(v.begin(), v.end()) #define mod 1000000007 #define M 100005 #define endl "\n" vector<int> adj[2 * M + 1], visited(2 * M); int co = 0; void dfs(int s, int nodes) { visited[s] = true; co++; for (int i = 0; i < adj[s].size(); i++) { if (visited[adj[s][i]] == 0) { dfs(adj[s][i], nodes); } } } void solve() { ll n, x = 0, ans = 0, y, m; // string s,t; cin >> n >> m; set<pair<int, int>> se; for (int i = 0; i < m; i++) { cin >> x >> y; if (x > y) swap(x, y); se.insert({x, y}); } for (auto i : se) { x = i.F, y = i.S; adj[x].pb(y); adj[y].pb(x); } for (int i = 1; i <= n; i++) { if (visited[i] == false) { dfs(i, n); ans = max((ll)co, ans); co = 0; } } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int q; // cin>>q; while(q--) solve(); return 0; }
replace
18
19
18
19
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int ans = 1; int par[200001] = {}; int r[200001] = {}; int si[200001] = {}; int find(int x) { if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (r[x] < r[y]) { par[x] += y; // 親をyにする si[y] += si[x]; ans = max(ans, si[y]); } else { par[y] = x; si[x] += si[y]; ans = max(ans, si[x]); if (r[x] == r[y]) r[x]++; } } int main() { int n, m; cin >> n >> m; for (int i = 0; i < n + 1; i++) { par[i] = i; si[i] = 1; } for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; unite(x, y); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int ans = 1; int par[200001] = {}; int r[200001] = {}; int si[200001] = {}; int find(int x) { if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (r[x] < r[y]) { par[x] = y; // 親をyにする si[y] += si[x]; ans = max(ans, si[y]); } else { par[y] = x; si[x] += si[y]; ans = max(ans, si[x]); if (r[x] == r[y]) r[x]++; } } int main() { int n, m; cin >> n >> m; for (int i = 0; i < n + 1; i++) { par[i] = i; si[i] = 1; } for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; unite(x, y); } cout << ans << endl; }
replace
22
23
22
23
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> typedef long long int ll; using namespace std; const int MX = 100010; vector<vector<int>> adj(MX + 1); // adding edge utility void add_edge(vector<vector<int>> &ref, int start, int end, bool dir) { ref[start].push_back(end); if (!dir) { ref[end].push_back(start); } } std::vector<bool> vis(MX + 1, false); std::vector<ll> comp; // DFS void dfs(int v) { vis[v] = true; comp.push_back(v); for (auto u : adj[v]) { if (!vis[u]) { dfs(u); } } return; } // CONNECTED COMPONENTS void find_comps(int n) { // std::vector<ll> arr; ll ans = INT_MIN; for (int i = 0; i < n; i++) { if (!vis[i]) { comp.clear(); dfs(i); // for(auto u: comp) { // cout << u << ' '; // } // cout << '\n'; // arr.push_back(comp.size()); ans = max(ans, (ll)comp.size()); } } cout << ans << '\n'; // for(auto it: arr) { // cout << it << '\n'; // } } // testing int32_t main() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); // for debug in error.txt freopen("error.txt", "w", stderr); #endif int t = 1; while (t--) { ll n, m; cin >> n >> m; while (m--) { int s, d; cin >> s >> d; s--, d--; add_edge(adj, s, d, 0); } find_comps(n); } }
#include <bits/stdc++.h> typedef long long int ll; using namespace std; const int MX = 400010; vector<vector<int>> adj(MX + 1); // adding edge utility void add_edge(vector<vector<int>> &ref, int start, int end, bool dir) { ref[start].push_back(end); if (!dir) { ref[end].push_back(start); } } std::vector<bool> vis(MX + 1, false); std::vector<ll> comp; // DFS void dfs(int v) { vis[v] = true; comp.push_back(v); for (auto u : adj[v]) { if (!vis[u]) { dfs(u); } } return; } // CONNECTED COMPONENTS void find_comps(int n) { // std::vector<ll> arr; ll ans = INT_MIN; for (int i = 0; i < n; i++) { if (!vis[i]) { comp.clear(); dfs(i); // for(auto u: comp) { // cout << u << ' '; // } // cout << '\n'; // arr.push_back(comp.size()); ans = max(ans, (ll)comp.size()); } } cout << ans << '\n'; // for(auto it: arr) { // cout << it << '\n'; // } } // testing int32_t main() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); // for debug in error.txt freopen("error.txt", "w", stderr); #endif int t = 1; while (t--) { ll n, m; cin >> n >> m; while (m--) { int s, d; cin >> s >> d; s--, d--; add_edge(adj, s, d, 0); } find_comps(n); } }
replace
5
6
5
6
-11
p02573
C++
Runtime Error
// C++ implementation of the above approach #include <bits/stdc++.h> #define int long long using namespace std; const int maxx = 100005; vector<int> graph[maxx]; // Function to perform the DFS calculating the // count of the elements in a connected component void dfs(int curr, int &cnt, int *visited, vector<int> &duringdfs) { visited[curr] = 1; // Number of nodes in this component ++cnt; // Stores the nodes which belong // to current component duringdfs.push_back(curr); for (auto &child : graph[curr]) { // If the child is not visited if (visited[child] == 0) { dfs(child, cnt, visited, duringdfs); } } } // Function to return the desired // count for every node in the graph void MaximumVisit(int n, int k) { // To keep track of nodes we visit int visited[maxx]; // Mark every node unvisited memset(visited, 0, sizeof visited); int ans[maxx]; // No of connected elements for each node memset(ans, 0, sizeof ans); vector<int> duringdfs; for (int i = 1; i <= n; ++i) { duringdfs.clear(); int cnt = 0; // If a node is not visited, perform a DFS as // this node belongs to a different component // which is not yet visited if (visited[i] == 0) { cnt = 0; dfs(i, cnt, visited, duringdfs); } // Now store the count of all the visited // nodes for any particular component. for (auto &x : duringdfs) { ans[x] = cnt; } } // Print the result int res = 0; for (int i = 1; i <= n; i++) { if (res < ans[i]) res = ans[i]; } cout << res; return; } // Function to build the graph void MakeGraph(int n, int k) { for (int i = 1; i <= k; i++) { int a, b; cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); } } // Driver code int32_t main() { int n, k; cin >> n >> k; // Build the graph MakeGraph(n, k); MaximumVisit(n, k); return 0; }
// C++ implementation of the above approach #include <bits/stdc++.h> #define int long long using namespace std; const int maxx = 200005; vector<int> graph[maxx]; // Function to perform the DFS calculating the // count of the elements in a connected component void dfs(int curr, int &cnt, int *visited, vector<int> &duringdfs) { visited[curr] = 1; // Number of nodes in this component ++cnt; // Stores the nodes which belong // to current component duringdfs.push_back(curr); for (auto &child : graph[curr]) { // If the child is not visited if (visited[child] == 0) { dfs(child, cnt, visited, duringdfs); } } } // Function to return the desired // count for every node in the graph void MaximumVisit(int n, int k) { // To keep track of nodes we visit int visited[maxx]; // Mark every node unvisited memset(visited, 0, sizeof visited); int ans[maxx]; // No of connected elements for each node memset(ans, 0, sizeof ans); vector<int> duringdfs; for (int i = 1; i <= n; ++i) { duringdfs.clear(); int cnt = 0; // If a node is not visited, perform a DFS as // this node belongs to a different component // which is not yet visited if (visited[i] == 0) { cnt = 0; dfs(i, cnt, visited, duringdfs); } // Now store the count of all the visited // nodes for any particular component. for (auto &x : duringdfs) { ans[x] = cnt; } } // Print the result int res = 0; for (int i = 1; i <= n; i++) { if (res < ans[i]) res = ans[i]; } cout << res; return; } // Function to build the graph void MakeGraph(int n, int k) { for (int i = 1; i <= k; i++) { int a, b; cin >> a >> b; graph[a].push_back(b); graph[b].push_back(a); } } // Driver code int32_t main() { int n, k; cin >> n >> k; // Build the graph MakeGraph(n, k); MaximumVisit(n, k); return 0; }
replace
4
5
4
5
0
p02573
C++
Runtime Error
// It doesn't matter as long as you rise to the top - Katsuki Bakugo #include <bits/stdc++.h> using namespace std; #define Fast_as_duck \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define forn(i, st, n) for (int i = st; i < n; i++) #define rev(i, st, n) for (int i = st; i >= n; i--) #define ss second #define ff first #define ll long long typedef pair<int, int> pii; const int N = 1e5 + 10, mod = 1000000007; int visited[N]; void dfs(std::vector<int> path[], int u, int val, int visited[]) { visited[u] = val; // cout << u << " " << visited[u] << "\n"; forn(i, 0, (int)path[u].size()) { if (visited[path[u][i]] == 0) { dfs(path, path[u][i], val, visited); } } } void solve() { int n, m; cin >> n >> m; std::vector<int> frnd[n + 1]; int x, y; forn(i, 0, m) { cin >> x >> y; frnd[x].pb(y); frnd[y].pb(x); } // cout << "ans from here\n\n\n"; // std::vector<int> visited(n+1 , 0); int val = 0; forn(i, 0, n) { if (visited[i + 1] == 0) { val++; visited[i + 1] = val; // cout << "dfs " << val << "\n"; dfs(frnd, i + 1, val, visited); } } std::vector<int> ans(val + 1, 0); forn(i, 1, n + 1) { // cout << visited[i] << " "; ans[visited[i]]++; } sort(ans.begin(), ans.end()); cout << ans.back() << "\n"; } int main() { Fast_as_duck; /* #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif */ int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
// It doesn't matter as long as you rise to the top - Katsuki Bakugo #include <bits/stdc++.h> using namespace std; #define Fast_as_duck \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define forn(i, st, n) for (int i = st; i < n; i++) #define rev(i, st, n) for (int i = st; i >= n; i--) #define ss second #define ff first #define ll long long typedef pair<int, int> pii; const int N = 1e5 + 10, mod = 1000000007; int visited[2 * N]; void dfs(std::vector<int> path[], int u, int val, int visited[]) { visited[u] = val; // cout << u << " " << visited[u] << "\n"; forn(i, 0, (int)path[u].size()) { if (visited[path[u][i]] == 0) { dfs(path, path[u][i], val, visited); } } } void solve() { int n, m; cin >> n >> m; std::vector<int> frnd[n + 1]; int x, y; forn(i, 0, m) { cin >> x >> y; frnd[x].pb(y); frnd[y].pb(x); } // cout << "ans from here\n\n\n"; // std::vector<int> visited(n+1 , 0); int val = 0; forn(i, 0, n) { if (visited[i + 1] == 0) { val++; visited[i + 1] = val; // cout << "dfs " << val << "\n"; dfs(frnd, i + 1, val, visited); } } std::vector<int> ans(val + 1, 0); forn(i, 1, n + 1) { // cout << visited[i] << " "; ans[visited[i]]++; } sort(ans.begin(), ans.end()); cout << ans.back() << "\n"; } int main() { Fast_as_duck; /* #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif */ int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
replace
19
20
19
20
0
p02573
C++
Time Limit Exceeded
/* author:ujwalll */ #pragma GCC optimize("O2") #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define for1(i, n) for (int i = 1; i <= n; i++) #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (a); i >= (b); i--) const int INF = 1 << 29; const int MOD = 1073741824; #define pp pair<ll, ll> #define ppi pair<int, int> typedef long long int ll; bool isPowerOfTwo(ll x) { return x && (!(x & (x - 1))); } void fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } long long binpow(long long a, long long b) { long long res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; const int dy[] = {0, -1, 0, 1, 1, -1, -1, 1}; //////////////////////////////////////////////////////////////////// set<int> adj[200005]; bool vis[200005]; int cnt = 0; int solve(int s) { vis[s] = 1; cnt++; for (auto i : adj[s]) { if (vis[i]) continue; solve(i); } } int main() { int tc = 1; // cin>>tc; while (tc--) { memset(vis, 0, sizeof(vis)); int n, m; cin >> n >> m; rep(i, m) { int x, y; cin >> x >> y; adj[x].insert(y); adj[y].insert(x); } int ans = 0; for1(i, n) { if (!vis[i]) { vis[i] = 1; solve(i); ans = max(ans, cnt); cnt = 0; } } cout << ans; } return 0; }
/* author:ujwalll */ #pragma GCC optimize("O2") #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define for1(i, n) for (int i = 1; i <= n; i++) #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (a); i >= (b); i--) const int INF = 1 << 29; const int MOD = 1073741824; #define pp pair<ll, ll> #define ppi pair<int, int> typedef long long int ll; bool isPowerOfTwo(ll x) { return x && (!(x & (x - 1))); } void fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } long long binpow(long long a, long long b) { long long res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; const int dy[] = {0, -1, 0, 1, 1, -1, -1, 1}; //////////////////////////////////////////////////////////////////// set<int> adj[200005]; bool vis[200005]; int cnt = 0; void solve(int s) { vis[s] = 1; cnt++; for (auto i : adj[s]) { if (vis[i]) continue; solve(i); } } int main() { int tc = 1; // cin>>tc; while (tc--) { memset(vis, 0, sizeof(vis)); int n, m; cin >> n >> m; rep(i, m) { int x, y; cin >> x >> y; adj[x].insert(y); adj[y].insert(x); } int ans = 0; for1(i, n) { if (!vis[i]) { vis[i] = 1; solve(i); ans = max(ans, cnt); cnt = 0; } } cout << ans; } return 0; }
replace
37
38
37
38
TLE
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define F first #define S second #define endl '\n' #define all(x) (x).begin(), (x).end() #define FOR(i, n) for (int i = 0; i < n; i++) #define FORR(i, a, b) for (int i = a; i < b; i++) #define fast \ std::ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define print(a) \ for (auto x : a) \ cout << x << ' '; \ cout << endl; #define printM(b) \ for (auto y : b) { \ print(y); \ } #define printP(p) cout << p.first << ' ' << p.second << endl; typedef long long int ll; typedef unsigned long long int ull; template <typename T> T cmax(T x, T y) { return (x > y) ? x : y; } /* 5 4 1 2 2 3 4 1 3 5 1 2 4 3 5 a->b->c */ // User function template for C++ vector<int> parent; int find(int x) { return parent[x] == x ? x : find(parent[x]); } void solve() { int n, m, t1, t2; cin >> n >> m; parent.resize(n + 1, 0); FOR(i, n + 1) parent[i] = i; for (int i = 0; i < m; i++) { cin >> t1 >> t2; int x, y; x = find(t1); y = find(t2); if (x != y) { int mn = min(x, y); int mx = max(x, y); parent[mx] = mn; } } unordered_map<int, int> mp; int ans = 0; for (int i : parent) { int j = find(i); mp[j]++; ans = max(ans, mp[j]); } // print(parent); mp.clear(); parent.clear(); cout << ans; } int main() { fast; int t = 1; // cin>>t; while (t--) { solve(); cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define F first #define S second #define endl '\n' #define all(x) (x).begin(), (x).end() #define FOR(i, n) for (int i = 0; i < n; i++) #define FORR(i, a, b) for (int i = a; i < b; i++) #define fast \ std::ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define print(a) \ for (auto x : a) \ cout << x << ' '; \ cout << endl; #define printM(b) \ for (auto y : b) { \ print(y); \ } #define printP(p) cout << p.first << ' ' << p.second << endl; typedef long long int ll; typedef unsigned long long int ull; template <typename T> T cmax(T x, T y) { return (x > y) ? x : y; } /* 5 4 1 2 2 3 4 1 3 5 1 2 4 3 5 a->b->c */ // User function template for C++ vector<int> parent; int find(int x) { return parent[x] == x ? x : parent[x] = find(parent[x]); } void solve() { int n, m, t1, t2; cin >> n >> m; parent.resize(n + 1, 0); FOR(i, n + 1) parent[i] = i; for (int i = 0; i < m; i++) { cin >> t1 >> t2; int x, y; x = find(t1); y = find(t2); if (x != y) { int mn = min(x, y); int mx = max(x, y); parent[mx] = mn; } } unordered_map<int, int> mp; int ans = 0; for (int i : parent) { int j = find(i); mp[j]++; ans = max(ans, mp[j]); } // print(parent); mp.clear(); parent.clear(); cout << ans; } int main() { fast; int t = 1; // cin>>t; while (t--) { solve(); cout << endl; } return 0; }
replace
48
49
48
49
TLE
p02573
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int #define li long int #define ld long double #define pb push_back using namespace std; vector<int> lis[100001]; bool vis[100001]; void dfs(int node, int &curr) { vis[node] = true; curr++; for (int x : lis[node]) { if (!vis[x]) { dfs(x, curr); } } } int main() { int n, m, a, b; cin >> n >> m; int ans = 0; for (int i = 1; i <= m; i++) { cin >> a >> b; lis[a].pb(b); lis[b].pb(a); } for (int i = 1; i <= n; i++) { if (!vis[i]) { int curr = 0; dfs(i, curr); ans = max(ans, curr); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define ll long long int #define li long int #define ld long double #define pb push_back using namespace std; vector<int> lis[200001]; bool vis[200001]; void dfs(int node, int &curr) { vis[node] = true; curr++; for (int x : lis[node]) { if (!vis[x]) { dfs(x, curr); } } } int main() { int n, m, a, b; cin >> n >> m; int ans = 0; for (int i = 1; i <= m; i++) { cin >> a >> b; lis[a].pb(b); lis[b].pb(a); } for (int i = 1; i <= n; i++) { if (!vis[i]) { int curr = 0; dfs(i, curr); ans = max(ans, curr); } } cout << ans << endl; return 0; }
replace
7
9
7
9
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> using namespace std; #define ll long long int const int md = 1e9 + 7; ll Parent[100000]; ll sze[100000]; void Build(int n) { for (ll i = 1; i <= n; i++) { Parent[i] = i; sze[i] = 1; } } ll find(ll u) { if (Parent[u] == u) return u; else { return Parent[u] = find(Parent[u]); } } void Union(ll a, ll b) { ll P_a = find(a); ll P_b = find(b); if (P_a != P_b) { sze[P_b] += sze[P_a]; Parent[P_a] = Parent[P_b]; } } int main() { ll n, m; cin >> n >> m; // std::vector<Edge> E(m) ; Build(n); // for(ll i=0;i<m;i++) // { // cin>>E[i].src; // E[i].src--; // cin>>E[i].dest; // E[i].dest--; // cin>>E[i].wt; // } for (int i = 0; i < m; i++) { ll x, y; cin >> x >> y; Union(x, y); } unordered_map<int, int> mp; ll mx = 0; for (int i = 1; i <= n; i++) { int p = find(i); // cout<<p<<endl; if (mp.find(p) == mp.end()) { mp[p] = 1; mx = max(mx, sze[p]); } } cout << mx << endl; }
#include <bits/stdc++.h> #include <iostream> using namespace std; #define ll long long int const int md = 1e9 + 7; ll Parent[200005]; ll sze[200005]; void Build(int n) { for (ll i = 1; i <= n; i++) { Parent[i] = i; sze[i] = 1; } } ll find(ll u) { if (Parent[u] == u) return u; else { return Parent[u] = find(Parent[u]); } } void Union(ll a, ll b) { ll P_a = find(a); ll P_b = find(b); if (P_a != P_b) { sze[P_b] += sze[P_a]; Parent[P_a] = Parent[P_b]; } } int main() { ll n, m; cin >> n >> m; // std::vector<Edge> E(m) ; Build(n); // for(ll i=0;i<m;i++) // { // cin>>E[i].src; // E[i].src--; // cin>>E[i].dest; // E[i].dest--; // cin>>E[i].wt; // } for (int i = 0; i < m; i++) { ll x, y; cin >> x >> y; Union(x, y); } unordered_map<int, int> mp; ll mx = 0; for (int i = 1; i <= n; i++) { int p = find(i); // cout<<p<<endl; if (mp.find(p) == mp.end()) { mp[p] = 1; mx = max(mx, sze[p]); } } cout << mx << endl; }
replace
7
9
7
9
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll mod = 1e9 + 7; #define pival 3.14159265359 #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define mp make_pair #define fi first #define se second #define pqq priority_queue #define all(a) a.begin(), a.end() #define sz(a) (ll)(a.size()) ll power(ll x, ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } const ll L = 1e5 + 5; ll arr[L]; ll szz[L]; ll root(ll i) { while (arr[i] != i) { arr[i] = arr[arr[i]]; i = arr[i]; } return i; } void union1(ll i, ll j) { ll ri = root(i); ll rj = root(j); if (ri == rj) return; if (szz[ri] <= szz[rj]) { arr[ri] = rj; szz[rj] += szz[ri]; } else { arr[rj] = ri; szz[ri] += szz[rj]; } } ll find(ll i, ll j) { if (root(i) == root(j)) return true; return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, m; cin >> n >> m; for (ll i = 1; i <= n; i++) { arr[i] = i; szz[i] = 1; } ll a, b; while (m--) { cin >> a >> b; union1(a, b); } ll ans = 0; for (ll i = 1; i <= n; i++) { ans = max(ans, szz[i]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll mod = 1e9 + 7; #define pival 3.14159265359 #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define mp make_pair #define fi first #define se second #define pqq priority_queue #define all(a) a.begin(), a.end() #define sz(a) (ll)(a.size()) ll power(ll x, ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } const ll L = 2e5 + 5; ll arr[L]; ll szz[L]; ll root(ll i) { while (arr[i] != i) { arr[i] = arr[arr[i]]; i = arr[i]; } return i; } void union1(ll i, ll j) { ll ri = root(i); ll rj = root(j); if (ri == rj) return; if (szz[ri] <= szz[rj]) { arr[ri] = rj; szz[rj] += szz[ri]; } else { arr[rj] = ri; szz[ri] += szz[rj]; } } ll find(ll i, ll j) { if (root(i) == root(j)) return true; return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, m; cin >> n >> m; for (ll i = 1; i <= n; i++) { arr[i] = i; szz[i] = 1; } ll a, b; while (m--) { cin >> a >> b; union1(a, b); } ll ans = 0; for (ll i = 1; i <= n; i++) { ans = max(ans, szz[i]); } cout << ans << endl; return 0; }
replace
26
27
26
27
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int64 long long const int mod = (int)1e9 + 7; const int nax = 1e5 + 5; vector<int> par(nax), siz(nax); int find(int u) { if (par[u] == u) return u; return par[u] = find(par[u]); } void union_set(int a, int b) { a = find(a), b = find(b); if (a == b) return; if (siz[a] > siz[b]) swap(a, b); par[a] = b; siz[b] += siz[a]; } int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { par[i] = i, siz[i] = 1; } for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; --u, --v; union_set(u, v); } int ans = 0; for (int i = 0; i < n; i++) { if (i == par[i]) { ans = max(ans, siz[i]); } } cout << ans; }
#include <bits/stdc++.h> using namespace std; #define int64 long long const int mod = (int)1e9 + 7; const int nax = 2e5 + 5; vector<int> par(nax), siz(nax); int find(int u) { if (par[u] == u) return u; return par[u] = find(par[u]); } void union_set(int a, int b) { a = find(a), b = find(b); if (a == b) return; if (siz[a] > siz[b]) swap(a, b); par[a] = b; siz[b] += siz[a]; } int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { par[i] = i, siz[i] = 1; } for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; --u, --v; union_set(u, v); } int ans = 0; for (int i = 0; i < n; i++) { if (i == par[i]) { ans = max(ans, siz[i]); } } cout << ans; }
replace
7
8
7
8
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> #define pb push_back #define mpr make_pair #define pii pair<int, int> #define pll pair<ll, ll> #define ll long long #define ld long double #define all(arr) arr.begin(), arr.end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define fo(i, l, r) for (int i = l; i <= r; i++) #define INF 1000000001 #define inf1 1000000000000000001 #define mod 1000000007 #define pie 3.14159265358979323846264338327950L #define N 100005 #define mid(l, r) l + (r - l) / 2 #define vec vector<int> #define vecl vector<ll> #define umap unordered_map<ll, ll> #define yes cout << "Yes" << endl; #define no cout << "No" << endl; #define endl "\n" using namespace std; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; ll gcd(ll a, ll b) { if (!a) return b; return gcd(b % a, a); } unordered_map<int, vector<int>> mp; int vis[N]; int ans = 0; int dfs(int u) { int cnt = 1; vis[u] = 1; for (auto it : mp[u]) { if (vis[it] == 0) { cnt += dfs(it); } } return cnt; } void test_case() { int n, m; cin >> n; cin >> m; rep(i, m) { int a, b; cin >> a >> b; mp[a].pb(b); mp[b].pb(a); } for (int i = 1; i <= n; i++) { if (vis[i] == 0) { ans = max(ans, dfs(i)); } } cout << ans << endl; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(20); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int t = 1; // cin >> t; while (t--) { test_case(); } }
#include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> #define pb push_back #define mpr make_pair #define pii pair<int, int> #define pll pair<ll, ll> #define ll long long #define ld long double #define all(arr) arr.begin(), arr.end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define fo(i, l, r) for (int i = l; i <= r; i++) #define INF 1000000001 #define inf1 1000000000000000001 #define mod 1000000007 #define pie 3.14159265358979323846264338327950L #define N 100005 #define mid(l, r) l + (r - l) / 2 #define vec vector<int> #define vecl vector<ll> #define umap unordered_map<ll, ll> #define yes cout << "Yes" << endl; #define no cout << "No" << endl; #define endl "\n" using namespace std; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; ll gcd(ll a, ll b) { if (!a) return b; return gcd(b % a, a); } unordered_map<int, vector<int>> mp; int vis[1000005]; int ans = 0; int dfs(int u) { int cnt = 1; vis[u] = 1; for (auto it : mp[u]) { if (vis[it] == 0) { cnt += dfs(it); } } return cnt; } void test_case() { int n, m; cin >> n; cin >> m; rep(i, m) { int a, b; cin >> a >> b; mp[a].pb(b); mp[b].pb(a); } for (int i = 1; i <= n; i++) { if (vis[i] == 0) { ans = max(ans, dfs(i)); } } cout << ans << endl; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(20); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int t = 1; // cin >> t; while (t--) { test_case(); } }
replace
35
36
35
36
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> #pragma GCC optimize("O2") using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define F first #define S second #define migmig \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define sortv(X) sort(X.begin(), X.end()); #define ll long long #define ld long double #define pii pair<int, int> #define bug(x) cout << "passed " << x << endl; #define ashar(x, y, z) \ cout << setprecision(x) << fixed << y; \ if (z == 1) \ cout << "\n"; #define ppi pair<pair<int, int>, int> #define ordered_set \ tree<pair<long long, long long>, null_type, \ less<pair<long long, long long>>, rb_tree_tag, \ tree_order_statistics_node_update> long long const inf = 3e18, linf = 2e9, mod = 1e9 + 7, inf2 = 1e12; int const mxn = 5e5 + 10; ll poww(ll a, ll b, ll md) { return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md)); } int n, m, mark[mxn], now, ans; vector<int> adj[mxn]; int dfs(int v) { now++; mark[v] = 1; for (auto u : adj[v]) { if (!mark[u]) dfs(u); } } int main() { cin >> n >> m; for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } for (int i = 1; i <= n; i++) { if (!mark[i]) { now = 0; dfs(i); ans = max(ans, now); } } cout << ans; }
#include <bits/stdc++.h> #pragma GCC optimize("O2") using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define F first #define S second #define migmig \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define sortv(X) sort(X.begin(), X.end()); #define ll long long #define ld long double #define pii pair<int, int> #define bug(x) cout << "passed " << x << endl; #define ashar(x, y, z) \ cout << setprecision(x) << fixed << y; \ if (z == 1) \ cout << "\n"; #define ppi pair<pair<int, int>, int> #define ordered_set \ tree<pair<long long, long long>, null_type, \ less<pair<long long, long long>>, rb_tree_tag, \ tree_order_statistics_node_update> long long const inf = 3e18, linf = 2e9, mod = 1e9 + 7, inf2 = 1e12; int const mxn = 5e5 + 10; ll poww(ll a, ll b, ll md) { return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md)); } int n, m, mark[mxn], now, ans; vector<int> adj[mxn]; void dfs(int v) { now++; mark[v] = 1; for (auto u : adj[v]) { if (!mark[u]) dfs(u); } } int main() { cin >> n >> m; for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } for (int i = 1; i <= n; i++) { if (!mark[i]) { now = 0; dfs(i); ans = max(ans, now); } } cout << ans; }
replace
36
37
36
37
-11
p02573
C++
Runtime Error
/* LANG:C++ PROB: */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> #include <iostream> // #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long i64; typedef vector<i64> vi64; typedef vector<vi64> vvi64; typedef pair<i64, i64> pi64; typedef double ld; typedef unsigned long long ui64; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } const int mod = 1000000007; i64 poww(i64 a, i64 b) { a %= mod; i64 res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b /= 2; } return res; } i64 inv(i64 a) { return poww(a, mod - 2); } int par[200009], sz[100009]; int p(int x) { if (x == par[x]) return x; return par[x] = p(par[x]); } void unite(int x, int y) { x = p(x); y = p(y); if (x == y) return; if (sz[x] > sz[y]) swap(x, y); sz[y] += sz[x]; par[x] = y; } void solve() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) par[i] = i, sz[i] = 1; forn(i, m) { int x, y; cin >> x >> y; unite(x, y); } int ans = 0; for (int i = 1; i <= n; i++) { ans = max(ans, sz[p(i)]); } cout << ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; while (t--) { solve(); } return 0; }
/* LANG:C++ PROB: */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> #include <iostream> // #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long i64; typedef vector<i64> vi64; typedef vector<vi64> vvi64; typedef pair<i64, i64> pi64; typedef double ld; typedef unsigned long long ui64; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } const int mod = 1000000007; i64 poww(i64 a, i64 b) { a %= mod; i64 res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b /= 2; } return res; } i64 inv(i64 a) { return poww(a, mod - 2); } int par[200009], sz[200009]; int p(int x) { if (x == par[x]) return x; return par[x] = p(par[x]); } void unite(int x, int y) { x = p(x); y = p(y); if (x == y) return; if (sz[x] > sz[y]) swap(x, y); sz[y] += sz[x]; par[x] = y; } void solve() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) par[i] = i, sz[i] = 1; forn(i, m) { int x, y; cin >> x >> y; unite(x, y); } int ans = 0; for (int i = 1; i <= n; i++) { ans = max(ans, sz[p(i)]); } cout << ans; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; while (t--) { solve(); } return 0; }
replace
57
58
57
58
-11
p02573
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <vector> // #include<unordered_map> using namespace std; #define ll long long #define dd cout << endl const long long int inf = 1e18 + 7; const int mod = 1e9 + 7; inline ll int max(ll int a, ll int b) { return a > b ? a : b; } inline ll int min(ll int a, ll int b) { return a < b ? a : b; } const int maxn = 2e5 + 10; int f[maxn]; int n, m; inline void init() { for (int i = 0; i <= n; i++) f[i] = i; } int getf(int x) { if (f[x] == x) return x; else return getf(f[x]); } void merge(int x, int y) { x = getf(x); y = getf(y); if (x != y) f[y] = x; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; init(); for (int i = 0, x, y; i < m; i++) { cin >> x >> y; merge(x, y); } map<int, int> book; int maxx = 0; for (int i = 1; i <= n; i++) { int now = getf(i); book[now]++; if (book[now] > maxx) maxx = book[now]; } cout << maxx << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <vector> // #include<unordered_map> using namespace std; #define ll long long #define dd cout << endl const long long int inf = 1e18 + 7; const int mod = 1e9 + 7; inline ll int max(ll int a, ll int b) { return a > b ? a : b; } inline ll int min(ll int a, ll int b) { return a < b ? a : b; } const int maxn = 2e5 + 10; int f[maxn]; int n, m; inline void init() { for (int i = 0; i <= n; i++) f[i] = i; } int getf(int x) { if (f[x] == x) return x; else return f[x] = getf(f[x]); } void merge(int x, int y) { x = getf(x); y = getf(y); if (x != y) f[y] = x; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; init(); for (int i = 0, x, y; i < m; i++) { cin >> x >> y; merge(x, y); } map<int, int> book; int maxx = 0; for (int i = 1; i <= n; i++) { int now = getf(i); book[now]++; if (book[now] > maxx) maxx = book[now]; } cout << maxx << endl; return 0; }
replace
35
36
35
36
TLE
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> using i16 = std::int16_t; using i32 = std::int32_t; using i64 = std::int64_t; using usize = std::size_t; using namespace std; #define rep(i, max) for (usize i = 0; i < max; ++i) #define loop while (true) #define allOf(collection) collection.begin(), collection.end() unique_ptr<string> readLine() { unique_ptr<string> line(new string()); getline(cin, *line); return line; } template <typename T1, typename T2> pair<T1, T2> readPair() { T1 res1; cin >> res1; T2 res2; cin >> res2; readLine(); return make_pair(res1, res2); } template <typename T> unique_ptr<vector<T>> readVector(usize num) { unique_ptr<vector<T>> list(new vector<T>(num)); rep(i, num) cin >> (*list)[i]; readLine(); return list; } void readValues() { readLine(); } template <typename H, typename... T> void readValues(H &head, T &&...tails) { H a; cin >> a; head = a; readValues(forward<T>(tails)...); } void writeLine() { cout << endl; } template <typename T> void write(const T &arg) { cout << arg; } template <typename T> void writeLine(const vector<T> &arg) { if (arg.empty()) { writeLine(); return; } write(arg[0]); for (int i = 1; i < arg.size(); ++i) { write(" "); write(arg[i]); } writeLine(); } template <typename T> void writeLine(const T &arg) { cout << arg << endl; } void recursiveCombination(vector<i32> &indexes, i32 s, i32 rest, function<void(vector<i32> &)> f) { if (rest == 0) { f(indexes); } else { if (s < 0) return; recursiveCombination(indexes, s - 1, rest, f); indexes[rest - 1] = s; recursiveCombination(indexes, s - 1, rest - 1, f); } } void foreachWithCombination(i32 n, i32 k, function<void(vector<i32> &)> f) { auto indexes = vector<i32>(k); recursiveCombination(indexes, n - 1, k, f); } void foreachWithPermutaton(i32 n, function<void(vector<i32> &)> f) { auto indexes = vector<i32>(); indexes.reserve(n); rep(i, n) indexes.push_back(i); do f(indexes); while (next_permutation(allOf(indexes))); } void foreachWithPermutaton(i32 n, i32 k, function<void(vector<i32> &)> f) { foreachWithCombination(n, k, [=](vector<i32> &combIndexes) { foreachWithPermutaton(k, [=](vector<i32> &permIndexes) { auto indexes = vector<i32>(); indexes.reserve(k); rep(i, k) { indexes.push_back(combIndexes[permIndexes[i]]); } f(indexes); }); }); } void program(); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); program(); } struct UnionFind { vector<i32> list; UnionFind(i32 size) { list = vector<i32>(size, -1); } i32 root(i32 x) { if (list[x] < 0) return x; else return root(list[x]); } void unite(i32 x, i32 y) { i32 xRoot = root(x); i32 yRoot = root(y); if (xRoot == yRoot) return; list[xRoot] += list[yRoot]; list[yRoot] = xRoot; } i32 sizeAt(i32 n) { return max(0, -list[n]); } }; int n; int m; void program() { readValues(n, m); UnionFind uf = UnionFind(n); rep(i, m) { auto info = readPair<i32, i32>(); uf.unite(info.first - 1, info.second - 1); } i32 maxi = 0; rep(i, n) { maxi = max(maxi, uf.sizeAt(i)); } writeLine(maxi); }
#include <bits/stdc++.h> using i16 = std::int16_t; using i32 = std::int32_t; using i64 = std::int64_t; using usize = std::size_t; using namespace std; #define rep(i, max) for (usize i = 0; i < max; ++i) #define loop while (true) #define allOf(collection) collection.begin(), collection.end() unique_ptr<string> readLine() { unique_ptr<string> line(new string()); getline(cin, *line); return line; } template <typename T1, typename T2> pair<T1, T2> readPair() { T1 res1; cin >> res1; T2 res2; cin >> res2; readLine(); return make_pair(res1, res2); } template <typename T> unique_ptr<vector<T>> readVector(usize num) { unique_ptr<vector<T>> list(new vector<T>(num)); rep(i, num) cin >> (*list)[i]; readLine(); return list; } void readValues() { readLine(); } template <typename H, typename... T> void readValues(H &head, T &&...tails) { H a; cin >> a; head = a; readValues(forward<T>(tails)...); } void writeLine() { cout << endl; } template <typename T> void write(const T &arg) { cout << arg; } template <typename T> void writeLine(const vector<T> &arg) { if (arg.empty()) { writeLine(); return; } write(arg[0]); for (int i = 1; i < arg.size(); ++i) { write(" "); write(arg[i]); } writeLine(); } template <typename T> void writeLine(const T &arg) { cout << arg << endl; } void recursiveCombination(vector<i32> &indexes, i32 s, i32 rest, function<void(vector<i32> &)> f) { if (rest == 0) { f(indexes); } else { if (s < 0) return; recursiveCombination(indexes, s - 1, rest, f); indexes[rest - 1] = s; recursiveCombination(indexes, s - 1, rest - 1, f); } } void foreachWithCombination(i32 n, i32 k, function<void(vector<i32> &)> f) { auto indexes = vector<i32>(k); recursiveCombination(indexes, n - 1, k, f); } void foreachWithPermutaton(i32 n, function<void(vector<i32> &)> f) { auto indexes = vector<i32>(); indexes.reserve(n); rep(i, n) indexes.push_back(i); do f(indexes); while (next_permutation(allOf(indexes))); } void foreachWithPermutaton(i32 n, i32 k, function<void(vector<i32> &)> f) { foreachWithCombination(n, k, [=](vector<i32> &combIndexes) { foreachWithPermutaton(k, [=](vector<i32> &permIndexes) { auto indexes = vector<i32>(); indexes.reserve(k); rep(i, k) { indexes.push_back(combIndexes[permIndexes[i]]); } f(indexes); }); }); } void program(); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); program(); } struct UnionFind { vector<i32> list; UnionFind(i32 size) { list = vector<i32>(size, -1); } i32 root(i32 x) { if (list[x] < 0) return x; else return root(list[x]); } void unite(i32 x, i32 y) { i32 xRoot = root(x); i32 yRoot = root(y); if (xRoot == yRoot) return; if (list[xRoot] > list[yRoot]) swap(xRoot, yRoot); list[xRoot] += list[yRoot]; list[yRoot] = xRoot; } i32 sizeAt(i32 n) { return max(0, -list[n]); } }; int n; int m; void program() { readValues(n, m); UnionFind uf = UnionFind(n); rep(i, m) { auto info = readPair<i32, i32>(); uf.unite(info.first - 1, info.second - 1); } i32 maxi = 0; rep(i, n) { maxi = max(maxi, uf.sizeAt(i)); } writeLine(maxi); }
insert
112
112
112
114
TLE
p02573
C++
Time Limit Exceeded
/*author @dhanush*/ #include <bits/stdc++.h> using namespace std; #define ll long long #define boost \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define pb push_back #define se second #define fi first #define INF INT_MAX int parent[200001]; int find(int a) { while (parent[a] > 0) a = parent[a]; return a; } void Union(int a, int b) { parent[a] += parent[b]; // adding size of set b to set a parent[b] = a; // making a , parent of new set } int main() { int n, m, a, b; cin >> n >> m; for (int i = 1; i <= n; i++) parent[i] = -1; // initializing while (m--) { cin >> a >> b; a = find(a), b = find(b); if (a != b) Union(a, b); } int res = -1; for (int i = 1; i <= n; i++) if (parent[i] < 0) res = min(res, parent[i]); cout << abs(res); }
/*author @dhanush*/ #include <bits/stdc++.h> using namespace std; #define ll long long #define boost \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define pb push_back #define se second #define fi first #define INF INT_MAX int parent[200001]; int find(int a) { if (parent[a] < 0) { return a; } else { int x = find(parent[a]); parent[a] = x; return x; } } void Union(int a, int b) { parent[a] += parent[b]; // adding size of set b to set a parent[b] = a; // making a , parent of new set } int main() { int n, m, a, b; cin >> n >> m; for (int i = 1; i <= n; i++) parent[i] = -1; // initializing while (m--) { cin >> a >> b; a = find(a), b = find(b); if (a != b) Union(a, b); } int res = -1; for (int i = 1; i <= n; i++) if (parent[i] < 0) res = min(res, parent[i]); cout << abs(res); }
replace
16
20
16
23
TLE
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define M_PI 3.1415926535 #define ll long long #define ld long double #define all(a) a.begin(), a.end() #define Summon_Tourist \ ios::sync_with_stdio(false); \ cin.tie(0); ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll inf = 1e9 + 7; ll modexp(ll base, ll power) { if (power == 0) return 1; if (power & 1) return base * modexp(base, power - 1) % inf; return modexp(base * base % inf, power / 2); } vector<ll> a[20005]; vector<ll> visited(20005, 0), weights(20005, 1); ll dfs(ll x) { if (visited[x]) return 0; visited[x] = 1; ll ret = weights[x]; for (auto it : a[x]) { if (visited[it]) continue; ret += dfs(it); } return ret; } int main() { Summon_Tourist // freopen("input.txt" , "r" , stdin ) ; ll t = 1; // cin>>t; while (t--) { ll n, m; cin >> n >> m; for (ll i = 0; i < m; i++) { ll x, y; cin >> x >> y; a[x].push_back(y); a[y].push_back(x); } ll ans = -1; for (ll i = 1; i <= n; i++) { if (visited[i] != 1) { ll ret = dfs(i); ans = max(ans, ret); } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define M_PI 3.1415926535 #define ll long long #define ld long double #define all(a) a.begin(), a.end() #define Summon_Tourist \ ios::sync_with_stdio(false); \ cin.tie(0); ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll inf = 1e9 + 7; ll modexp(ll base, ll power) { if (power == 0) return 1; if (power & 1) return base * modexp(base, power - 1) % inf; return modexp(base * base % inf, power / 2); } vector<ll> a[200005]; vector<ll> visited(200005, 0), weights(200005, 1); ll dfs(ll x) { if (visited[x]) return 0; visited[x] = 1; ll ret = weights[x]; for (auto it : a[x]) { if (visited[it]) continue; ret += dfs(it); } return ret; } int main() { Summon_Tourist // freopen("input.txt" , "r" , stdin ) ; ll t = 1; // cin>>t; while (t--) { ll n, m; cin >> n >> m; for (ll i = 0; i < m; i++) { ll x, y; cin >> x >> y; a[x].push_back(y); a[y].push_back(x); } ll ans = -1; for (ll i = 1; i <= n; i++) { if (visited[i] != 1) { ll ret = dfs(i); ans = max(ans, ret); } } cout << ans << endl; } return 0; }
replace
19
21
19
21
0
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int findSet(vector<int> a, int i) { if (a[i] < 0) return i; return a[i] = findSet(a, a[i]); } void mergeSets(vector<int> &a, int i, int j) { int x = findSet(a, i); int y = findSet(a, j); if (x == y) { return; } if (a[x] > a[y]) { int t = x; x = y; y = t; } a[x] += a[y]; a[y] = x; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<int> v(n); for (int i = 0; i < n; i++) { v[i] = -1; } for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; mergeSets(v, a, b); } int ans = 0; for (int i = 0; i < n; i++) { // cout << v[i] << " " << i << endl; ans = min(ans, v[i]); } ans = abs(ans); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int findSet(vector<int> &a, int i) { if (a[i] < 0) return i; return a[i] = findSet(a, a[i]); } void mergeSets(vector<int> &a, int i, int j) { int x = findSet(a, i); int y = findSet(a, j); if (x == y) { return; } if (a[x] > a[y]) { int t = x; x = y; y = t; } a[x] += a[y]; a[y] = x; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; vector<int> v(n); for (int i = 0; i < n; i++) { v[i] = -1; } for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; mergeSets(v, a, b); } int ans = 0; for (int i = 0; i < n; i++) { // cout << v[i] << " " << i << endl; ans = min(ans, v[i]); } ans = abs(ans); cout << ans << endl; }
replace
3
4
3
4
TLE
p02573
C++
Time Limit Exceeded
#include <iostream> #include <map> #include <set> #include <stdio.h> #include <string.h> #include <vector> using namespace std; int dfs(int i, vector<bool> &visited, std::map<int, std::set<int>> friends) { int result = 1; for (std::set<int>::iterator it = friends[i].begin(); it != friends[i].end(); ++it) { if (!visited[*it]) { visited[*it] = true; result += dfs(*it, visited, friends); } } return result; } int main() { int n = 0; int m = 0; int a = 0; int b = 0; scanf("%d %d", &n, &m); vector<bool> visited(n, false); std::map<int, std::set<int>> friends; for (int i = 0; i < m; i++) { scanf("%d %d", &a, &b); friends[a - 1].insert(b - 1); friends[b - 1].insert(a - 1); } int max_size = 1; for (int i = 0; i < n; i++) { if (!visited[i]) { visited[i] = true; int size = dfs(i, visited, friends); max_size = std::max(size, max_size); // printf("%d\n", i); } } printf("%d\n", max_size); // for(int i=0; i<n; i++){ // for(int j=0; j<k+1; j++){ // printf("%lld ", arr[i][j]); // } // printf("\n"); // } // printf("%lld\n", (arr[n-1][k] - arr[n-1][k-1] + base) % base); }
#include <iostream> #include <map> #include <set> #include <stdio.h> #include <string.h> #include <vector> using namespace std; int dfs(int i, vector<bool> &visited, std::map<int, std::set<int>> &friends) { int result = 1; for (std::set<int>::iterator it = friends[i].begin(); it != friends[i].end(); ++it) { if (!visited[*it]) { visited[*it] = true; result += dfs(*it, visited, friends); } } return result; } int main() { int n = 0; int m = 0; int a = 0; int b = 0; scanf("%d %d", &n, &m); vector<bool> visited(n, false); std::map<int, std::set<int>> friends; for (int i = 0; i < m; i++) { scanf("%d %d", &a, &b); friends[a - 1].insert(b - 1); friends[b - 1].insert(a - 1); } int max_size = 1; for (int i = 0; i < n; i++) { if (!visited[i]) { visited[i] = true; int size = dfs(i, visited, friends); max_size = std::max(size, max_size); // printf("%d\n", i); } } printf("%d\n", max_size); // for(int i=0; i<n; i++){ // for(int j=0; j<k+1; j++){ // printf("%lld ", arr[i][j]); // } // printf("\n"); // } // printf("%lld\n", (arr[n-1][k] - arr[n-1][k-1] + base) % base); }
replace
8
9
8
9
TLE
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) template <typename T> string join(vector<T> &vec, string &sp) { int si = vec.length; if (si == 0) { return ""; } else { stringstream ss; rep(i, si - 1) { ss << vec[i] << sp; } ss << vec[si - 1]; return ss.str(); } } vector<int> uf(200010); int root(int p) { if (p == uf[p]) return p; else return root(uf[p]); } int main(void) { int n, m; cin >> n >> m; n++; rep(i, n + 1) { uf[i] = i; } rep(i, m) { int a, b; cin >> a >> b; int rx = root(uf[a]); int ry = root(uf[b]); if (rx != ry) { uf[rx] = ry; } } unordered_map<int, int> mp; rep(i, n) { int p = root(i); if (!mp[p]) { mp[p] = 1; } else { mp[p]++; } } int max = 0; for (auto i = mp.begin(); i != mp.end(); i++) { if (max < i->second) max = i->second; } cout << max << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) template <typename T> string join(vector<T> &vec, string &sp) { int si = vec.length; if (si == 0) { return ""; } else { stringstream ss; rep(i, si - 1) { ss << vec[i] << sp; } ss << vec[si - 1]; return ss.str(); } } vector<int> uf(200010); int root(int p) { if (p == uf[p]) return p; else { return uf[p] = root(uf[p]); } } int main(void) { int n, m; cin >> n >> m; n++; rep(i, n + 1) { uf[i] = i; } rep(i, m) { int a, b; cin >> a >> b; int rx = root(uf[a]); int ry = root(uf[b]); if (rx != ry) { uf[rx] = ry; } } unordered_map<int, int> mp; rep(i, n) { int p = root(i); if (!mp[p]) { mp[p] = 1; } else { mp[p]++; } } int max = 0; for (auto i = mp.begin(); i != mp.end(); i++) { if (max < i->second) max = i->second; } cout << max << endl; }
replace
18
20
18
22
TLE
p02573
C++
Runtime Error
#include <bits/stdc++.h> #define fr(i, n) for (int i = 1; i <= n; i++) #define mod 1000000007 #define pb push_back #define ff first #define ss second #define ii pair<ll, ll> #define vi vector<int> #define vii vector<ii> #define ll long long int #define INF 1000000000 #define endl '\n' using namespace std; vector<int> v[100001]; vector<int> parent(100001, -1); int R[100001] = {1}; ll ct = 0; int find(int a) { // cout<<parent[a]<<endl; if (parent[a] < 0) return a; return parent[a] = find(parent[a]); } void u(int a, int b) { // cout<<a<<b<<endl; parent[a] = -(abs(parent[a]) + abs(parent[b])); // cout<<parent[a]<<endl; if (R[a] >= R[b]) { parent[b] = a; R[a] += R[b]; } else { parent[a] = b; R[b] += R[a]; } // Rank decrease we can find in o(logn) max time; } int main() { // freopen("in4.txt", "r", stdin); // freopen("output4.txt", "w", stdout); ll n, m, a, b; cin >> n >> m; for (int i = 1; i <= n; i++) { v[i].pb(i); } for (int i = 1; i <= m; i++) { cin >> a >> b; a = find(a); // cout<<a<<endl; b = find(b); // cout<<b<<endl; if (a != b) u(a, b); } int maxi = INT_MIN; for (int i = 1; i <= n; i++) { // cout<<parent[i]<<" "; if (parent[i] < 0) { maxi = max(maxi, abs(parent[i])); } } cout << maxi << endl; }
#include <bits/stdc++.h> #define fr(i, n) for (int i = 1; i <= n; i++) #define mod 1000000007 #define pb push_back #define ff first #define ss second #define ii pair<ll, ll> #define vi vector<int> #define vii vector<ii> #define ll long long int #define INF 1000000000 #define endl '\n' using namespace std; vector<int> v[2000001]; vector<int> parent(2000001, -1); int R[2000001] = {1}; ll ct = 0; int find(int a) { // cout<<parent[a]<<endl; if (parent[a] < 0) return a; return parent[a] = find(parent[a]); } void u(int a, int b) { // cout<<a<<b<<endl; parent[a] = -(abs(parent[a]) + abs(parent[b])); // cout<<parent[a]<<endl; if (R[a] >= R[b]) { parent[b] = a; R[a] += R[b]; } else { parent[a] = b; R[b] += R[a]; } // Rank decrease we can find in o(logn) max time; } int main() { // freopen("in4.txt", "r", stdin); // freopen("output4.txt", "w", stdout); ll n, m, a, b; cin >> n >> m; for (int i = 1; i <= n; i++) { v[i].pb(i); } for (int i = 1; i <= m; i++) { cin >> a >> b; a = find(a); // cout<<a<<endl; b = find(b); // cout<<b<<endl; if (a != b) u(a, b); } int maxi = INT_MIN; for (int i = 1; i <= n; i++) { // cout<<parent[i]<<" "; if (parent[i] < 0) { maxi = max(maxi, abs(parent[i])); } } cout << maxi << endl; }
replace
13
16
13
16
0
p02573
C++
Time Limit Exceeded
#include <iostream> using namespace std; int a[200005]; int cnt[200005]; int findroot(int v) { return a[v] == v ? v : findroot(a[v]); } int main() { int n, m; cin >> n; cin >> m; for (int i = 1; i <= n; i++) { a[i] = i; cnt[i] = 1; } int max = 0; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; int findrootx = findroot(x); int findrooty = findroot(y); if (findrootx != findrooty) { a[findrooty] = findrootx; cnt[findrootx] += cnt[findrooty]; } } for (int i = 1; i <= n; i++) { if (findroot(i) == i) { if (max < cnt[i]) { max = cnt[i]; } } } cout << max; }
#include <iostream> using namespace std; int a[200005]; int cnt[200005]; int findroot(int v) { return a[v] == v ? v : a[v] = findroot(a[v]); } int main() { int n, m; cin >> n; cin >> m; for (int i = 1; i <= n; i++) { a[i] = i; cnt[i] = 1; } int max = 0; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; int findrootx = findroot(x); int findrooty = findroot(y); if (findrootx != findrooty) { a[findrooty] = findrootx; cnt[findrootx] += cnt[findrooty]; } } for (int i = 1; i <= n; i++) { if (findroot(i) == i) { if (max < cnt[i]) { max = cnt[i]; } } } cout << max; }
replace
4
5
4
5
TLE
p02573
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <iterator> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; struct Node { int pos; int flag; std::vector<int> connects; }; Node nodes[200010]; int n, m; int curFlag; int maxCount; int checkAround(int pos, int curFlag) { int count = 0; std::queue<int> q; q.push(pos); nodes[pos].flag = curFlag; count++; int newPos; while (!q.empty()) { int curPos = q.front(); q.pop(); if (nodes[curPos].flag != curFlag) { nodes[curPos].flag = curFlag; count++; } for (int j = 0; j < nodes[curPos].connects.size(); j++) { int newPos = nodes[pos].connects[j]; if (nodes[newPos].flag == -1) { nodes[newPos].flag = curFlag; count++; q.push(newPos); } } } return count; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { nodes[i].flag = -1; nodes[i].pos = i; } for (int i = 0; i < m; i++) { int u, v; scanf("%d%d", &u, &v); nodes[u].connects.push_back(v); nodes[v].connects.push_back(u); } maxCount = 0; curFlag = 1; for (int i = 1; i <= n; i++) { if (nodes[i].flag == -1) { int count = checkAround(i, curFlag); if (count > maxCount) maxCount = count; curFlag++; } } printf("%d\n", maxCount); return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <iterator> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; struct Node { int pos; int flag; std::vector<int> connects; }; Node nodes[200010]; int n, m; int curFlag; int maxCount; int checkAround(int pos, int curFlag) { int count = 0; std::queue<int> q; q.push(pos); nodes[pos].flag = curFlag; count++; int newPos; while (!q.empty()) { int curPos = q.front(); q.pop(); if (nodes[curPos].flag != curFlag) { nodes[curPos].flag = curFlag; count++; } for (int j = 0; j < nodes[curPos].connects.size(); j++) { int newPos = nodes[curPos].connects[j]; if (nodes[newPos].flag == -1) { nodes[newPos].flag = curFlag; count++; q.push(newPos); } } } return count; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { nodes[i].flag = -1; nodes[i].pos = i; } for (int i = 0; i < m; i++) { int u, v; scanf("%d%d", &u, &v); nodes[u].connects.push_back(v); nodes[v].connects.push_back(u); } maxCount = 0; curFlag = 1; for (int i = 1; i <= n; i++) { if (nodes[i].flag == -1) { int count = checkAround(i, curFlag); if (count > maxCount) maxCount = count; curFlag++; } } printf("%d\n", maxCount); return 0; }
replace
43
44
43
44
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int mex = 100005; #define ll long long #define test \ int t; \ cin >> t; \ while (t--) #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define fo(i, a, n) for (int i = a; i < n; i++) #define rfo(i, a, b) for (int i = a; i >= b; i--) #define bg begin() #define en end() #define fi first #define se second #define ub upper_bound #define lb lower_bound #define pb push_back #define veci vector<int> #define veclli vector<long long int> #define all(x) x.begin(), x.end() #define sci(x) scanf("%d", &x); #define scc(x) scanf("%c", &x); #define scs(x) scanf("%s", x); #define debug(arr, n) \ for (int i = 0; i < n; i++) \ printf("%d ", arr[i]); #define sz(x) x.size() #define loop(x) for (auto it = x.begin(); it != x.end(); it++) ll int power(ll int a, ll int b) { ll int ans = 1, f = a; while (b) { if (b & 1ll) ans = (ans * f) % mod; b = b >> 1ll; f = (f * f) % mod; } return ans; } vector<int> v[mex]; int vis[mex], cnt = 0; void dfs(int n) { vis[n] = 1; cnt++; fo(i, 0, sz(v[n])) if (vis[v[n][i]] == 0) dfs(v[n][i]); } int main() { int n, m; cin >> n >> m; fo(i, 0, m) { int a, b; cin >> a >> b; v[a].pb(b); v[b].pb(a); } int ans = 0; fo(i, 1, n + 1) { if (vis[i] == 0) { dfs(i); ans = max(ans, cnt); cnt = 0; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int mex = 200005; #define ll long long #define test \ int t; \ cin >> t; \ while (t--) #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define fo(i, a, n) for (int i = a; i < n; i++) #define rfo(i, a, b) for (int i = a; i >= b; i--) #define bg begin() #define en end() #define fi first #define se second #define ub upper_bound #define lb lower_bound #define pb push_back #define veci vector<int> #define veclli vector<long long int> #define all(x) x.begin(), x.end() #define sci(x) scanf("%d", &x); #define scc(x) scanf("%c", &x); #define scs(x) scanf("%s", x); #define debug(arr, n) \ for (int i = 0; i < n; i++) \ printf("%d ", arr[i]); #define sz(x) x.size() #define loop(x) for (auto it = x.begin(); it != x.end(); it++) ll int power(ll int a, ll int b) { ll int ans = 1, f = a; while (b) { if (b & 1ll) ans = (ans * f) % mod; b = b >> 1ll; f = (f * f) % mod; } return ans; } vector<int> v[mex]; int vis[mex], cnt = 0; void dfs(int n) { vis[n] = 1; cnt++; fo(i, 0, sz(v[n])) if (vis[v[n][i]] == 0) dfs(v[n][i]); } int main() { int n, m; cin >> n >> m; fo(i, 0, m) { int a, b; cin >> a >> b; v[a].pb(b); v[b].pb(a); } int ans = 0; fo(i, 1, n + 1) { if (vis[i] == 0) { dfs(i); ans = max(ans, cnt); cnt = 0; } } cout << ans << endl; }
replace
3
4
3
4
0
p02573
C++
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(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; }
#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; }
replace
10
12
10
12
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mx = 200009; ll mod = 1000000007; ll a[mx]; /* int siz[mx]; int par[mx]; int parent(int i){ while(i!=par[i]){ i=par[i]; } return i; } void unit(int x,int y){ if(siz[x]<siz[y]){swap(x,y);} int par1=parent(x); int par2=parent(y); par[par2]=par1; siz[par1]+=siz[par2]; }bool same(int a, int b) { return parent(a) == parent(b); } */ vector<int> edges[100000]; int visited[mx]; int dfs(int i) { if (visited[i]) { return 0; } visited[i] = 1; ll ans = 0; for (int j = 0; j < edges[i].size(); j++) { ans += dfs(edges[i][j]); } return ans + 1; } int main() { ios::sync_with_stdio(0); cin.tie(0); ll n, m; cin >> n >> m; int ans = 0; for (int i = 1; i <= m; i++) { int x, y; cin >> x >> y; edges[x].push_back(y); edges[y].push_back(x); } for (int i = 1; i <= n; i++) { if (!visited[i]) { ans = max(ans, dfs(i)); } } cout << ans; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mx = 200009; ll mod = 1000000007; ll a[mx]; /* int siz[mx]; int par[mx]; int parent(int i){ while(i!=par[i]){ i=par[i]; } return i; } void unit(int x,int y){ if(siz[x]<siz[y]){swap(x,y);} int par1=parent(x); int par2=parent(y); par[par2]=par1; siz[par1]+=siz[par2]; }bool same(int a, int b) { return parent(a) == parent(b); } */ vector<int> edges[mx]; int visited[mx]; int dfs(int i) { if (visited[i]) { return 0; } visited[i] = 1; ll ans = 0; for (int j = 0; j < edges[i].size(); j++) { ans += dfs(edges[i][j]); } return ans + 1; } int main() { ios::sync_with_stdio(0); cin.tie(0); ll n, m; cin >> n >> m; int ans = 0; for (int i = 1; i <= m; i++) { int x, y; cin >> x >> y; edges[x].push_back(y); edges[y].push_back(x); } for (int i = 1; i <= n; i++) { if (!visited[i]) { ans = max(ans, dfs(i)); } } cout << ans; }
replace
34
35
34
35
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define pii pair<int, int> using namespace std; const int mxn = 1e5 + 5; const int inf = 1e9; int sz[mxn]; int par[mxn]; int findrep(int u) { return par[u] == u ? u : (par[u] = findrep(par[u])); } void unite(int u, int v) { u = findrep(u); v = findrep(v); if (u == v) return; if (sz[u] > sz[v]) swap(u, v); sz[v] += sz[u]; par[u] = v; } int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { par[i] = i; sz[i] = 1; } for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; unite(u, v); } int ans = 0; for (int i = 1; i <= n; i++) { if (findrep(i) == i) { ans = max(ans, sz[i]); } } cout << ans << endl; }
#include <bits/stdc++.h> #define ll long long #define pii pair<int, int> using namespace std; const int mxn = 2e5 + 5; const int inf = 1e9; int sz[mxn]; int par[mxn]; int findrep(int u) { return par[u] == u ? u : (par[u] = findrep(par[u])); } void unite(int u, int v) { u = findrep(u); v = findrep(v); if (u == v) return; if (sz[u] > sz[v]) swap(u, v); sz[v] += sz[u]; par[u] = v; } int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { par[i] = i; sz[i] = 1; } for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; unite(u, v); } int ans = 0; for (int i = 1; i <= n; i++) { if (findrep(i) == i) { ans = max(ans, sz[i]); } } cout << ans << endl; }
replace
4
5
4
5
0
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> using namespace std; // using namespace boost::multiprecision; typedef long long int ll; typedef long double ld; #define PI 3.141592653589793 #define MOD 1000000007 #define ALL(obj) (obj).begin(), (obj).end() template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1LL << 60; // 四方向への移動ベクトル const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; struct edge { // グラフに使うヤツ ll from, to, cost; }; typedef vector<vector<edge>> G; ll gcd(ll a, ll b) { if (a % b == 0) return (b); else return (gcd(b, a % b)); } struct UnionFind { vector<ll> par, rank, con; UnionFind(ll n) : par(n, -1), rank(n, 0), con(n, 1) {} ll root(ll x) { if (par[x] < 0) return x; return par[x] = root(par[x]); } bool unite(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; con[x] += con[y]; return true; } bool same(ll x, ll y) { ll rx = root(x); ll ry = root(y); return rx == ry; } ll size(int x) { return -par[root(x)]; } }; int main() { ll n, m, ans = 1; cin >> n >> m; UnionFind uf(n); for (ll i = 0; i < m; i++) { ll a, b; cin >> a >> b; a--; b--; uf.unite(a, b); } bool visited[n]; fill(visited, visited + n, false); for (ll i = 0; i < n; i++) { if (visited[i]) continue; ll con = 1; for (ll j = i + 1; j < n; j++) { if (uf.same(i, j)) { visited[j] = true; con++; } } ans = max(con, ans); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> using namespace std; // using namespace boost::multiprecision; typedef long long int ll; typedef long double ld; #define PI 3.141592653589793 #define MOD 1000000007 #define ALL(obj) (obj).begin(), (obj).end() template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1LL << 60; // 四方向への移動ベクトル const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; struct edge { // グラフに使うヤツ ll from, to, cost; }; typedef vector<vector<edge>> G; ll gcd(ll a, ll b) { if (a % b == 0) return (b); else return (gcd(b, a % b)); } struct UnionFind { vector<ll> par, rank, con; UnionFind(ll n) : par(n, -1), rank(n, 0), con(n, 1) {} ll root(ll x) { if (par[x] < 0) return x; return par[x] = root(par[x]); } bool unite(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; con[x] += con[y]; return true; } bool same(ll x, ll y) { ll rx = root(x); ll ry = root(y); return rx == ry; } ll size(int x) { return -par[root(x)]; } }; int main() { ll n, m, ans = 1; cin >> n >> m; UnionFind uf(n); for (ll i = 0; i < m; i++) { ll a, b; cin >> a >> b; a--; b--; uf.unite(a, b); } bool visited[n]; fill(visited, visited + n, false); for (ll i = 0; i < n; i++) { ans = max(ans, uf.size(i)); } cout << ans << endl; return 0; }
replace
83
93
83
84
TLE
p02573
C++
Runtime Error
#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; }
#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; }
replace
4
5
4
5
0
p02573
C++
Runtime Error
#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; }
#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; }
replace
7
8
7
8
0
p02573
C++
Runtime Error
/***** author : C0d1ngPhenomena *****/ #include <bits/stdc++.h> #define endl "\n" #define ll long long int #define TestCases \ int T; \ cin >> T; \ while (T--) #define rep(i, a, b) for (ll i = a; i < b; i++) #define revrep(i, a, b) for (ll i = b - 1; i >= a; i--) #define vll vector<ll> #define vvll vector<vll> #define pll pair<ll, ll> #define vpll vector<pll> #define mp(x, y) make_pair(x, y) #define mod 1000000007 #define inf 1000000000000000001; #define all(c) c.begin(), c.end() #define alld(c) c.begin(), c.end(), greater<int>() #define mem(a, val) memset(a, val, sizeof(a)) #define f first #define s second #define pb push_back using namespace std; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } ll maxi = 0; bool visited[100000]; vector<ll> G[100000]; void dfs(int x) { visited[x] = true; for (auto &i : G[x]) { if (visited[i] == false) { dfs(i); maxi++; } } } int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n; ll m; cin >> n >> m; rep(i, 0, m) { ll x, y; cin >> x >> y; G[x].pb(y); G[y].pb(x); } ll cnt = -1; rep(i, 1, n + 1) { if (!visited[i]) dfs(i); cnt = max(cnt, maxi); maxi = 0; } cout << cnt + 1; return 0; }
/***** author : C0d1ngPhenomena *****/ #include <bits/stdc++.h> #define endl "\n" #define ll long long int #define TestCases \ int T; \ cin >> T; \ while (T--) #define rep(i, a, b) for (ll i = a; i < b; i++) #define revrep(i, a, b) for (ll i = b - 1; i >= a; i--) #define vll vector<ll> #define vvll vector<vll> #define pll pair<ll, ll> #define vpll vector<pll> #define mp(x, y) make_pair(x, y) #define mod 1000000007 #define inf 1000000000000000001; #define all(c) c.begin(), c.end() #define alld(c) c.begin(), c.end(), greater<int>() #define mem(a, val) memset(a, val, sizeof(a)) #define f first #define s second #define pb push_back using namespace std; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } ll maxi = 0; bool visited[1000000]; vector<ll> G[1000000]; void dfs(int x) { visited[x] = true; for (auto &i : G[x]) { if (visited[i] == false) { dfs(i); maxi++; } } } int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n; ll m; cin >> n >> m; rep(i, 0, m) { ll x, y; cin >> x >> y; G[x].pb(y); G[y].pb(x); } ll cnt = -1; rep(i, 1, n + 1) { if (!visited[i]) dfs(i); cnt = max(cnt, maxi); maxi = 0; } cout << cnt + 1; return 0; }
replace
31
33
31
33
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long int ull; #define IO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) const int MOD = 1e9 + 7; int dsu[200005]; int getParent(int num) { if (dsu[num] == num) return num; return dsu[num] = getParent(dsu[num]); } int makeParent(int a, int b) { a = getParent(a); b = getParent(b); dsu[a] = b; } int main() { IO; int n, m; cin >> n >> m; for (int i = 0; i <= n; i++) { dsu[i] = i; } for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; makeParent(a, b); } map<int, int> dd; int ans = 0; for (int i = 0; i <= n; i++) { dd[getParent(i)]++; ans = max(ans, dd[getParent(i)]); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long int ull; #define IO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) const int MOD = 1e9 + 7; int dsu[200005]; int getParent(int num) { if (dsu[num] == num) return num; return dsu[num] = getParent(dsu[num]); } void makeParent(int a, int b) { a = getParent(a); b = getParent(b); dsu[a] = b; } int main() { IO; int n, m; cin >> n >> m; for (int i = 0; i <= n; i++) { dsu[i] = i; } for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; makeParent(a, b); } map<int, int> dd; int ans = 0; for (int i = 0; i <= n; i++) { dd[getParent(i)]++; ans = max(ans, dd[getParent(i)]); } cout << ans << endl; }
replace
15
16
15
16
0
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int a[200020]; int si[200020]; int ff(int x) { return a[x] == x ? x : ff(a[x]); } int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) a[i] = i, si[i] = 1; for (int i = 1; i <= m; i++) { int x, y; cin >> x >> y; x = ff(x); y = ff(y); if (x != y) { a[y] = x; si[x] += si[y]; } } int ma = 1; for (int i = 1; i <= n; i++) { ma = max(ma, si[i]); } cout << ma << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int a[200020]; int si[200020]; int ff(int x) { return a[x] = a[x] == x ? x : ff(a[x]); } int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) a[i] = i, si[i] = 1; for (int i = 1; i <= m; i++) { int x, y; cin >> x >> y; x = ff(x); y = ff(y); if (x != y) { a[y] = x; si[x] += si[y]; } } int ma = 1; for (int i = 1; i <= n; i++) { ma = max(ma, si[i]); } cout << ma << endl; return 0; }
replace
7
8
7
8
TLE
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define F first #define S second #define MP make_pair #define pb push_back #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define LCM(a, b) (a) / __gcd((a), (b)) * (b) #define CEIL(a, b) (a) / (b) + (((a) % (b)) ? 1 : 0) #define log_2(a) (log((a)) / log(2)) #define ln '\n' using namespace std; using LL = long long; using ldouble = long double; using P = pair<int, int>; using LP = pair<LL, LL>; static const int INF = INT_MAX; static const LL LINF = LLONG_MAX; static const int MIN = INT_MIN; static const LL LMIN = LLONG_MIN; static const int MOD = 1e9 + 7; static const int SIZE = 200005; const int dx[] = {0, -1, 1, 0}; const int dy[] = {-1, 0, 0, 1}; vector<LL> Div(LL n) { vector<LL> ret; for (LL i = 1; i * i <= n; ++i) { if (n % i == 0) { ret.pb(i); if (i * i != n) ret.pb(n / i); } } sort(all(ret)); return ret; } int root[SIZE]; int sz[SIZE]; void init() { for (int i = 0; i < SIZE; ++i) { root[i] = i; sz[i] = 1; } } int Root(int x) { if (x == root[x]) return x; int rt = Root(root[x]); sz[x] = sz[rt]; return rt; } bool Unite(int x, int y) { int rx, ry; rx = Root(x); ry = Root(y); if (rx == ry) return false; if (rx < ry) { root[ry] = rx; } else { root[rx] = ry; } sz[rx] += sz[ry]; sz[ry] = sz[rx]; return true; } int main() { ios::sync_with_stdio(false); cin.tie(0); int N; int M; cin >> N >> M; init(); for (int i = 0; i < M; ++i) { int a, b; cin >> a >> b; Unite(a, b); } int res = 0; for (int i = 1; i <= N; ++i) { Root(i); res = max(res, sz[i]); } cout << res << endl; return 0; }
#include <bits/stdc++.h> #define F first #define S second #define MP make_pair #define pb push_back #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define LCM(a, b) (a) / __gcd((a), (b)) * (b) #define CEIL(a, b) (a) / (b) + (((a) % (b)) ? 1 : 0) #define log_2(a) (log((a)) / log(2)) #define ln '\n' using namespace std; using LL = long long; using ldouble = long double; using P = pair<int, int>; using LP = pair<LL, LL>; static const int INF = INT_MAX; static const LL LINF = LLONG_MAX; static const int MIN = INT_MIN; static const LL LMIN = LLONG_MIN; static const int MOD = 1e9 + 7; static const int SIZE = 200005; const int dx[] = {0, -1, 1, 0}; const int dy[] = {-1, 0, 0, 1}; vector<LL> Div(LL n) { vector<LL> ret; for (LL i = 1; i * i <= n; ++i) { if (n % i == 0) { ret.pb(i); if (i * i != n) ret.pb(n / i); } } sort(all(ret)); return ret; } int root[SIZE]; int sz[SIZE]; void init() { for (int i = 0; i < SIZE; ++i) { root[i] = i; sz[i] = 1; } } int Root(int x) { if (x == root[x]) return x; int rt = Root(root[x]); sz[x] = sz[rt]; return rt; } bool Unite(int x, int y) { int rx, ry; rx = Root(x); ry = Root(y); if (rx == ry) return false; if (sz[rx] > sz[ry]) { root[ry] = rx; } else { root[rx] = ry; } sz[rx] += sz[ry]; sz[ry] = sz[rx]; return true; } int main() { ios::sync_with_stdio(false); cin.tie(0); int N; int M; cin >> N >> M; init(); for (int i = 0; i < M; ++i) { int a, b; cin >> a >> b; Unite(a, b); } int res = 0; for (int i = 1; i <= N; ++i) { Root(i); res = max(res, sz[i]); } cout << res << endl; return 0; }
replace
66
67
66
67
TLE
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define LL long long int #define FASTIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); const int N = 1e5 + 5; const int M = 21; const int oo = 1e9 + 5; const LL ooll = (LL)1e18 + 5; const int MOD = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define rand(l, r) uniform_int_distribution<int>(l, r)(rng) clock_t start = clock(); vector<int> g[N]; int viscnt, vis[N]; void dfs(int node) { vis[node] = 1; viscnt++; for (auto it : g[node]) if (!vis[it]) { dfs(it); } } void solve() { int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) { g[i].clear(); vis[i] = 0; } for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } int ans = 0; for (int i = 1; i <= n; ++i) if (!vis[i]) { viscnt = 0; dfs(i); ans = max(ans, viscnt); } cout << ans << '\n'; } int main() { FASTIO; int T = 1; // cin >> T; for (int t = 1; t <= T; ++t) { solve(); } // cerr << fixed << setprecision(10); // cerr << (clock() - start) / ((long double)CLOCKS_PER_SEC) << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define LL long long int #define FASTIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); const int N = 2e5 + 5; const int oo = 1e9 + 5; const LL ooll = (LL)1e18 + 5; const int MOD = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define rand(l, r) uniform_int_distribution<int>(l, r)(rng) clock_t start = clock(); vector<int> g[N]; int viscnt, vis[N]; void dfs(int node) { vis[node] = 1; viscnt++; for (auto it : g[node]) if (!vis[it]) { dfs(it); } } void solve() { int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) { g[i].clear(); vis[i] = 0; } for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } int ans = 0; for (int i = 1; i <= n; ++i) if (!vis[i]) { viscnt = 0; dfs(i); ans = max(ans, viscnt); } cout << ans << '\n'; } int main() { FASTIO; int T = 1; // cin >> T; for (int t = 1; t <= T; ++t) { solve(); } // cerr << fixed << setprecision(10); // cerr << (clock() - start) / ((long double)CLOCKS_PER_SEC) << '\n'; return 0; }
replace
9
11
9
10
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct UnionFind { vector<int> d; UnionFind(int n = 0) : d(n, -1) {} int find(int x) { if (d.at(x) < 0) { return x; } return d.at(x) = find(d.at(x)); } bool unite(int x, int y) { x = find(x); y = find(y); if (x == y) { return false; } if (d.at(x) > d.at(y)) { swap(x, y); } d.at(x) += d.at(y); d.at(y) = x; return true; } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return -d.at(find(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 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct UnionFind { vector<int> d; UnionFind(int n = 0) : d(n, -1) {} int find(int x) { if (d.at(x) < 0) { return x; } return d.at(x) = find(d.at(x)); } bool unite(int x, int y) { x = find(x); y = find(y); if (x == y) { return false; } if (d.at(x) > d.at(y)) { swap(x, y); } d.at(x) += d.at(y); d.at(y) = x; return true; } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return -d.at(find(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--; b--; uf.unite(a, b); } int ans = 0; for (int i = 0; i < n; i++) { ans = max(ans, uf.size(i)); } cout << ans << endl; return 0; }
insert
37
37
37
39
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 5) >= this->size() (which is 5)
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 // #define MOD 998244353 #define INF 1000000010 #define EPS 1e-9 #define F first #define S second #define debug(x) cout << x << endl; #define repi(i, x, n) for (int i = x; i < n; i++) #define rep(i, n) repi(i, 0, n) #define lp(i, n) repi(i, 0, n) #define repn(i, n) for (int i = n; i >= 0; i--) #define int long long #define endl "\n" typedef pair<int, int> PII; typedef pair<int, string> PIS; typedef pair<string, int> PSI; struct UnionFind { vector<int> data; UnionFind(int N) { data.assign(N, -1); } bool unite(int x, int y) { x = find(x), y = find(y); if (x == y) return (false); if (data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return (true); } int find(int k) { if (data[k] < 0) return (k); return (data[k] = find(data[k])); } int size(int k) { return (-data[find(k)]); } }; UnionFind uf(2); signed main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; int ans = 1; rep(i, m) { int a, b; cin >> a >> b; a--; b--; uf.unite(a, b); ans = max(ans, uf.size(a)); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 // #define MOD 998244353 #define INF 1000000010 #define EPS 1e-9 #define F first #define S second #define debug(x) cout << x << endl; #define repi(i, x, n) for (int i = x; i < n; i++) #define rep(i, n) repi(i, 0, n) #define lp(i, n) repi(i, 0, n) #define repn(i, n) for (int i = n; i >= 0; i--) #define int long long #define endl "\n" typedef pair<int, int> PII; typedef pair<int, string> PIS; typedef pair<string, int> PSI; struct UnionFind { vector<int> data; UnionFind(int N) { data.assign(N, -1); } bool unite(int x, int y) { x = find(x), y = find(y); if (x == y) return (false); if (data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return (true); } int find(int k) { if (data[k] < 0) return (k); return (data[k] = find(data[k])); } int size(int k) { return (-data[find(k)]); } }; UnionFind uf(200000); signed main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; int ans = 1; rep(i, m) { int a, b; cin >> a >> b; a--; b--; uf.unite(a, b); ans = max(ans, uf.size(a)); } cout << ans << endl; return 0; }
replace
46
47
46
47
0
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int NMAX = 2e5 + 10; const int MOD = 1e9 + 7; int pre[NMAX], a[NMAX]; inline int find(int x) { return x == pre[x] ? x : find(pre[x]); } int main(int argc, char const *argv[]) { int n, m; scanf("%d%d", &n, &m); for (register int i = 1; i <= n; i++) pre[i] = i; int u, v; while (m--) { scanf("%d%d", &u, &v); int u_pre = find(u), v_pre = find(v); if (u_pre == v_pre) continue; pre[u_pre] = v_pre; } int ans = 0; for (register int i = 1; i <= n; i++) a[find(i)] += 1, ans = max(ans, a[find(i)]); printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int NMAX = 2e5 + 10; const int MOD = 1e9 + 7; int pre[NMAX], a[NMAX]; inline int find(int x) { return pre[x] = (x == pre[x] ? x : find(pre[x])); } int main(int argc, char const *argv[]) { int n, m; scanf("%d%d", &n, &m); for (register int i = 1; i <= n; i++) pre[i] = i; int u, v; while (m--) { scanf("%d%d", &u, &v); int u_pre = find(u), v_pre = find(v); if (u_pre == v_pre) continue; pre[u_pre] = v_pre; } int ans = 0; for (register int i = 1; i <= n; i++) a[find(i)] += 1, ans = max(ans, a[find(i)]); printf("%d\n", ans); return 0; }
replace
8
9
8
9
TLE
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int>> d(n); vector<int> list(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; d[a].push_back(b); d[b].push_back(a); } int ans = 0; for (int i = 0; i < n; i++) { if (list[i] == 1) continue; queue<int> q; q.push(i); list[i] = 1; int sum = 1; while (!q.empty()) { int p = q.front(); q.pop(); for (auto np : d[p]) { list[np] = 1; q.push(np); sum += 1; } } ans = max(ans, sum); } cout << ans; }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int>> d(n); vector<int> list(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; d[a].push_back(b); d[b].push_back(a); } int ans = 0; for (int i = 0; i < n; i++) { if (list[i] == 1) continue; queue<int> q; q.push(i); list[i] = 1; int sum = 1; while (!q.empty()) { int p = q.front(); q.pop(); for (auto np : d[p]) { if (list[np] == 1) continue; list[np] = 1; q.push(np); sum += 1; } } ans = max(ans, sum); } cout << ans; }
insert
28
28
28
30
TLE
p02573
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define X first #define Y second #define nl '\n' #define AC return 0 #define pb(a) push_back(a) #define mst(a, b) memset(a, b, sizeof a) #define rep(i, n) for (int i = 0; (i) < (n); i++) #define rep1(i, n) for (int i = 1; (i) <= (n); i++) #define scd(a) scanf("%lld", &a) #define scdd(a, b) scanf("%lld%lld", &a, &b) #define scs(s) scanf("%s", s) // #pragma GCC optimize(2) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18; const int N = 1e6 + 10, M = 2e6 + 10, mod = 1e9 + 7, inf = 0x3f3f3f; ll cnt[N], pre[N]; int find(int x) { return x == pre[x] ? x : find(pre[x]); } int main() { IOS; ll n, m, ans = MIN; cin >> n >> m; rep1(i, n) pre[i] = i; while (m--) { int a, b; cin >> a >> b; int x = find(a), y = find(b); if (x != y) pre[x] = y; } rep1(i, n) { int x = find(i); cnt[x]++, ans = max(ans, cnt[x]); } cout << ans << nl; AC; }
#include <bits/stdc++.h> #define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define X first #define Y second #define nl '\n' #define AC return 0 #define pb(a) push_back(a) #define mst(a, b) memset(a, b, sizeof a) #define rep(i, n) for (int i = 0; (i) < (n); i++) #define rep1(i, n) for (int i = 1; (i) <= (n); i++) #define scd(a) scanf("%lld", &a) #define scdd(a, b) scanf("%lld%lld", &a, &b) #define scs(s) scanf("%s", s) // #pragma GCC optimize(2) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18; const int N = 1e6 + 10, M = 2e6 + 10, mod = 1e9 + 7, inf = 0x3f3f3f; ll cnt[N], pre[N]; int find(int x) { return x == pre[x] ? x : pre[x] = find(pre[x]); } int main() { IOS; ll n, m, ans = MIN; cin >> n >> m; rep1(i, n) pre[i] = i; while (m--) { int a, b; cin >> a >> b; int x = find(a), y = find(b); if (x != y) pre[x] = y; } rep1(i, n) { int x = find(i); cnt[x]++, ans = max(ans, cnt[x]); } cout << ans << nl; AC; }
replace
23
24
23
24
TLE
p02573
C++
Runtime Error
// control+option+n to run! #include <bits/stdc++.h> using namespace std; #define pb push_back #define ll long long #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define NEGFOR(i, a, b) for (ll i = (a); i > (b); i--) #define vll vector<long long> #define sll set<long long> #define ld long double #define inf 1000000000000000000; #define mll multiset<long long> #define nn << "\n" #define F(i, b) for (ll i = 0; i < b; i++) // 10^8 operations per second // greatest int is 2,147,483,647 // greates long long is 9.22337204e18 // ALL FUNCTIONS SHOULD BE LL!!!! int n, m; ll co = 0; vector<int> v[100002]; bool visited[100002]; void dfs(int node) { co++; visited[node] = true; for (int i = 0; i < v[node].size(); ++i) { int nxt = v[node][i]; if (visited[nxt] == false) dfs(nxt); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (int i = 1; i <= m; ++i) { int a, b; cin >> a >> b; v[a].push_back(b); v[b].push_back(a); } vll vec; for (int i = 0; i < n; ++i) { if (visited[i] == false) { dfs(i); vec.pb(co); co = 0; } } ll x = vec.size(); sort(vec.begin(), vec.end()); ll currdelete = 0; ll ans = 0; FOR(i, 0, vec.size()) { ans += vec[i] - currdelete; currdelete = vec[i]; } cout << ans; cout << "\n"; // GET RID OF THIS FOR THE ACTUAL PROGRAM!!!! }
// control+option+n to run! #include <bits/stdc++.h> using namespace std; #define pb push_back #define ll long long #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define NEGFOR(i, a, b) for (ll i = (a); i > (b); i--) #define vll vector<long long> #define sll set<long long> #define ld long double #define inf 1000000000000000000; #define mll multiset<long long> #define nn << "\n" #define F(i, b) for (ll i = 0; i < b; i++) // 10^8 operations per second // greatest int is 2,147,483,647 // greates long long is 9.22337204e18 // ALL FUNCTIONS SHOULD BE LL!!!! int n, m; ll co = 0; vector<int> v[500002]; bool visited[500002]; void dfs(int node) { co++; visited[node] = true; for (int i = 0; i < v[node].size(); ++i) { int nxt = v[node][i]; if (visited[nxt] == false) dfs(nxt); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (int i = 1; i <= m; ++i) { int a, b; cin >> a >> b; v[a].push_back(b); v[b].push_back(a); } vll vec; for (int i = 0; i < n; ++i) { if (visited[i] == false) { dfs(i); vec.pb(co); co = 0; } } ll x = vec.size(); sort(vec.begin(), vec.end()); ll currdelete = 0; ll ans = 0; FOR(i, 0, vec.size()) { ans += vec[i] - currdelete; currdelete = vec[i]; } cout << ans; cout << "\n"; // GET RID OF THIS FOR THE ACTUAL PROGRAM!!!! }
replace
20
22
20
22
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) struct UnionFind { vector<int> d; // データ UnionFind(int n = 0) : d(n, -1) {} // 初期値は全部根(-1)とする int find(int x) { if (d[x] < 0) return x; return d[x] = find(d[x]); } bool unite(int x, int y) { // 2つ頂点をくっつける x = find(x); y = find(y); if (x == y) return false; // 一致していればOK if (d[x] > d[y]) swap(x, y); // サイズが大きいものをxとする(根は負なので大小関係に注意) d[x] += d[y]; // サイズの合算 d[y] = x; // 根をxとする return false; } bool same(int x, int y) { // 同じ集合に属しているかを判定する return find(x) == find(y); } int size(int x) { // サイズを求める(根はマイナスなので、マイナスをとる) return -d[find(x)]; } }; int deg[100005]; vector<int> to[100005]; int main() { int n, m; cin >> n >> m; UnionFind uf(n); rep(i, m) { int a, b; cin >> a >> b; a--; b--; deg[a]++; deg[b]++; uf.unite(a, b); } int saidai = 0; rep(i, n) { saidai = max(saidai, uf.size(i)); } cout << saidai << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) struct UnionFind { vector<int> d; // データ UnionFind(int n = 0) : d(n, -1) {} // 初期値は全部根(-1)とする int find(int x) { if (d[x] < 0) return x; return d[x] = find(d[x]); } bool unite(int x, int y) { // 2つ頂点をくっつける x = find(x); y = find(y); if (x == y) return false; // 一致していればOK if (d[x] > d[y]) swap(x, y); // サイズが大きいものをxとする(根は負なので大小関係に注意) d[x] += d[y]; // サイズの合算 d[y] = x; // 根をxとする return false; } bool same(int x, int y) { // 同じ集合に属しているかを判定する return find(x) == find(y); } int size(int x) { // サイズを求める(根はマイナスなので、マイナスをとる) return -d[find(x)]; } }; int deg[200200]; vector<int> to[200200]; int main() { int n, m; cin >> n >> m; UnionFind uf(n); rep(i, m) { int a, b; cin >> a >> b; a--; b--; deg[a]++; deg[b]++; uf.unite(a, b); } int saidai = 0; rep(i, n) { saidai = max(saidai, uf.size(i)); } cout << saidai << endl; return 0; }
replace
29
31
29
31
0
p02573
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <vector> using namespace std; const int MAXN = 1e5 + 7; int N, M; vector<int> graph[MAXN]; bool visited[MAXN]; int DFS(int cur) { int ret = 1; visited[cur] = true; for (auto adj : graph[cur]) { if (visited[adj]) continue; ret += DFS(adj); } return ret; } int main() { scanf("%d%d", &N, &M); for (int i = 0; i < M; i++) { int x, y; scanf("%d%d", &x, &y); graph[x].push_back(y); graph[y].push_back(x); } int ans = 0; for (int i = 1; i <= N; i++) { if (visited[i]) continue; ans = max(ans, DFS(i)); } printf("%d\n", ans); return 0; }
#include <algorithm> #include <cstdio> #include <vector> using namespace std; const int MAXN = 2e5 + 7; int N, M; vector<int> graph[MAXN]; bool visited[MAXN]; int DFS(int cur) { int ret = 1; visited[cur] = true; for (auto adj : graph[cur]) { if (visited[adj]) continue; ret += DFS(adj); } return ret; } int main() { scanf("%d%d", &N, &M); for (int i = 0; i < M; i++) { int x, y; scanf("%d%d", &x, &y); graph[x].push_back(y); graph[y].push_back(x); } int ans = 0; for (int i = 1; i <= N; i++) { if (visited[i]) continue; ans = max(ans, DFS(i)); } printf("%d\n", ans); return 0; }
replace
6
7
6
7
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000; vector<int> adj[MAXN]; bool visited[MAXN]; int n, m, mx = 0, curr = 0; void dfs(int node) { visited[node] = true; for (int next : adj[node]) { if (!visited[next]) { curr++; dfs(next); } } } int main() { cin >> n >> m; int a, b; for (int i = 0; i < m; i++) { cin >> a >> b; a--; b--; adj[a].push_back(b); adj[b].push_back(a); } for (int i = 0; i < n; i++) { if (!visited[i]) { curr = 1; dfs(i); mx = max(mx, curr); } } cout << mx << endl; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 200000; vector<int> adj[MAXN]; bool visited[MAXN]; int n, m, mx = 0, curr = 0; void dfs(int node) { visited[node] = true; for (int next : adj[node]) { if (!visited[next]) { curr++; dfs(next); } } } int main() { cin >> n >> m; int a, b; for (int i = 0; i < m; i++) { cin >> a >> b; a--; b--; adj[a].push_back(b); adj[b].push_back(a); } for (int i = 0; i < n; i++) { if (!visited[i]) { curr = 1; dfs(i); mx = max(mx, curr); } } cout << mx << endl; }
replace
2
3
2
3
0
p02573
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; using P = pair<int, int>; int main() { int N, M; cin >> N >> M; vector<int> A(M), B(M); vector<vector<int>> f(N); for (int i = 0; i < M; i++) { cin >> A.at(i) >> B.at(i); int a = A.at(i) - 1; int b = B.at(i) - 1; if (find(f[a].begin(), f[a].end(), b) == f[a].end()) { f[a].push_back(b); } if (find(f[b].begin(), f[b].end(), a) == f[b].end()) { f[b].push_back(a); } } int ans = 0; vector<bool> seen(N, false); for (int i = 0; i < N; i++) { if (seen.at(i)) continue; seen.at(i) = true; int num = 1; queue<int> q; q.push(i); while (!q.empty()) { int j = q.front(); q.pop(); for (auto v : f[j]) { if (seen.at(v)) continue; seen.at(v) = true; q.push(v); num++; } } ans = max(ans, num); } cout << ans; return 0; }
#include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; using P = pair<int, int>; int main() { int N, M; cin >> N >> M; vector<int> A(M), B(M); vector<vector<int>> f(N); for (int i = 0; i < M; i++) { cin >> A.at(i) >> B.at(i); int a = A.at(i) - 1; int b = B.at(i) - 1; f[a].push_back(b); f[b].push_back(a); } int ans = 0; vector<bool> seen(N, false); for (int i = 0; i < N; i++) { if (seen.at(i)) continue; seen.at(i) = true; int num = 1; queue<int> q; q.push(i); while (!q.empty()) { int j = q.front(); q.pop(); for (auto v : f[j]) { if (seen.at(v)) continue; seen.at(v) = true; q.push(v); num++; } } ans = max(ans, num); } cout << ans; return 0; }
replace
16
22
16
18
TLE
p02573
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define pi acos(-1.0) #define pb push_back #define vi vector<int> #define mapii map<int, int> #define mapci map<char, int> #define mapsi map<string, int> #define FOR(i, n) for (int i = 0; i < n; i++) #define CP(n) cout << "Case " << n << ": " #define fr freopen("input.txt", "r", stdin) #define fw freopen("output.txt", "w", stdout) #define MAX 1000007 #define all(x) (x.begin(), x.end()) #define debug(x, c) cout << x << ": " << c << " "; #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(0) using namespace std; int par[200005]; mapii mp; int find_parent(int a) { if (par[a] == a) return a; return par[a] = find_parent(par[a]); } void dsu(int a, int b) { int x = find_parent(a); int y = find_parent(b); par[x] = y; par[y] = x; return; } int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) par[i] = i; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; dsu(a, b); } int ans = 1; for (int i = 1; i <= n; i++) mp[find_parent(i)]++; for (auto x : mp) ans = max(ans, x.second); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define pi acos(-1.0) #define pb push_back #define vi vector<int> #define mapii map<int, int> #define mapci map<char, int> #define mapsi map<string, int> #define FOR(i, n) for (int i = 0; i < n; i++) #define CP(n) cout << "Case " << n << ": " #define fr freopen("input.txt", "r", stdin) #define fw freopen("output.txt", "w", stdout) #define MAX 1000007 #define all(x) (x.begin(), x.end()) #define debug(x, c) cout << x << ": " << c << " "; #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(0) using namespace std; int par[200005]; mapii mp; int find_parent(int a) { if (par[a] == a) return a; return par[a] = find_parent(par[a]); } void dsu(int a, int b) { int x = find_parent(a); int y = find_parent(b); if (y > x) par[y] = x; else par[x] = y; return; } int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) par[i] = i; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; dsu(a, b); } int ans = 1; for (int i = 1; i <= n; i++) mp[find_parent(i)]++; for (auto x : mp) ans = max(ans, x.second); cout << ans << endl; return 0; }
replace
29
31
29
33
-11
p02573
C++
Runtime Error
// R<3S #include <bits/stdc++.h> #define hell 1000000007 #define PI 3.14159265358979323844 #define mp make_pair #define pb push_back #define fi first #define se second #define ALL(v) v.begin(), v.end() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define endl "\n" #define vecmax(v) max_element(all(v)) #define vecmin(v) min_element(all(v)) #define GCD(m, n) __gcd(m, n) #define LCM(m, n) m *(n / GCD(m, n)) #define rep(i, n) for (int i = 0; i < (n); ++i) #define repA(i, a, n) for (int i = a; i <= (n); ++i) #define repD(i, a, n) for (int i = a; i >= (n); --i) #define trav(x) for (auto i : x) #define sz(a) (int)a.size() #define sl(a) (int)a.length() #define int long long #define ld long double #define pii std::pair<int, int> #define pll std::pair<ll, ll> #define vi vector<int> #define vl vector<ll> #define vvi vector<vi> #define vii vector<pii> #define mii map<int, int> #define mll map<ll, ll> using namespace std; vector<int> adj[100005]; bool vis[100005]; int cnt; void dfs(int node) { vis[node] = true; cnt++; for (int i = 0; i < adj[node].size(); ++i) { if (!vis[adj[node][i]]) dfs(adj[node][i]); } } void solve() { int n, m; cin >> n >> m; memset(vis, false, sizeof vis); rep(i, m) { int x, y; cin >> x >> y; adj[x].pb(y); adj[y].pb(x); } int maxm = 0; repA(i, 1, n) { cnt = 0; if (!vis[i]) dfs(i); maxm = max(maxm, cnt); } cout << maxm; } signed main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; t = 1; // cin>>t; while (t--) { solve(); } return 0; }
// R<3S #include <bits/stdc++.h> #define hell 1000000007 #define PI 3.14159265358979323844 #define mp make_pair #define pb push_back #define fi first #define se second #define ALL(v) v.begin(), v.end() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define endl "\n" #define vecmax(v) max_element(all(v)) #define vecmin(v) min_element(all(v)) #define GCD(m, n) __gcd(m, n) #define LCM(m, n) m *(n / GCD(m, n)) #define rep(i, n) for (int i = 0; i < (n); ++i) #define repA(i, a, n) for (int i = a; i <= (n); ++i) #define repD(i, a, n) for (int i = a; i >= (n); --i) #define trav(x) for (auto i : x) #define sz(a) (int)a.size() #define sl(a) (int)a.length() #define int long long #define ld long double #define pii std::pair<int, int> #define pll std::pair<ll, ll> #define vi vector<int> #define vl vector<ll> #define vvi vector<vi> #define vii vector<pii> #define mii map<int, int> #define mll map<ll, ll> using namespace std; vector<int> adj[200005]; bool vis[200005]; int cnt; void dfs(int node) { vis[node] = true; cnt++; for (int i = 0; i < adj[node].size(); ++i) { if (!vis[adj[node][i]]) dfs(adj[node][i]); } } void solve() { int n, m; cin >> n >> m; memset(vis, false, sizeof vis); rep(i, m) { int x, y; cin >> x >> y; adj[x].pb(y); adj[y].pb(x); } int maxm = 0; repA(i, 1, n) { cnt = 0; if (!vis[i]) dfs(i); maxm = max(maxm, cnt); } cout << maxm; } signed main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; t = 1; // cin>>t; while (t--) { solve(); } return 0; }
replace
35
37
35
37
0
p02573
C++
Runtime Error
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define DEBUG(x) cout << #x << "=" << x << endl #define DEBUG2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl typedef long long ll; // #define LOCAL const int MAXN = 2e5 + 10; const ll MOD = 17; ll _gcd(ll a, ll b) { if (b == 0) return a; return _gcd(b, a % b); } ll gcd(ll a, ll b) { a = abs(a), b = abs(b); if (a < b) swap(a, b); return _gcd(a, b); } ll qpow(ll a, ll n) { ll rt = 1; while (n) { if (n & 1) rt = (rt * a) % MOD; a = a * a % MOD; n >>= 1; } return rt; } ll factor[MAXN]; void cal_factor() { factor[0] = 1; for (int u = 1; u < MAXN; u++) { factor[u] = (factor[u - 1] * u) % MOD; } } ll C(ll n, ll k) { return factor[n] * qpow(factor[n - k], MOD - 2) % MOD * qpow(factor[k], MOD - 2) % MOD; } int fa[MAXN]; int cnt[MAXN]; void init() { for (int u = 0; u < MAXN; u++) { fa[u] = u; cnt[u] = 1; } } int rfind(int r) { if (fa[r] == r) return r; int x = rfind(fa[r]); fa[r] = x; return x; } int runion(int a, int b) { int ta = rfind(a), tb = rfind(b); if (ta != tb) { fa[tb] = ta; cnt[ta] += cnt[tb]; } } void solve() { ios::sync_with_stdio(false); cin.tie(0); init(); int n, m; cin >> n >> m; set<pair<int, int>> ex; for (int u = 0; u < m; u++) { int a, b; cin >> a >> b; if (a > b) swap(a, b); if (ex.count({a, b})) continue; ex.insert({a, b}); runion(a, b); } vector<int> sz; int verify = 0; for (int u = 1; u <= n; u++) { if (fa[u] == u) { sz.push_back(cnt[u]); verify += cnt[u]; } } // assert(verify==n); sort(sz.begin(), sz.end()); int nsz = sz.size(); int delta = 0; int grs = 0; for (int u = 0; u < nsz; u++) { if (delta + sz[u] <= 0) continue; int t = sz[u] + delta; grs += t; delta -= t; } cout << grs; } int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); #endif solve(); }
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define DEBUG(x) cout << #x << "=" << x << endl #define DEBUG2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl typedef long long ll; // #define LOCAL const int MAXN = 2e5 + 10; const ll MOD = 17; ll _gcd(ll a, ll b) { if (b == 0) return a; return _gcd(b, a % b); } ll gcd(ll a, ll b) { a = abs(a), b = abs(b); if (a < b) swap(a, b); return _gcd(a, b); } ll qpow(ll a, ll n) { ll rt = 1; while (n) { if (n & 1) rt = (rt * a) % MOD; a = a * a % MOD; n >>= 1; } return rt; } ll factor[MAXN]; void cal_factor() { factor[0] = 1; for (int u = 1; u < MAXN; u++) { factor[u] = (factor[u - 1] * u) % MOD; } } ll C(ll n, ll k) { return factor[n] * qpow(factor[n - k], MOD - 2) % MOD * qpow(factor[k], MOD - 2) % MOD; } int fa[MAXN]; int cnt[MAXN]; void init() { for (int u = 0; u < MAXN; u++) { fa[u] = u; cnt[u] = 1; } } int rfind(int r) { if (fa[r] == r) return r; int x = rfind(fa[r]); fa[r] = x; return x; } void runion(int a, int b) { int ta = rfind(a), tb = rfind(b); if (ta != tb) { fa[tb] = ta; cnt[ta] += cnt[tb]; } } void solve() { ios::sync_with_stdio(false); cin.tie(0); init(); int n, m; cin >> n >> m; set<pair<int, int>> ex; for (int u = 0; u < m; u++) { int a, b; cin >> a >> b; if (a > b) swap(a, b); if (ex.count({a, b})) continue; ex.insert({a, b}); runion(a, b); } vector<int> sz; int verify = 0; for (int u = 1; u <= n; u++) { if (fa[u] == u) { sz.push_back(cnt[u]); verify += cnt[u]; } } // assert(verify==n); sort(sz.begin(), sz.end()); int nsz = sz.size(); int delta = 0; int grs = 0; for (int u = 0; u < nsz; u++) { if (delta + sz[u] <= 0) continue; int t = sz[u] + delta; grs += t; delta -= t; } cout << grs; } int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); #endif solve(); }
replace
68
69
68
69
0
p02573
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int MAX = 1000 * 100 + 11; vector<int> a[MAX]; vector<bool> vis(MAX); int n, m; int res = 0, curr = 0; void dfs(int currNode) { if (vis[currNode]) { return; } curr++; vis[currNode] = true; for (auto it : a[currNode]) { dfs(it); } } int main() { cin >> n >> m; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; x--; y--; a[x].push_back(y); a[y].push_back(x); } for (int i = 0; i < n; i++) { dfs(i); res = max(res, curr); curr = 0; } cout << res; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAX = 2000 * 100 + 11; vector<int> a[MAX]; vector<bool> vis(MAX); int n, m; int res = 0, curr = 0; void dfs(int currNode) { if (vis[currNode]) { return; } curr++; vis[currNode] = true; for (auto it : a[currNode]) { dfs(it); } } int main() { cin >> n >> m; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; x--; y--; a[x].push_back(y); a[y].push_back(x); } for (int i = 0; i < n; i++) { dfs(i); res = max(res, curr); curr = 0; } cout << res; return 0; }
replace
4
5
4
5
0
p02573
C++
Runtime Error
/* vrrtll==???>;::::~~~~~~......`.`````````````````````...-?777!_.._?7u,~~~::::;>>??=lllttrrzu rtll==??>>;::::~~~~......`.`````````````````` ..J77!`````````...`..._T,~~~~:::;;>??==lttrrv tll=??>>;:::~~~~......``````````````````..J7^ ` `` ` `` .,```````...._4,.~~~::;;>>?===lttr l=???>;;::~~~......`````HTSu,.`` `..J7! ` `` .J"~N```````````..?&.~~~~::;;>>?==llt =??>;;::~~~~.....``````.@????7SJ.?= ` ` `` .J=....J; ``````````..h..~~~~::;;>??=ll ?>>;::~~~~.....````````.D?>>?>?>?8+.`` `.J"_......_b` ````````.S_.~~~~::;;>??=l >;;::~~~~....``````````.C>??>>>?>>>?8J.` ```..Y~..........J; ` ` ``````` G...~~~~::;>??= ;;::~~~....```````` `..W1>>?>>>>?>>>>>?S,.`.7^.............-N`` ` ``````` 6...~~~~::;>?? ;:~~~~....``````` ..7` d??>>?>?>>?>>?>>1udMgggNNNNggJ.......([ `````.L...~~~~::;>? :~~~.....`````` .7` `K>?>?>>>>>>+ugNMMMB""7<!~~<?7TWMNNa,..w.` ` ` ` `````,)....~~:::;> ~~~....``````.J^ ` #>>?>>>?jgMMM9=_................-?TMMa,b` ` ` ` ````(,...~~~~:;; ~~~....``` .7`` ` @?>>?1uMM#=.........................(TMNa...... ` ``````4....~~~::; ~~~...`` .=`` ` ` .b>>jgNH".................`.............?HNmx??17TYY9SA+(..L....~~~:: ~....` ,^`` ` ` .b+dN#^............6..-(,-...`............(HMm+>>>>>?>>????zOM_.~~~:: .... .=``` `` ` ...JNMM^..........`..._n.(MMN,....`..`.........?MNe<>>?>??>????d^...~~~: ~...v```` ` ..-Z""!_..(M@_........`........?7MMMMp.................-TNN+?>>>????1d4-..-(Jk9 ..(^`...zY"!_........(MD..............`......JMMMMp....`..`..`......./MNx>??>>?1d!.h7=~(??= (v_`,R_.............(NF..(/..(&,...`..........?MMMM;..................(MMs>>?1&T"!``....(1= t..`` 4,...........(N@....?,(NMNR_.....`..`....(WMM$..`....`..`..`....._HMe7=```````....~_1 ...````.4,........-dM:.....(7MMMNR-.....................`............(.?^ `` ``````....~~~ ...``````,4,....`.(NF........(MMMMb..`....--................`....(.7! ` ````....~~: ..````` ` `.5J_...JMt.........?NMMM[...`.HH5._(J7[...`...`...--?^` ` `````....~~~: ...````` ` ` 7a,.dM{....`...../MMMN......(J=` .>......._(/= ` ` `````...~~~: ....```` `` (4MN{..........._7"^...(/^ `.C....-(J=` ` ` ```....~~~: ....````` ` JdM[...`...`........`_3.. ..?!..(-7! ` ` ``````....~~~:: r...`````` ` ``(CJMb..............`......__..-(?^ ` ` `````....~~::; J/...````` ` `,3>+MN-.`..`...`..........._(J=`` ` ` ```````....~~~::; _j,..`.```` ``.5>>?dNb...`......`......_-?'` ` `````....~~~::;; ~~j,..```````.D??>>>MM/....`........(-=` ` ` ` ```````...~~~:::;> ~~~j,...````.E??>??>?MN-.........(J= ` ` ` ``````....~~~~::;?? :~~~?,...``.@>?>?>>??dMN_....-(?^ ` ` ` ` ````````...~~~~:;;>?? ::~~~?/....K??????>>?>dMN-_(7! ` ` ` ````````....~~~:::>>??l ;:::~~/e.(K==?????????<dM"! ` ` ` ` `` ``````...~~~~:::;>??=l @TT_beginner */ #include <bits/stdc++.h> using namespace std; #define ok1 cerr << "ok1\n"; #define ok2 cerr << "ok2\n"; #define M LLONG_MAX #define rep(i, n) for (int i = 0; i < n; ++i) #define REP(i, s, n) for (int i = (s); i < (n); ++i) #define repr(i, n) for (int i = n - 1; i >= 0; --i) #define REPR(i, s, n) for (int i = (s); i >= (n); --(i)) #define all(a) (a).begin(), (a).end() #define reall(a) (a).rbegin(), (a).rend() #define pb emplace_back // emplace_backの方が早いが慣れているため #define DOUBLE fixed << setprecision(15) #define fi first #define se second #define mp make_pair #define mt make_tuple const double pi = acos(-1.0L); typedef vector<int> vi; typedef vector<string> vs; typedef long long ll; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef vector<char> vc; typedef vector<double> vd; typedef vector<bool> vb; typedef deque<ll> dll; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> TLL; typedef vector<P> vP; typedef vector<TLL> vTLL; const ll mod = 1e9 + 7; // const ll mod = 998244353; ll dy[4] = {1, 0, -1, 0}; ll dx[4] = {0, 1, 0, -1}; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class A, class B> ostream &operator<<(ostream &ost, const pair<A, B> &p) { ost << "{ " << p.first << ", " << p.second << " }"; return ost; } template <class T> ostream &operator<<(ostream &ost, const vector<T> &v) { ost << "{ "; for (int i = 0; i < v.size(); i++) { if (i) ost << ", "; ost << v[i]; } ost << " }"; return ost; } template <class A, class B> ostream &operator<<(ostream &ost, const map<A, B> &v) { ost << "{ "; for (auto p : v) { ost << "{ " << p.first << ", " << p.second << " }"; } ost << " }"; return ost; } bool out_check(ll a, ll b) { return (0 <= a && a < b); } double pitagoras(ll a, ll b, ll c, ll d) { double dx = a - b, dy = c - d; return pow(dx * dx + dy * dy, 0.5); } ll modpow(ll a, ll b) { ll c = 1; while (b > 0) { if (b & 1) { c = a * c % mod; } a = a * a % mod; b >>= 1; } return c; } ll modinv(ll a) { return modpow(a, mod - 2); } void Yes(bool x) { cout << ((x) ? "Yes\n" : "No\n"); } void YES(bool x) { cout << ((x) ? "YES\n" : "NO\n"); } void yes(bool x) { cout << ((x) ? "yes\n" : "no\n"); } void Yay(bool x) { cout << ((x) ? "Yay!\n" : ":(\n"); } struct UnionFind { private: vector<long long> data; public: UnionFind(long long size) : data(size, -1) {} bool unite(long long x, long long y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool same(long long x, long long y) { return root(x) == root(y); } int root(long long x) { return data[x] < 0 ? x : data[x] = root(data[x]); } ll size(long long x) { return -data[root(x)]; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); // not Interactive ll n, m, k, l, r, d = 0, Q, ans = 0, ret = M; string s, t; cin >> n >> m; vll a(m), b(m); UnionFind tree(n); rep(i, m) { cin >> a[i] >> b[i]; tree.unite(a[i], b[i]); } rep(i, n) { chmax(ans, tree.size(i + 1)); } cout << ans << endl; }
/* vrrtll==???>;::::~~~~~~......`.`````````````````````...-?777!_.._?7u,~~~::::;>>??=lllttrrzu rtll==??>>;::::~~~~......`.`````````````````` ..J77!`````````...`..._T,~~~~:::;;>??==lttrrv tll=??>>;:::~~~~......``````````````````..J7^ ` `` ` `` .,```````...._4,.~~~::;;>>?===lttr l=???>;;::~~~......`````HTSu,.`` `..J7! ` `` .J"~N```````````..?&.~~~~::;;>>?==llt =??>;;::~~~~.....``````.@????7SJ.?= ` ` `` .J=....J; ``````````..h..~~~~::;;>??=ll ?>>;::~~~~.....````````.D?>>?>?>?8+.`` `.J"_......_b` ````````.S_.~~~~::;;>??=l >;;::~~~~....``````````.C>??>>>?>>>?8J.` ```..Y~..........J; ` ` ``````` G...~~~~::;>??= ;;::~~~....```````` `..W1>>?>>>>?>>>>>?S,.`.7^.............-N`` ` ``````` 6...~~~~::;>?? ;:~~~~....``````` ..7` d??>>?>?>>?>>?>>1udMgggNNNNggJ.......([ `````.L...~~~~::;>? :~~~.....`````` .7` `K>?>?>>>>>>+ugNMMMB""7<!~~<?7TWMNNa,..w.` ` ` ` `````,)....~~:::;> ~~~....``````.J^ ` #>>?>>>?jgMMM9=_................-?TMMa,b` ` ` ` ````(,...~~~~:;; ~~~....``` .7`` ` @?>>?1uMM#=.........................(TMNa...... ` ``````4....~~~::; ~~~...`` .=`` ` ` .b>>jgNH".................`.............?HNmx??17TYY9SA+(..L....~~~:: ~....` ,^`` ` ` .b+dN#^............6..-(,-...`............(HMm+>>>>>?>>????zOM_.~~~:: .... .=``` `` ` ...JNMM^..........`..._n.(MMN,....`..`.........?MNe<>>?>??>????d^...~~~: ~...v```` ` ..-Z""!_..(M@_........`........?7MMMMp.................-TNN+?>>>????1d4-..-(Jk9 ..(^`...zY"!_........(MD..............`......JMMMMp....`..`..`......./MNx>??>>?1d!.h7=~(??= (v_`,R_.............(NF..(/..(&,...`..........?MMMM;..................(MMs>>?1&T"!``....(1= t..`` 4,...........(N@....?,(NMNR_.....`..`....(WMM$..`....`..`..`....._HMe7=```````....~_1 ...````.4,........-dM:.....(7MMMNR-.....................`............(.?^ `` ``````....~~~ ...``````,4,....`.(NF........(MMMMb..`....--................`....(.7! ` ````....~~: ..````` ` `.5J_...JMt.........?NMMM[...`.HH5._(J7[...`...`...--?^` ` `````....~~~: ...````` ` ` 7a,.dM{....`...../MMMN......(J=` .>......._(/= ` ` `````...~~~: ....```` `` (4MN{..........._7"^...(/^ `.C....-(J=` ` ` ```....~~~: ....````` ` JdM[...`...`........`_3.. ..?!..(-7! ` ` ``````....~~~:: r...`````` ` ``(CJMb..............`......__..-(?^ ` ` `````....~~::; J/...````` ` `,3>+MN-.`..`...`..........._(J=`` ` ` ```````....~~~::; _j,..`.```` ``.5>>?dNb...`......`......_-?'` ` `````....~~~::;; ~~j,..```````.D??>>>MM/....`........(-=` ` ` ` ```````...~~~:::;> ~~~j,...````.E??>??>?MN-.........(J= ` ` ` ``````....~~~~::;?? :~~~?,...``.@>?>?>>??dMN_....-(?^ ` ` ` ` ````````...~~~~:;;>?? ::~~~?/....K??????>>?>dMN-_(7! ` ` ` ````````....~~~:::>>??l ;:::~~/e.(K==?????????<dM"! ` ` ` ` `` ``````...~~~~:::;>??=l @TT_beginner */ #include <bits/stdc++.h> using namespace std; #define ok1 cerr << "ok1\n"; #define ok2 cerr << "ok2\n"; #define M LLONG_MAX #define rep(i, n) for (int i = 0; i < n; ++i) #define REP(i, s, n) for (int i = (s); i < (n); ++i) #define repr(i, n) for (int i = n - 1; i >= 0; --i) #define REPR(i, s, n) for (int i = (s); i >= (n); --(i)) #define all(a) (a).begin(), (a).end() #define reall(a) (a).rbegin(), (a).rend() #define pb emplace_back // emplace_backの方が早いが慣れているため #define DOUBLE fixed << setprecision(15) #define fi first #define se second #define mp make_pair #define mt make_tuple const double pi = acos(-1.0L); typedef vector<int> vi; typedef vector<string> vs; typedef long long ll; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef vector<char> vc; typedef vector<double> vd; typedef vector<bool> vb; typedef deque<ll> dll; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> TLL; typedef vector<P> vP; typedef vector<TLL> vTLL; const ll mod = 1e9 + 7; // const ll mod = 998244353; ll dy[4] = {1, 0, -1, 0}; ll dx[4] = {0, 1, 0, -1}; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class A, class B> ostream &operator<<(ostream &ost, const pair<A, B> &p) { ost << "{ " << p.first << ", " << p.second << " }"; return ost; } template <class T> ostream &operator<<(ostream &ost, const vector<T> &v) { ost << "{ "; for (int i = 0; i < v.size(); i++) { if (i) ost << ", "; ost << v[i]; } ost << " }"; return ost; } template <class A, class B> ostream &operator<<(ostream &ost, const map<A, B> &v) { ost << "{ "; for (auto p : v) { ost << "{ " << p.first << ", " << p.second << " }"; } ost << " }"; return ost; } bool out_check(ll a, ll b) { return (0 <= a && a < b); } double pitagoras(ll a, ll b, ll c, ll d) { double dx = a - b, dy = c - d; return pow(dx * dx + dy * dy, 0.5); } ll modpow(ll a, ll b) { ll c = 1; while (b > 0) { if (b & 1) { c = a * c % mod; } a = a * a % mod; b >>= 1; } return c; } ll modinv(ll a) { return modpow(a, mod - 2); } void Yes(bool x) { cout << ((x) ? "Yes\n" : "No\n"); } void YES(bool x) { cout << ((x) ? "YES\n" : "NO\n"); } void yes(bool x) { cout << ((x) ? "yes\n" : "no\n"); } void Yay(bool x) { cout << ((x) ? "Yay!\n" : ":(\n"); } struct UnionFind { private: vector<long long> data; public: UnionFind(long long size) : data(size, -1) {} bool unite(long long x, long long y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool same(long long x, long long y) { return root(x) == root(y); } int root(long long x) { return data[x] < 0 ? x : data[x] = root(data[x]); } ll size(long long x) { return -data[root(x)]; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); // not Interactive ll n, m, k, l, r, d = 0, Q, ans = 0, ret = M; string s, t; cin >> n >> m; vll a(m), b(m); UnionFind tree(n + 1); rep(i, m) { cin >> a[i] >> b[i]; tree.unite(a[i], b[i]); } rep(i, n) { chmax(ans, tree.size(i + 1)); } cout << ans << endl; }
replace
188
189
188
189
-11
p02573
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long using namespace std; int root[100010]; // root[i]=i's parent int element[100010]; // element[i]=i's group's element // element[find(i)] is better void init(int n) { for (int i = 0; i < n; i++) root[i] = i, element[i] = 1; } // reset int find(int x) { if (root[x] == x) { return x; } else { return root[x] = find(root[x]); } } // search x's parent bool same(int x, int y) { return find(x) == find(y); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; root[x] = y; element[y] += element[x]; } // x"->"y int main() { int n, m; cin >> n >> m; init(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; unite(a, b); } int ans = 0; for (int i = 0; i < n; i++) { ans = max(ans, element[i]); } cout << ans << endl; }
#include <bits/stdc++.h> #define ll long long using namespace std; int root[200010]; // root[i]=i's parent int element[200010]; // element[i]=i's group's element // element[find(i)] is better void init(int n) { for (int i = 0; i < n; i++) root[i] = i, element[i] = 1; } // reset int find(int x) { if (root[x] == x) { return x; } else { return root[x] = find(root[x]); } } // search x's parent bool same(int x, int y) { return find(x) == find(y); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; root[x] = y; element[y] += element[x]; } // x"->"y int main() { int n, m; cin >> n >> m; init(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; unite(a, b); } int ans = 0; for (int i = 0; i < n; i++) { ans = max(ans, element[i]); } cout << ans << endl; }
replace
4
6
4
6
0
p02573
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iostream> #include <list> #include <vector> #define llong long long #define rep(i, l, n) for (llong(i) = (l); (i) < (n); (i++)) #define _min(a, b) ((a) < (b) ? (a) : (b)) #define _max(a, b) ((a) > (b) ? (a) : (b)) #define _abs(a) ((a) > 0 ? (a) : (-(a))) using namespace std; struct group { int num; int size; }; int root(struct group *data, int x) { if ((data + x)->num == x) return x; else return root(data, (data + x)->num); } void unite(struct group *data, int x, int y) { int rx = root(data, x), ry = root(data, y); if (rx == ry) return; (data + rx)->num = ry; (data + ry)->size += (data + rx)->size; } int main() { int N, M; cin >> N >> M; struct group data[N]; rep(i, 0, N) { data[i].num = i; data[i].size = 1; } rep(i, 0, M) { int a, b; cin >> a >> b; a--; b--; unite(data, a, b); } int ans = 0; rep(i, 0, N) { ans = _max(ans, data[i].size); } cout << ans; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <list> #include <vector> #define llong long long #define rep(i, l, n) for (llong(i) = (l); (i) < (n); (i++)) #define _min(a, b) ((a) < (b) ? (a) : (b)) #define _max(a, b) ((a) > (b) ? (a) : (b)) #define _abs(a) ((a) > 0 ? (a) : (-(a))) using namespace std; struct group { int num; int size; }; int root(struct group *data, int x) { if ((data + x)->num == x) return x; else { int rx = root(data, (data + x)->num); (data + x)->num = rx; return rx; } } void unite(struct group *data, int x, int y) { int rx = root(data, x), ry = root(data, y); if (rx == ry) return; (data + rx)->num = ry; (data + ry)->size += (data + rx)->size; } int main() { int N, M; cin >> N >> M; struct group data[N]; rep(i, 0, N) { data[i].num = i; data[i].size = 1; } rep(i, 0, M) { int a, b; cin >> a >> b; a--; b--; unite(data, a, b); } int ans = 0; rep(i, 0, N) { ans = _max(ans, data[i].size); } cout << ans; return 0; }
replace
22
24
22
27
TLE