Datasets:

problem_id
stringlengths
6
6
buggy_code
stringlengths
8
526k
fixed_code
stringlengths
12
526k
labels
listlengths
0
15
buggy_submission_id
int64
1
1.54M
fixed_submission_id
int64
2
1.54M
user_id
stringlengths
10
10
language
stringclasses
9 values
p03106
#include <bitset> #include <cmath> #include <iostream> #include <string> #include <tuple> #include <vector> using namespace std; //# Functions for Vector/Matrix template <typename T> vector<T> zeros(int length) { vector<T> vec(length, 0); return vec; } template <typename T> vector<vector<T>> zeros(tuple<int, int> dim) { vector<vector<T>> mat(get<0>(dim), vector<T>(get<1>(dim), 0)); return mat; } // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); // debug #define dump(x) cerr << #x << " = " << (x) << endl #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl #define VARNAME(VariableName) #VariableName template <typename T> void show(vector<T> &vec) { cerr << VARNAME(vec) << ": " << endl; for (auto value : vec) { cerr << value << " "; } cerr << endl; } template <typename T> void show(vector<vector<T>> &mat) { for (auto vec : mat) { show(vec); } } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define SORT(a) sort(ALL(a)) #define RSORT(a) sort(RALL(a)) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } bool iseven(int x) { return x % 2 == 0; } bool isodd(int x) { return !iseven(x); } int dist(int x, int y) { return abs(x - y); } int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { // cin.tie(0); // ios::sync_with_stdio(false); int A, B, K; cin >> A >> B >> K; dump(A); dump(B); dump(K); int gcd_AB = gcd(A, B); dump(gcd_AB); // // gcd_ABを素因数分解して小さい方因数をk個取り除いたものが // // 求める数 // VI x(gcd_AB + 1); // int num = gcd_AB; // for (int i = 2; i <= gcd_AB; i++) { // while (num%i == 0) { // 素数で割り切れなくなるまで割っていく // x.at(i)++; //割った個数を配列に足す // num /= i; // } // } int div = 1; // gcd_ABをK番目に大きな数にするために割る for (int i = gcd_AB; i >= 2; i--) { div = i; if (gcd_AB % i == 0) K--; if (K == 0) break; } cout << div; return 0; }
#include <bitset> #include <cmath> #include <iostream> #include <string> #include <tuple> #include <vector> using namespace std; //# Functions for Vector/Matrix template <typename T> vector<T> zeros(int length) { vector<T> vec(length, 0); return vec; } template <typename T> vector<vector<T>> zeros(tuple<int, int> dim) { vector<vector<T>> mat(get<0>(dim), vector<T>(get<1>(dim), 0)); return mat; } // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); // debug #define dump(x) cerr << #x << " = " << (x) << endl #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl #define VARNAME(VariableName) #VariableName template <typename T> void show(vector<T> &vec) { cerr << VARNAME(vec) << ": " << endl; for (auto value : vec) { cerr << value << " "; } cerr << endl; } template <typename T> void show(vector<vector<T>> &mat) { for (auto vec : mat) { show(vec); } } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define SORT(a) sort(ALL(a)) #define RSORT(a) sort(RALL(a)) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } bool iseven(int x) { return x % 2 == 0; } bool isodd(int x) { return !iseven(x); } int dist(int x, int y) { return abs(x - y); } int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { // cin.tie(0); // ios::sync_with_stdio(false); int A, B, K; cin >> A >> B >> K; dump(A); dump(B); dump(K); int gcd_AB = gcd(A, B); dump(gcd_AB); // // gcd_ABを素因数分解して小さい方因数をk個取り除いたものが // // 求める数 // VI x(gcd_AB + 1); // int num = gcd_AB; // for (int i = 2; i <= gcd_AB; i++) { // while (num%i == 0) { // 素数で割り切れなくなるまで割っていく // x.at(i)++; //割った個数を配列に足す // num /= i; // } // } int div = 1; // gcd_ABをK番目に大きな数にするために割る for (int i = gcd_AB; i >= 1; i--) { div = i; if (gcd_AB % i == 0) K--; if (K == 0) break; } cout << div; return 0; }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
918,035
918,036
u190076745
cpp
p03106
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <float.h> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define endl '\n' #define MOD 1000000007 #define INF 1ll << 30 #define MAX 100010 #define eps 1e-11 #define bit_max 1ll << 32 #define _USE_MATH_DEFINES long double dp[4000][4000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); int a, b, c; cin >> a >> b >> c; for (int i = min(a, b) - 1; i >= 1; i--) { if (a % i == 0 && b % i == 0) { c--; if (c == 0) { cout << i; return 0; } } } }
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <float.h> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define endl '\n' #define MOD 1000000007 #define INF 1ll << 30 #define MAX 100010 #define eps 1e-11 #define bit_max 1ll << 32 #define _USE_MATH_DEFINES long double dp[4000][4000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); int a, b, c; cin >> a >> b >> c; for (int i = min(a, b); i >= 1; i--) { if (a % i == 0 && b % i == 0) { c--; if (c == 0) { cout << i; return 0; } } } }
[ "control_flow.loop.for.initializer.change", "expression.operation.binary.remove" ]
918,039
918,040
u566864240
cpp
p03106
#include <stdio.h> #include <stdlib.h> int main(void) { int A, B, K; scanf("%d%d%d", &A, &B, &K); int cnt = 0, i; for (i = 0; i < K; i++) { do { cnt++; } while (A % cnt != 0 || B % cnt != 0); } printf("%d", cnt); puts(""); return 0; }
#include <stdio.h> #include <stdlib.h> int main(void) { int A, B, K; scanf("%d%d%d", &A, &B, &K); int cnt = A + 1, i; for (i = 0; i < K; i++) { do { cnt--; } while (A % cnt != 0 || B % cnt != 0); } printf("%d", cnt); puts(""); return 0; }
[ "identifier.replace.add", "literal.replace.remove" ]
918,041
918,042
u792455295
cpp
p03106
#include <bits/stdc++.h> using namespace std; int cd(int a, int b, int k) { int count = 0; int i; int list[100]; int u = max(a, b); for (i = 1; i < u; i++) { if (a % i == 0 && b % i == 0) { count++; list[count] = i; } } return list[count - k + 1]; } int main() { int a, b, k; int count; cin >> a >> b >> k; cout << cd(a, b, k); }
#include <bits/stdc++.h> using namespace std; int cd(int a, int b, int k) { int count = 0; int i; int list[100]; int u = max(a, b); for (i = 1; i <= u; i++) { if (a % i == 0 && b % i == 0) { count++; list[count] = i; } } return list[count - k + 1]; } int main() { int a, b, k; int count; cin >> a >> b >> k; cout << cd(a, b, k); }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
918,043
918,044
u637568962
cpp
p03106
#include <stdio.h> int main() { long long int A, B, K, D = 0, j; scanf("%lld%lld%lld", &A, &B, &K); for (long long int i = 1; D != K; i++) { if (A % i == 0 && B % i == 0) D++; j = i; } printf("%lld", j); return 0; }
#include <stdio.h> int main() { long long int A, B, K, D = 0, j; scanf("%lld%lld%lld", &A, &B, &K); for (long long int i = A; D != K; i--) { if (A % i == 0 && B % i == 0) D++; j = i; } printf("%lld", j); return 0; }
[ "variable_declaration.value.change", "identifier.replace.add", "literal.replace.remove", "control_flow.loop.for.initializer.change" ]
918,045
918,046
u910424986
cpp
p03106
#include <iostream> using namespace std; int main() { int a, b, k; cin >> a >> b >> k; int ans[100], i, j = 0; for (i = 1; i <= 100; i++) { if ((a % i == 0) && (b % i == 0)) { ans[j++] = i; } } cout << ans[k - 1] << endl; return 0; }
#include <iostream> using namespace std; int main() { int a, b, k; cin >> a >> b >> k; int ans[100], i, j = 0; for (i = 1; i <= 100; i++) { if ((a % i == 0) && (b % i == 0)) { ans[j++] = i; } } cout << ans[j - k] << endl; return 0; }
[ "identifier.change", "variable_access.subscript.index.change", "io.output.change", "identifier.replace.add", "literal.replace.remove" ]
918,058
918,059
u483349999
cpp
p03106
#include <iostream> using namespace std; int main() { int a, b, k; cin >> a >> b >> k; int ans[100], i, j = 0; for (i = 1; i <= 100; i++) { if ((a % i == 0) && (b % i == 0)) { ans[j++] = i; } } cout << ans[k - 1]; return 0; }
#include <iostream> using namespace std; int main() { int a, b, k; cin >> a >> b >> k; int ans[100], i, j = 0; for (i = 1; i <= 100; i++) { if ((a % i == 0) && (b % i == 0)) { ans[j++] = i; } } cout << ans[j - k] << endl; return 0; }
[ "identifier.change", "variable_access.subscript.index.change", "io.output.change", "identifier.replace.add", "literal.replace.remove", "io.output.newline.add" ]
918,060
918,059
u483349999
cpp
p03106
#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; #define ll long long #define ld long double #define pp pair<ll, pair<ll, ll>> #define rep(i, a, b) for (ll i = a; i < b; i += 1) #define all(c) (c).begin(), (c).end() #define pb push_back #define sz(a) int((a).size()) #define hell 1000000007 #define f first #define s second #define sll(x) scanf("%lld", &x) #define si(x) scanf("%d", &x) typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; ll t = 1; ll powMod(ll base, ll expo) { ll ans = 1; while (expo > 0) { if (expo & 1) ans = (ans * base) % hell; expo >>= 1; base = (base * base) % hell; } return ans; } ll findroot(ll x) { ll lo = 1, hi = hell, mid; while (hi - lo > 1) { mid = (lo + hi) / 2; if (mid * mid > x) hi = mid; else lo = mid; } return lo; } ll calc(ll n) { ll x = findroot(n), y; y = n - x * x; ll a1, a2, ans = 1; a1 = powMod(3, x); a2 = powMod(a1, x); if (y < hell) { ans = (ans * a2) % hell; ans = (ans * powMod(3, y)) % hell; return ans; } else { ans = (ans * a2) % hell; ans = (ans * calc(y)) % hell; return ans; } } void solve() { ll a, b, k; cin >> a >> b >> k; vector<ll> v; rep(i, 1, 105) { if (a % i == 0 && b % i == 0) v.pb(i); } cout << v[k - 1]; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); // cin>>t; while (t--) solve(); return 0; }
#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; #define ll long long #define ld long double #define pp pair<ll, pair<ll, ll>> #define rep(i, a, b) for (ll i = a; i < b; i += 1) #define all(c) (c).begin(), (c).end() #define pb push_back #define sz(a) int((a).size()) #define hell 1000000007 #define f first #define s second #define sll(x) scanf("%lld", &x) #define si(x) scanf("%d", &x) typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; ll t = 1; ll powMod(ll base, ll expo) { ll ans = 1; while (expo > 0) { if (expo & 1) ans = (ans * base) % hell; expo >>= 1; base = (base * base) % hell; } return ans; } ll findroot(ll x) { ll lo = 1, hi = hell, mid; while (hi - lo > 1) { mid = (lo + hi) / 2; if (mid * mid > x) hi = mid; else lo = mid; } return lo; } ll calc(ll n) { ll x = findroot(n), y; y = n - x * x; ll a1, a2, ans = 1; a1 = powMod(3, x); a2 = powMod(a1, x); if (y < hell) { ans = (ans * a2) % hell; ans = (ans * powMod(3, y)) % hell; return ans; } else { ans = (ans * a2) % hell; ans = (ans * calc(y)) % hell; return ans; } } void solve() { ll a, b, k; cin >> a >> b >> k; vector<ll> v; rep(i, 1, 105) { if (a % i == 0 && b % i == 0) v.pb(i); } cout << v[sz(v) - k]; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); // cin>>t; while (t--) solve(); return 0; }
[ "variable_access.subscript.index.change", "io.output.change", "call.arguments.add", "identifier.replace.add", "literal.replace.remove" ]
918,061
918,062
u889695981
cpp
p03106
#include <iostream> #include <vector> using namespace std; int main() { int a, b, k; cin >> a >> b >> k; int x; if (a < b) x = a; else x = b; vector<int> v; for (int i = 1; i <= x; i++) { if (a % i == 0 && b % i == 0) { v.push_back(i); } } cout << v[k - 1] << endl; }
#include <iostream> #include <vector> using namespace std; int main() { int a, b, k; cin >> a >> b >> k; int x; if (a < b) x = a; else x = b; vector<int> v; for (int i = 1; i <= x; i++) { if (a % i == 0 && b % i == 0) { v.push_back(i); } } cout << v[v.size() - k] << endl; }
[ "variable_access.subscript.index.change", "io.output.change", "call.add", "identifier.replace.add", "literal.replace.remove" ]
918,063
918,064
u927804708
cpp
p03106
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int a, b, k; cin >> a >> b >> k; int i; vector<int> aa, bb, common; for (i = 1; i < a; i++) { if (a % i == 0) aa.push_back(i); } for (i = 1; i < b; i++) { if (b % i == 0) bb.push_back(i); } set_intersection(aa.begin(), aa.end(), bb.begin(), bb.end(), back_inserter(common)); sort(common.begin(), common.end(), greater<int>()); cout << common[k - 1] << "\n"; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int a, b, k; cin >> a >> b >> k; int i; vector<int> aa, bb, common; for (i = 1; i <= a; i++) { if (a % i == 0) aa.push_back(i); } for (i = 1; i <= b; i++) { if (b % i == 0) bb.push_back(i); } set_intersection(aa.begin(), aa.end(), bb.begin(), bb.end(), back_inserter(common)); sort(common.begin(), common.end(), greater<int>()); cout << common[k - 1] << "\n"; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
918,078
918,079
u820315626
cpp
p03106
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int a, b, k; cin >> a >> b >> k; vector<int> intersection; int limit = max(a, b); for (int i = 1; i < limit; i++) { if (a % i == 0 && b % i == 0) { intersection.push_back(i); } } cout << intersection[intersection.size() - k] << "\n"; }
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int a, b, k; cin >> a >> b >> k; vector<int> intersection; int limit = max(a, b); for (int i = 1; i <= limit; i++) { if (a % i == 0 && b % i == 0) { intersection.push_back(i); } } cout << intersection[intersection.size() - k] << "\n"; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
918,089
918,090
u422029490
cpp
p03106
#include <iostream> using namespace std; int main() { int a, b, k; int n = 1; int m = 1; cin >> a >> b >> k; for (int i = 1; i <= a; i++) { if (a % i == 0 && b % i == 0) { n = n + 1; } } for (int l = 1; l <= a; l++) { if (a % l == 0 && b % l == 0) { if (n - k + 1 == m) { cout << l << endl; } m = m + 1; } } return 0; }
#include <iostream> using namespace std; int main() { int a, b, k; int n = 1; int m = 1; cin >> a >> b >> k; for (int i = 1; i <= a; i++) { if (a % i == 0 && b % i == 0) { n = n + 1; } } for (int l = 1; l <= a; l++) { if (a % l == 0 && b % l == 0) { if (n - k == m) { cout << l << endl; } m = m + 1; } } return 0; }
[ "control_flow.loop.for.condition.change", "expression.operation.binary.remove" ]
918,116
918,117
u401817927
cpp
p03107
#include <bits/stdc++.h> using namespace std; #define ll long long inline ll read() { ll x = 0, f = 1; char ch = getchar(); for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -f; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0'; return x * f; } inline void chkmin(int &a, int b) { if (a > b) a = b; } inline void chkmax(int &a, int b) { if (a < b) a = b; } #define _ read() int top, S[1000005]; int main() { string s; cin >> s; int n = s.length(); for (int i = 0; i < n; i++) { if (s[i] != s[S[top]]) top--; else S[++top] = i; } cout << n - top; }
#include <bits/stdc++.h> using namespace std; #define ll long long inline ll read() { ll x = 0, f = 1; char ch = getchar(); for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -f; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0'; return x * f; } inline void chkmin(int &a, int b) { if (a > b) a = b; } inline void chkmax(int &a, int b) { if (a < b) a = b; } #define _ read() int top, S[1000005]; int main() { string s; cin >> s; int n = s.length(); for (int i = 0; i < n; i++) { if (s[i] != s[S[top]] && top) top--; else S[++top] = i; } cout << n - top; }
[ "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change" ]
918,124
918,125
u900306103
cpp
p03107
#include "bits/stdc++.h" using namespace std; void solve() { string S; cin >> S; int l = S.size(), z = 0; for (char c : S) { z += c == '0'; } z = min(z, l - z); cout << l - z * 2 << endl; } int main(void) { solve(); // cout << "yui(*-v・)yui" << endl; return 0; }
#include "bits/stdc++.h" using namespace std; void solve() { string S; cin >> S; int l = S.size(), z = 0; for (char c : S) { z += c == '0'; } z = min(z, l - z); cout << z * 2 << endl; } int main(void) { solve(); // cout << "yui(*-v・)yui" << endl; return 0; }
[ "expression.operation.binary.remove" ]
918,126
918,127
u344412812
cpp
p03107
#define debug_interval ',' #define dump_interval ' ' #define debug_toggle 1 //{ #pragma GCC optimize("O3") #pragma GCC target("avx") #include <bits/stdc++.h> using namespace std; #define hi // cerr<<"hi"<<endl; #define int long long #define INT_MAX LLONG_MAX #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i <= (n); i++) #define pb push_back #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define fi first #define se second #define mp make_pair #define rev reverse #define dans dump(ans) //#define MOD 1000000007 #define amp(v, n) (v).count(n) ? v[n]++ : v[n] = 1 #define sysp system("pause") #define PI acos(-1) #define ins insert #define aer(v) (v).erase((v).begin(), (v).end()) //{ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } template <class... A> inline void dump() { cout << endl; } template <class... A> inline void dump_rest() { cout << endl; } template <class T, class... A> inline void dump_rest(const T &first, const A &...rest) { cout << dump_interval << first; dump_rest(rest...); } template <class T, class... A> inline void dump(const T &first, const A &...rest) { cout << first; dump_rest(rest...); } template <class... A> inline void debug() { cerr << endl; } template <class... A> inline void debug_rest() { cerr << endl; } template <class T, class... A> inline void debug_rest(const T &first, const A &...rest) { cerr << debug_interval << first; debug_rest(rest...); } template <class T, class... A> inline void debug(const T &first, const A &...rest) { if (debug_toggle) cerr << first, debug_rest(rest...); } //} typedef vector<int> vint; typedef pair<int, int> pint; typedef vector<pint> vpint; template <typename A, typename B> inline void chmin(A &a, B b) { if (a > b) a = b; } template <typename A, typename B> inline void chmax(A &a, B b) { if (a < b) a = b; } template <int m> class mint { private: int i; public: mint() : i(0) {} mint(int i) : i((i % m + m) % m) {} mint operator+(const mint &o) { return o.i + i; } mint operator*(const mint &o) { return o.i * i; } mint operator-() { return -i; } operator int() { return i; } }; //} int a, b, c, n, m, k; string s; main() { cin >> s; for (int i = 0; i <= s.size(); i++) { if (s[i] == '0') a++; else b++; } dump(2 * min(a, b)); }
#define debug_interval ',' #define dump_interval ' ' #define debug_toggle 1 //{ #pragma GCC optimize("O3") #pragma GCC target("avx") #include <bits/stdc++.h> using namespace std; #define hi // cerr<<"hi"<<endl; #define int long long #define INT_MAX LLONG_MAX #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i <= (n); i++) #define pb push_back #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define fi first #define se second #define mp make_pair #define rev reverse #define dans dump(ans) //#define MOD 1000000007 #define amp(v, n) (v).count(n) ? v[n]++ : v[n] = 1 #define sysp system("pause") #define PI acos(-1) #define ins insert #define aer(v) (v).erase((v).begin(), (v).end()) //{ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } template <class... A> inline void dump() { cout << endl; } template <class... A> inline void dump_rest() { cout << endl; } template <class T, class... A> inline void dump_rest(const T &first, const A &...rest) { cout << dump_interval << first; dump_rest(rest...); } template <class T, class... A> inline void dump(const T &first, const A &...rest) { cout << first; dump_rest(rest...); } template <class... A> inline void debug() { cerr << endl; } template <class... A> inline void debug_rest() { cerr << endl; } template <class T, class... A> inline void debug_rest(const T &first, const A &...rest) { cerr << debug_interval << first; debug_rest(rest...); } template <class T, class... A> inline void debug(const T &first, const A &...rest) { if (debug_toggle) cerr << first, debug_rest(rest...); } //} typedef vector<int> vint; typedef pair<int, int> pint; typedef vector<pint> vpint; template <typename A, typename B> inline void chmin(A &a, B b) { if (a > b) a = b; } template <typename A, typename B> inline void chmax(A &a, B b) { if (a < b) a = b; } template <int m> class mint { private: int i; public: mint() : i(0) {} mint(int i) : i((i % m + m) % m) {} mint operator+(const mint &o) { return o.i + i; } mint operator*(const mint &o) { return o.i * i; } mint operator-() { return -i; } operator int() { return i; } }; //} int a, b, c, n, m, k; string s; main() { cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == '0') a++; else b++; } dump(2 * min(a, b)); }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
918,132
918,133
u130196064
cpp
p03107
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.size(); stack<int> st; int res = 0; for (int i = 0; i < n; i++) { if (!st.empty() && st.top() != s[i]) { res++; st.pop(); } else st.push(s[i]); } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.size(); stack<int> st; int res = 0; for (int i = 0; i < n; i++) { if (!st.empty() && st.top() != s[i]) { res += 2; st.pop(); } else st.push(s[i]); } cout << res << endl; return 0; }
[]
918,138
918,139
u283229916
cpp
p03107
#include <bits/stdc++.h> using namespace std; #define db(x) cout << #x << " = " << (x) << "\n"; using ll = long long; using ld = long double; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); string s; cin >> s; stack<char> st; int count = 0; for (int i = 0; i < s.length(); ++i) { if (!st.empty()) { if (st.top() != s[i]) { count += 2; } else { st.push(s[i]); } } else { st.push(s[i]); } } cout << count; return 0; }
#include <bits/stdc++.h> using namespace std; #define db(x) cout << #x << " = " << (x) << "\n"; using ll = long long; using ld = long double; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); string s; cin >> s; stack<char> st; int count = 0; for (int i = 0; i < s.length(); ++i) { if (!st.empty()) { if (st.top() != s[i]) { count += 2; st.pop(); } else { st.push(s[i]); } } else { st.push(s[i]); } } cout << count; return 0; }
[ "call.add" ]
918,140
918,141
u448203679
cpp
p03107
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <functional> #include <iomanip> #include <ios> #include <iostream> #include <map> #include <queue> #include <set> #include <tuple> #include <utility> #include <vector> using namespace std; template <class T> void chmax(T &a, T b) { if (a < b) { a = b; } } template <class T> void chmin(T &a, T b) { if (a > b) { a = b; } } #define REP(i, a, n) for (int i = a; i < n; ++i) #define RUP(a, b) ((a + b - 1) / (b)) #define ENT "\n" #define REV(v) reverse(v.begin(), v.end()) #define SRTV(v) sort(v.begin(), v.end()) #define SRTAG(a, n) sort(a, a + n, greater<>()) #define MOD 1000000007 typedef long long ll; typedef tuple<int, int, bool> Tb; typedef tuple<ll, ll, ll> Tl; int atcoder() { //入力 string s; cin >> s; int cnt0 = 0; int cnt1 = 0; REP(i, 0, s.length()) { if (s[i] == '0') cnt0++; if (s[i] == '1') cnt1++; } cout << min(cnt0, cnt1) << ENT; return 0; } int main() { cin.tie(0); ios::sync_with_stdio(false); atcoder(); return 0; }
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <functional> #include <iomanip> #include <ios> #include <iostream> #include <map> #include <queue> #include <set> #include <tuple> #include <utility> #include <vector> using namespace std; template <class T> void chmax(T &a, T b) { if (a < b) { a = b; } } template <class T> void chmin(T &a, T b) { if (a > b) { a = b; } } #define REP(i, a, n) for (int i = a; i < n; ++i) #define RUP(a, b) ((a + b - 1) / (b)) #define ENT "\n" #define REV(v) reverse(v.begin(), v.end()) #define SRTV(v) sort(v.begin(), v.end()) #define SRTAG(a, n) sort(a, a + n, greater<>()) #define MOD 1000000007 typedef long long ll; typedef tuple<int, int, bool> Tb; typedef tuple<ll, ll, ll> Tl; int atcoder() { //入力 string s; cin >> s; int cnt0 = 0; int cnt1 = 0; REP(i, 0, s.length()) { if (s[i] == '0') cnt0++; if (s[i] == '1') cnt1++; } cout << min(cnt0, cnt1) * 2 << ENT; return 0; } int main() { cin.tie(0); ios::sync_with_stdio(false); atcoder(); return 0; }
[ "expression.operation.binary.add" ]
918,144
918,145
u635484372
cpp
p03107
#include <bits/stdc++.h> #include <cstdio> #include <iostream> #include <sys/time.h> #include <sys/timeb.h> #include <time.h> using namespace std; #define ll long long #define uint unsigned int #define ulong unsigned long long int template <typename T> bool InRange(T t, T l, T r) { return l <= t && t < r; } int main() { string S; int N = S.length(); int one = 0; for (int i = 0; i < N; i++) one += (S[i] - '0'); int zero = N - one; cout << min(one, zero) * 2 << endl; return 0; }
#include <bits/stdc++.h> #include <cstdio> #include <iostream> #include <sys/time.h> #include <sys/timeb.h> #include <time.h> using namespace std; #define ll long long #define uint unsigned int #define ulong unsigned long long int template <typename T> bool InRange(T t, T l, T r) { return l <= t && t < r; } int main() { string S; cin >> S; int N = S.length(); int one = 0; for (int i = 0; i < N; i++) one += (S[i] - '0'); int zero = N - one; cout << min(one, zero) * 2 << endl; return 0; }
[]
918,146
918,147
u774845108
cpp
p03107
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define dbg(x) cerr << #x << " = " << x << endl #define _ << ' ' << using namespace std; using ll = long long; using vi = vector<int>; using ii = pair<int, int>; using vii = vector<ii>; int main() { ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int n = s.size(), a = 0, b = 0; for (int i = 0; i < n; ++i) { if (s[i] == '0') a++; else b++; } cout << min(a, b); }
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define dbg(x) cerr << #x << " = " << x << endl #define _ << ' ' << using namespace std; using ll = long long; using vi = vector<int>; using ii = pair<int, int>; using vii = vector<ii>; int main() { ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int n = s.size(), a = 0, b = 0; for (int i = 0; i < n; ++i) { if (s[i] == '0') a++; else b++; } cout << min(a, b) * 2; }
[ "expression.operation.binary.add" ]
918,148
918,149
u562319622
cpp
p03107
#include <stdio.h> #include <string.h> typedef long long ll; using namespace std; int main(void) { ll i, j, k, a = 0, b = 0, c, n, m; char s[100010]; scanf("%s", s); n = strlen(s); for (i = 0; i < n; ++i) { if (s[i] == '0') ++a; else ++b; } printf("%lld", a < b ? a : b); return 0; }
#include <stdio.h> #include <string.h> typedef long long ll; using namespace std; int main(void) { ll i, j, k, a = 0, b = 0, c, n, m; char s[100010]; scanf("%s", s); n = strlen(s); for (i = 0; i < n; ++i) { if (s[i] == '0') ++a; else ++b; } printf("%lld", a < b ? a * 2 : b * 2); return 0; }
[ "expression.operation.binary.add" ]
918,150
918,151
u440920318
cpp
p03107
#include <algorithm> #include <bitset> #include <climits> #include <complex> #include <cstring> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #define rep(i, m, n) for (int i = int(m); i < int(n); i++) #define all(c) begin(c), end(c) template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } //改造 typedef long long int ll; using namespace std; #define INF (1 << 30) - 1 #define INFl (ll)5e15 #define DEBUG 0 //デバッグする時1にしてね #define dump(x) cerr << #x << " = " << (x) << endl #define MOD 1000000007 //ここから編集する class Solve { public: void input() {} void solve() { input(); string s; cin >> s; int _0 = 0, _1 = 1; for (auto e : s) { if (e == '0') _0++; else _1++; } int ans = min(_0, _1) * 2; cout << ans << endl; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); Solve().solve(); return 0; }
#include <algorithm> #include <bitset> #include <climits> #include <complex> #include <cstring> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #define rep(i, m, n) for (int i = int(m); i < int(n); i++) #define all(c) begin(c), end(c) template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } //改造 typedef long long int ll; using namespace std; #define INF (1 << 30) - 1 #define INFl (ll)5e15 #define DEBUG 0 //デバッグする時1にしてね #define dump(x) cerr << #x << " = " << (x) << endl #define MOD 1000000007 //ここから編集する class Solve { public: void input() {} void solve() { input(); string s; cin >> s; int _0 = 0, _1 = 0; for (auto e : s) { if (e == '0') _0++; else _1++; } int ans = min(_0, _1) * 2; cout << ans << endl; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); Solve().solve(); return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
918,152
918,153
u003873207
cpp
p03108
#include <algorithm> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; #define fi first #define se second #define mp make_pair #define mt make_tuple #define pqueue priority_queue const int inf = 1e9 + 7; const ll mod = 1e9 + 7; const ll mod1 = 998244353; const ll big = 1e18; const double PI = 2 * asin(1); ll parent[100005]; ll siz[100005]; ll root(ll x) { if (x == parent[x]) return x; else return parent[x] = root(parent[x]); } bool same(ll x, ll y) { return root(x) == root(y); } ll unite(ll x, ll y) { x = root(x); y = root(y); if (siz[x] < siz[y]) swap(x, y); ll ans; if (x == y) ans = 0; else ans = siz[x] * siz[y]; parent[y] = x; siz[x] += siz[y]; return ans; } int main() { ll N, M; cin >> N >> M; for (ll i = 0; i < N; ++i) { parent[i] = i; siz[i] = 1; } ll A[M], B[M]; for (ll i = 0; i < M; ++i) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } ll ans[M]; ans[M - 1] = N * (N - 1) / 2; for (ll i = M - 2; i >= 0; --i) { ans[i] = ans[i + 1] - unite(A[i + 1], B[i + 1]); } for (ll i = 0; i < M; ++i) cout << ans[i] << endl; }
#include <algorithm> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; #define fi first #define se second #define mp make_pair #define mt make_tuple #define pqueue priority_queue const int inf = 1e9 + 7; const ll mod = 1e9 + 7; const ll mod1 = 998244353; const ll big = 1e18; const double PI = 2 * asin(1); ll parent[100005]; ll siz[100005]; ll root(ll x) { if (x == parent[x]) return x; else return parent[x] = root(parent[x]); } bool same(ll x, ll y) { return root(x) == root(y); } ll unite(ll x, ll y) { x = root(x); y = root(y); if (siz[x] < siz[y]) swap(x, y); ll ans; if (x == y) { ans = 0; return ans; } else ans = siz[x] * siz[y]; parent[y] = x; siz[x] += siz[y]; return ans; } int main() { ll N, M; cin >> N >> M; for (ll i = 0; i < N; ++i) { parent[i] = i; siz[i] = 1; } ll A[M], B[M]; for (ll i = 0; i < M; ++i) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } ll ans[M]; ans[M - 1] = N * (N - 1) / 2; for (ll i = M - 2; i >= 0; --i) { ans[i] = ans[i + 1] - unite(A[i + 1], B[i + 1]); } for (ll i = 0; i < M; ++i) cout << ans[i] << endl; }
[ "control_flow.return.add" ]
918,178
918,179
u860546679
cpp
p03108
#include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long int ll; typedef pair<int, int> P; 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; } class union_find { private: vector<int> par; vector<int> ran; vector<ll> size; public: union_find(int n); int find(int x); void unite(int x, int y); bool same(int x, int y); ll show_size(int x); }; union_find::union_find(int n) { par.resize(n); ran.resize(n); size.resize(n); rep(i, n) par[i] = i; rep(i, n) ran[i] = 0; rep(i, n) size[i] = 1; }; int union_find::find(int x) { if (par[x] == x) return x; else return par[x] = find(par[x]); }; void union_find::unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; ll t = show_size(x) + show_size(y); size[x] = size[y] = t; if (ran[x] < ran[y]) { par[x] = y; // size[y] += size[x]; } else { par[y] = x; // size[x] += size[y]; if (ran[x] == ran[y]) ran[x]++; } }; ll union_find::show_size(int x) { if (par[x] == x) return size[x]; return show_size(par[x] = find(par[x])); } bool union_find::same(int x, int y) { return (find(x) == find(y)); }; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, m; cin >> n >> m; union_find uf(n); vector<ll> a(m), b(m); rep(i, m) { cin >> a[i] >> b[i]; --a[i]; --b[i]; } ll cnt = n * (n - 1) / 2; vector<ll> ans(m); for (int i = m - 1; i > 0; --i) { ans[i] = cnt; if (!uf.same(a[i], b[i])) { cnt -= uf.show_size(a[i]) * uf.show_size(b[i]); uf.unite(a[i], b[i]); } } rep(i, m) cout << ans[i] << endl; return 0; }
#include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long int ll; typedef pair<int, int> P; 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; } class union_find { private: vector<int> par; vector<int> ran; vector<ll> size; public: union_find(int n); int find(int x); void unite(int x, int y); bool same(int x, int y); ll show_size(int x); }; union_find::union_find(int n) { par.resize(n); ran.resize(n); size.resize(n); rep(i, n) par[i] = i; rep(i, n) ran[i] = 0; rep(i, n) size[i] = 1; }; int union_find::find(int x) { if (par[x] == x) return x; else return par[x] = find(par[x]); }; void union_find::unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; ll t = show_size(x) + show_size(y); size[x] = size[y] = t; if (ran[x] < ran[y]) { par[x] = y; // size[y] += size[x]; } else { par[y] = x; // size[x] += size[y]; if (ran[x] == ran[y]) ran[x]++; } }; ll union_find::show_size(int x) { if (par[x] == x) return size[x]; return show_size(par[x] = find(par[x])); } bool union_find::same(int x, int y) { return (find(x) == find(y)); }; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, m; cin >> n >> m; union_find uf(n); vector<ll> a(m), b(m); rep(i, m) { cin >> a[i] >> b[i]; --a[i]; --b[i]; } ll cnt = n * (n - 1) / 2; vector<ll> ans(m); for (int i = m - 1; i >= 0; --i) { ans[i] = cnt; if (!uf.same(a[i], b[i])) { cnt -= uf.show_size(a[i]) * uf.show_size(b[i]); uf.unite(a[i], b[i]); } } rep(i, m) cout << ans[i] << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
918,193
918,194
u415325136
cpp
p03107
#include <algorithm> #include <cstdio> #include <cstdlib> #include <iostream> #include <string> using namespace std; int main(void) { int num1 = 0, num0 = 0; string s; cin >> s; // cout << atoi(s.cs()) << "\n"; for (int k = 0; k < s.size(); k++) { if (s[k] - '0' == 1) num1++; else if (s[k] - '0' == 0) num0++; } cout << min(num1, num0) << "\n"; return 0; }
#include <algorithm> #include <cstdio> #include <cstdlib> #include <iostream> #include <string> using namespace std; int main(void) { int num1 = 0, num0 = 0; string s; cin >> s; // cout << atoi(s.cs()) << "\n"; for (int k = 0; k < s.size(); k++) { if (s[k] - '0' == 1) num1++; else if (s[k] - '0' == 0) num0++; } cout << min(num1, num0) * 2 << "\n"; return 0; }
[ "expression.operation.binary.add" ]
918,210
918,211
u217596176
cpp
p03107
#include <algorithm> #include <bitset> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = (ll)1000000007 * 1000000007; typedef pair<int, int> P; #define stop \ char nyaa; \ cin >> nyaa; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef long double ld; typedef complex<ld> Point; const ld eps = 1e-2; const ld pi = acos(-1.0); typedef pair<ll, ll> LP; int main() { stack<char> st; string s; cin >> s; int n = s.length(); int ans = 0; rep(i, n) { char t = s[i]; if (!st.empty() && st.top() != t) { ans++; st.pop(); } else st.push(t); } cout << ans << endl; // stop return 0; }
#include <algorithm> #include <bitset> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = (ll)1000000007 * 1000000007; typedef pair<int, int> P; #define stop \ char nyaa; \ cin >> nyaa; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef long double ld; typedef complex<ld> Point; const ld eps = 1e-2; const ld pi = acos(-1.0); typedef pair<ll, ll> LP; int main() { stack<char> st; string s; cin >> s; int n = s.length(); int ans = 0; rep(i, n) { char t = s[i]; if (!st.empty() && st.top() != t) { ans++; st.pop(); } else st.push(t); } cout << 2 * ans << endl; // stop return 0; }
[ "expression.operation.binary.add" ]
918,214
918,215
u294531924
cpp
p03107
#include <bits/stdc++.h> using namespace std; int main() { int count = 0, count1 = 0, count2 = 0; string S; cin >> S; int N = S.size(); if (N == 0) { cout << 0 << endl; } else { for (int i = 0; i < N - 1; i++) { if (S.at(i) == '1') { count1++; } else count2++; } count = min(count1, count2); cout << count * 2 << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int count = 0, count1 = 0, count2 = 0; string S; cin >> S; int N = S.size(); if (N == 1) { cout << 0 << endl; } else { for (int i = 0; i < N; i++) { if (S.at(i) == '1') { count1++; } else count2++; } count = min(count1, count2); cout << count * 2 << endl; } }
[ "literal.number.change", "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "expression.operation.binary.remove" ]
918,220
918,221
u332840922
cpp
p03107
#include <iostream> using namespace std; int main() { string s; cin >> s; int a = 0, b = 0; for (int i = 1; i < s.length(); i++) { if (s[i] == '0') a++; if (s[i] == '1') b++; } if (a > b) a = b; cout << a * 2 << endl; }
#include <iostream> using namespace std; int main() { string s; cin >> s; int a = 0, b = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == '0') a++; if (s[i] == '1') b++; } if (a > b) a = b; cout << a * 2 << endl; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
918,231
918,232
u412025794
cpp
p03107
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int c1 = 0, c0 = 0, ans = 0; for (int i = 0; i < ((sizeof s) - 1); i++) { if (s[i] == '1') c1++; if (s[i] == '0') c0++; } while (c0 > 0 && c1 > 0) { ans += 2; c0--; c1--; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int c1 = 0, c0 = 0, ans = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == '1') c1++; if (s[i] == '0') c0++; } while (c0 > 0 && c1 > 0) { ans += 2; c0--; c1--; } cout << ans << endl; return 0; }
[ "control_flow.loop.for.condition.change" ]
918,237
918,238
u022832318
cpp
p03107
#include <bits/stdc++.h> using namespace std; int in() { int a; cin >> a; return a; } // int型関数の受け取り void forin(int *x, int y) { for (int i = 0; i < y; i++) { cin >> x[i]; } } //配列の受け取り int intpow(int x, int y) { double a = x, b = y; return pow(a, b); } //(x,y) xをy乗する int intfabs(int x) { double a = x; return fabs(a); } //(x) の絶対値 main() { string s; cin >> s; if (s.size() < 2) { cout << '0' << endl; return 0; } int o = 0, z = 0; for (int i = 0; i < s.size(); i++) { if (s.at(i) == '0') z++; else o++; } cout << min(z, o) << endl; }
#include <bits/stdc++.h> using namespace std; int in() { int a; cin >> a; return a; } // int型関数の受け取り void forin(int *x, int y) { for (int i = 0; i < y; i++) { cin >> x[i]; } } //配列の受け取り int intpow(int x, int y) { double a = x, b = y; return pow(a, b); } //(x,y) xをy乗する int intfabs(int x) { double a = x; return fabs(a); } //(x) の絶対値 main() { string s; cin >> s; if (s.size() < 2) { cout << '0' << endl; return 0; } int o = 0, z = 0; for (int i = 0; i < s.size(); i++) { if (s.at(i) == '0') z++; else o++; } cout << 2 * min(z, o) << endl; }
[ "expression.operation.binary.add" ]
918,241
918,242
u160321725
cpp
p03107
#include <bits/stdc++.h> //#include <mylib.h> using namespace std; // cin.sync_with_stdio(false); #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FOR_EQ(i, a, b) for (int i = (a); i <= (b); ++i) #define FOR_RE(i, a, b) for (int i = (a); i > (b); --i) #define rep(i, n) FOR(i, 0, n) #define rep_eq(i, n) FOR_EQ(i, 0, n) #define rep_re(i, n) FOR_RE(i, n, 0) #define DEBUG_VARIABLE(variable) cout << #variable << ":" << variable << endl #define WHITE 1 //(未訪問) #define GRAY \ 2 //(訪問)未だに訪問していない頂点への辺を持っている。スタックに退避。 #define BLACK 3 //(訪問完了)未訪問への頂点への辺を持たない #define N 100 #define INFTY (1 << 21) // 10^21 #define INF (1 << 9) int M[N][N]; //隣接行列 int color[N]; // 1個上から時計周り const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1}; //上右下左 const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {-1, 0, 1, 0}; static const int NIL = -1; typedef unsigned long long ull; typedef long long ll; typedef vector<int> Vector; typedef vector<Vector> DVector; int n; void printArray(int *array, int); void printVector(vector<char> &v); void printDimention(DVector &dv); // nCr方式で組み合わせの数を求める int combination(int, int); // nPrで階乗を求める int factorial(int, int); //桁数を返す int find_digits(int); // 各桁の和を計算する関数 int findSumOfDigits(int); //次数を得る int degree(int); //四捨五入 int shishagonyu(double); //切り上げ int roundUp(double); //切り捨て int roundDown(double); //四捨五入 int roundOff(double); //最大公約数(Greatest Common Divisor) int gcd(int, int); //最小公倍数(Least Common Multiple) int lcm(int, int); //素因数分解 void prime_factorization(int); //エラトステネスの篩 int Eratosthenes(int); //偶奇判定。奇数ならtrue。 bool odd_even(int); int main(int argc, char const *argv[]) { cin.tie(0); ios::sync_with_stdio(false); string s; vector<char> cube; int cnt = 0; cin >> s; rep(i, s.size()) { cube.push_back(s[i]); } // printVector(cube); // while(flg){ // bool flg = false; char pre = '2'; rep(i, cube.size()) { if (cube[i] == '0' && pre == '1') { cube.erase(cube.begin() + i); cube.erase(cube.begin() + i - 1); if (i - 2 < 0) { pre = '2'; i = 0; } else { pre = cube[i - 2]; i = i - 2; } cnt++; } else if (cube[i] == '1' && pre == '0') { cube.erase(cube.begin() + i); cube.erase(cube.begin() + i - 1); if (i - 2 < 0) { pre = '2'; i = 0; } else { pre = cube[i - 2]; i = i - 2; } cnt++; } else { pre = cube[i]; } } cout << cnt * 2 << endl; //} } //配列の表示 void printArray(int array[], int n) { rep(i, n) { if (i) cout << " "; cout << array[i]; } cout << endl; } // Vectorの表示 void printVector(vector<char> &v) { rep(i, (int)v.size()) { if (i) cout << " "; cout << v[i]; } cout << endl; } //二次元配列の表示 void printDimention(DVector &dv) { rep(i, (int)dv.size()) { rep(j, (int)dv[i].size()) { if (j) cout << " "; cout << dv[i][j]; } cout << endl; } } // numの中に何個2がかかってるか int factor2(int num) { int cnt = 0; while (num % 2 == 0) { num /= 2; cnt++; } return cnt; } // nCr方式で組み合わせの数を求める int combination(int n, int r) { int up = 1, down = 1; rep(i, n) up *= (i + 1); rep(i, n - r) down *= (i + 1); rep(i, r) down *= (i + 1); return up / down; } // nPr方式で階乗を求める int factorial(int n, int r) { if (n < r) { cout << "error" << endl; return 0; } else { int res = 1; while (r) { r--; res *= n; n--; } return res; } } //桁数を返す int find_digits(int n) { int digit = 0; while (n) { n /= 10; digit++; } return digit; } // 各桁の和を計算する関数 int findSumOfDigits(int n) { int sum = 0; while (n > 0) { // n が 0 になるまで sum += n % 10; n /= 10; } return sum; } //次数を得る int degree(int n) { int count = 0; while (1) { if (count <= 0) break; count /= 2; count++; } return count; } //四捨五入 int shishagonyu(double x) { return (int)(x < 0.0 ? x - 0.5 : x + 0.5); } //切り上げ int roundUp(double n) { if (n >= 0) { return (int)n + 1; } else { return (int)n - 1; } } //切り捨て int roundDown(double n) { return (int)n; } //四捨五入 int roundOff(double n) { double decimal = 0; decimal = n - (int)n; if (decimal >= 0.5 || decimal <= -0.5) { return roundUp(n); } else { return roundDown(n); } } //最大公約数(Greatest Common Divisor) int gcd(int m, int n) { //引数に0がある場合は0を返す if (m == 0 || n == 0) return 0; //ユークリッドの互除法 while (m != n) { if (m > n) m = m - n; else n = n - m; } return m; } //最小公倍数(Least Common Multiple) int lcm(int m, int n) { //引数に0がある場合は0を返す if (m == 0 || n == 0) return 0; // lcm = m * n / gcd(m, n) return ((m / gcd(m, n)) * n); } //素因数分解 void prime_factorization(int n) { int a = 2, res; while (n >= a * a) { if (n % a == 0) { res = a; // resをグローバルな配列に代入すれば記録できる。 n /= a; } else { a++; } } //ラス1の素因数 res = n; } //エラトステネスの篩 int Eratosthenes(int n) { bool prime[n]; // prime[0]が1、prime[n - 1]がn。 rep(i, n) prime[i] = true; for (int i = 2; i < sqrt(n); i++) { if (prime[i]) { for (int j = 0; i * (j + 2) < n; j++) { prime[i * (j + 2)] = false; } } } int cnt = 0; for (int i = 2; i < n; i++) { if (prime[i]) { cnt++; } } return cnt; } //偶奇判定。奇数ならtrue。 bool odd_even(int num) { bool judge; if (num % 2) { judge = true; } else { judge = false; } return judge; }
#include <bits/stdc++.h> //#include <mylib.h> using namespace std; // cin.sync_with_stdio(false); #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FOR_EQ(i, a, b) for (int i = (a); i <= (b); ++i) #define FOR_RE(i, a, b) for (int i = (a); i > (b); --i) #define rep(i, n) FOR(i, 0, n) #define rep_eq(i, n) FOR_EQ(i, 0, n) #define rep_re(i, n) FOR_RE(i, n, 0) #define DEBUG_VARIABLE(variable) cout << #variable << ":" << variable << endl #define WHITE 1 //(未訪問) #define GRAY \ 2 //(訪問)未だに訪問していない頂点への辺を持っている。スタックに退避。 #define BLACK 3 //(訪問完了)未訪問への頂点への辺を持たない #define N 100 #define INFTY (1 << 21) // 10^21 #define INF (1 << 9) int M[N][N]; //隣接行列 int color[N]; // 1個上から時計周り const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1}; //上右下左 const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {-1, 0, 1, 0}; static const int NIL = -1; typedef unsigned long long ull; typedef long long ll; typedef vector<int> Vector; typedef vector<Vector> DVector; int n; void printArray(int *array, int); void printVector(vector<char> &v); void printDimention(DVector &dv); // nCr方式で組み合わせの数を求める int combination(int, int); // nPrで階乗を求める int factorial(int, int); //桁数を返す int find_digits(int); // 各桁の和を計算する関数 int findSumOfDigits(int); //次数を得る int degree(int); //四捨五入 int shishagonyu(double); //切り上げ int roundUp(double); //切り捨て int roundDown(double); //四捨五入 int roundOff(double); //最大公約数(Greatest Common Divisor) int gcd(int, int); //最小公倍数(Least Common Multiple) int lcm(int, int); //素因数分解 void prime_factorization(int); //エラトステネスの篩 int Eratosthenes(int); //偶奇判定。奇数ならtrue。 bool odd_even(int); int main(int argc, char const *argv[]) { cin.tie(0); ios::sync_with_stdio(false); string s; vector<char> cube; int cnt = 0; cin >> s; rep(i, s.size()) { cube.push_back(s[i]); } // printVector(cube); // while(flg){ // bool flg = false; char pre = '2'; rep(i, cube.size()) { /* cout << "s" << endl; DEBUG_VARIABLE(pre); DEBUG_VARIABLE(cube[i]); DEBUG_VARIABLE(i); DEBUG_VARIABLE(cube.size()); */ if (cube[i] == '0' && pre == '1') { cube.erase(cube.begin() + i); cube.erase(cube.begin() + i - 1); if (i - 2 < 0) { pre = '2'; i = -1; } else { pre = cube[i - 2]; i = i - 2; } cnt++; // cout << "d" << endl; } else if (cube[i] == '1' && pre == '0') { cube.erase(cube.begin() + i); cube.erase(cube.begin() + i - 1); if (i - 2 < 0) { pre = '2'; i = -1; } else { pre = cube[i - 2]; i = i - 2; } cnt++; // cout << "d" << endl; } else { pre = cube[i]; } } cout << cnt * 2 << endl; //} } //配列の表示 void printArray(int array[], int n) { rep(i, n) { if (i) cout << " "; cout << array[i]; } cout << endl; } // Vectorの表示 void printVector(vector<char> &v) { rep(i, (int)v.size()) { if (i) cout << " "; cout << v[i]; } cout << endl; } //二次元配列の表示 void printDimention(DVector &dv) { rep(i, (int)dv.size()) { rep(j, (int)dv[i].size()) { if (j) cout << " "; cout << dv[i][j]; } cout << endl; } } // numの中に何個2がかかってるか int factor2(int num) { int cnt = 0; while (num % 2 == 0) { num /= 2; cnt++; } return cnt; } // nCr方式で組み合わせの数を求める int combination(int n, int r) { int up = 1, down = 1; rep(i, n) up *= (i + 1); rep(i, n - r) down *= (i + 1); rep(i, r) down *= (i + 1); return up / down; } // nPr方式で階乗を求める int factorial(int n, int r) { if (n < r) { cout << "error" << endl; return 0; } else { int res = 1; while (r) { r--; res *= n; n--; } return res; } } //桁数を返す int find_digits(int n) { int digit = 0; while (n) { n /= 10; digit++; } return digit; } // 各桁の和を計算する関数 int findSumOfDigits(int n) { int sum = 0; while (n > 0) { // n が 0 になるまで sum += n % 10; n /= 10; } return sum; } //次数を得る int degree(int n) { int count = 0; while (1) { if (count <= 0) break; count /= 2; count++; } return count; } //四捨五入 int shishagonyu(double x) { return (int)(x < 0.0 ? x - 0.5 : x + 0.5); } //切り上げ int roundUp(double n) { if (n >= 0) { return (int)n + 1; } else { return (int)n - 1; } } //切り捨て int roundDown(double n) { return (int)n; } //四捨五入 int roundOff(double n) { double decimal = 0; decimal = n - (int)n; if (decimal >= 0.5 || decimal <= -0.5) { return roundUp(n); } else { return roundDown(n); } } //最大公約数(Greatest Common Divisor) int gcd(int m, int n) { //引数に0がある場合は0を返す if (m == 0 || n == 0) return 0; //ユークリッドの互除法 while (m != n) { if (m > n) m = m - n; else n = n - m; } return m; } //最小公倍数(Least Common Multiple) int lcm(int m, int n) { //引数に0がある場合は0を返す if (m == 0 || n == 0) return 0; // lcm = m * n / gcd(m, n) return ((m / gcd(m, n)) * n); } //素因数分解 void prime_factorization(int n) { int a = 2, res; while (n >= a * a) { if (n % a == 0) { res = a; // resをグローバルな配列に代入すれば記録できる。 n /= a; } else { a++; } } //ラス1の素因数 res = n; } //エラトステネスの篩 int Eratosthenes(int n) { bool prime[n]; // prime[0]が1、prime[n - 1]がn。 rep(i, n) prime[i] = true; for (int i = 2; i < sqrt(n); i++) { if (prime[i]) { for (int j = 0; i * (j + 2) < n; j++) { prime[i * (j + 2)] = false; } } } int cnt = 0; for (int i = 2; i < n; i++) { if (prime[i]) { cnt++; } } return cnt; } //偶奇判定。奇数ならtrue。 bool odd_even(int num) { bool judge; if (num % 2) { judge = true; } else { judge = false; } return judge; }
[ "literal.number.change", "assignment.value.change" ]
918,243
918,244
u669551866
cpp
p03107
#include <stdio.h> int main() { int n_red = 0, n_blue = 0; char c; while (1) { scanf("%c", &c); if (c == '0') n_red++; else if (c == '1') n_blue; else break; } int ans = n_red > n_blue ? 2 * n_blue : 2 * n_red; printf("%d", ans); return 0; }
#include <stdio.h> int main() { int n_red = 0, n_blue = 0; char c; while (1) { scanf("%c", &c); if (c == '0') n_red++; else if (c == '1') n_blue++; else break; } int ans = n_red > n_blue ? 2 * n_blue : 2 * n_red; printf("%d", ans); return 0; }
[]
918,245
918,246
u735008991
cpp
p03107
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int ans = 0, n = s.size(); stack<char> st; for (int i = 0; i < n; i++) { if (st.empty()) st.push(s[i]); else { if (st.top() != s[i]) { ans++; st.pop(); } else st.push(s[i]); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int ans = 0, n = s.size(); stack<char> st; for (int i = 0; i < n; i++) { if (st.empty()) st.push(s[i]); else { if (st.top() != s[i]) { ans++; st.pop(); } else st.push(s[i]); } } cout << ans * 2 << endl; }
[ "expression.operation.binary.add" ]
918,251
918,252
u401775402
cpp
p03107
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { string s; cin >> s; vector<int> a; for (int i = 0; i < s.size(); i++) { a.push_back(s[i] - '0'); while (a.size() > 1 && abs(a[a.size() - 1] - a[a.size() - 2]) > 0) a.erase(a.begin() + a.size() - 1), a.erase(a.begin() - 1); } cout << (int)s.size() - (int)a.size() << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { string s; cin >> s; vector<int> a; for (int i = 0; i < s.size(); i++) { a.push_back(s[i] - '0'); while (a.size() > 1 && abs(a[a.size() - 1] - a[a.size() - 2]) > 0) a.erase(a.begin() + a.size() - 1), a.erase(a.begin() + a.size() - 1); } cout << (int)s.size() - (int)a.size() << endl; return 0; }
[ "expression.operation.binary.add" ]
918,257
918,258
u036561304
cpp
p03107
// // Created by 永徳泰明 on 2019-03-03. // #include <bits/stdc++.h> typedef long long ll; using namespace std; #define dump(x) cout << #x << " = " << (x) << endl; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define fill(x, y) memset(x, y, sizeof(x)) int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; const int INF = 999999999; void readFromInputFile() { #ifdef LOCAL static std::ifstream in("/Users/hoo/CLionProjects/for_atcoder/input"); std::cin.rdbuf(in.rdbuf()); #endif } int main() { readFromInputFile(); string s; cin >> s; int a, b; rep(i, s.size()) { if (s[i] == '1') { a++; } else { b++; } } cout << min(a, b) * 2 << endl; return 0; }
// // Created by 永徳泰明 on 2019-03-03. // #include <bits/stdc++.h> typedef long long ll; using namespace std; #define dump(x) cout << #x << " = " << (x) << endl; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define fill(x, y) memset(x, y, sizeof(x)) int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; const int INF = 999999999; void readFromInputFile() { #ifdef LOCAL static std::ifstream in("/Users/hoo/CLionProjects/for_atcoder/input"); std::cin.rdbuf(in.rdbuf()); #endif } int main() { readFromInputFile(); string s; cin >> s; int a = 0, b = 0; rep(i, s.size()) { if (s[i] == '1') { a++; } else { b++; } } cout << min(a, b) * 2 << endl; return 0; }
[ "variable_declaration.value.change" ]
918,264
918,265
u779937111
cpp
p03107
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int N0 = 0, N1 = 0; for (int i = 0; i < S.length(); i++) { if (S[i] == '0') N0++; else N1++; } cout << min(N0, N1) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int N0 = 0, N1 = 0; for (int i = 0; i < S.length(); i++) { if (S[i] == '0') N0++; else N1++; } cout << 2 * min(N0, N1) << endl; }
[ "expression.operation.binary.add" ]
918,268
918,269
u017271745
cpp
p03107
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define FORR(i, m, n) for (int i = m; i >= n; i--) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define llong long long #define pb(a) push_back(a) #define INF 999999999 using namespace std; typedef pair<int, int> P; typedef pair<llong, llong> LP; typedef pair<int, P> PP; typedef pair<llong, LP> LPP; int dy[] = {0, 0, 1, -1, 0}; int dx[] = {1, -1, 0, 0, 0}; int main() { int a, b, c; string s; // scanf("%d %d %d", &a, &b, &c); cin >> s; int zero = 0; int one = 0; for (int i = 0; i < (int)s.length(); i++) { if (((int)s[i]) == 0) { zero++; } else { one++; } } if (zero > one) { cout << 2 * one; } else { cout << 2 * zero; } }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define FORR(i, m, n) for (int i = m; i >= n; i--) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define llong long long #define pb(a) push_back(a) #define INF 999999999 using namespace std; typedef pair<int, int> P; typedef pair<llong, llong> LP; typedef pair<int, P> PP; typedef pair<llong, LP> LPP; int dy[] = {0, 0, 1, -1, 0}; int dx[] = {1, -1, 0, 0, 0}; int main() { int a, b, c; string s; // scanf("%d %d %d", &a, &b, &c); cin >> s; int zero = 0; int one = 0; for (int i = 0; i < (int)s.length(); i++) { if ((int)(s[i] - '0') == 0) { zero++; } else { one++; } } if (zero > one) { cout << 2 * one; } else { cout << 2 * zero; } }
[ "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change" ]
918,270
918,271
u978036461
cpp
p03107
#include <iostream> #include <map> #include <string> #include <vector> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); string s; int c0 = 0; int c1 = 1; cin >> s; for (int i = 0; i < s.size(); i++) { if (stoi(s.substr(i, 1)) == 1) { c1++; } else { c0++; } } if (c1 > c0) { cout << 2 * c0; } else { cout << 2 * c1; } }
#include <iostream> #include <map> #include <string> #include <vector> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); string s; int c0 = 0; int c1 = 0; cin >> s; for (int i = 0; i < s.size(); i++) { if (stoi(s.substr(i, 1)) == 1) { c1++; } else { c0++; } } if (c1 > c0) { cout << 2 * c0; } else { cout << 2 * c1; } }
[ "literal.number.change", "variable_declaration.value.change" ]
918,278
918,279
u347588083
cpp
p03107
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <stack> #include <string> int main() { std ::string Str; std ::cin >> Str; int Len = Str.size(), Ans = 0; std ::stack<int> Stack; Stack.push(Str[0] - '0'); for (int i = 1; i < Len; i++) { int Now = Str[i] - '0'; if (Stack.empty()) Stack.push(Now); if (Now != Stack.top()) { Stack.pop(); Ans += 2; } else { Stack.push(Now); } } printf("%d", Ans); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <stack> #include <string> int main() { std ::string Str; std ::cin >> Str; int Len = Str.size(), Ans = 0; std ::stack<int> Stack; Stack.push(Str[0] - '0'); for (int i = 1; i < Len; i++) { int Now = Str[i] - '0'; if (Stack.empty()) Stack.push(Now); else if (Now != Stack.top()) { Stack.pop(); Ans += 2; } else { Stack.push(Now); } } printf("%d", Ans); return 0; }
[ "control_flow.branch.else_if.replace.add", "control_flow.branch.if.replace.remove" ]
918,282
918,283
u317481056
cpp
p03108
#include <bits/stdc++.h> using namespace std; using ll = long long; //しょっぱなやばい、とけなそう感・・・ //方針たたんな //最後から見るか。 //連結数はN(N-1)/2。最後は-1; //毎回すべての連結確認する、はむりむり // 1[2,3,,,10] 2[3,4,,,10] 3[4,5,,,10]みたいな //和を足せばいい? //んなことないか。1-2,1-3,2-3で1-2きれても3連結 //孤立した島の積をとるか // 1-2-3,4-5-6だったら3*3=9がだめ 3+3+3 // 1,2,3,4,5だったら?5*4/2 4+4+4+4+4)/2 // 1-2,3-4,5だったら8 3+3+3+3+4)/2 //はしを1本折るごとに探索してたんじゃ絶対むりむりちん10^5でしょ // DP,どんなふうに・・・。 //俺のもってる知識じゃまったくあてにならなそうだな。 //解答みちゃう。 //ミカサがどうしたって? // Union-Findすげえ。sizeを調べるのはどうしたらいいか //子どものsizeの配列をつねに用意。親に+1しとく // 1-2でS[1]=2 S[2]=1 // 1-2-3 1-2-4 で、S[4]=1 S[3]=1 S[2]=3 S[1]=4みたいな感じか // S[親]+=S[子1]+S[子2]か struct UnionFind { vector<ll> par; vector<ll> siz; UnionFind(ll N) : par(N), siz(N, 1) { for (int i = 0; i < N; i++) { par[i] = i; } } ll root(ll x) { if (par[x] == x) return x; par[x] = root(par[x]); } void unite(ll x, ll y) { ll rx = root(x), ry = root(y); if (rx == ry) return; par[ry] = rx; // x<yとしたい siz[rx] += siz[ry]; //小さい数に集める } bool issame(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } }; int main() { ll N, M; cin >> N >> M; vector<ll> A(M, 0), B(M, 0); for (int i = 0; i < M; i++) { ll a, b; cin >> a >> b; A[i] = a - 1; B[i] = b - 1; } UnionFind tree(N); ll all = N * (N - 1) / 2; vector<ll> ans(M, 0); for (int i = M - 1; i >= 0; i--) { ans[i] = all; if (all == 0) break; //連結成分の大きさってなんだ // all-N1*N2をしたい //いみわかった。 // 1 2-3 4 5 9 10-1*1 // 1 2-3 4-5 8 9-1*1 // 1-2-3 4-5 6 8-1*2 // 1-2-3-4-5 0 6-3*2 if (tree.issame(A[i], B[i]) == false) { all -= tree.size(A[i]) * tree.size(B[i]); } tree.unite(A[i], B[i]); } for (int i = 0; i < M; i++) cout << ans[i] << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; //しょっぱなやばい、とけなそう感・・・ //方針たたんな //最後から見るか。 //連結数はN(N-1)/2。最後は-1; //毎回すべての連結確認する、はむりむり // 1[2,3,,,10] 2[3,4,,,10] 3[4,5,,,10]みたいな //和を足せばいい? //んなことないか。1-2,1-3,2-3で1-2きれても3連結 //孤立した島の積をとるか // 1-2-3,4-5-6だったら3*3=9がだめ 3+3+3 // 1,2,3,4,5だったら?5*4/2 4+4+4+4+4)/2 // 1-2,3-4,5だったら8 3+3+3+3+4)/2 //はしを1本折るごとに探索してたんじゃ絶対むりむりちん10^5でしょ // DP,どんなふうに・・・。 //俺のもってる知識じゃまったくあてにならなそうだな。 //解答みちゃう。 //ミカサがどうしたって? // Union-Findすげえ。sizeを調べるのはどうしたらいいか //子どものsizeの配列をつねに用意。親に+1しとく // 1-2でS[1]=2 S[2]=1 // 1-2-3 1-2-4 で、S[4]=1 S[3]=1 S[2]=3 S[1]=4みたいな感じか // S[親]+=S[子1]+S[子2]か struct UnionFind { vector<ll> par; vector<ll> siz; UnionFind(ll N) : par(N), siz(N, 1) { for (int i = 0; i < N; i++) { par[i] = i; } } ll root(ll x) { if (par[x] == x) return x; par[x] = root(par[x]); return par[x]; } void unite(ll x, ll y) { ll rx = root(x), ry = root(y); if (rx == ry) return; par[ry] = rx; // x<yとしたい siz[rx] += siz[ry]; //小さい数に集める } bool issame(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } }; int main() { ll N, M; cin >> N >> M; vector<ll> A(M, 0), B(M, 0); for (int i = 0; i < M; i++) { ll a, b; cin >> a >> b; A[i] = a - 1; B[i] = b - 1; } UnionFind tree(N); ll all = N * (N - 1) / 2; vector<ll> ans(M, 0); for (int i = M - 1; i >= 0; i--) { ans[i] = all; if (all == 0) break; //連結成分の大きさってなんだ // all-N1*N2をしたい //いみわかった。 // 1 2-3 4 5 9 10-1*1 // 1 2-3 4-5 8 9-1*1 // 1-2-3 4-5 6 8-1*2 // 1-2-3-4-5 0 6-3*2 if (tree.issame(A[i], B[i]) == false) { all -= tree.size(A[i]) * tree.size(B[i]); } tree.unite(A[i], B[i]); } for (int i = 0; i < M; i++) cout << ans[i] << endl; }
[ "control_flow.return.add" ]
918,407
918,410
u071282706
cpp
p03108
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define REP(i, a, b) for (int i = a; i < (b); ++i) #define all(x) (x).begin(), (x).end() #define YY cout << "Yes" << endl; #define NN cout << "No" << endl; #define ve vector const int INF = 1000000007; typedef long long ll; using namespace std; using Graph = vector<vector<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; } 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); } // *max_element(all(d)); class UnionFind { private: vector<int> par; public: UnionFind(int n) : par(n, -1) {} int root(int x) { if (par[x] < 0) return x; return par[x] = root(par[x]); } bool unite(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return true; } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return -par[root(x)]; } }; int solve() { int n, m; cin >> n >> m; vector<pair<int, int>> v(m); vector<ll> anser; ll ans = n * (ll)(n - 1) / 2; UnionFind uf(n); rep(i, m) { int a, b; cin >> a >> b; a--; b--; v[i].first = a; v[i].second = b; } for (int i = m - 1; i >= 0; i--) { int a = v[i].first, b = v[i].second; anser.push_back(ans); if (uf.same(a, b)) continue; ans -= uf.size(a) * (ll)uf.size(b); uf.unite(a, b); } reverse(all(anser)); rep(i, n) cout << anser[i] << endl; return 0; } int main() { // ios::sync_with_stdio(false);cin.tie(nullptr); // cout << fixed;cout << setprecision(16) << endl; solve(); return 0; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define REP(i, a, b) for (int i = a; i < (b); ++i) #define all(x) (x).begin(), (x).end() #define YY cout << "Yes" << endl; #define NN cout << "No" << endl; #define ve vector const int INF = 1000000007; typedef long long ll; using namespace std; using Graph = vector<vector<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; } 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); } // *max_element(all(d)); class UnionFind { private: vector<int> par; public: UnionFind(int n) : par(n, -1) {} int root(int x) { if (par[x] < 0) return x; return par[x] = root(par[x]); } bool unite(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return true; } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return -par[root(x)]; } }; int solve() { int n, m; cin >> n >> m; vector<pair<int, int>> v(m); vector<ll> anser; ll ans = n * (ll)(n - 1) / 2; UnionFind uf(n); rep(i, m) { int a, b; cin >> a >> b; a--; b--; v[i].first = a; v[i].second = b; } for (int i = m - 1; i >= 0; i--) { int a = v[i].first, b = v[i].second; anser.push_back(ans); if (uf.same(a, b)) continue; ans -= uf.size(a) * (ll)uf.size(b); uf.unite(a, b); } reverse(all(anser)); rep(i, m) cout << anser[i] << endl; return 0; } int main() { // ios::sync_with_stdio(false);cin.tie(nullptr); // cout << fixed;cout << setprecision(16) << endl; solve(); return 0; }
[ "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
918,435
918,438
u820341516
cpp
p03108
#include <bits/stdc++.h> #define MAXN 100005 using namespace std; long long fa[MAXN], a[MAXN], b[MAXN], cnt[MAXN], ans[MAXN]; long long find1(long long v) { return fa[v] = fa[v] == v ? v : find1(fa[v]); } void merge1(long long x, long long y) { fa[x] = y; cnt[x] += cnt[y]; } int main() { long long n, m; cin >> n >> m; for (long long i = 0; i < n; i++) { fa[i] = i; cnt[i] = 1; } for (long long i = 0; i < m; i++) cin >> a[i] >> b[i]; ans[m - 1] = n * (n - 1) / 2; for (long long i = m - 1; i > 0; i--) { long long x = find1(a[i]); long long y = find1(b[i]); if (x != y) { ans[i - 1] = ans[i] - cnt[x] * cnt[y]; merge1(x, y); } else ans[i - 1] = ans[i]; } for (long long i = 0; i < m; i++) cout << ans[i] << endl; return 0; }
#include <bits/stdc++.h> #define MAXN 100005 using namespace std; long long fa[MAXN], a[MAXN], b[MAXN], cnt[MAXN], ans[MAXN]; long long find1(long long v) { return fa[v] = fa[v] == v ? v : find1(fa[v]); } void merge1(long long x, long long y) { fa[x] = y; cnt[y] += cnt[x]; } int main() { long long n, m; cin >> n >> m; for (long long i = 0; i < n; i++) { fa[i] = i; cnt[i] = 1; } for (long long i = 0; i < m; i++) cin >> a[i] >> b[i]; ans[m - 1] = n * (n - 1) / 2; for (long long i = m - 1; i > 0; i--) { long long x = find1(a[i]); long long y = find1(b[i]); if (x != y) { ans[i - 1] = ans[i] - cnt[x] * cnt[y]; merge1(x, y); } else ans[i - 1] = ans[i]; } for (long long i = 0; i < m; i++) cout << ans[i] << endl; return 0; }
[ "assignment.change" ]
918,460
918,461
u959625800
cpp
p03108
#include <bits/stdc++.h> typedef long long ll; using namespace std; struct union_find { union_find(int n) { for (int i = 0; i <= n; i++) { par.push_back(i); rank.push_back(0); size.push_back(1); } } 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 (rank[x] < rank[y]) { par[x] = y; size[y] += size[x]; } else { par[y] = x; if (rank[x] == rank[y]) rank[x]++; size[x] += size[y]; } } int getSize(int x) { return size[x]; } private: vector<int> par, rank, size; }; int main() { ll N, M; cin >> N >> M; vector<pair<int, int>> bridge(M + 1); for (int i = 1; i <= M; i++) { int A, B; cin >> A >> B; bridge.push_back(make_pair(A, B)); } union_find island(N); vector<ll> conv(M + 2, 0); // 橋 i 建設後の便利さ = conv[i] conv[M + 1] = 0; // 橋が 1 つも無いとき便利さは 0 // 橋 M, M-1, ……, 1 の順に橋を建設する for (int i = M; i >= 0; i--) { int A = bridge[i].first; int B = bridge[i].second; // A と B の根を求める A = island.find(A); B = island.find(B); if (A == B) { // A, B が互いに行き来できるとき、AとBを繋いでも便利さは増えない conv[i] = conv[i + 1]; } else { // A, B が互いに行き来できないとき、 // A, B の各グループの連結成分の数の積だけ便利さが増える conv[i] = conv[i + 1] + island.getSize(A) * island.getSize(B); } // A と B を併合 island.unite(A, B); } // (橋 i 崩落後の不便さ)+(橋 i + 1 建設後の便利さ)= N*(N-1)/2 for (int i = 1; i <= M; i++) { ll ans = N * (N - 1) / 2 - conv[i + 1]; cout << ans << endl; } }
#include <bits/stdc++.h> typedef long long ll; using namespace std; struct union_find { union_find(int n) { for (int i = 0; i <= n; i++) { par.push_back(i); rank.push_back(0); size.push_back(1); } } 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 (rank[x] < rank[y]) { par[x] = y; size[y] += size[x]; } else { par[y] = x; if (rank[x] == rank[y]) rank[x]++; size[x] += size[y]; } } int getSize(int x) { return size[x]; } private: vector<int> par, rank, size; }; int main() { ll N, M; cin >> N >> M; vector<pair<int, int>> bridge(M + 1); for (int i = 1; i <= M; i++) { int A, B; cin >> A >> B; bridge[i] = make_pair(A, B); } union_find island(N); vector<ll> conv(M + 2, 0); // 橋 i 建設後の便利さ = conv[i] conv[M + 1] = 0; // 橋が 1 つも無いとき便利さは 0 // 橋 M, M-1, ……, 1 の順に橋を建設する for (int i = M; i >= 0; i--) { int A = bridge[i].first; int B = bridge[i].second; // A と B の根を求める A = island.find(A); B = island.find(B); if (A == B) { // A, B が互いに行き来できるとき、AとBを繋いでも便利さは増えない conv[i] = conv[i + 1]; } else { // A, B が互いに行き来できないとき、 // A, B の各グループの連結成分の数の積だけ便利さが増える conv[i] = conv[i + 1] + island.getSize(A) * island.getSize(B); } // A と B を併合 island.unite(A, B); } // (橋 i 崩落後の不便さ)+(橋 i + 1 建設後の便利さ)= N*(N-1)/2 for (int i = 1; i <= M; i++) { ll ans = N * (N - 1) / 2 - conv[i + 1]; cout << ans << endl; } }
[ "call.arguments.change" ]
918,515
918,517
u119098168
cpp
p03108
#include <bits/stdc++.h> #define FOR(i, k, n) for (int i = (k); i < (n); i++) #define FORe(i, k, n) for (int i = (k); i <= (n); i++) #define FORr(i, k, n) for (int i = (k)-1; i > (n); i--) #define FORre(i, k, n) for (int i = (k)-1; i >= (n); i--) #define REP(i, n) FOR(i, 0, n) #define REPr(i, n) FORre(i, n, 0) #define ALL(x) (x).begin(), (x).end() #define ALLr(x) (x).rbegin(), (x).rend() #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1001001001; struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} int root(int x) { return (par[x] < 0) ? x : par[x] = root(par[x]); } int size(int x) { return -par[root(x)]; } bool issame(int x, int y) { return root(x) == root(y); } void marge(int x, int y) { x = root(x); y = root(y); if (x == y) return; if (x > y) swap(x, y); par[x] += par[y]; par[y] = x; } }; int main(void) { int n, m; cin >> n >> m; UnionFind uf(n); vector<P> bridges(m); REP(i, m) { int a, b; cin >> a >> b; a--; b--; bridges[i] = P(a, b); } vector<ll> ans(m); ll cur = n * (n - 1) / 2; FORr(i, m, 0) { ans[i] = cur; int a = bridges[i].first; int b = bridges[i].second; if (uf.issame(a, b)) continue; ll sa = uf.size(a); ll sb = uf.size(b); cur -= sa * sb; uf.marge(a, b); } REP(i, m) cout << ans[i] << endl; return 0; }
#include <bits/stdc++.h> #define FOR(i, k, n) for (int i = (k); i < (n); i++) #define FORe(i, k, n) for (int i = (k); i <= (n); i++) #define FORr(i, k, n) for (int i = (k)-1; i > (n); i--) #define FORre(i, k, n) for (int i = (k)-1; i >= (n); i--) #define REP(i, n) FOR(i, 0, n) #define REPr(i, n) FORre(i, n, 0) #define ALL(x) (x).begin(), (x).end() #define ALLr(x) (x).rbegin(), (x).rend() #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1001001001; struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} int root(int x) { return (par[x] < 0) ? x : par[x] = root(par[x]); } int size(int x) { return -par[root(x)]; } bool issame(int x, int y) { return root(x) == root(y); } void marge(int x, int y) { x = root(x); y = root(y); if (x == y) return; if (x > y) swap(x, y); par[x] += par[y]; par[y] = x; } }; int main(void) { ll n, m; cin >> n >> m; UnionFind uf(n); vector<P> bridges(m); REP(i, m) { int a, b; cin >> a >> b; a--; b--; bridges[i] = P(a, b); } vector<ll> ans(m); ll cur = n * (n - 1) / 2; FORre(i, m, 0) { ans[i] = cur; int a = bridges[i].first; int b = bridges[i].second; if (uf.issame(a, b)) continue; ll sa = uf.size(a); ll sb = uf.size(b); cur -= sa * sb; uf.marge(a, b); } REP(i, m) cout << ans[i] << endl; return 0; }
[ "variable_declaration.type.change", "identifier.change", "call.function.change" ]
918,605
918,603
u961136005
cpp
p03108
#include <bits/stdc++.h> #include <cmath> #include <iostream> #include <string> #include <unordered_map> #include <unordered_set> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define FORR(i, a, b) for (ll i = (a); i <= (b); i++) #define repR(i, n) for (ll i = n; i >= 0; i--) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define F first #define S second #define pb push_back #define pu push #define COUT(x) cout << (x) << endl #define PQ priority_queue<ll> #define PQR priority_queue<ll, vector<ll>, greater<ll>> #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define mp make_pair #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) #define sz(x) (int)(x).size() typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll MOD = 1000000007LL; const ll INF = 1LL << 60; using vll = vector<ll>; using vb = vector<bool>; using vvb = vector<vb>; using vvll = vector<vll>; using vstr = vector<string>; using pll = pair<ll, ll>; using vc = vector<char>; using vvc = vector<vc>; ll dx[4] = {0, 1, 0, -1}; ll dy[4] = {1, 0, -1, 0}; template <typename T> struct UnionFind { vector<T> par; vector<T> rank; vector<T> sizes; UnionFind(T n) : par(n), rank(n, 0), sizes(n, 1) { for (T i = 0; i < n; i++) { par[i] = i; } } T root(T x) { return par[x] == x ? x : par[x] = root(par[x]); } bool unite(T x, T y) { if (x == y) return false; x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) rank[x]++; par[y] = x; sizes[x] = sizes[x] + sizes[y]; return true; } bool same(T x, T y) { return root(x) == root(y); } T size(T x) { return sizes[root(x)]; } }; int main() { ll n, m; cin >> n >> m; vll a(m), b(m); rep(i, m) cin >> a[i] >> b[i]; vll ans(m); UnionFind<ll> uf(n + 1); ans[m - 1] = (n * (n - 1) / 2); for (int i = m - 1; i > 0; i++) { if (uf.same(a[i], b[i])) { ans[i - 1] = ans[i]; } else { ans[i - 1] = ans[i] - uf.size(a[i]) * uf.size(b[i]); uf.unite(a[i], b[i]); } } rep(i, m) { COUT(ans[i]); } }
#include <bits/stdc++.h> #include <cmath> #include <iostream> #include <string> #include <unordered_map> #include <unordered_set> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define FORR(i, a, b) for (ll i = (a); i <= (b); i++) #define repR(i, n) for (ll i = n; i >= 0; i--) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define F first #define S second #define pb push_back #define pu push #define COUT(x) cout << (x) << endl #define PQ priority_queue<ll> #define PQR priority_queue<ll, vector<ll>, greater<ll>> #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define mp make_pair #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) #define sz(x) (int)(x).size() typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll MOD = 1000000007LL; const ll INF = 1LL << 60; using vll = vector<ll>; using vb = vector<bool>; using vvb = vector<vb>; using vvll = vector<vll>; using vstr = vector<string>; using pll = pair<ll, ll>; using vc = vector<char>; using vvc = vector<vc>; ll dx[4] = {0, 1, 0, -1}; ll dy[4] = {1, 0, -1, 0}; template <typename T> struct UnionFind { vector<T> par; vector<T> rank; vector<T> sizes; UnionFind(T n) : par(n), rank(n, 0), sizes(n, 1) { for (T i = 0; i < n; i++) { par[i] = i; } } T root(T x) { return par[x] == x ? x : par[x] = root(par[x]); } bool unite(T x, T y) { if (x == y) return false; x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) rank[x]++; par[y] = x; sizes[x] = sizes[x] + sizes[y]; return true; } bool same(T x, T y) { return root(x) == root(y); } T size(T x) { return sizes[root(x)]; } }; int main() { ll n, m; cin >> n >> m; vll a(m), b(m); rep(i, m) cin >> a[i] >> b[i]; vll ans(m); UnionFind<ll> uf(n + 1); ans[m - 1] = (n * (n - 1) / 2); for (int i = m - 1; i > 0; i--) { if (uf.same(a[i], b[i])) { ans[i - 1] = ans[i]; } else { ans[i - 1] = ans[i] - uf.size(a[i]) * uf.size(b[i]); uf.unite(a[i], b[i]); } } rep(i, m) { COUT(ans[i]); } }
[]
918,632
918,634
u103850114
cpp
p03108
#include <bits/stdc++.h> using namespace std; struct unionFind { vector<int> par; vector<long> count; unionFind(int n) : par(n) { for (int i = 0; i < n; i++) par[i] = i; count.resize(n); for (int i = 0; i < n; i++) count[i] = 1; } int find(int x) { if (par[x] == x) return x; else return par[x] = find(par[x]); } void unite(int x, int y) { int rx = find(x); int ry = find(y); if (rx == ry) return; else { par[rx] = ry; count[ry]++; return; } } bool same(int x, int y) { return find(x) == find(y); } }; int main() { long n, m; cin >> n >> m; vector<long> ans(m, 0); vector<int> a(m); vector<int> b(m); int i; for (i = 0; i < m; i++) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } unionFind unif(n); ans[m - 1] = (n * (n - 1)) / 2; for (i = m - 1; i > 0; i--) { if (!unif.same(a[i], b[i])) ans[i - 1] = ans[i] - (unif.count[unif.find(a[i])] * unif.count[unif.find(b[i])]); else ans[i - 1] = ans[i]; unif.unite(a[i], b[i]); } for (i = 0; i < m; i++) { cout << ans[i] << endl; } }
#include <bits/stdc++.h> using namespace std; struct unionFind { vector<int> par; vector<long> count; unionFind(int n) : par(n) { for (int i = 0; i < n; i++) par[i] = i; count.resize(n); for (int i = 0; i < n; i++) count[i] = 1; } int find(int x) { if (par[x] == x) return x; else return par[x] = find(par[x]); } void unite(int x, int y) { int rx = find(x); int ry = find(y); if (rx == ry) return; else { par[rx] = ry; count[ry] += count[rx]; return; } } bool same(int x, int y) { return find(x) == find(y); } }; int main() { long n, m; cin >> n >> m; vector<long> ans(m, 0); vector<int> a(m); vector<int> b(m); int i; for (i = 0; i < m; i++) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } unionFind unif(n); ans[m - 1] = (n * (n - 1)) / 2; for (i = m - 1; i > 0; i--) { if (!unif.same(a[i], b[i])) ans[i - 1] = ans[i] - (unif.count[unif.find(a[i])] * unif.count[unif.find(b[i])]); else ans[i - 1] = ans[i]; unif.unite(a[i], b[i]); } for (i = 0; i < m; i++) { cout << ans[i] << endl; } }
[]
918,650
918,652
u523698212
cpp
p03108
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; #define all(x) (x).begin(), (x).end() ll inf = LLONG_MAX; long double pi = M_PI; void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } // UnionFind //全て添字で扱うこと struct union_find { vll parent; vll sizes; void init(ll n) { for (ll i = 0; i < n; i++) parent.push_back(i); for (ll i = 0; i < n; i++) sizes.push_back(1); return; } ll root(ll n) { if (parent[n] == n) return n; return parent[n] = root(parent[n]); } ll size(ll n) { return sizes[root(n)]; } bool is_united(ll a, ll b) { return (root(a) == root(b)); } void unite(ll a, ll b) { if (is_united(a, b)) return; sizes[root(a)] += size(a); parent[root(b)] = root(a); return; } }; int main() { ll n, m; cin >> n >> m; vll a(m), b(m); for (ll i = 0; i < m; i++) cin >> a[i] >> b[i]; struct union_find uf; uf.init(n); ll unconv = n * (n - 1) / 2; vll ans(1, unconv); for (ll i = m - 1; i > 0; i--) { if (!uf.is_united(a[i] - 1, b[i] - 1)) { unconv -= uf.size(a[i] - 1) * uf.size(b[i] - 1); } uf.unite(a[i] - 1, b[i] - 1); ans.push_back(unconv); } for (ll i = 0; i < m; i++) cout << ans[m - 1 - i] << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; #define all(x) (x).begin(), (x).end() ll inf = LLONG_MAX; long double pi = M_PI; void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } // UnionFind //全て添字で扱うこと struct union_find { vll parent; vll sizes; void init(ll n) { for (ll i = 0; i < n; i++) parent.push_back(i); for (ll i = 0; i < n; i++) sizes.push_back(1); return; } ll root(ll n) { if (parent[n] == n) return n; return parent[n] = root(parent[n]); } ll size(ll n) { return sizes[root(n)]; } bool is_united(ll a, ll b) { return (root(a) == root(b)); } void unite(ll a, ll b) { if (is_united(a, b)) return; sizes[root(a)] += size(b); parent[root(b)] = root(a); return; } }; int main() { ll n, m; cin >> n >> m; vll a(m), b(m); for (ll i = 0; i < m; i++) cin >> a[i] >> b[i]; struct union_find uf; uf.init(n); ll unconv = n * (n - 1) / 2; vll ans(1, unconv); for (ll i = m - 1; i > 0; i--) { if (!uf.is_united(a[i] - 1, b[i] - 1)) { unconv -= uf.size(a[i] - 1) * uf.size(b[i] - 1); } uf.unite(a[i] - 1, b[i] - 1); ans.push_back(unconv); } for (ll i = 0; i < m; i++) cout << ans[m - 1 - i] << endl; }
[ "assignment.value.change", "identifier.change", "call.arguments.change" ]
918,656
918,658
u071019032
cpp
p03108
#include <bits/stdc++.h> using namespace std; class DisjointSet { public: vector<int> p; DisjointSet(int n) { p = vector<int>(n, -1); } int root(int x) { if (p[x] < 0) return x; p[x] = root(p[x]); return p[x]; } int size(int x) { return -p[root(x)]; } bool connect(int x, int y) { x = root(x); y = root(y); if (x == y) { return false; } if (size(x) < size(y)) swap(x, y); p[x] += p[y]; p[y] = x; return true; } }; int main() { int n, m; cin >> n >> m; int a[m], b[m]; for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; } long long ans[m]; ans[m - 1] = (long long)n * (n - 1) / 2; DisjointSet ds = DisjointSet(n); for (int i = m - 1; i >= 1; i--) { if (ds.root(a[i]) != ds.root(b[i])) { ans[i - 1] = ans[i] - (long long)ds.size(a[i]) * ds.size(b[i]); ds.connect(a[i], b[i]); } else ans[i - 1] = ans[i]; } for (int i = 0; i < m; i++) { cout << ans[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; class DisjointSet { public: vector<int> p; DisjointSet(int n) { p = vector<int>(n, -1); } int root(int x) { if (p[x] < 0) return x; p[x] = root(p[x]); return p[x]; } int size(int x) { return -p[root(x)]; } bool connect(int x, int y) { x = root(x); y = root(y); if (x == y) { return false; } if (size(x) < size(y)) swap(x, y); p[x] += p[y]; p[y] = x; return true; } }; int main() { int n, m; cin >> n >> m; int a[m], b[m]; for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; } long long ans[m]; ans[m - 1] = (long long)n * (n - 1) / 2; DisjointSet ds = DisjointSet(n + 1); for (int i = m - 1; i >= 1; i--) { if (ds.root(a[i]) != ds.root(b[i])) { ans[i - 1] = ans[i] - (long long)ds.size(a[i]) * ds.size(b[i]); ds.connect(a[i], b[i]); } else ans[i - 1] = ans[i]; } for (int i = 0; i < m; i++) { cout << ans[i] << endl; } return 0; }
[ "assignment.change" ]
918,761
918,762
u142234618
cpp
p03108
#include <algorithm> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } typedef long long ll; ll MOD = 1000000007; // a^p // 2^3 = 2 * 2^2 // 2^2 = 2 * (2^1) // 2^1 = 2 ll modpow(ll a, ll p, ll mod) { if (p == 0) return 1; if (p % 2 == 0) { ll half = modpow(a, p / 2, mod) % mod; return half * half % mod; } else { return a * modpow(a, p - 1, mod) % mod; } } // nCa を求める ll modCombination(ll n, ll a, ll mod) { if (n - a < a) { return modCombination(n, n - a, mod); } ll denominator = 1; // 分母 ll numerator = 1; // 分子 for (ll i = 0; i < a; i++) { denominator *= a - i; numerator *= n - i; denominator %= mod; numerator %= mod; } return numerator * modpow(denominator, mod - 2, mod) % mod; } class UnionFind { private: vector<ll> parents; public: UnionFind(ll n) : parents(n, -1) {} bool issame(ll x, ll y) { return root(x) == root(y); } bool merge(ll x, ll y) { if (issame(x, y)) return false; ll rx = root(x); ll ry = root(y); if (parents[rx] > parents[ry]) swap(rx, ry); // サイズ情報を更新 parents[rx] += parents[ry]; // yの親を更新 parents[ry] = rx; return true; } ll size(ll x) { return -parents[root(x)]; } private: ll root(ll x) { if (parents[x] < 0) return x; // 根の親の値に木の(-)サイズの情報を入れる return parents[x] = root(parents[x]); } }; int main() { ll N, M; cin >> N >> M; vector<pair<ll, ll>> bridges(M); for (ll i = 0; i < M; i++) { ll a, b; cin >> a >> b; bridges[i] = make_pair(a - 1, b - 1); } vector<ll> ans(M, 0); ans[M - 1] = N * (N - 1) / 2; UnionFind uni(N); for (ll i = M - 1; i > 0; i--) { auto points = bridges[i]; ll a = points.first; ll b = points.second; if (uni.issame(a, b)) { ans[i - 1] = 0; } else { ans[i - 1] = ans[i] - uni.size(a) * uni.size(b); } uni.merge(a, b); } for (auto a : ans) { cout << a << endl; } return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } typedef long long ll; ll MOD = 1000000007; // a^p // 2^3 = 2 * 2^2 // 2^2 = 2 * (2^1) // 2^1 = 2 ll modpow(ll a, ll p, ll mod) { if (p == 0) return 1; if (p % 2 == 0) { ll half = modpow(a, p / 2, mod) % mod; return half * half % mod; } else { return a * modpow(a, p - 1, mod) % mod; } } // nCa を求める ll modCombination(ll n, ll a, ll mod) { if (n - a < a) { return modCombination(n, n - a, mod); } ll denominator = 1; // 分母 ll numerator = 1; // 分子 for (ll i = 0; i < a; i++) { denominator *= a - i; numerator *= n - i; denominator %= mod; numerator %= mod; } return numerator * modpow(denominator, mod - 2, mod) % mod; } class UnionFind { private: vector<ll> parents; public: UnionFind(ll n) : parents(n, -1) {} bool issame(ll x, ll y) { return root(x) == root(y); } bool merge(ll x, ll y) { if (issame(x, y)) return false; ll rx = root(x); ll ry = root(y); if (parents[rx] > parents[ry]) swap(rx, ry); // サイズ情報を更新 parents[rx] += parents[ry]; // yの親を更新 parents[ry] = rx; return true; } ll size(ll x) { return -parents[root(x)]; } private: ll root(ll x) { if (parents[x] < 0) return x; // 根の親の値に木の(-)サイズの情報を入れる return parents[x] = root(parents[x]); } }; int main() { ll N, M; cin >> N >> M; vector<pair<ll, ll>> bridges(M); for (ll i = 0; i < M; i++) { ll a, b; cin >> a >> b; bridges[i] = make_pair(a - 1, b - 1); } vector<ll> ans(M, 0); ans[M - 1] = N * (N - 1) / 2; UnionFind uni(N); for (ll i = M - 1; i > 0; i--) { auto points = bridges[i]; ll a = points.first; ll b = points.second; if (uni.issame(a, b)) { ans[i - 1] = ans[i]; } else { ans[i - 1] = ans[i] - uni.size(a) * uni.size(b); } uni.merge(a, b); } for (auto a : ans) { cout << a << endl; } return 0; }
[ "assignment.value.change", "identifier.replace.add", "literal.replace.remove" ]
918,770
918,771
u237620737
cpp
p03108
#include <algorithm> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } typedef long long ll; class UnionFind { public: // 親の番号を格納。ルートだった場合は-(その集合のサイズ) vector<ll> parents; UnionFind(ll N) { parents = vector<ll>(N, -1); } // iがどのグループに属しているか ll root(ll i) { if (parents[i] < 0) { return i; } else { return parents[i] = root(parents[i]); } } // iが属しているグループの大きさ ll size(ll i) { return -parents[root(i)]; } // root(a)とroot(b)を接続する bool connect(ll a, ll b) { ll rootA = root(a); ll rootB = root(b); if (rootA == rootB) { return false; } else { // 大きいほう(a)に小さいほう(b)をくっつける // 大小が逆の場合はスワップ if (size(rootA) < size(rootB)) { swap(rootA, rootB); } // aグループのサイズを増やす parents[rootA] += parents[rootB]; // bの親をaのルートに変更する parents[rootB] = rootA; return true; } } }; int main() { ll N, M; cin >> N >> M; vector<ll> A(M), B(M); for (ll i = 0; i < M; i++) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<ll> ans(M); // 橋が全部崩落した ans[M - 1] = N * (N - 1) / 2; UnionFind Uni(N); for (ll i = M - 1; i >= 1; i--) { // A[i]とB[i]がつなげる if (Uni.root(A[i] != Uni.root(B[i]))) { ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]); Uni.connect(A[i], B[i]); } else { ans[i - 1] = ans[i]; } } for (ll i = 0; i < M; i++) { cout << ans[i] << endl; } return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } typedef long long ll; class UnionFind { public: // 親の番号を格納。ルートだった場合は-(その集合のサイズ) vector<ll> parents; UnionFind(ll N) { parents = vector<ll>(N, -1); } // iがどのグループに属しているか ll root(ll i) { if (parents[i] < 0) { return i; } else { return parents[i] = root(parents[i]); } } // iが属しているグループの大きさ ll size(ll i) { return -parents[root(i)]; } // root(a)とroot(b)を接続する bool connect(ll a, ll b) { ll rootA = root(a); ll rootB = root(b); if (rootA == rootB) { return false; } else { // 大きいほう(a)に小さいほう(b)をくっつける // 大小が逆の場合はスワップ if (size(rootA) < size(rootB)) { swap(rootA, rootB); } // aグループのサイズを増やす parents[rootA] += parents[rootB]; // bの親をaのルートに変更する parents[rootB] = rootA; return true; } } }; int main() { ll N, M; cin >> N >> M; vector<ll> A(M), B(M); for (ll i = 0; i < M; i++) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<ll> ans(M); // 橋が全部崩落した ans[M - 1] = N * (N - 1) / 2; UnionFind Uni(N); for (ll i = M - 1; i >= 1; i--) { // A[i]とB[i]がつなげる if (Uni.root(A[i]) != Uni.root(B[i])) { ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]); Uni.connect(A[i], B[i]); } else { ans[i - 1] = ans[i]; } } for (ll i = 0; i < M; i++) { cout << ans[i] << endl; } return 0; }
[ "control_flow.branch.if.condition.change" ]
918,772
918,773
u237620737
cpp
p03108
#include <algorithm> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } typedef long long ll; class UnionFind { public: // 親の番号を格納。ルートだった場合は-(その集合のサイズ) vector<ll> parents; UnionFind(ll N) { parents = vector<ll>(N, -1); } // iがどのグループに属しているか ll root(ll i) { if (parents[i] < 0) { return i; } else { return parents[i] = root(parents[i]); } } // iが属しているグループの大きさ ll size(ll i) { return -parents[root(i)]; } // root(a)とroot(b)を接続する bool connect(ll a, ll b) { ll rootA = root(a); ll rootB = root(b); if (rootA == rootB) { return false; } else { // 大きいほう(a)に小さいほう(b)をくっつける // 大小が逆の場合はスワップ if (size(rootA) < size(rootB)) { swap(rootA, rootB); } // aグループのサイズを増やす parents[rootA] += parents[rootB]; // bの親をaのルートに変更する parents[rootB] = rootA; return true; } } }; int main() { ll N, M; cin >> N >> M; vector<int> A(M), B(M); for (ll i = 0; i < M; i++) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<ll> ans(M); // 橋が全部崩落した ans[M - 1] = N * (N - 1) / 2; UnionFind Uni(N); for (ll i = M - 1; i >= 1; i--) { // A[i]とB[i]がつなげる if (Uni.root(A[i] != Uni.root(B[i]))) { ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]); Uni.connect(A[i], B[i]); } else { ans[i - 1] = ans[i]; } } for (ll i = 0; i < M; i++) { cout << ans[i] << endl; } return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } typedef long long ll; class UnionFind { public: // 親の番号を格納。ルートだった場合は-(その集合のサイズ) vector<ll> parents; UnionFind(ll N) { parents = vector<ll>(N, -1); } // iがどのグループに属しているか ll root(ll i) { if (parents[i] < 0) { return i; } else { return parents[i] = root(parents[i]); } } // iが属しているグループの大きさ ll size(ll i) { return -parents[root(i)]; } // root(a)とroot(b)を接続する bool connect(ll a, ll b) { ll rootA = root(a); ll rootB = root(b); if (rootA == rootB) { return false; } else { // 大きいほう(a)に小さいほう(b)をくっつける // 大小が逆の場合はスワップ if (size(rootA) < size(rootB)) { swap(rootA, rootB); } // aグループのサイズを増やす parents[rootA] += parents[rootB]; // bの親をaのルートに変更する parents[rootB] = rootA; return true; } } }; int main() { ll N, M; cin >> N >> M; vector<ll> A(M), B(M); for (ll i = 0; i < M; i++) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<ll> ans(M); // 橋が全部崩落した ans[M - 1] = N * (N - 1) / 2; UnionFind Uni(N); for (ll i = M - 1; i >= 1; i--) { // A[i]とB[i]がつなげる if (Uni.root(A[i]) != Uni.root(B[i])) { ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]); Uni.connect(A[i], B[i]); } else { ans[i - 1] = ans[i]; } } for (ll i = 0; i < M; i++) { cout << ans[i] << endl; } return 0; }
[ "control_flow.branch.if.condition.change" ]
918,774
918,773
u237620737
cpp
p03108
#include <algorithm> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } typedef long long ll; class UnionFind { public: // 親の番号を格納。ルートだった場合は-(その集合のサイズ) vector<ll> parents; UnionFind(ll N) { parents = vector<ll>(N, -1); } // iがどのグループに属しているか ll root(ll i) { if (parents[i] < 0) { return i; } else { return parents[i] = root(parents[i]); } } // iが属しているグループの大きさ ll size(ll i) { return -parents[root(i)]; } // root(a)とroot(b)を接続する bool connect(ll a, ll b) { ll rootA = root(a); ll rootB = root(b); if (rootA == rootB) { return false; } else { // union by size // 大きいほう(a)に小さいほう(b)をくっつける // 大小が逆の場合はスワップ if (size(rootA) < size(rootB)) { swap(rootA, rootB); } // aグループのサイズを増やす parents[rootA] += parents[rootB]; // bの親をaのルートに変更する parents[rootB] = rootA; return true; } } }; int main() { ll N, M; cin >> N >> M; vector<ll> A(M), B(M); for (ll i = 0; i < M; i++) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<ll> ans(M); // 橋が全部崩落した ans[M - 1] = N * (N - 1) / 2; UnionFind Uni(N); for (ll i = M - 1; i >= 1; i--) { // A[i]とB[i]がつなげる if (Uni.root(A[i] != Uni.root(B[i]))) { ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]); Uni.connect(A[i], B[i]); } else { ans[i - 1] = ans[i]; } } for (ll i = 0; i < M; i++) { cout << ans[i] << endl; } return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } typedef long long ll; class UnionFind { public: // 親の番号を格納。ルートだった場合は-(その集合のサイズ) vector<ll> parents; UnionFind(ll N) { parents = vector<ll>(N, -1); } // iがどのグループに属しているか ll root(ll i) { if (parents[i] < 0) { return i; } else { return parents[i] = root(parents[i]); } } // iが属しているグループの大きさ ll size(ll i) { return -parents[root(i)]; } // root(a)とroot(b)を接続する bool connect(ll a, ll b) { ll rootA = root(a); ll rootB = root(b); if (rootA == rootB) { return false; } else { // 大きいほう(a)に小さいほう(b)をくっつける // 大小が逆の場合はスワップ if (size(rootA) < size(rootB)) { swap(rootA, rootB); } // aグループのサイズを増やす parents[rootA] += parents[rootB]; // bの親をaのルートに変更する parents[rootB] = rootA; return true; } } }; int main() { ll N, M; cin >> N >> M; vector<ll> A(M), B(M); for (ll i = 0; i < M; i++) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<ll> ans(M); // 橋が全部崩落した ans[M - 1] = N * (N - 1) / 2; UnionFind Uni(N); for (ll i = M - 1; i >= 1; i--) { // A[i]とB[i]がつなげる if (Uni.root(A[i]) != Uni.root(B[i])) { ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]); Uni.connect(A[i], B[i]); } else { ans[i - 1] = ans[i]; } } for (ll i = 0; i < M; i++) { cout << ans[i] << endl; } return 0; }
[ "control_flow.branch.if.condition.change" ]
918,775
918,773
u237620737
cpp
p03108
#include <algorithm> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } typedef long long ll; class UnionFind { public: // 親の番号を格納。ルートだった場合は-(その集合のサイズ) vector<ll> parents; UnionFind(ll N) { parents = vector<ll>(N, -1); } // iがどのグループに属しているか ll root(ll i) { if (parents[i] < 0) { return i; } else { return parents[i] = root(parents[i]); } } // iが属しているグループの大きさ ll size(ll i) { return -parents[root(i)]; } // root(a)とroot(b)を接続する bool connect(ll a, ll b) { ll rootA = root(a); ll rootB = root(b); if (rootA == rootB) { return false; } else { // 大きいほう(a)に小さいほう(b)をくっつける // 大小が逆の場合はスワップ if (size(rootA) < size(rootB)) { swap(rootA, rootB); } // aグループのサイズを増やす parents[rootA] += parents[rootB]; // bの親をaのルートに変更する parents[rootB] = rootA; return true; } } }; int main() { ll N, M; cin >> N >> M; vector<int> A(M), B(M); for (ll i = 0; i < M; i++) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<ll> ans(M); // 橋が全部崩落した ans[M - 1] = N * (N - 1) / 2; UnionFind Uni(N); for (int i = M - 1; i >= 1; i--) { //繋がってなかったのが繋がった時 if (Uni.root(A[i]) != Uni.root(B[i])) { ans[i - 1] -= Uni.size(A[i]) * Uni.size(B[i]); Uni.connect(A[i], B[i]); } else { ans[i - 1] = ans[i]; } } for (ll i = 0; i < M; i++) { cout << ans[i] << endl; } return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } typedef long long ll; class UnionFind { public: // 親の番号を格納。ルートだった場合は-(その集合のサイズ) vector<ll> parents; UnionFind(ll N) { parents = vector<ll>(N, -1); } // iがどのグループに属しているか ll root(ll i) { if (parents[i] < 0) { return i; } else { return parents[i] = root(parents[i]); } } // iが属しているグループの大きさ ll size(ll i) { return -parents[root(i)]; } // root(a)とroot(b)を接続する bool connect(ll a, ll b) { ll rootA = root(a); ll rootB = root(b); if (rootA == rootB) { return false; } else { // 大きいほう(a)に小さいほう(b)をくっつける // 大小が逆の場合はスワップ if (size(rootA) < size(rootB)) { swap(rootA, rootB); } // aグループのサイズを増やす parents[rootA] += parents[rootB]; // bの親をaのルートに変更する parents[rootB] = rootA; return true; } } }; int main() { ll N, M; cin >> N >> M; vector<int> A(M), B(M); for (ll i = 0; i < M; i++) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<ll> ans(M); // 橋が全部崩落した ans[M - 1] = N * (N - 1) / 2; UnionFind Uni(N); for (int i = M - 1; i >= 1; i--) { //繋がってなかったのが繋がった時 if (Uni.root(A[i]) != Uni.root(B[i])) { ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]); Uni.connect(A[i], B[i]); } else { ans[i - 1] = ans[i]; } } for (ll i = 0; i < M; i++) { cout << ans[i] << endl; } return 0; }
[ "assignment.value.change", "assignment.change" ]
918,776
918,777
u237620737
cpp
p03108
#include <algorithm> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } typedef long long ll; class UnionFind { public: // 親の番号を格納。ルートだった場合は-(その集合のサイズ) vector<ll> parents; UnionFind(ll N) { parents = vector<ll>(N, -1); } // iがどのグループに属しているか ll root(ll i) { if (parents[i] < 0) { return i; } else { return parents[i] = root(parents[i]); } } // iが属しているグループの大きさ ll size(ll i) { return -parents[root(i)]; } // root(a)とroot(b)を接続する bool connect(ll a, ll b) { ll rootA = root(a); ll rootB = root(b); if (rootA == rootB) { return false; } else { // union by size // 大きいほう(a)に小さいほう(b)をくっつける // 大小が逆の場合はスワップ if (size(rootA) < size(rootB)) { swap(rootA, rootB); } // aグループのサイズを増やす parents[rootA] += parents[rootB]; // bの親をaのルートに変更する parents[rootB] = rootA; return true; } } }; int main() { ll N, M; cin >> N >> M; vector<ll> A(M), B(M); for (ll i = 0; i < M; i++) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<ll> ans(M); // 橋が全部崩落した ans[M - 1] = N * (N - 1) / 2; UnionFind Uni(N); for (ll i = M - 1; i >= 1; i--) { // A[i]とB[i]がつなげる if (Uni.root(A[i] != Uni.root(B[i]))) { ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]); Uni.connect(A[i], B[i]); } else { ans[i - 1] = ans[i]; } } for (ll i = 0; i < M; i++) { cout << ans[i] << endl; } return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } typedef long long ll; class UnionFind { public: // 親の番号を格納。ルートだった場合は-(その集合のサイズ) vector<ll> parents; UnionFind(ll N) { parents = vector<ll>(N, -1); } // iがどのグループに属しているか ll root(ll i) { if (parents[i] < 0) { return i; } else { return parents[i] = root(parents[i]); } } // iが属しているグループの大きさ ll size(ll i) { return -parents[root(i)]; } // root(a)とroot(b)を接続する bool connect(ll a, ll b) { ll rootA = root(a); ll rootB = root(b); if (rootA == rootB) { return false; } else { // 大きいほう(a)に小さいほう(b)をくっつける // 大小が逆の場合はスワップ if (size(rootA) < size(rootB)) { swap(rootA, rootB); } // aグループのサイズを増やす parents[rootA] += parents[rootB]; // bの親をaのルートに変更する parents[rootB] = rootA; return true; } } }; int main() { ll N, M; cin >> N >> M; vector<int> A(M), B(M); for (ll i = 0; i < M; i++) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<ll> ans(M); // 橋が全部崩落した ans[M - 1] = N * (N - 1) / 2; UnionFind Uni(N); for (int i = M - 1; i >= 1; i--) { //繋がってなかったのが繋がった時 if (Uni.root(A[i]) != Uni.root(B[i])) { ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]); Uni.connect(A[i], B[i]); } else { ans[i - 1] = ans[i]; } } for (ll i = 0; i < M; i++) { cout << ans[i] << endl; } return 0; }
[ "control_flow.loop.for.initializer.change", "variable_declaration.type.change", "control_flow.branch.if.condition.change" ]
918,775
918,777
u237620737
cpp
p03108
#include <iostream> #include <vector> using namespace std; typedef long long ll; class UnionFind { public: vector<int> Parent; UnionFind(int n) { Parent = vector<int>(n, -1); } int root(int a) { if (Parent[a] < 0) return a; return Parent[a] = root(Parent[a]); } int size(int a) { return -Parent[root(a)]; } bool connect(int a, int b) { a = root(a); b = root(b); if (a == b) return false; if (size(a) < size(b)) swap(a, b); Parent[a] += Parent[b]; Parent[b] = a; return true; } }; int main() { ll n, m; cin >> n >> m; vector<ll> a(m), b(m); for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } vector<ll> ans(m); ans[m - 1] = n * (n - 1) / 2; UnionFind Uni(n); for (int i = m - 1; i >= 1; i--) { ans[i - 1] = ans[i]; if (Uni.root(a[i]) != Uni.root(b[i])) { ans[i - 1] -= ans[i] - (ll)Uni.size(a[i]) * Uni.size(b[i]); Uni.connect(a[i], b[i]); } } for (int i = 0; i < m; i++) { cout << ans[i] << endl; } return 0; }
#include <iostream> #include <vector> using namespace std; typedef long long ll; class UnionFind { public: vector<int> Parent; UnionFind(int n) { Parent = vector<int>(n, -1); } int root(int a) { if (Parent[a] < 0) return a; return Parent[a] = root(Parent[a]); } int size(int a) { return -Parent[root(a)]; } bool connect(int a, int b) { a = root(a); b = root(b); if (a == b) return false; if (size(a) < size(b)) swap(a, b); Parent[a] += Parent[b]; Parent[b] = a; return true; } }; int main() { ll n, m; cin >> n >> m; vector<ll> a(m), b(m); for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } vector<ll> ans(m); ans[m - 1] = n * (n - 1) / 2; UnionFind Uni(n); for (int i = m - 1; i >= 1; i--) { ans[i - 1] = ans[i]; if (Uni.root(a[i]) != Uni.root(b[i])) { ans[i - 1] -= (ll)Uni.size(a[i]) * Uni.size(b[i]); Uni.connect(a[i], b[i]); } } for (int i = 0; i < m; i++) { cout << ans[i] << endl; } return 0; }
[ "expression.operation.binary.remove" ]
918,790
918,791
u633402865
cpp
p03108
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> P1; typedef pair<P, P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define fi first #define sc second #define rep(i, x) for (int i = 0; i < x; i++) #define repn(i, x) for (int i = 1; i <= x; i++) #define SORT(x) sort(x.begin(), x.end()) #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin()) #define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin()) const int MAX = 510000; const int MOD = 1000000007; class UnionFind { public: //親の番号を格納する。親だった場合は-(その集合のサイズ) vector<int> Parent; //作る時はParentの値を全て-1にする //こうするとずべてバラバラになる UnionFind(int N) { Parent = vector<int>(N, -1); } // Aがどのグループに属しているのか調べる int root(int A) { if (Parent[A] < 0) return A; return Parent[A] = root(Parent[A]); } //自分のいるグループの頂点数を調べる int size(int A) { return -Parent[root(A)]; //親を取ってきたい } // AとBをくっつける bool connect(int A, int B) { // AとBを直すつつなぐのではなく、root(A)にroot(B)をくっつける) A = root(A); B = root(B); if (A == B) { //すでにくっついているからくっつけない return false; } //大きい方(A)に小さい方(B)をくっつけたい //大小が逆だったらひっくり返しちゃう if (size(A) < size(B)) swap(A, B); // Aのサイズを更新する Parent[A] += Parent[B]; // Bの親をAに変更する Parent[B] = A; return true; } }; int main() { ll N, M; cin >> N >> M; ll i, j; vector<pair<ll, ll>> a(M); rep(i, M) cin >> a[i].first >> a[i].second; rep(i, M) { a[i].first--; a[i].second--; } UnionFind Uni(N); vector<ll> ans(M); ans[M - 1] = N * (N - 1) / 2; for (i = M - 1; i >= 1; i--) { ans[i - 1] = ans[i]; if (Uni.root(a[i].first != Uni.root(a[i].second))) { ans[i - 1] -= Uni.size(a[i].first) * Uni.size(a[i].second); Uni.connect(a[i].first, a[i].second); } else continue; } rep(i, M) { cout << ans[i] << endl; } }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> P1; typedef pair<P, P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define fi first #define sc second #define rep(i, x) for (int i = 0; i < x; i++) #define repn(i, x) for (int i = 1; i <= x; i++) #define SORT(x) sort(x.begin(), x.end()) #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin()) #define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin()) const int MAX = 510000; const int MOD = 1000000007; class UnionFind { public: //親の番号を格納する。親だった場合は-(その集合のサイズ) vector<int> Parent; //作る時はParentの値を全て-1にする //こうするとずべてバラバラになる UnionFind(int N) { Parent = vector<int>(N, -1); } // Aがどのグループに属しているのか調べる int root(int A) { if (Parent[A] < 0) return A; return Parent[A] = root(Parent[A]); } //自分のいるグループの頂点数を調べる int size(int A) { return -Parent[root(A)]; //親を取ってきたい } // AとBをくっつける bool connect(int A, int B) { // AとBを直すつつなぐのではなく、root(A)にroot(B)をくっつける) A = root(A); B = root(B); if (A == B) { //すでにくっついているからくっつけない return false; } //大きい方(A)に小さい方(B)をくっつけたい //大小が逆だったらひっくり返しちゃう if (size(A) < size(B)) swap(A, B); // Aのサイズを更新する Parent[A] += Parent[B]; // Bの親をAに変更する Parent[B] = A; return true; } }; int main() { ll N, M; cin >> N >> M; ll i, j; vector<pair<ll, ll>> a(M); rep(i, M) cin >> a[i].first >> a[i].second; rep(i, M) { a[i].first--; a[i].second--; } UnionFind Uni(N); vector<ll> ans(M); ans[M - 1] = N * (N - 1) / 2; for (i = M - 1; i >= 1; i--) { ans[i - 1] = ans[i]; if (Uni.root(a[i].first) != Uni.root(a[i].second)) { ans[i - 1] -= Uni.size(a[i].first) * Uni.size(a[i].second); Uni.connect(a[i].first, a[i].second); } else continue; } rep(i, M) { cout << ans[i] << endl; } }
[ "control_flow.branch.if.condition.change" ]
918,333
918,334
u284045566
cpp
p03108
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> P1; typedef pair<P, P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define fi first #define sc second #define rep(i, x) for (int i = 0; i < x; i++) #define repn(i, x) for (int i = 1; i <= x; i++) #define SORT(x) sort(x.begin(), x.end()) #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin()) #define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin()) const int MAX = 510000; const int MOD = 1000000007; class UnionFind { public: //親の番号を格納する。親だった場合は-(その集合のサイズ) vector<int> Parent; //作る時はParentの値を全て-1にする //こうするとずべてバラバラになる UnionFind(int N) { Parent = vector<int>(N, -1); } // Aがどのグループに属しているのか調べる int root(int A) { if (Parent[A] < 0) return A; return Parent[A] = root(Parent[A]); } //自分のいるグループの頂点数を調べる int size(int A) { return -Parent[root(A)]; //親を取ってきたい } // AとBをくっつける bool connect(int A, int B) { // AとBを直すつつなぐのではなく、root(A)にroot(B)をくっつける) A = root(A); B = root(B); if (A == B) { //すでにくっついているからくっつけない return false; } //大きい方(A)に小さい方(B)をくっつけたい //大小が逆だったらひっくり返しちゃう if (size(A) < size(B)) swap(A, B); // Aのサイズを更新する Parent[A] += Parent[B]; // Bの親をAに変更する Parent[B] = A; return true; } }; int main() { ll N, M; cin >> N >> M; ll i, j; vector<pair<ll, ll>> a(M); rep(i, M) cin >> a[i].first >> a[i].second; rep(i, M) { a[i].first--; a[i].second--; } UnionFind Uni(N); vector<ll> ans(M); ans[M - 1] = N * (N - 1) / 2; for (i = M - 1; i >= 1; i--) { ans[i - 1] = ans[i]; if (Uni.root(a[i].first != Uni.root(a[i].second))) { ans[i - 1] -= Uni.size(a[i].first) * Uni.size(a[i].second); Uni.connect(a[i].first, a[i].second); } // else continue; } rep(i, M) { cout << ans[i] << endl; } }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> P1; typedef pair<P, P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define fi first #define sc second #define rep(i, x) for (int i = 0; i < x; i++) #define repn(i, x) for (int i = 1; i <= x; i++) #define SORT(x) sort(x.begin(), x.end()) #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin()) #define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin()) const int MAX = 510000; const int MOD = 1000000007; class UnionFind { public: //親の番号を格納する。親だった場合は-(その集合のサイズ) vector<int> Parent; //作る時はParentの値を全て-1にする //こうするとずべてバラバラになる UnionFind(int N) { Parent = vector<int>(N, -1); } // Aがどのグループに属しているのか調べる int root(int A) { if (Parent[A] < 0) return A; return Parent[A] = root(Parent[A]); } //自分のいるグループの頂点数を調べる int size(int A) { return -Parent[root(A)]; //親を取ってきたい } // AとBをくっつける bool connect(int A, int B) { // AとBを直すつつなぐのではなく、root(A)にroot(B)をくっつける) A = root(A); B = root(B); if (A == B) { //すでにくっついているからくっつけない return false; } //大きい方(A)に小さい方(B)をくっつけたい //大小が逆だったらひっくり返しちゃう if (size(A) < size(B)) swap(A, B); // Aのサイズを更新する Parent[A] += Parent[B]; // Bの親をAに変更する Parent[B] = A; return true; } }; int main() { ll N, M; cin >> N >> M; ll i, j; vector<pair<ll, ll>> a(M); rep(i, M) cin >> a[i].first >> a[i].second; rep(i, M) { a[i].first--; a[i].second--; } UnionFind Uni(N); vector<ll> ans(M); ans[M - 1] = N * (N - 1) / 2; for (i = M - 1; i >= 1; i--) { ans[i - 1] = ans[i]; if (Uni.root(a[i].first) != Uni.root(a[i].second)) { ans[i - 1] -= Uni.size(a[i].first) * Uni.size(a[i].second); Uni.connect(a[i].first, a[i].second); } else continue; } rep(i, M) { cout << ans[i] << endl; } }
[ "control_flow.branch.if.condition.change", "control_flow.branch.else_if.replace.remove", "control_flow.branch.if.replace.add" ]
918,335
918,334
u284045566
cpp
p03108
#include <algorithm> #include <cmath> #include <ctime> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <queue> #include <set> #include <stack> #include <stdlib.h> #include <string> #include <vector> using namespace std; const int MAXN = 1e5; struct FndUn { int p[MAXN], sz[MAXN]; void MakeSet(int x) { p[x] = x; sz[x] = 1; } int Find(int x) { if (p[x] != x) p[x] = Find(p[x]); return p[x]; } pair<int, int> Union(int x, int y) { x = Find(x), y = Find(y); if (sz[x] > sz[y]) swap(x, y); if (p[x] == y || p[y] == x) return make_pair(0, 0); p[x] = y; int pr1 = sz[x], pr2 = sz[y]; sz[y] += sz[x]; return make_pair(pr1, pr2); } int Size(int x) { return sz[Find(x)]; } }; int main() { long long n, m; cin >> n >> m; vector<pair<long long, long long>> a(m); for (int i = 0; i < m; ++i) { cin >> a[i].first >> a[i].second; a[i].first--, a[i].second--; } FndUn f; for (int i = 0; i < m; ++i) { f.MakeSet(i); } vector<long long> ans(m); ans[m - 1] = n * (n - 1) / 2; for (int i = m - 2; i >= 0; --i) { auto mns = f.Union(a[i + 1].first, a[i + 1].second); long long m1 = mns.first, m2 = mns.second; ans[i] = ans[i + 1] - (m1 + m2) * (m1 + m2 - 1) / 2; ans[i] += m1 * (m1 - 1) / 2; ans[i] += m2 * (m2 - 1) / 2; } for (int i = 0; i < m; ++i) cout << ans[i] << endl; }
#include <algorithm> #include <cmath> #include <ctime> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <queue> #include <set> #include <stack> #include <stdlib.h> #include <string> #include <vector> using namespace std; const int MAXN = 1e5; struct FndUn { int p[MAXN], sz[MAXN]; void MakeSet(int x) { p[x] = x; sz[x] = 1; } int Find(int x) { if (p[x] != x) p[x] = Find(p[x]); return p[x]; } pair<int, int> Union(int x, int y) { x = Find(x), y = Find(y); if (sz[x] > sz[y]) swap(x, y); if (p[x] == y || p[y] == x) return make_pair(0, 0); p[x] = y; int pr1 = sz[x], pr2 = sz[y]; sz[y] += sz[x]; return make_pair(pr1, pr2); } int Size(int x) { return sz[Find(x)]; } }; int main() { long long n, m; cin >> n >> m; vector<pair<long long, long long>> a(m); for (int i = 0; i < m; ++i) { cin >> a[i].first >> a[i].second; a[i].first--, a[i].second--; } FndUn f; for (int i = 0; i < n; ++i) { f.MakeSet(i); } vector<long long> ans(m); ans[m - 1] = n * (n - 1) / 2; for (int i = m - 2; i >= 0; --i) { auto mns = f.Union(a[i + 1].first, a[i + 1].second); long long m1 = mns.first, m2 = mns.second; ans[i] = ans[i + 1] - (m1 + m2) * (m1 + m2 - 1) / 2; ans[i] += m1 * (m1 - 1) / 2; ans[i] += m2 * (m2 - 1) / 2; } for (int i = 0; i < m; ++i) cout << ans[i] << endl; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
918,375
918,376
u595984176
cpp
p03108
#include <bits/stdc++.h> #define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++) #define rep(x, to) for (int(x) = 0; (x) < (to); (x)++) #define repr(x, fr, to) for (int(x) = (fr); (x) >= (to); (x)--) #define all(c) (c).begin(), (c).end() #define sz(v) (int)(v).size() using namespace std; typedef long long ll; typedef vector<int> VI; typedef pair<int, int> pii; const int mod = (int)1e9 + 7; void dbg() { cerr << "\n"; } template <typename T, typename... T2> void dbg(const T &fst, const T2 &...rst) { cerr << fst << ": "; dbg(rst...); } struct UF { vector<int> p; vector<int> chg; UF() {} UF(int n) : p(n, -1) {} int find(int a) { return p[a] < 0 ? a : p[a] = find(p[a]); } bool unite(int a, int b) { chg.clear(); a = find(a); b = find(b); if (a == b) return false; if (-p[a] < -p[b]) swap(a, b); p[a] += p[b]; p[b] = a; chg.push_back(a); chg.push_back(b); return true; } bool root(int a) { return p[a] < 0; } bool same(int a, int b) { return find(a) == find(b); } int size(int a) { return -p[find(a)]; } }; int main() { // cin.tie(0); ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; vector<VI> g(m, VI(2)); rep(i, m) cin >> g[i][0] >> g[i][1]; vector<ll> ans(m); ll sp = (ll)n * (n - 1) / 2; ans[m - 1] = sp; UF uf(m); VI old(n, 1); repr(i, m - 1, 1) { uf.unite(g[i][0] - 1, g[i][1] - 1); ll sk = 0; // rep(i,n) if(uf.root(i)) sk += (ll)uf.size(i) * (uf.size(i) -1) /2; for (auto x : uf.chg) { if (uf.p[x] < 0) sp -= (ll)uf.size(x) * (uf.size(x) - 1) / 2; if (old[x] > 1) sp += (ll)old[x] * (old[x] - 1) / 2; old[x] = uf.size(x); } ans[i - 1] = sp; } for (auto x : ans) { cout << x << "\n"; } return 0; }
#include <bits/stdc++.h> #define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++) #define rep(x, to) for (int(x) = 0; (x) < (to); (x)++) #define repr(x, fr, to) for (int(x) = (fr); (x) >= (to); (x)--) #define all(c) (c).begin(), (c).end() #define sz(v) (int)(v).size() using namespace std; typedef long long ll; typedef vector<int> VI; typedef pair<int, int> pii; const int mod = (int)1e9 + 7; void dbg() { cerr << "\n"; } template <typename T, typename... T2> void dbg(const T &fst, const T2 &...rst) { cerr << fst << ": "; dbg(rst...); } struct UF { vector<int> p; vector<int> chg; UF() {} UF(int n) : p(n, -1) {} int find(int a) { return p[a] < 0 ? a : p[a] = find(p[a]); } bool unite(int a, int b) { chg.clear(); a = find(a); b = find(b); if (a == b) return false; if (-p[a] < -p[b]) swap(a, b); p[a] += p[b]; p[b] = a; chg.push_back(a); chg.push_back(b); return true; } bool root(int a) { return p[a] < 0; } bool same(int a, int b) { return find(a) == find(b); } int size(int a) { return -p[find(a)]; } }; int main() { // cin.tie(0); ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; vector<VI> g(m, VI(2)); rep(i, m) cin >> g[i][0] >> g[i][1]; vector<ll> ans(m); ll sp = (ll)n * (n - 1) / 2; ans[m - 1] = sp; UF uf(n); VI old(n, 1); repr(i, m - 1, 1) { uf.unite(g[i][0] - 1, g[i][1] - 1); ll sk = 0; // rep(i,n) if(uf.root(i)) sk += (ll)uf.size(i) * (uf.size(i) -1) /2; for (auto x : uf.chg) { if (uf.p[x] < 0) sp -= (ll)uf.size(x) * (uf.size(x) - 1) / 2; if (old[x] > 1) sp += (ll)old[x] * (old[x] - 1) / 2; old[x] = uf.size(x); } ans[i - 1] = sp; } for (auto x : ans) { cout << x << "\n"; } return 0; }
[]
918,381
918,383
u714564133
cpp
p03108
#include <algorithm> #include <assert.h> #include <bitset> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <vector> // #include<bits/stdc++.h> using namespace std; typedef long long ll; constexpr long long int INFLL = 1001001001001001LL; constexpr long long int infll = 1001001001001001LL; constexpr int INF = 1000000007; constexpr int inf = 1000000007; const int mod = 1000000007; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll gcd(ll a, ll b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <typename T> T seinomi(T a) { if (a > 0) { return a; } else { return 0; } } //連想配列[素因数f.first][個数f.second] template <typename T> map<T, T> soinsuubunkai(T n) { map<T, T> ret; for (T i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } //桁数取得 template <typename T> T ketasuu(T num) { return std::to_string(num).length(); } //階乗 ll kaizyou(ll k) { ll sum = 1; for (ll i = 1; i <= k; ++i) { sum *= i; } return sum; } //階乗を(10^9)+7で割った余り ll modkaizyou(ll k) { ll sum = 1; for (int i = 1; i <= k; ++i) { sum *= i; sum = sum % mod; } return sum; } template <class ForwardIt, class T> void iota(ForwardIt first, ForwardIt last, T value) { while (first != last) { *first++ = value; ++value; } } //整数乗 ll llpow(ll a, ll n) { if (n == 0) { return 1; } else { ll rep = a; for (ll i = 1; i < n; i++) { rep *= a; } return rep; } } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } template <typename T> T amarinasi(T a, T b) { if (a % b == 0) { return a / b; } else if (a % b > 0) { return a / b + 1; } else { return a / b - 1; } } //組み合わせ nCr vector<vector<ll>> nCr_v(5010, vector<ll>()); bool nCr_maekeisan = false; void nCr_Calculater() { for (int i = 0; i < 5010; i++) { nCr_v[i][0] = 1; nCr_v[i][i] = 1; } for (int k = 1; k < 5010; k++) { for (int j = 1; j < k; j++) { nCr_v[k][j] = (nCr_v[k - 1][j - 1] + nCr_v[k - 1][j]); } } } ll nCr(ll n, ll r) { if (n > 5010 || n < 0 || r > 5010 || r < 0) { cout << "Error!! n or r is over 5010 or under 0" << endl; return 1; } else { if (nCr_maekeisan == false) { for (ll i = 0; i < 5010; i++) { nCr_v[i].resize(5010); } nCr_Calculater(); nCr_maekeisan = true; } return nCr_v[n][r]; } } // テーブル生成版(0<=k<=n<=10^6) 組み合わせnCr 10^9+7で割った余り vector<ll> modnCr_fac, modnCr_finv, modnCr_inv; bool modnCr_maekeisan = false; void COMinit() { modnCr_fac[0] = modnCr_fac[1] = 1; modnCr_finv[0] = modnCr_finv[1] = 1; modnCr_inv[1] = 1; for (int i = 2; i < 1000010; i++) { modnCr_fac[i] = modnCr_fac[i - 1] * i % mod; modnCr_inv[i] = mod - modnCr_inv[mod % i] * (mod / i) % mod; modnCr_finv[i] = modnCr_finv[i - 1] * modnCr_inv[i] % mod; } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return modnCr_fac[n] * (modnCr_finv[k] * modnCr_finv[n - k] % mod) % mod; } ll modnCr(ll n, ll r) { if (modnCr_maekeisan == false) { modnCr_fac.resize(1000010); modnCr_finv.resize(1000010); modnCr_inv.resize(1000010); COMinit(); modnCr_maekeisan = true; } return COM(n, r); } //単発版(nが大きくrが小さい場合) 組み合わせnCr 10^9+7で割った余り long long modnCr2(long long n, long long a) { long long ans = 1, ans1 = 1; for (long long i = n - a + 1; i <= n; i++) { ans *= i % mod; ans %= mod; } for (long long i = 2; i <= a; i++) ans1 = (ans1 * i) % mod; ans1 = modpow(ans1, mod - 2, mod); return ((ans % mod) * ans1) % mod; } //順列 nPr ll nPr(ll n, ll r) { r = n - r; ll sum = 1; ll i; for (i = n; i >= r + 1; i--) sum *= i; return sum; } //重複組み合わせ nHr = (r+n-1)Cr ll nHr(ll n, ll r) { return modnCr(r + n - 1, r); } //弧度法から度数法に変換 double to_deg(double r) { return r * 180.0 / (atan(1.0) * 4.0); } //座標から度数法の角度に変換 double kakudo(double dx, double dy) { return atan2(dx, dy) * 180.0 / (atan(1.0) * 4.0); } //約数列挙配列(1を必ず含むことに注意) vector<ll> yakusuu(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } //素数判定bool型配列 std::vector<bool> sosuuhantei(ll max) { vector<bool> ret; if (max + 1 > ret.size()) { // resizeで要素数が減らないように ret.resize(max + 1, true); // IsPrimeに必要な要素数を確保 } ret[0] = false; // 0は素数ではない ret[1] = false; // 1は素数ではない for (ll i = 2; i * i <= max; ++i) { // 0からsqrt(max)まで調べる if (ret[i]) { // iが素数ならば for (ll j = 2; i * j <= max; ++j) { // (max以下の)iの倍数は ret[i * j] = false; // 素数ではない } } } return (ret); } //素数列挙longlong型配列 std::vector<ll> sosuurekkyo(ll max) { vector<bool> tmp; vector<ll> ret; if (max + 1 > tmp.size()) { // resizeで要素数が減らないように tmp.resize(max + 1, true); // IsPrimeに必要な要素数を確保 } tmp[0] = false; // 0は素数ではない tmp[1] = false; // 1は素数ではない for (ll i = 2; i * i <= max; ++i) { // 0からsqrt(max)まで調べる if (tmp[i]) { // iが素数ならば for (ll j = 2; i * j <= max; ++j) { // (max以下の)iの倍数は tmp[i * j] = false; // 素数ではない } } } for (ll i = 0; i <= max; i++) { if (tmp[i]) { ret.push_back(i); } } return (ret); } //十進数を二進数にしたときの桁数 ll nisinsize(ll n) { ll rep = 0; ll tmp = 1; while (1) { rep++; tmp *= 2; if (tmp > n) { break; } } return rep; } // UnionFind木 struct UnionFind { vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 vector<ll> siz; UnionFind(ll N) : par(N), siz(N) { //最初は全てが根であるとして初期化 for (ll i = 0; i < N; i++) { par[i] = i; siz[i] = 1; } } 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の根が同じ(=同じ木にある)時はそのまま if (siz[rx] < siz[ry]) swap(rx, ry); siz[rx] += siz[ry]; par[ry] = rx; return; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す ll rx = root(x); ll ry = root(y); return rx == ry; } }; //小数点以下10桁テンプレート(main関数内の最初に貼付け) // std::cout << std::fixed << std::setprecision(10); //---------------------------------------------------------------- int main() { ll n, m; cin >> n >> m; ll a[m], b[m]; ll ans[m]; for (ll i = 0; i < m; i++) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } UnionFind uf(n); ans[m - 1] = (n * (n - 1)) / 2; for (ll i = m - 2; i >= 0; i--) { if (uf.same(a[i], b[i])) { ans[i] = ans[i + 1]; } else { ans[i] = ans[i + 1] - uf.size(a[i + 1]) * uf.size(b[i + 1]); } uf.unite(a[i + 1], b[i + 1]); } for (auto f : ans) { cout << f << endl; } }
#include <algorithm> #include <assert.h> #include <bitset> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <vector> // #include<bits/stdc++.h> using namespace std; typedef long long ll; constexpr long long int INFLL = 1001001001001001LL; constexpr long long int infll = 1001001001001001LL; constexpr int INF = 1000000007; constexpr int inf = 1000000007; const int mod = 1000000007; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll gcd(ll a, ll b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <typename T> T seinomi(T a) { if (a > 0) { return a; } else { return 0; } } //連想配列[素因数f.first][個数f.second] template <typename T> map<T, T> soinsuubunkai(T n) { map<T, T> ret; for (T i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } //桁数取得 template <typename T> T ketasuu(T num) { return std::to_string(num).length(); } //階乗 ll kaizyou(ll k) { ll sum = 1; for (ll i = 1; i <= k; ++i) { sum *= i; } return sum; } //階乗を(10^9)+7で割った余り ll modkaizyou(ll k) { ll sum = 1; for (int i = 1; i <= k; ++i) { sum *= i; sum = sum % mod; } return sum; } template <class ForwardIt, class T> void iota(ForwardIt first, ForwardIt last, T value) { while (first != last) { *first++ = value; ++value; } } //整数乗 ll llpow(ll a, ll n) { if (n == 0) { return 1; } else { ll rep = a; for (ll i = 1; i < n; i++) { rep *= a; } return rep; } } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } template <typename T> T amarinasi(T a, T b) { if (a % b == 0) { return a / b; } else if (a % b > 0) { return a / b + 1; } else { return a / b - 1; } } //組み合わせ nCr vector<vector<ll>> nCr_v(5010, vector<ll>()); bool nCr_maekeisan = false; void nCr_Calculater() { for (int i = 0; i < 5010; i++) { nCr_v[i][0] = 1; nCr_v[i][i] = 1; } for (int k = 1; k < 5010; k++) { for (int j = 1; j < k; j++) { nCr_v[k][j] = (nCr_v[k - 1][j - 1] + nCr_v[k - 1][j]); } } } ll nCr(ll n, ll r) { if (n > 5010 || n < 0 || r > 5010 || r < 0) { cout << "Error!! n or r is over 5010 or under 0" << endl; return 1; } else { if (nCr_maekeisan == false) { for (ll i = 0; i < 5010; i++) { nCr_v[i].resize(5010); } nCr_Calculater(); nCr_maekeisan = true; } return nCr_v[n][r]; } } // テーブル生成版(0<=k<=n<=10^6) 組み合わせnCr 10^9+7で割った余り vector<ll> modnCr_fac, modnCr_finv, modnCr_inv; bool modnCr_maekeisan = false; void COMinit() { modnCr_fac[0] = modnCr_fac[1] = 1; modnCr_finv[0] = modnCr_finv[1] = 1; modnCr_inv[1] = 1; for (int i = 2; i < 1000010; i++) { modnCr_fac[i] = modnCr_fac[i - 1] * i % mod; modnCr_inv[i] = mod - modnCr_inv[mod % i] * (mod / i) % mod; modnCr_finv[i] = modnCr_finv[i - 1] * modnCr_inv[i] % mod; } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return modnCr_fac[n] * (modnCr_finv[k] * modnCr_finv[n - k] % mod) % mod; } ll modnCr(ll n, ll r) { if (modnCr_maekeisan == false) { modnCr_fac.resize(1000010); modnCr_finv.resize(1000010); modnCr_inv.resize(1000010); COMinit(); modnCr_maekeisan = true; } return COM(n, r); } //単発版(nが大きくrが小さい場合) 組み合わせnCr 10^9+7で割った余り long long modnCr2(long long n, long long a) { long long ans = 1, ans1 = 1; for (long long i = n - a + 1; i <= n; i++) { ans *= i % mod; ans %= mod; } for (long long i = 2; i <= a; i++) ans1 = (ans1 * i) % mod; ans1 = modpow(ans1, mod - 2, mod); return ((ans % mod) * ans1) % mod; } //順列 nPr ll nPr(ll n, ll r) { r = n - r; ll sum = 1; ll i; for (i = n; i >= r + 1; i--) sum *= i; return sum; } //重複組み合わせ nHr = (r+n-1)Cr ll nHr(ll n, ll r) { return modnCr(r + n - 1, r); } //弧度法から度数法に変換 double to_deg(double r) { return r * 180.0 / (atan(1.0) * 4.0); } //座標から度数法の角度に変換 double kakudo(double dx, double dy) { return atan2(dx, dy) * 180.0 / (atan(1.0) * 4.0); } //約数列挙配列(1を必ず含むことに注意) vector<ll> yakusuu(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } //素数判定bool型配列 std::vector<bool> sosuuhantei(ll max) { vector<bool> ret; if (max + 1 > ret.size()) { // resizeで要素数が減らないように ret.resize(max + 1, true); // IsPrimeに必要な要素数を確保 } ret[0] = false; // 0は素数ではない ret[1] = false; // 1は素数ではない for (ll i = 2; i * i <= max; ++i) { // 0からsqrt(max)まで調べる if (ret[i]) { // iが素数ならば for (ll j = 2; i * j <= max; ++j) { // (max以下の)iの倍数は ret[i * j] = false; // 素数ではない } } } return (ret); } //素数列挙longlong型配列 std::vector<ll> sosuurekkyo(ll max) { vector<bool> tmp; vector<ll> ret; if (max + 1 > tmp.size()) { // resizeで要素数が減らないように tmp.resize(max + 1, true); // IsPrimeに必要な要素数を確保 } tmp[0] = false; // 0は素数ではない tmp[1] = false; // 1は素数ではない for (ll i = 2; i * i <= max; ++i) { // 0からsqrt(max)まで調べる if (tmp[i]) { // iが素数ならば for (ll j = 2; i * j <= max; ++j) { // (max以下の)iの倍数は tmp[i * j] = false; // 素数ではない } } } for (ll i = 0; i <= max; i++) { if (tmp[i]) { ret.push_back(i); } } return (ret); } //十進数を二進数にしたときの桁数 ll nisinsize(ll n) { ll rep = 0; ll tmp = 1; while (1) { rep++; tmp *= 2; if (tmp > n) { break; } } return rep; } // UnionFind木 struct UnionFind { vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 vector<ll> siz; UnionFind(ll N) : par(N), siz(N) { //最初は全てが根であるとして初期化 for (ll i = 0; i < N; i++) { par[i] = i; siz[i] = 1; } } 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の根が同じ(=同じ木にある)時はそのまま if (siz[rx] < siz[ry]) swap(rx, ry); siz[rx] += siz[ry]; par[ry] = rx; return; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す ll rx = root(x); ll ry = root(y); return rx == ry; } }; //小数点以下10桁テンプレート(main関数内の最初に貼付け) // std::cout << std::fixed << std::setprecision(10); //---------------------------------------------------------------- int main() { ll n, m; cin >> n >> m; ll a[m], b[m]; ll ans[m]; for (ll i = 0; i < m; i++) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } UnionFind uf(n); ans[m - 1] = (n * (n - 1)) / 2; for (ll i = m - 2; i >= 0; i--) { if (uf.same(a[i + 1], b[i + 1])) { ans[i] = ans[i + 1]; } else { ans[i] = ans[i + 1] - uf.size(a[i + 1]) * uf.size(b[i + 1]); } uf.unite(a[i + 1], b[i + 1]); } for (auto f : ans) { cout << f << endl; } }
[ "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "misc.off_by_one" ]
918,390
918,396
u863537799
cpp
p03108
#include <algorithm> #include <assert.h> #include <bitset> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <vector> // #include<bits/stdc++.h> using namespace std; typedef long long ll; constexpr long long int INFLL = 1001001001001001LL; constexpr long long int infll = 1001001001001001LL; constexpr int INF = 1000000007; constexpr int inf = 1000000007; const int mod = 1000000007; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll gcd(ll a, ll b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <typename T> T seinomi(T a) { if (a > 0) { return a; } else { return 0; } } //連想配列[素因数f.first][個数f.second] template <typename T> map<T, T> soinsuubunkai(T n) { map<T, T> ret; for (T i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } //桁数取得 template <typename T> T ketasuu(T num) { return std::to_string(num).length(); } //階乗 ll kaizyou(ll k) { ll sum = 1; for (ll i = 1; i <= k; ++i) { sum *= i; } return sum; } //階乗を(10^9)+7で割った余り ll modkaizyou(ll k) { ll sum = 1; for (int i = 1; i <= k; ++i) { sum *= i; sum = sum % mod; } return sum; } template <class ForwardIt, class T> void iota(ForwardIt first, ForwardIt last, T value) { while (first != last) { *first++ = value; ++value; } } //整数乗 ll llpow(ll a, ll n) { if (n == 0) { return 1; } else { ll rep = a; for (ll i = 1; i < n; i++) { rep *= a; } return rep; } } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } template <typename T> T amarinasi(T a, T b) { if (a % b == 0) { return a / b; } else if (a % b > 0) { return a / b + 1; } else { return a / b - 1; } } //組み合わせ nCr vector<vector<ll>> nCr_v(5010, vector<ll>()); bool nCr_maekeisan = false; void nCr_Calculater() { for (int i = 0; i < 5010; i++) { nCr_v[i][0] = 1; nCr_v[i][i] = 1; } for (int k = 1; k < 5010; k++) { for (int j = 1; j < k; j++) { nCr_v[k][j] = (nCr_v[k - 1][j - 1] + nCr_v[k - 1][j]); } } } ll nCr(ll n, ll r) { if (n > 5010 || n < 0 || r > 5010 || r < 0) { cout << "Error!! n or r is over 5010 or under 0" << endl; return 1; } else { if (nCr_maekeisan == false) { for (ll i = 0; i < 5010; i++) { nCr_v[i].resize(5010); } nCr_Calculater(); nCr_maekeisan = true; } return nCr_v[n][r]; } } // テーブル生成版(0<=k<=n<=10^6) 組み合わせnCr 10^9+7で割った余り vector<ll> modnCr_fac, modnCr_finv, modnCr_inv; bool modnCr_maekeisan = false; void COMinit() { modnCr_fac[0] = modnCr_fac[1] = 1; modnCr_finv[0] = modnCr_finv[1] = 1; modnCr_inv[1] = 1; for (int i = 2; i < 1000010; i++) { modnCr_fac[i] = modnCr_fac[i - 1] * i % mod; modnCr_inv[i] = mod - modnCr_inv[mod % i] * (mod / i) % mod; modnCr_finv[i] = modnCr_finv[i - 1] * modnCr_inv[i] % mod; } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return modnCr_fac[n] * (modnCr_finv[k] * modnCr_finv[n - k] % mod) % mod; } ll modnCr(ll n, ll r) { if (modnCr_maekeisan == false) { modnCr_fac.resize(1000010); modnCr_finv.resize(1000010); modnCr_inv.resize(1000010); COMinit(); modnCr_maekeisan = true; } return COM(n, r); } //単発版(nが大きくrが小さい場合) 組み合わせnCr 10^9+7で割った余り long long modnCr2(long long n, long long a) { long long ans = 1, ans1 = 1; for (long long i = n - a + 1; i <= n; i++) { ans *= i % mod; ans %= mod; } for (long long i = 2; i <= a; i++) ans1 = (ans1 * i) % mod; ans1 = modpow(ans1, mod - 2, mod); return ((ans % mod) * ans1) % mod; } //順列 nPr ll nPr(ll n, ll r) { r = n - r; ll sum = 1; ll i; for (i = n; i >= r + 1; i--) sum *= i; return sum; } //重複組み合わせ nHr = (r+n-1)Cr ll nHr(ll n, ll r) { return modnCr(r + n - 1, r); } //弧度法から度数法に変換 double to_deg(double r) { return r * 180.0 / (atan(1.0) * 4.0); } //座標から度数法の角度に変換 double kakudo(double dx, double dy) { return atan2(dx, dy) * 180.0 / (atan(1.0) * 4.0); } //約数列挙配列(1を必ず含むことに注意) vector<ll> yakusuu(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } //素数判定bool型配列 std::vector<bool> sosuuhantei(ll max) { vector<bool> ret; if (max + 1 > ret.size()) { // resizeで要素数が減らないように ret.resize(max + 1, true); // IsPrimeに必要な要素数を確保 } ret[0] = false; // 0は素数ではない ret[1] = false; // 1は素数ではない for (ll i = 2; i * i <= max; ++i) { // 0からsqrt(max)まで調べる if (ret[i]) { // iが素数ならば for (ll j = 2; i * j <= max; ++j) { // (max以下の)iの倍数は ret[i * j] = false; // 素数ではない } } } return (ret); } //素数列挙longlong型配列 std::vector<ll> sosuurekkyo(ll max) { vector<bool> tmp; vector<ll> ret; if (max + 1 > tmp.size()) { // resizeで要素数が減らないように tmp.resize(max + 1, true); // IsPrimeに必要な要素数を確保 } tmp[0] = false; // 0は素数ではない tmp[1] = false; // 1は素数ではない for (ll i = 2; i * i <= max; ++i) { // 0からsqrt(max)まで調べる if (tmp[i]) { // iが素数ならば for (ll j = 2; i * j <= max; ++j) { // (max以下の)iの倍数は tmp[i * j] = false; // 素数ではない } } } for (ll i = 0; i <= max; i++) { if (tmp[i]) { ret.push_back(i); } } return (ret); } //十進数を二進数にしたときの桁数 ll nisinsize(ll n) { ll rep = 0; ll tmp = 1; while (1) { rep++; tmp *= 2; if (tmp > n) { break; } } return rep; } // UnionFind木 struct UnionFind { vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 vector<ll> siz; UnionFind(ll N) : par(N), siz(N) { //最初は全てが根であるとして初期化 for (ll i = 0; i < N; i++) { par[i] = i; siz[i] = 1; } } 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の根が同じ(=同じ木にある)時はそのまま if (siz[rx] < siz[ry]) swap(rx, ry); siz[rx] += siz[ry]; par[ry] = rx; return; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す ll rx = root(x); ll ry = root(y); return rx == ry; } }; //小数点以下10桁テンプレート(main関数内の最初に貼付け) // std::cout << std::fixed << std::setprecision(10); //---------------------------------------------------------------- int main() { ll n, m; cin >> n >> m; ll a[m], b[m]; ll ans[m]; for (ll i = 0; i < m; i++) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } UnionFind uf(n); ans[m - 1] = n * (n - 1) / 2; for (ll i = m - 2; i >= 0; i--) { if (uf.same(a[i], b[i])) { ans[i] = ans[i + 1]; } else { ans[i] = ans[i + 1] - uf.size(a[i + 1]) * uf.size(b[i + 1]); } uf.unite(a[i + 1], b[i + 1]); } for (auto f : ans) { cout << f << endl; } }
#include <algorithm> #include <assert.h> #include <bitset> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <vector> // #include<bits/stdc++.h> using namespace std; typedef long long ll; constexpr long long int INFLL = 1001001001001001LL; constexpr long long int infll = 1001001001001001LL; constexpr int INF = 1000000007; constexpr int inf = 1000000007; const int mod = 1000000007; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll gcd(ll a, ll b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <typename T> T seinomi(T a) { if (a > 0) { return a; } else { return 0; } } //連想配列[素因数f.first][個数f.second] template <typename T> map<T, T> soinsuubunkai(T n) { map<T, T> ret; for (T i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } //桁数取得 template <typename T> T ketasuu(T num) { return std::to_string(num).length(); } //階乗 ll kaizyou(ll k) { ll sum = 1; for (ll i = 1; i <= k; ++i) { sum *= i; } return sum; } //階乗を(10^9)+7で割った余り ll modkaizyou(ll k) { ll sum = 1; for (int i = 1; i <= k; ++i) { sum *= i; sum = sum % mod; } return sum; } template <class ForwardIt, class T> void iota(ForwardIt first, ForwardIt last, T value) { while (first != last) { *first++ = value; ++value; } } //整数乗 ll llpow(ll a, ll n) { if (n == 0) { return 1; } else { ll rep = a; for (ll i = 1; i < n; i++) { rep *= a; } return rep; } } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } template <typename T> T amarinasi(T a, T b) { if (a % b == 0) { return a / b; } else if (a % b > 0) { return a / b + 1; } else { return a / b - 1; } } //組み合わせ nCr vector<vector<ll>> nCr_v(5010, vector<ll>()); bool nCr_maekeisan = false; void nCr_Calculater() { for (int i = 0; i < 5010; i++) { nCr_v[i][0] = 1; nCr_v[i][i] = 1; } for (int k = 1; k < 5010; k++) { for (int j = 1; j < k; j++) { nCr_v[k][j] = (nCr_v[k - 1][j - 1] + nCr_v[k - 1][j]); } } } ll nCr(ll n, ll r) { if (n > 5010 || n < 0 || r > 5010 || r < 0) { cout << "Error!! n or r is over 5010 or under 0" << endl; return 1; } else { if (nCr_maekeisan == false) { for (ll i = 0; i < 5010; i++) { nCr_v[i].resize(5010); } nCr_Calculater(); nCr_maekeisan = true; } return nCr_v[n][r]; } } // テーブル生成版(0<=k<=n<=10^6) 組み合わせnCr 10^9+7で割った余り vector<ll> modnCr_fac, modnCr_finv, modnCr_inv; bool modnCr_maekeisan = false; void COMinit() { modnCr_fac[0] = modnCr_fac[1] = 1; modnCr_finv[0] = modnCr_finv[1] = 1; modnCr_inv[1] = 1; for (int i = 2; i < 1000010; i++) { modnCr_fac[i] = modnCr_fac[i - 1] * i % mod; modnCr_inv[i] = mod - modnCr_inv[mod % i] * (mod / i) % mod; modnCr_finv[i] = modnCr_finv[i - 1] * modnCr_inv[i] % mod; } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return modnCr_fac[n] * (modnCr_finv[k] * modnCr_finv[n - k] % mod) % mod; } ll modnCr(ll n, ll r) { if (modnCr_maekeisan == false) { modnCr_fac.resize(1000010); modnCr_finv.resize(1000010); modnCr_inv.resize(1000010); COMinit(); modnCr_maekeisan = true; } return COM(n, r); } //単発版(nが大きくrが小さい場合) 組み合わせnCr 10^9+7で割った余り long long modnCr2(long long n, long long a) { long long ans = 1, ans1 = 1; for (long long i = n - a + 1; i <= n; i++) { ans *= i % mod; ans %= mod; } for (long long i = 2; i <= a; i++) ans1 = (ans1 * i) % mod; ans1 = modpow(ans1, mod - 2, mod); return ((ans % mod) * ans1) % mod; } //順列 nPr ll nPr(ll n, ll r) { r = n - r; ll sum = 1; ll i; for (i = n; i >= r + 1; i--) sum *= i; return sum; } //重複組み合わせ nHr = (r+n-1)Cr ll nHr(ll n, ll r) { return modnCr(r + n - 1, r); } //弧度法から度数法に変換 double to_deg(double r) { return r * 180.0 / (atan(1.0) * 4.0); } //座標から度数法の角度に変換 double kakudo(double dx, double dy) { return atan2(dx, dy) * 180.0 / (atan(1.0) * 4.0); } //約数列挙配列(1を必ず含むことに注意) vector<ll> yakusuu(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } //素数判定bool型配列 std::vector<bool> sosuuhantei(ll max) { vector<bool> ret; if (max + 1 > ret.size()) { // resizeで要素数が減らないように ret.resize(max + 1, true); // IsPrimeに必要な要素数を確保 } ret[0] = false; // 0は素数ではない ret[1] = false; // 1は素数ではない for (ll i = 2; i * i <= max; ++i) { // 0からsqrt(max)まで調べる if (ret[i]) { // iが素数ならば for (ll j = 2; i * j <= max; ++j) { // (max以下の)iの倍数は ret[i * j] = false; // 素数ではない } } } return (ret); } //素数列挙longlong型配列 std::vector<ll> sosuurekkyo(ll max) { vector<bool> tmp; vector<ll> ret; if (max + 1 > tmp.size()) { // resizeで要素数が減らないように tmp.resize(max + 1, true); // IsPrimeに必要な要素数を確保 } tmp[0] = false; // 0は素数ではない tmp[1] = false; // 1は素数ではない for (ll i = 2; i * i <= max; ++i) { // 0からsqrt(max)まで調べる if (tmp[i]) { // iが素数ならば for (ll j = 2; i * j <= max; ++j) { // (max以下の)iの倍数は tmp[i * j] = false; // 素数ではない } } } for (ll i = 0; i <= max; i++) { if (tmp[i]) { ret.push_back(i); } } return (ret); } //十進数を二進数にしたときの桁数 ll nisinsize(ll n) { ll rep = 0; ll tmp = 1; while (1) { rep++; tmp *= 2; if (tmp > n) { break; } } return rep; } // UnionFind木 struct UnionFind { vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 vector<ll> siz; UnionFind(ll N) : par(N), siz(N) { //最初は全てが根であるとして初期化 for (ll i = 0; i < N; i++) { par[i] = i; siz[i] = 1; } } 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の根が同じ(=同じ木にある)時はそのまま if (siz[rx] < siz[ry]) swap(rx, ry); siz[rx] += siz[ry]; par[ry] = rx; return; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す ll rx = root(x); ll ry = root(y); return rx == ry; } }; //小数点以下10桁テンプレート(main関数内の最初に貼付け) // std::cout << std::fixed << std::setprecision(10); //---------------------------------------------------------------- int main() { ll n, m; cin >> n >> m; ll a[m], b[m]; ll ans[m]; for (ll i = 0; i < m; i++) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } UnionFind uf(n); ans[m - 1] = (n * (n - 1)) / 2; for (ll i = m - 2; i >= 0; i--) { if (uf.same(a[i + 1], b[i + 1])) { ans[i] = ans[i + 1]; } else { ans[i] = ans[i + 1] - uf.size(a[i + 1]) * uf.size(b[i + 1]); } uf.unite(a[i + 1], b[i + 1]); } for (auto f : ans) { cout << f << endl; } }
[ "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "misc.off_by_one" ]
918,400
918,396
u863537799
cpp
p03108
#include <bits/stdc++.h> using namespace std; using ll = long long; struct union_find { vector<int> par; union_find(int n) : par(n, -1) {} int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return false; if (par[rx] > par[ry]) swap(rx, ry); par[rx] += par[ry]; par[ry] = rx; return true; } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return -par[root(x)]; } }; int main() { ll n, m; cin >> n >> m; union_find tree(n); vector<pair<ll, ll>> bridge(m); for (int i = 0; i < m; i++) { cin >> bridge[i].first >> bridge[i].second; } vector<ll> ans(m, 0); ans[0] = n * (n - 1) / 2; reverse(bridge.begin(), bridge.end()); for (int i = 0; i < m; i++) { ans[i + 1] = ans[i]; ll x = bridge[i].first - 1; ll y = bridge[i].second - 1; ll xs = tree.size(x); ll ys = tree.size(y); if (tree.same(x, y) == false) { ans[i + 1] -= xs * ys; } tree.unite(x, y); } reverse(ans.begin(), ans.end()); for (int i = 0; i < m; i++) { cout << ans[i] << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; struct union_find { vector<int> par; union_find(int n) : par(n, -1) {} int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return false; if (par[rx] > par[ry]) swap(rx, ry); par[rx] += par[ry]; par[ry] = rx; return true; } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return -par[root(x)]; } }; int main() { ll n, m; cin >> n >> m; union_find tree(n); vector<pair<ll, ll>> bridge(m); for (int i = 0; i < m; i++) { cin >> bridge[i].first >> bridge[i].second; } vector<ll> ans(m, 0); ans[0] = n * (n - 1) / 2; reverse(bridge.begin(), bridge.end()); for (int i = 0; i < m - 1; i++) { ans[i + 1] = ans[i]; ll x = bridge[i].first - 1; ll y = bridge[i].second - 1; ll xs = tree.size(x); ll ys = tree.size(y); if (tree.same(x, y) == false) { ans[i + 1] -= xs * ys; } tree.unite(x, y); } reverse(ans.begin(), ans.end()); for (int i = 0; i < m; i++) { cout << ans[i] << endl; } }
[ "control_flow.loop.for.condition.change", "misc.off_by_one" ]
918,411
918,412
u646962247
cpp
p03108
#include <bits/stdc++.h> #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define _GLIBCXX_DEBUG using ll = long long; using vi = vector<int>; using vll = vector<ll>; using vd = vector<double>; using vvi = vector<vi>; using vvll = vector<vll>; using vvd = vector<vd>; using vvvi = vector<vvi>; using vvvll = vector<vvll>; using vvvd = vector<vvd>; const double pi = 3.141592653589793; class UnionFind { // まとめる 判定 サイズを知る public: // Aから見た親の番号を格納する。rootだったら-1*その集合のサイズ。 vector<ll> Parent; // 初期化 UnionFind(ll N) { Parent = vector<ll>(N, -1); } // Aのrootを調べる int root(ll A) { if (Parent[A] < 0) return A; // マイナスならそれはroot return Parent[A] = root(Parent[A]); } // rootの値をプラスに戻して返す(サイズ) int size(ll A) { return -Parent[root(A)]; } // くっつける関数 bool connect(ll A, ll B) { // AとBのroot同士をくっつける A = root(A); // ここのAは、"rootの場所"の意味 B = root(B); if (A == B) return false; // 既にくっついている if (size(A) < size(B)) swap(A, B); // 大きい方にくっつけるために中身交換 Parent[A] += Parent[B]; // 中身更新 Parent[B] = A; return true; } }; int main() { ll n, m; cin >> n >> m; ll now = (n * (n - 1)) / 2; vll ans; ans.push_back(now); UnionFind tree(n); vector<pair<ll, ll>> pp; rep(i, m) { ll x, y; cin >> x >> y; pp.push_back(make_pair(x, y)); } for (int i = m - 1; i >= 0; i--) { ll x, y; x = pp[i].first; y = pp[i].second; ll xs = tree.size(x); ll ys = tree.size(y); if (!tree.connect(x, y)) { ans.push_back(now); } else { now = now - xs * ys; ans.push_back(now); // cout<<111<<endl; } // cout<<now<<endl; } for (int i = m - 1; i >= 0; i--) { cout << ans[i] << endl; } return 0; }
#include <bits/stdc++.h> #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define _GLIBCXX_DEBUG using ll = long long; using vi = vector<int>; using vll = vector<ll>; using vd = vector<double>; using vvi = vector<vi>; using vvll = vector<vll>; using vvd = vector<vd>; using vvvi = vector<vvi>; using vvvll = vector<vvll>; using vvvd = vector<vvd>; const double pi = 3.141592653589793; class UnionFind { // まとめる 判定 サイズを知る public: // Aから見た親の番号を格納する。rootだったら-1*その集合のサイズ。 vector<ll> Parent; // 初期化 UnionFind(ll N) { Parent = vector<ll>(N, -1); } // Aのrootを調べる int root(ll A) { if (Parent[A] < 0) return A; // マイナスならそれはroot return Parent[A] = root(Parent[A]); } // rootの値をプラスに戻して返す(サイズ) int size(ll A) { return -Parent[root(A)]; } // くっつける関数 bool connect(ll A, ll B) { // AとBのroot同士をくっつける A = root(A); // ここのAは、"rootの場所"の意味 B = root(B); if (A == B) return false; // 既にくっついている if (size(A) < size(B)) swap(A, B); // 大きい方にくっつけるために中身交換 Parent[A] += Parent[B]; // 中身更新 Parent[B] = A; return true; } }; int main() { ll n, m; cin >> n >> m; ll now = (n * (n - 1)) / 2; vll ans; ans.push_back(now); UnionFind tree(n); vector<pair<ll, ll>> pp; rep(i, m) { ll x, y; cin >> x >> y; pp.push_back(make_pair(x, y)); } for (int i = m - 1; i >= 0; i--) { ll x, y; x = pp[i].first - 1; y = pp[i].second - 1; ll xs = tree.size(x); ll ys = tree.size(y); if (!tree.connect(x, y)) { ans.push_back(now); } else { now = now - xs * ys; ans.push_back(now); // cout<<111<<endl; } // cout<<now<<endl; } for (int i = m - 1; i >= 0; i--) { cout << ans[i] << endl; } return 0; }
[ "assignment.change" ]
918,528
918,530
u518042385
cpp
p03108
#define _USE_MATH_DEFINES #include <iomanip> #include <iostream> #include <stdio.h> #include <algorithm> #include <cmath> #include <complex> #include <iterator> #include <sstream> #include <bitset> #include <cstring> #include <string> #include <vector> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <ctime> //// //#include <random>// ///////// typedef long long LL; typedef long double LD; typedef unsigned long long ULL; ////定数 const int INF = (int)1e9 + 10; const LL MOD = (LL)1e9 + 7; const LL LINF = (LL)4e18 + 20; const LD PI = acos(-1.0); const double EPS = 1e-9; ///////// using namespace ::std; void chmax(LL &a, LL b) { a = max(a, b); } ////////////// class UnionFind { public: int cNum; //要素数 vector<int> parent; vector<int> count; vector<vector<int>> GList; UnionFind(int n) { cNum = n; parent = vector<int>(n); count = vector<int>(n, 1); GList.resize(n); for (int i = 0; i < n; ++i) { parent[i] = i; GList[i].push_back(i); } } int find(int x) { if (parent[x] == x) { return x; } return parent[x] = find(parent[x]); } bool same(int x, int y) { return find(x) == find(y); } int Count(int x) { return count[find(x)]; } void add(int x, int y) { // union x = find(x); y = find(y); if (x == y) return; parent[x] = y; count[y] += count[x]; if (GList[y].size() < GList[x].size()) { swap(GList[x], GList[y]); } GList[y].insert(GList[y].end(), GList[x].begin(), GList[x].end()); } }; void solve() { int N, M; cin >> N >> M; vector<pair<int, int>> E(M); for (int i = 0; i < M; ++i) { cin >> E[i].first >> E[i].second; E[i].first--; E[i].second--; } reverse(E.begin(), E.end()); vector<LL> ans; UnionFind uf(N); LL now = N * (N - 1) / 2; ans.push_back(now); for (int i = 0; i < M; ++i) { int a = E[i].first; int b = E[i].second; if (uf.same(a, b)) { ans.push_back(0); continue; } LL aC = uf.Count(a); LL bC = uf.Count(b); now -= aC * bC; ans.push_back(now); uf.add(a, b); } reverse(ans.begin(), ans.end()); int len = ans.size(); for (int i = 1; i < len; ++i) { cout << ans[i] << endl; } } signed main(void) { std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed; //小数を10進数表示 cout << setprecision(16); //小数点以下の桁数を指定//coutとcerrで別 solve(); }
#define _USE_MATH_DEFINES #include <iomanip> #include <iostream> #include <stdio.h> #include <algorithm> #include <cmath> #include <complex> #include <iterator> #include <sstream> #include <bitset> #include <cstring> #include <string> #include <vector> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <ctime> //// //#include <random>// ///////// typedef long long LL; typedef long double LD; typedef unsigned long long ULL; ////定数 const int INF = (int)1e9 + 10; const LL MOD = (LL)1e9 + 7; const LL LINF = (LL)4e18 + 20; const LD PI = acos(-1.0); const double EPS = 1e-9; ///////// using namespace ::std; void chmax(LL &a, LL b) { a = max(a, b); } ////////////// class UnionFind { public: int cNum; //要素数 vector<int> parent; vector<int> count; vector<vector<int>> GList; UnionFind(int n) { cNum = n; parent = vector<int>(n); count = vector<int>(n, 1); GList.resize(n); for (int i = 0; i < n; ++i) { parent[i] = i; GList[i].push_back(i); } } int find(int x) { if (parent[x] == x) { return x; } return parent[x] = find(parent[x]); } bool same(int x, int y) { return find(x) == find(y); } int Count(int x) { return count[find(x)]; } void add(int x, int y) { // union x = find(x); y = find(y); if (x == y) return; parent[x] = y; count[y] += count[x]; if (GList[y].size() < GList[x].size()) { swap(GList[x], GList[y]); } GList[y].insert(GList[y].end(), GList[x].begin(), GList[x].end()); } }; void solve() { LL N, M; cin >> N >> M; vector<pair<int, int>> E(M); for (int i = 0; i < M; ++i) { cin >> E[i].first >> E[i].second; E[i].first--; E[i].second--; } reverse(E.begin(), E.end()); vector<LL> ans; UnionFind uf(N); LL now = N * (N - 1) / 2; //////////////////////////////// ans.push_back(now); for (int i = 0; i < M; ++i) { int a = E[i].first; int b = E[i].second; if (uf.same(a, b)) { ans.push_back(now - 0); continue; } LL aC = uf.Count(a); LL bC = uf.Count(b); now -= aC * bC; ans.push_back(now); uf.add(a, b); } reverse(ans.begin(), ans.end()); int len = ans.size(); for (int i = 1; i < len; ++i) { cout << ans[i] << endl; } } signed main(void) { std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed; //小数を10進数表示 cout << setprecision(16); //小数点以下の桁数を指定//coutとcerrで別 solve(); }
[ "variable_declaration.type.change" ]
918,540
918,537
u870307668
cpp
p03108
#include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; const int MAX_N = 100010; int par[MAX_N]; int rnk[MAX_N]; void init(int n) { rep(i, n) { par[i] = i; rnk[i] = 0; } } 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 (rnk[x] < rnk[y]) { par[x] = y; } else { par[y] = x; if (rnk[x] == rnk[y]) rnk[x]++; } } bool same(int x, int y) { return find(x) == find(y); } int main() { int N, M; cin >> N >> M; vector<ll> A(M), B(M), ans(M, N * (N - 1) / 2), c(N, 1); rep(i, M) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } init(N); for (int i = M - 2; i >= 0; i--) { if (same(A[i], B[i])) { ans[i] = ans[i + 1]; continue; } ll c1 = c[find(A[i + 1])], c2 = c[find(B[i + 1])]; ans[i] = ans[i + 1] - c1 * c2; unite(A[i + 1], B[i + 1]); c[find(A[i + 1])] = c1 + c2; } rep(i, M) { cout << ans[i] << endl; } }
#include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; const int MAX_N = 100010; int par[MAX_N]; int rnk[MAX_N]; void init(int n) { rep(i, n) { par[i] = i; rnk[i] = 0; } } 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 (rnk[x] < rnk[y]) { par[x] = y; } else { par[y] = x; if (rnk[x] == rnk[y]) rnk[x]++; } } bool same(int x, int y) { return find(x) == find(y); } int main() { ll N, M; cin >> N >> M; vector<ll> A(M), B(M), ans(M, N * (N - 1) / 2), c(N, 1); rep(i, M) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } init(N); for (int i = M - 2; i >= 0; i--) { if (same(A[i + 1], B[i + 1])) { ans[i] = ans[i + 1]; continue; } ll c1 = c[find(A[i + 1])], c2 = c[find(B[i + 1])]; ans[i] = ans[i + 1] - c1 * c2; unite(A[i + 1], B[i + 1]); c[find(A[i + 1])] = c1 + c2; } rep(i, M) { cout << ans[i] << endl; } }
[ "variable_declaration.type.change", "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "misc.off_by_one" ]
918,587
918,586
u555962250
cpp
p03108
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; using vint = vector<int>; using vvint = vector<vint>; using vll = vector<ll>; using vvll = vector<vll>; using vchar = vector<char>; using vvchar = vector<vchar>; using vp = vector<P>; using vpp = vector<pair<P, P>>; using vvp = vector<vp>; #define rep(i, n) for (int i = 0; i < n; ++i) #pragma region Debug istream &operator>>(istream &is, P &a) { return is >> a.first >> a.second; } ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; } template <typename T> void view(const std::vector<T> &v) { for (const auto &e : v) { std::cout << e << " "; } std::cout << std::endl; } template <typename T> void view(const std::vector<std::vector<T>> &vv) { for (const auto &v : vv) { view(v); } } #pragma endregion #pragma region UnionFind struct UnionFind { vector<int> d; // d[x] is the index of the parent of x // d[x] is -size if x is a root UnionFind(int n) : d(vector<int>(n, -1)) {} int root(int x) { if (d[x] < 0) { return x; } return d[x] = root(d[x]); } bool unite(int x, int y) { x = root(x); y = root(y); if (x == y) { return false; } if (d[x] > d[y]) swap(x, y); // x always bigger tree d[x] += d[y]; d[y] = x; return true; } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return -d[root(x)]; } }; #pragma endregion int main() { int n, m; cin >> n >> m; vp e(m); rep(i, m) { cin >> e[i]; e[i].first--; e[i].second--; } reverse(e.begin(), e.end()); UnionFind uft(n); ll fuck = (ll)n * (n - 1) / 2; vll ans(m); rep(i, m) { ans[i] = fuck; ll a = uft.size(e[i].first), b = uft.size(e[i].second); bool newB = uft.unite(e[i].first, e[i].second); if (newB) { fuck -= a * b; } } assert(false); reverse(ans.begin(), ans.end()); for (int a : ans) { cout << a << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; using vint = vector<int>; using vvint = vector<vint>; using vll = vector<ll>; using vvll = vector<vll>; using vchar = vector<char>; using vvchar = vector<vchar>; using vp = vector<P>; using vpp = vector<pair<P, P>>; using vvp = vector<vp>; #define rep(i, n) for (int i = 0; i < n; ++i) #pragma region Debug istream &operator>>(istream &is, P &a) { return is >> a.first >> a.second; } ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; } template <typename T> void view(const std::vector<T> &v) { for (const auto &e : v) { std::cout << e << " "; } std::cout << std::endl; } template <typename T> void view(const std::vector<std::vector<T>> &vv) { for (const auto &v : vv) { view(v); } } #pragma endregion #pragma region UnionFind struct UnionFind { vector<int> d; // d[x] is the index of the parent of x // d[x] is -size if x is a root UnionFind(int n) : d(vector<int>(n, -1)) {} int root(int x) { if (d[x] < 0) { return x; } return d[x] = root(d[x]); } bool unite(int x, int y) { x = root(x); y = root(y); if (x == y) { return false; } if (d[x] > d[y]) swap(x, y); // x always bigger tree d[x] += d[y]; d[y] = x; return true; } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return -d[root(x)]; } }; #pragma endregion int main() { int n, m; cin >> n >> m; vp e(m); rep(i, m) { cin >> e[i]; e[i].first--; e[i].second--; } reverse(e.begin(), e.end()); UnionFind uft(n); ll fuck = (ll)n * (n - 1) / 2; vll ans(m); rep(i, m) { ans[i] = fuck; ll a = uft.size(e[i].first), b = uft.size(e[i].second); bool newB = uft.unite(e[i].first, e[i].second); if (newB) { fuck -= a * b; } } reverse(ans.begin(), ans.end()); for (ll a : ans) { cout << a << endl; } return 0; }
[ "call.remove" ]
918,647
918,651
u395620499
cpp
p03108
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (ll i = 0; i < n; i++) #define repl(i, l, r) for (ll i = (l); i < (r); i++) #define per(i, n) for (ll i = n - 1; i >= 0; i--) #define lper(i, r, l) for (ll i = r - 1; i >= l; i--) #define fi first #define se second #define mp make_pair #define pb push_back #define ins insert #define pqueue(x) priority_queue<x, vector<x>, greater<x>> #define all(x) (x).begin(), (x).end() #define CST(x) cout << fixed << setprecision(x) #define vtpl(x, y, z) vector<tuple<x, y, z>> #define at(x, i) get<i>(x); #define rev(x) reverse(x); using ll = long long; using vl = vector<ll>; using vvl = vector<vector<ll>>; using pl = pair<ll, ll>; using vpl = vector<pl>; using vvpl = vector<vpl>; const ll MOD = 1000000007; const ll MOD9 = 998244353; const int inf = 1e9 + 10; const ll INF = 4e18; const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1}; const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1}; ll modfac(ll a) { ll ans = 1; while (a > 1) { ans *= a; ans %= 1000000007; a--; } return ans; } ll modinv(ll a, ll 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; } struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool same(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { ll n, m; cin >> n >> m; vl l(m), r(m); rep(i, m) { cin >> l[i] >> r[i]; l[i]--; r[i]--; } rev(all(l)); rev(all(r)); vl ans(m); ans[0] = n * (n - 1) / 2; UnionFind uf(n); rep(i, n - 1) { ll a = l[i], b = r[i]; ll s = uf.size(a) * uf.size(b); if (!uf.same(a, b)) ans[i + 1] = ans[i] - s; else ans[i + 1] = ans[i]; uf.merge(a, b); } rev(all(ans)); rep(i, m) { cout << ans[i] << endl; } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (ll i = 0; i < n; i++) #define repl(i, l, r) for (ll i = (l); i < (r); i++) #define per(i, n) for (ll i = n - 1; i >= 0; i--) #define lper(i, r, l) for (ll i = r - 1; i >= l; i--) #define fi first #define se second #define mp make_pair #define pb push_back #define ins insert #define pqueue(x) priority_queue<x, vector<x>, greater<x>> #define all(x) (x).begin(), (x).end() #define CST(x) cout << fixed << setprecision(x) #define vtpl(x, y, z) vector<tuple<x, y, z>> #define at(x, i) get<i>(x); #define rev(x) reverse(x); using ll = long long; using vl = vector<ll>; using vvl = vector<vector<ll>>; using pl = pair<ll, ll>; using vpl = vector<pl>; using vvpl = vector<vpl>; const ll MOD = 1000000007; const ll MOD9 = 998244353; const int inf = 1e9 + 10; const ll INF = 4e18; const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1}; const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1}; ll modfac(ll a) { ll ans = 1; while (a > 1) { ans *= a; ans %= 1000000007; a--; } return ans; } ll modinv(ll a, ll 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; } struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool same(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { ll n, m; cin >> n >> m; vl l(m), r(m); rep(i, m) { cin >> l[i] >> r[i]; l[i]--; r[i]--; } rev(all(l)); rev(all(r)); vl ans(m); ans[0] = n * (n - 1) / 2; UnionFind uf(n); rep(i, m - 1) { ll a = l[i], b = r[i]; ll s = uf.size(a) * uf.size(b); if (!uf.same(a, b)) ans[i + 1] = ans[i] - s; else ans[i + 1] = ans[i]; uf.merge(a, b); } rev(all(ans)); rep(i, m) { cout << ans[i] << endl; } }
[ "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
918,690
918,692
u160429264
cpp
p03108
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; #define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i)) #define all(x) x.begin(), x.end() #pragma region UnionFind struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} void init(int n) { par.assign(n, -1); } int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } void merge(int x, int y) { x = root(x); y = root(y); if (x == y) return; if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return; } int size(int x) { return -par[root(x)]; } }; #pragma endregion int main() { int n, m; cin >> n >> m; vector<long long> res(m); vector<int> a(m), b(m); rep(i, 0, m - 1) { cin >> a[i] >> b[i]; --a[i], --b[i]; } UnionFind uf(n); long long cur = n * (n - 1) / 2; rep(i, 0, m - 2) { res[i] = cur; if (uf.issame(a[m - 1 - i], b[m - 1 - i])) continue; long long sa = uf.size(a[m - 1 - i]), sb = uf.size(b[m - 1 - i]); cur -= sa * sb; uf.merge(a[m - 1 - i], b[m - 1 - i]); } reverse(all(res)); rep(i, 0, m - 1) cout << res[i] << endl; }
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; #define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i)) #define all(x) x.begin(), x.end() #pragma region UnionFind struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} void init(int n) { par.assign(n, -1); } int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } void merge(int x, int y) { x = root(x); y = root(y); if (x == y) return; if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return; } int size(int x) { return -par[root(x)]; } }; #pragma endregion int main() { long long n, m; cin >> n >> m; vector<long long> res(m); vector<int> a(m), b(m); rep(i, 0, m - 1) { cin >> a[i] >> b[i]; --a[i], --b[i]; } UnionFind uf(n); long long cur = n * (n - 1) / 2; rep(i, 0, m - 1) { res[i] = cur; if (uf.issame(a[m - 1 - i], b[m - 1 - i])) continue; long long sa = uf.size(a[m - 1 - i]), sb = uf.size(b[m - 1 - i]); cur -= sa * sb; uf.merge(a[m - 1 - i], b[m - 1 - i]); } reverse(all(res)); rep(i, 0, m - 1) cout << res[i] << endl; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change", "literal.number.change", "call.arguments.change", "expression.operation.binary.change" ]
918,701
918,700
u521389909
cpp
p03108
#include <bits/stdc++.h> using namespace std; struct UnionFind { vector<long> p; vector<long> w; UnionFind(long n) { p.resize(n + 1); w.resize(n + 1, 1); for (long i = 1; i <= n; i++) p[i] = i; } long find(long x) { if (p[x] == x) return x; return p[x] = find(p[x]); } void unite(long x, long y) { x = find(x); y = find(y); if (x == y) return; p[x] = y; w[x] += w[y]; w[y] = w[x]; } long weight(long x) { return w[find(x)]; } }; int main() { long n, m; cin >> n >> m; UnionFind uf(n); vector<pair<long, long>> bri(m); for (long i = 0; i < m; i++) cin >> bri[i].first >> bri[i].second; long ma = n * (n - 1) / 2; vector<long> ans(m, 0); ans[m - 1] = ma; for (long i = m - 2; i >= 0; i--) { if (uf.find(bri[i].first) == uf.find(bri[i].second)) { ans[i] = ans[i + 1]; continue; } ans[i] = ans[i + 1] - uf.weight(bri[i + 1].first) * uf.weight(bri[i + 1].second); uf.unite(bri[i + 1].first, bri[i + 1].second); } for (auto ai : ans) cout << ai << endl; return 0; }
#include <bits/stdc++.h> using namespace std; struct UnionFind { vector<long> p; vector<long> w; UnionFind(long n) { p.resize(n + 1); w.resize(n + 1, 1); for (long i = 1; i <= n; i++) p[i] = i; } long find(long x) { if (p[x] == x) return x; return p[x] = find(p[x]); } void unite(long x, long y) { x = find(x); y = find(y); if (x == y) return; p[x] = y; w[x] += w[y]; w[y] = w[x]; } long weight(long x) { return w[find(x)]; } }; int main() { long n, m; cin >> n >> m; UnionFind uf(n); vector<pair<long, long>> bri(m); for (long i = 0; i < m; i++) cin >> bri[i].first >> bri[i].second; long ma = n * (n - 1) / 2; vector<long> ans(m, 0); ans[m - 1] = ma; for (long i = m - 2; i >= 0; i--) { if (uf.find(bri[i + 1].first) == uf.find(bri[i + 1].second)) { ans[i] = ans[i + 1]; continue; } ans[i] = ans[i + 1] - uf.weight(bri[i + 1].first) * uf.weight(bri[i + 1].second); uf.unite(bri[i + 1].first, bri[i + 1].second); } for (auto ai : ans) cout << ai << endl; return 0; }
[ "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "misc.off_by_one" ]
918,971
918,972
u792720861
cpp
p03108
#include <bits/stdc++.h> #define rep(i, a, n) for (int i = a; i < n; i++) #define repr(i, a, n) for (int i = n - 1; i >= a; i--) using namespace std; using ll = long long; using P = pair<int, int>; template <typename T> void chmin(T &a, T b) { a = min(a, b); } template <typename T> void chmax(T &a, T b) { a = max(a, b); } struct UnionFind { vector<int> par; vector<int> rank; vector<ll> Size; UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1); for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); return par[x] = r; } } bool is_same(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) ++rank[x]; par[y] = x; Size[x] += Size[y]; return true; } ll size(int x) { return Size[root(x)]; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<P> v(m); rep(i, 0, m) { int a, b; cin >> a >> b; a--, b--; v[i] = make_pair(a, b); } vector<ll> ans(m); ans[m - 1] = (n * (n - 1)) / 2; UnionFind uf(n); repr(i, 0, m - 1) { if (uf.is_same(v[i].first, v[i].second)) ans[i] = ans[i + 1]; else ans[i] = ans[i + 1] - (ll)(uf.size(v[i + 1].first)) * (ll)(uf.size(v[i + 1].second)); uf.merge(v[i + 1].first, v[i + 1].second); } rep(i, 0, m) cout << ans[i] << endl; }
#include <bits/stdc++.h> #define rep(i, a, n) for (int i = a; i < n; i++) #define repr(i, a, n) for (int i = n - 1; i >= a; i--) using namespace std; using ll = long long; using P = pair<int, int>; template <typename T> void chmin(T &a, T b) { a = min(a, b); } template <typename T> void chmax(T &a, T b) { a = max(a, b); } struct UnionFind { vector<int> par; vector<int> rank; vector<ll> Size; UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1); for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); return par[x] = r; } } bool is_same(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) ++rank[x]; par[y] = x; Size[x] += Size[y]; return true; } ll size(int x) { return Size[root(x)]; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, m; cin >> n >> m; vector<P> v(m); rep(i, 0, m) { int a, b; cin >> a >> b; a--, b--; v[i] = make_pair(a, b); } vector<ll> ans(m); ans[m - 1] = (n * (n - 1)) / 2; UnionFind uf(n); repr(i, 0, m - 1) { if (uf.is_same(v[i + 1].first, v[i + 1].second)) ans[i] = ans[i + 1]; else ans[i] = ans[i + 1] - (ll)(uf.size(v[i + 1].first)) * (ll)(uf.size(v[i + 1].second)); uf.merge(v[i + 1].first, v[i + 1].second); } rep(i, 0, m) cout << ans[i] << endl; }
[ "variable_declaration.type.change", "control_flow.branch.if.condition.change" ]
918,983
918,982
u688789047
cpp
p03108
#include <bits/stdc++.h> using namespace std; using i64 = int_fast64_t; #define INF (i64)(1e18) #define MOD (i64)(1e9 + 7) #define REP(i, n) for (i64 i = 0; i < (n); i++) #define RREP(i, n) for (i64 i = (n)-1; i >= 0; i--) #define RANGE(i, a, b) for (i64 i = (a); i < (b); i++) #define RRANGE(i, a, b) for (i64 i = (b)-1; i >= (a); i--) #define ALL(v) (v).begin(), (v).end() #define SIZE(v) ((i64)(v).size()) template <class T> inline void chmax(T &a, const T &b) { if (a < b) a = b; } template <class T> inline void chmin(T &a, const T &b) { if (a > b) a = b; } struct UnionFind { vector<i64> par, sz; UnionFind(i64 n) : par(n), sz(n, 1) { REP(i, n) par[i] = i; } i64 root(i64 x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(i64 x, i64 y) { i64 rx = root(x), ry = root(y); if (rx == ry) return; if (size(rx) < size(ry)) swap(rx, ry); par[ry] = rx; sz[rx] += sz[ry]; } i64 size(i64 x) { return sz[root(x)]; } bool same(i64 x, i64 y) { return root(x) == root(y); } }; int main() { i64 n, m; cin >> n >> m; vector<i64> a(m), b(m); REP(i, m) { cin >> a.at(i) >> b.at(i); a[i]--; b[i]--; } UnionFind uf(n); i64 memo = n * (n - 1) / 2; vector<i64> ans(n); RREP(i, m) { ans[i] = memo; if (uf.same(a[i], b[i])) continue; memo -= uf.size(a[i]) * uf.size(b[i]); uf.unite(a[i], b[i]); } for (auto &x : ans) cout << x << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using i64 = int_fast64_t; #define INF (i64)(1e18) #define MOD (i64)(1e9 + 7) #define REP(i, n) for (i64 i = 0; i < (n); i++) #define RREP(i, n) for (i64 i = (n)-1; i >= 0; i--) #define RANGE(i, a, b) for (i64 i = (a); i < (b); i++) #define RRANGE(i, a, b) for (i64 i = (b)-1; i >= (a); i--) #define ALL(v) (v).begin(), (v).end() #define SIZE(v) ((i64)(v).size()) template <class T> inline void chmax(T &a, const T &b) { if (a < b) a = b; } template <class T> inline void chmin(T &a, const T &b) { if (a > b) a = b; } struct UnionFind { vector<i64> par, sz; UnionFind(i64 n) : par(n), sz(n, 1) { REP(i, n) par[i] = i; } i64 root(i64 x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(i64 x, i64 y) { i64 rx = root(x), ry = root(y); if (rx == ry) return; if (size(rx) < size(ry)) swap(rx, ry); par[ry] = rx; sz[rx] += sz[ry]; } i64 size(i64 x) { return sz[root(x)]; } bool same(i64 x, i64 y) { return root(x) == root(y); } }; int main() { i64 n, m; cin >> n >> m; vector<i64> a(m), b(m); REP(i, m) { cin >> a.at(i) >> b.at(i); a[i]--; b[i]--; } UnionFind uf(n); i64 memo = n * (n - 1) / 2; vector<i64> ans(m); RREP(i, m) { ans[i] = memo; if (uf.same(a[i], b[i])) continue; memo -= uf.size(a[i]) * uf.size(b[i]); uf.unite(a[i], b[i]); } for (auto &x : ans) cout << x << endl; return 0; }
[]
919,016
919,017
u880126159
cpp
p03108
#include <iostream> #include <vector> using namespace std; struct UnionFind { vector<long long> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(long long N) : par(N) { //最初は全てが根であるとして初期化 for (long long i = 0; i < N; i++) par[i] = i; } long long root( long long x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(long long x, long long y) { // xとyの木を併合 long long rx = root(x); // xの根をrx long long ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(long long x, long long y) { long long rx = root(x); long long ry = root(y); return rx == ry; } }; int main() { long long N, M; cin >> N >> M; vector<pair<long long, long long>> E(M); for (long long i = 0; i < M; i++) cin >> E[i].first >> E[i].second; vector<long long> Ans(M); UnionFind UF(N); vector<long long> Nums(N, 1); Ans[M - 1] = N * (N - 1) / 2; for (long long i = M - 1; i >= 1; i--) { long long a = E[i - 1].first, b = E[i - 1].second; Ans[i - 1] = Ans[i]; if (!UF.same(a - 1, b - 1)) { long long ra = UF.root(a - 1); long long rb = UF.root(b - 1); Ans[i - 1] -= Nums[ra] * Nums[rb]; UF.unite(a - 1, b - 1); Nums[rb] += Nums[ra]; Nums[ra] = 0; } } for (long long a : Ans) cout << a << endl; }
#include <iostream> #include <vector> using namespace std; struct UnionFind { vector<long long> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(long long N) : par(N) { //最初は全てが根であるとして初期化 for (long long i = 0; i < N; i++) par[i] = i; } long long root( long long x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(long long x, long long y) { // xとyの木を併合 long long rx = root(x); // xの根をrx long long ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(long long x, long long y) { long long rx = root(x); long long ry = root(y); return rx == ry; } }; int main() { long long N, M; cin >> N >> M; vector<pair<long long, long long>> E(M); for (long long i = 0; i < M; i++) cin >> E[i].first >> E[i].second; vector<long long> Ans(M); UnionFind UF(N); vector<long long> Nums(N, 1); Ans[M - 1] = N * (N - 1) / 2; for (long long i = M - 1; i >= 1; i--) { long long a = E[i].first, b = E[i].second; Ans[i - 1] = Ans[i]; if (!UF.same(a - 1, b - 1)) { long long ra = UF.root(a - 1); long long rb = UF.root(b - 1); Ans[i - 1] -= Nums[ra] * Nums[rb]; UF.unite(a - 1, b - 1); Nums[rb] += Nums[ra]; Nums[ra] = 0; } } for (long long a : Ans) cout << a << endl; }
[ "expression.operation.binary.remove" ]
919,061
919,062
u868132236
cpp
p03108
#include <bits/stdc++.h> using namespace std; using ll = long long; struct UnionFind { vector<ll> rnk, par, num; UnionFind(ll N) : rnk(N), par(N), num(N) { init(); } void init() { for (ll i = 0; i < rnk.size(); i++) { rnk[i] = 0; par[i] = i; num[i] = 1; } } ll find(ll x) { if (par[x] == x) return x; return par[x] = find(par[x]); } void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]) { par[x] = y; num[y] += num[x]; } else { par[y] = x; num[x] += num[y]; if (rnk[x] == rnk[y]) rnk[x]++; } } bool same(ll x, ll y) { return (find(x) == find(y)); } ll size(ll x) { return num[find(x)]; } }; signed main() { ll n, m; cin >> n >> m; vector<ll> a(m), b(m); for (int i = 0; i < m; i++) { scanf("ll%d%lld", &a[i], &b[i]); --a[i]; --b[i]; } UnionFind tree(n); vector<ll> ans(m); ll num = n * (n - 1) / 2; for (int i = m - 1; i >= 0; i--) { ans[i] = num; int x = a[i], y = b[i]; if (!tree.same(x, y)) { num -= tree.size(x) * tree.size(y); } tree.unite(x, y); } for (ll i : ans) cout << i << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; struct UnionFind { vector<ll> rnk, par, num; UnionFind(ll N) : rnk(N), par(N), num(N) { init(); } void init() { for (ll i = 0; i < rnk.size(); i++) { rnk[i] = 0; par[i] = i; num[i] = 1; } } ll find(ll x) { if (par[x] == x) return x; return par[x] = find(par[x]); } void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]) { par[x] = y; num[y] += num[x]; } else { par[y] = x; num[x] += num[y]; if (rnk[x] == rnk[y]) rnk[x]++; } } bool same(ll x, ll y) { return (find(x) == find(y)); } ll size(ll x) { return num[find(x)]; } }; signed main() { ll n, m; cin >> n >> m; vector<ll> a(m), b(m); for (int i = 0; i < m; i++) { scanf("%lld%lld", &a[i], &b[i]); --a[i]; --b[i]; } UnionFind tree(n); vector<ll> ans(m); ll num = n * (n - 1) / 2; for (ll i = m - 1; i >= 0; i--) { ans[i] = num; ll x = a[i], y = b[i]; if (!tree.same(x, y)) { num -= tree.size(x) * tree.size(y); } tree.unite(x, y); } for (ll i : ans) cout << i << endl; }
[ "literal.string.change", "call.arguments.change", "control_flow.loop.for.initializer.change", "variable_declaration.type.change" ]
919,108
919,109
u265359795
cpp
p03108
#include <bits/stdc++.h> using namespace std; const int MAX_V = 100000; int par[MAX_V]; int depth[MAX_V]; int num[MAX_V]; void init(int n) { for (int i = 0; i < n; i++) { par[i] = i; depth[i] = 0; num[i] = 1; } } int root(int x) { if (par[x] == x) return x; else return par[x] = root(par[x]); } void unite(int x, int y) { x = root(x); y = root(y); if (x == y) return; num[x] += num[y]; num[y] = num[x]; if (depth[x] < depth[y]) par[x] = y; else { par[y] = x; if (depth[x] == depth[y]) depth[x]++; } } bool same(int x, int y) { return root(x) == root(y); } int get_num(int x) { return num[root(x)]; } int main() { int n, m; cin >> n >> m; vector<int> a(m), b(m); for (int i = 0; i < m; i++) { cin >> a.at(i) >> b.at(i); a.at(i)--; b.at(i)--; } init(n); vector<long long> ans(m); long long cnt = (long long)n * (n - 1) / 2; ans.at(m - 1) = cnt; for (int i = m - 1; i >= 1; i--) { if (same(a.at(i), b.at(i))) continue; cnt -= (long long)get_num(a.at(i)) * get_num(b.at(i)); unite(a.at(i), b.at(i)); ans.at(i - 1) = cnt; } for (int i = 0; i < m; i++) { cout << ans.at(i) << endl; } }
#include <bits/stdc++.h> using namespace std; const int MAX_V = 100000; int par[MAX_V]; int depth[MAX_V]; int num[MAX_V]; void init(int n) { for (int i = 0; i < n; i++) { par[i] = i; depth[i] = 0; num[i] = 1; } } int root(int x) { if (par[x] == x) return x; else return par[x] = root(par[x]); } void unite(int x, int y) { x = root(x); y = root(y); if (x == y) return; num[x] += num[y]; num[y] = num[x]; if (depth[x] < depth[y]) par[x] = y; else { par[y] = x; if (depth[x] == depth[y]) depth[x]++; } } bool same(int x, int y) { return root(x) == root(y); } int get_num(int x) { return num[root(x)]; } int main() { int n, m; cin >> n >> m; vector<int> a(m), b(m); for (int i = 0; i < m; i++) { cin >> a.at(i) >> b.at(i); a.at(i)--; b.at(i)--; } init(n); vector<long long> ans(m); long long cnt = (long long)n * (n - 1) / 2; ans.at(m - 1) = cnt; for (int i = m - 1; i >= 1; i--) { if (!same(a.at(i), b.at(i))) { cnt -= (long long)get_num(a.at(i)) * get_num(b.at(i)); unite(a.at(i), b.at(i)); } ans.at(i - 1) = cnt; } for (int i = 0; i < m; i++) { cout << ans.at(i) << endl; } }
[ "expression.operation.unary.add", "control_flow.branch.if.condition.change" ]
919,203
919,204
u465233477
cpp
p03108
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() typedef long long ll; #define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i) #define REP(i, num, n) for (ll i = num, i##_len = (n); i < i##_len; ++i) #define repprev(i, a, b) for (int i = b - 1; i >= a; i--) #define reprev(i, n) repprev(i, 0, n) using namespace std; #define sz(x) ((int)(x).size()) #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) #define MEMSET(v, h) memset((v), h, sizeof(v)) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define pb push_back #define mp make_pair #define y0 y3487465 #define y1 y8687969 #define j0 j1347829 #define j1 j234892 ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } const ll INF = 1LL << 60; const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { 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; } } // 二項係数計算 long long 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; } struct UnionFind { vector<ll> par; UnionFind(ll n) : par(n, -1) {} void init(ll n) { par.assign(n, -1); } int root(ll x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(ll x, ll y) { return root(x) == root(y); } bool merge(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; return true; } int size(ll x) { return -par[root(x)]; } }; int main() { ll N, M; cin >> N >> M; vector<ll> A(M), B(M); rep(i, M) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<ll> ans(M); ans[M - 1] = N * (N - 1) / 2; UnionFind Uni(N); repprev(i, 1, M - 1) { //繋がってなかったのが繋がった時 if (Uni.root(A[i]) != Uni.root(B[i])) { ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]); Uni.merge(A[i], B[i]); } else ans[i - 1] = ans[i]; } rep(i, M) { cout << ans[i] << endl; } }
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() typedef long long ll; #define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i) #define REP(i, num, n) for (ll i = num, i##_len = (n); i < i##_len; ++i) #define repprev(i, a, b) for (int i = b - 1; i >= a; i--) #define reprev(i, n) repprev(i, 0, n) using namespace std; #define sz(x) ((int)(x).size()) #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) #define MEMSET(v, h) memset((v), h, sizeof(v)) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define pb push_back #define mp make_pair #define y0 y3487465 #define y1 y8687969 #define j0 j1347829 #define j1 j234892 ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } const ll INF = 1LL << 60; const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { 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; } } // 二項係数計算 long long 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; } struct UnionFind { vector<ll> par; UnionFind(ll n) : par(n, -1) {} void init(ll n) { par.assign(n, -1); } ll root(ll x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(ll x, ll y) { return root(x) == root(y); } bool merge(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; return true; } ll size(ll x) { return -par[root(x)]; } }; int main() { ll N, M; cin >> N >> M; vector<ll> A(M), B(M); rep(i, M) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<ll> ans(M); ans[M - 1] = N * (N - 1) / 2; UnionFind Uni(N); repprev(i, 1, M) { //繋がってなかったのが繋がった時 if (Uni.root(A[i]) != Uni.root(B[i])) { ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]); Uni.merge(A[i], B[i]); } else ans[i - 1] = ans[i]; } rep(i, M) { cout << ans[i] << endl; } }
[ "expression.operation.binary.remove" ]
919,242
919,243
u135572611
cpp
p03108
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() typedef long long ll; #define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i) #define REP(i, num, n) for (ll i = num, i##_len = (n); i < i##_len; ++i) #define repprev(i, a, b) for (int i = b - 1; i >= a; i--) #define reprev(i, n) repprev(i, 0, n) using namespace std; #define sz(x) ((int)(x).size()) #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) #define MEMSET(v, h) memset((v), h, sizeof(v)) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define pb push_back #define mp make_pair #define y0 y3487465 #define y1 y8687969 #define j0 j1347829 #define j1 j234892 ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } const ll INF = 1LL << 60; const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { 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; } } // 二項係数計算 long long 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; } struct UnionFind { vector<ll> par; UnionFind(ll n) : par(n, -1) {} void init(ll n) { par.assign(n, -1); } int root(ll x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(ll x, ll y) { return root(x) == root(y); } bool merge(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; return true; } int size(ll x) { return -par[root(x)]; } }; int main() { ll N, M; cin >> N >> M; vector<ll> A(M), B(M); rep(i, M) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<ll> ans(M); ans[M - 1] = N * (N - 1) / 2; UnionFind Uni(N); repprev(i, 1, M - 1) { //繋がってなかったのが繋がった時 if (Uni.root(A[i]) != Uni.root(B[i])) { ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]); Uni.merge(A[i], B[i]); } else ans[i - 1] = ans[i]; } rep(i, M) { cout << ans[i] << endl; } }
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() typedef long long ll; #define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i) #define REP(i, num, n) for (ll i = num, i##_len = (n); i < i##_len; ++i) #define repprev(i, a, b) for (int i = b - 1; i >= a; i--) #define reprev(i, n) repprev(i, 0, n) using namespace std; #define sz(x) ((int)(x).size()) #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) #define MEMSET(v, h) memset((v), h, sizeof(v)) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define pb push_back #define mp make_pair #define y0 y3487465 #define y1 y8687969 #define j0 j1347829 #define j1 j234892 ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } const ll INF = 1LL << 60; const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { 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; } } // 二項係数計算 long long 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; } struct UnionFind { vector<ll> par; UnionFind(ll n) : par(n, -1) {} void init(ll n) { par.assign(n, -1); } int root(ll x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(ll x, ll y) { return root(x) == root(y); } bool merge(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; return true; } int size(ll x) { return -par[root(x)]; } }; int main() { ll N, M; cin >> N >> M; vector<ll> A(M), B(M); rep(i, M) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<ll> ans(M); ans[M - 1] = N * (N - 1) / 2; UnionFind Uni(N); repprev(i, 1, M) { //繋がってなかったのが繋がった時 if (Uni.root(A[i]) != Uni.root(B[i])) { ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]); Uni.merge(A[i], B[i]); } else ans[i - 1] = ans[i]; } rep(i, M) { cout << ans[i] << endl; } }
[ "expression.operation.binary.remove" ]
919,242
919,245
u135572611
cpp
p03108
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() typedef long long ll; #define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i) #define REP(i, num, n) for (ll i = num, i##_len = (n); i < i##_len; ++i) #define repprev(i, a, b) for (int i = b - 1; i >= a; i--) #define reprev(i, n) repprev(i, 0, n) using namespace std; #define sz(x) ((int)(x).size()) #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) #define MEMSET(v, h) memset((v), h, sizeof(v)) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define pb push_back #define mp make_pair #define y0 y3487465 #define y1 y8687969 #define j0 j1347829 #define j1 j234892 ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } const ll INF = 1LL << 60; const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { 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; } } // 二項係数計算 long long 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; } struct UnionFind { vector<ll> par; UnionFind(ll n) : par(n, -1) {} void init(ll n) { par.assign(n, -1); } int root(ll x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(ll x, ll y) { return root(x) == root(y); } bool merge(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; return true; } int size(ll x) { return -par[root(x)]; } }; int main() { ll N, M; cin >> N >> M; vector<ll> A(M), B(M); rep(i, M) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<ll> ans(M); ans[M - 1] = N * (N - 1) / 2; UnionFind Uni(N); reprev(i, M - 1) { //繋がってなかったのが繋がった時 if (Uni.root(A[i]) != Uni.root(B[i])) { ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]); Uni.merge(A[i], B[i]); } else ans[i - 1] = ans[i]; } rep(i, M) { cout << ans[i] << endl; } }
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() typedef long long ll; #define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i) #define REP(i, num, n) for (ll i = num, i##_len = (n); i < i##_len; ++i) #define repprev(i, a, b) for (int i = b - 1; i >= a; i--) #define reprev(i, n) repprev(i, 0, n) using namespace std; #define sz(x) ((int)(x).size()) #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) #define MEMSET(v, h) memset((v), h, sizeof(v)) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define pb push_back #define mp make_pair #define y0 y3487465 #define y1 y8687969 #define j0 j1347829 #define j1 j234892 ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } const ll INF = 1LL << 60; const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { 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; } } // 二項係数計算 long long 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; } struct UnionFind { vector<ll> par; UnionFind(ll n) : par(n, -1) {} void init(ll n) { par.assign(n, -1); } int root(ll x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(ll x, ll y) { return root(x) == root(y); } bool merge(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; return true; } int size(ll x) { return -par[root(x)]; } }; int main() { ll N, M; cin >> N >> M; vector<ll> A(M), B(M); rep(i, M) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<ll> ans(M); ans[M - 1] = N * (N - 1) / 2; UnionFind Uni(N); repprev(i, 1, M) { //繋がってなかったのが繋がった時 if (Uni.root(A[i]) != Uni.root(B[i])) { ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]); Uni.merge(A[i], B[i]); } else ans[i - 1] = ans[i]; } rep(i, M) { cout << ans[i] << endl; } }
[ "identifier.change", "call.function.change", "expression.operation.binary.remove", "call.arguments.add" ]
919,246
919,245
u135572611
cpp
p03108
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <vector> typedef char SINT8; typedef unsigned char UINT8; typedef short SINT16; typedef unsigned short UINT16; typedef int SINT32; typedef unsigned int UINT32; typedef long long SINT64; typedef unsigned long long UINT64; typedef double DOUBLE; #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define ABS(a) ((a) > (0) ? (a) : -(a)) #define rep(i, a, b) for (int(i) = int(a); (i) < int(b); (i)++) #define rrep(i, a, b) for (int(i) = int(a); (i) >= int(b); (i)--) #define put(a) cout << (a) << endl #define puts(a) cout << (a) << " " #define pute(a) cout << endl #define INF 1000000001 #define MOD 1000000007 #define INF64 1000000000000000001 #define F first #define S second #define Pii pair<SINT32, SINT32> #define Pll pair<SINT64, SINT64> #define Piii pair<SINT32, pair<SINT32, SINT32>> #define Plll pair<SINT64, pair<SINT64, SINT64>> #define Vll(a, b, c) vector<vector<SINT64>> (a)((b),vector<SINT64>((c)) #define Vlll(a, b, c, d) vector<vector<vector<SINT64>>> (a)((b),vector<vector<SINT64>>((c),vector<SINT64>((d))) using namespace std; class UnionFind { public: vector<SINT64> parent; UnionFind(SINT64 N) { parent = vector<SINT64>(N, -1); } SINT64 root(SINT64 A) { if (parent[A] < 0) { return A; } else { parent[A] = root(parent[A]); return parent[A]; } } SINT64 size(SINT64 A) { return parent[root(A)] * (-1); } bool judge(SINT64 A, SINT64 B) { A = root(A); B = root(B); if (A == B) { return true; //同じグループ } else { return false; //違うグループ } } void connect(SINT64 A, SINT64 B) { A = root(A); B = root(B); if (A != B) { if (size(A) < size(B)) { swap(A, B); } parent[A] += parent[B]; parent[B] = A; } } }; int main() { SINT64 N; cin >> N; SINT64 M; cin >> M; vector<Pll> data(M); vector<SINT64> ans; SINT64 cnt = N * (N - 1) / 2; ans.emplace_back(cnt); UnionFind Uni(N); rep(i, 0, M) { cin >> data[i].F; cin >> data[i].S; } rrep(i, M - 1, 0) { if (Uni.judge(data[i].F, data[i].S) == false) { cnt -= Uni.size(data[i].F) * Uni.size(data[i].S); Uni.connect(data[i].F, data[i].S); } ans.emplace_back(cnt); } rrep(i, M - 1, 0) { put(ans[i]); } return 0; } // vector<vector<SINT64>> data(N,vector<SINT32>(3)); ////2次元配列 vector<vector<vector<SINT64>>> //data(N,vector<vector<SINT64>>(3,vector<SINT64>(3))); //3次元配列 // Vll(data,N,N); //2次元配列 // Vlll(data,N,N,N); //3次元配列 // sort(data.begin(),data.end()); // sort(data.begin(),data.end(),std::greater<SINT64>()); // __gcd(A,B); /* 複数条件ソート bool sortcompare(Pll A, Pll B) { if(A.F == B.F){ return A.S > B.S; } else { return A.F < B.F; } } sort(data.begin(),data.end(),sortcompare); */ // data.emplace_back(BUF); //後ろに追加 // data.erase(std::unique(data.begin(), data.end()), data.end()); // //ソート後に使用 同じ値を消す // data.insert(data.begin() + X, 0); //X番目の要素に0を挿入 // 隣接リスト // vector<vector<SINT64>> data(N); // data[ A ].emplace_back( B ); /* vector<Pll> data(N); rep(i,0,N) { cin >> data[i].F; cin >> data[i].S; } sort(data.begin(),data.end()); */ /* vector<Plll> data(N); rep(i,0,N) { cin >> data[i].F; cin >> data[i].S.F; cin >> data[i].S.S; } sort(data.begin(),data.end()); */ // posi = lower_bound(data.begin(),data.end(), X) - data.begin(); // // X以上を探す posi = lower_bound(data.begin(),data.end(),make_pair(X,0)) - // data.begin(); //pair /* 文字列回転 string N; cin >> N; N = N[N.length()-1] + N.substr(0,N.length()-1); s = to_string(i); //ストリング変換 */ /* 文字列合成 string N,M; cin >> N >> M; SINT64 ans = 0; ans = stoi(N+M); */ /* //ワーシャルフロイド vector<vector<SINT32>> dist(N,vector<SINT32>(N)); rep(i,0,N) { rep(j,0,N) { if (i != j) { dist[i][j] = INF; } } } rep(k,0,N) { rep(i,0,N) { rep(j,0,N) { dist[i][j] = MIN(dist[i][j], dist[i][k]+dist[k][j]); } } } */ /* 優先度付きキュー priority_queue<SINT64, vector<SINT64>, greater<SINT64>> data; //小さいほうから取り出せる priority_queue<SINT64, vector<SINT64>> data; //大きいほうから取り出せる data.push(X); //X を挿入 data.top(); //先頭データ読み data.pop(); //先頭データ削除 */ /* SET コンテナ set<SINT64> data; data.insert(X); //X を挿入 data.erase(data.begin()); //先頭を削除 data.erase(--data.end()); //末尾を削除 *data.begin(); //先頭要素にアクセス *data.rbegin(); //末尾要素にアクセス //全表示 set<SINT64>::iterator it; //イテレータを用意 for(it = data.begin(); it != data.end(); it++) { cout << *it << " "; } cout << endl; //N番目を一部表示 set<SINT64>::iterator it; // イテレータを用意 it = data.begin(); rep (i,0,N) { it++; } cout << *it << endl; */ /* map map<string,SINT32> mp; SINT32 N = 0; SINT32 mx = 0; cin >> N; for (SINT32 i = 0; i < N; i++) { string s; cin >> s; mp[s]++; } for(auto it=mp.begin();it!=mp.end();it++) { mx=max(mx,it->second); } */ /* //順列全表示 //sortしてからでないと全列挙にならない sort(data.begin(),data.end()); do { cout << buf << endl; rep(i,0,R) { cout << data[i] << " "; } cout << endl; } while (next_permutation(data.begin(),data.end())); */ // 桁指定表示 // ans = ans * M_PI; // cout << setprecision(15) << ans << endl; // 逆元 コンビネーション /* SINT64 modpow(SINT64 a, SINT64 p) { if (p == 0) return 1; if (p % 2 == 0) { //pが偶数の時 SINT64 halfP = p / 2; SINT64 half = modpow(a, halfP); //a^(p/2) をhalfとして、half*halfを計算 return half * half % MOD; } else { //pが奇数の時は、偶数にするために1減らす return a * modpow(a, p - 1) % MOD; } } SINT64 calcComb(SINT64 a, SINT64 b) { SINT64 Mul = 1; SINT64 Div = 1; SINT64 ans = 0; if (b > a - b) { return calcComb(a, a - b); } rep(i,0,b) { Mul *= (a - i); Div *= (i + 1); Mul %= MOD; Div %= MOD; } ans = Mul * modpow(Div, MOD - 2) % MOD; return ans; } */
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <vector> typedef char SINT8; typedef unsigned char UINT8; typedef short SINT16; typedef unsigned short UINT16; typedef int SINT32; typedef unsigned int UINT32; typedef long long SINT64; typedef unsigned long long UINT64; typedef double DOUBLE; #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define ABS(a) ((a) > (0) ? (a) : -(a)) #define rep(i, a, b) for (int(i) = int(a); (i) < int(b); (i)++) #define rrep(i, a, b) for (int(i) = int(a); (i) >= int(b); (i)--) #define put(a) cout << (a) << endl #define puts(a) cout << (a) << " " #define pute(a) cout << endl #define INF 1000000001 #define MOD 1000000007 #define INF64 1000000000000000001 #define F first #define S second #define Pii pair<SINT32, SINT32> #define Pll pair<SINT64, SINT64> #define Piii pair<SINT32, pair<SINT32, SINT32>> #define Plll pair<SINT64, pair<SINT64, SINT64>> #define Vll(a, b, c) vector<vector<SINT64>> (a)((b),vector<SINT64>((c)) #define Vlll(a, b, c, d) vector<vector<vector<SINT64>>> (a)((b),vector<vector<SINT64>>((c),vector<SINT64>((d))) using namespace std; class UnionFind { public: vector<SINT64> parent; UnionFind(SINT64 N) { parent = vector<SINT64>(N, -1); } SINT64 root(SINT64 A) { if (parent[A] < 0) { return A; } else { parent[A] = root(parent[A]); return parent[A]; } } SINT64 size(SINT64 A) { return parent[root(A)] * (-1); } bool judge(SINT64 A, SINT64 B) { A = root(A); B = root(B); if (A == B) { return true; //同じグループ } else { return false; //違うグループ } } void connect(SINT64 A, SINT64 B) { A = root(A); B = root(B); if (A != B) { if (size(A) < size(B)) { swap(A, B); } parent[A] += parent[B]; parent[B] = A; } } }; int main() { SINT64 N; cin >> N; SINT64 M; cin >> M; vector<Pll> data(M); vector<SINT64> ans; SINT64 cnt = N * (N - 1) / 2; ans.emplace_back(cnt); UnionFind Uni(N + 10); rep(i, 0, M) { cin >> data[i].F; cin >> data[i].S; } rrep(i, M - 1, 0) { if (Uni.judge(data[i].F, data[i].S) == false) { cnt -= Uni.size(data[i].F) * Uni.size(data[i].S); Uni.connect(data[i].F, data[i].S); } ans.emplace_back(cnt); } rrep(i, M - 1, 0) { put(ans[i]); } return 0; } // vector<vector<SINT64>> data(N,vector<SINT32>(3)); ////2次元配列 vector<vector<vector<SINT64>>> //data(N,vector<vector<SINT64>>(3,vector<SINT64>(3))); //3次元配列 // Vll(data,N,N); //2次元配列 // Vlll(data,N,N,N); //3次元配列 // sort(data.begin(),data.end()); // sort(data.begin(),data.end(),std::greater<SINT64>()); // __gcd(A,B); /* 複数条件ソート bool sortcompare(Pll A, Pll B) { if(A.F == B.F){ return A.S > B.S; } else { return A.F < B.F; } } sort(data.begin(),data.end(),sortcompare); */ // data.emplace_back(BUF); //後ろに追加 // data.erase(std::unique(data.begin(), data.end()), data.end()); // //ソート後に使用 同じ値を消す // data.insert(data.begin() + X, 0); //X番目の要素に0を挿入 // 隣接リスト // vector<vector<SINT64>> data(N); // data[ A ].emplace_back( B ); /* vector<Pll> data(N); rep(i,0,N) { cin >> data[i].F; cin >> data[i].S; } sort(data.begin(),data.end()); */ /* vector<Plll> data(N); rep(i,0,N) { cin >> data[i].F; cin >> data[i].S.F; cin >> data[i].S.S; } sort(data.begin(),data.end()); */ // posi = lower_bound(data.begin(),data.end(), X) - data.begin(); // // X以上を探す posi = lower_bound(data.begin(),data.end(),make_pair(X,0)) - // data.begin(); //pair /* 文字列回転 string N; cin >> N; N = N[N.length()-1] + N.substr(0,N.length()-1); s = to_string(i); //ストリング変換 */ /* 文字列合成 string N,M; cin >> N >> M; SINT64 ans = 0; ans = stoi(N+M); */ /* //ワーシャルフロイド vector<vector<SINT32>> dist(N,vector<SINT32>(N)); rep(i,0,N) { rep(j,0,N) { if (i != j) { dist[i][j] = INF; } } } rep(k,0,N) { rep(i,0,N) { rep(j,0,N) { dist[i][j] = MIN(dist[i][j], dist[i][k]+dist[k][j]); } } } */ /* 優先度付きキュー priority_queue<SINT64, vector<SINT64>, greater<SINT64>> data; //小さいほうから取り出せる priority_queue<SINT64, vector<SINT64>> data; //大きいほうから取り出せる data.push(X); //X を挿入 data.top(); //先頭データ読み data.pop(); //先頭データ削除 */ /* SET コンテナ set<SINT64> data; data.insert(X); //X を挿入 data.erase(data.begin()); //先頭を削除 data.erase(--data.end()); //末尾を削除 *data.begin(); //先頭要素にアクセス *data.rbegin(); //末尾要素にアクセス //全表示 set<SINT64>::iterator it; //イテレータを用意 for(it = data.begin(); it != data.end(); it++) { cout << *it << " "; } cout << endl; //N番目を一部表示 set<SINT64>::iterator it; // イテレータを用意 it = data.begin(); rep (i,0,N) { it++; } cout << *it << endl; */ /* map map<string,SINT32> mp; SINT32 N = 0; SINT32 mx = 0; cin >> N; for (SINT32 i = 0; i < N; i++) { string s; cin >> s; mp[s]++; } for(auto it=mp.begin();it!=mp.end();it++) { mx=max(mx,it->second); } */ /* //順列全表示 //sortしてからでないと全列挙にならない sort(data.begin(),data.end()); do { cout << buf << endl; rep(i,0,R) { cout << data[i] << " "; } cout << endl; } while (next_permutation(data.begin(),data.end())); */ // 桁指定表示 // ans = ans * M_PI; // cout << setprecision(15) << ans << endl; // 逆元 コンビネーション /* SINT64 modpow(SINT64 a, SINT64 p) { if (p == 0) return 1; if (p % 2 == 0) { //pが偶数の時 SINT64 halfP = p / 2; SINT64 half = modpow(a, halfP); //a^(p/2) をhalfとして、half*halfを計算 return half * half % MOD; } else { //pが奇数の時は、偶数にするために1減らす return a * modpow(a, p - 1) % MOD; } } SINT64 calcComb(SINT64 a, SINT64 b) { SINT64 Mul = 1; SINT64 Div = 1; SINT64 ans = 0; if (b > a - b) { return calcComb(a, a - b); } rep(i,0,b) { Mul *= (a - i); Div *= (i + 1); Mul %= MOD; Div %= MOD; } ans = Mul * modpow(Div, MOD - 2) % MOD; return ans; } */
[ "assignment.change" ]
919,356
919,357
u824905100
cpp
p03108
#include <bits/stdc++.h> using namespace std; using ll = long long; int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); } #define CIN(T, x) \ T x; \ cin >> x; #define CINS(T, x, N) \ vector<T> x(N); \ for (int i = 0; i < (N); i++) { \ cin >> x[i]; \ } #define SHOW(x) \ for (int i = 0; i < x.size(); i++) { \ cout << x[i] << " "; \ } \ cout << "\n"; #define SHOW2(x) \ for (int j = 0; j < x.size(); j++) { \ SHOW(x[j]); \ } \ cout << "\n"; int N, M; // int N_MAX = 1e5+5; int N_MAX = 30; vector<int> parent(N_MAX); vector<ll> treeSize(N_MAX, 1); int root(int x) { if (x == parent[x]) return x; parent[x] = root(parent[x]); return parent[x]; } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; if (treeSize[rx] >= treeSize[ry]) { parent[ry] = rx; treeSize[rx] += treeSize[ry]; treeSize[ry] = 0; } else { parent[rx] = ry; treeSize[ry] += treeSize[rx]; treeSize[rx] = 0; } } bool same(int x, int y) { return root(x) == root(y); } int main() { cin >> N >> M; vector<int> A(M); vector<int> B(M); for (int i = 0; i < M; i++) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<ll> ans(M); ans[M - 1] = N * (N - 1) / 2; for (int i = 0; i < N; i++) { parent[i] = i; } for (int i = M - 1; i > 0; i--) { if (same(A[i], B[i])) { ans[i - 1] = ans[i]; } else { ans[i - 1] = ans[i] - treeSize[parent[A[i]]] * treeSize[parent[B[i]]]; unite(A[i], B[i]); } } for (int i = 0; i < M; i++) { cout << ans[i] << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); } #define CIN(T, x) \ T x; \ cin >> x; #define CINS(T, x, N) \ vector<T> x(N); \ for (int i = 0; i < (N); i++) { \ cin >> x[i]; \ } #define SHOW(x) \ for (int i = 0; i < x.size(); i++) { \ cout << x[i] << " "; \ } \ cout << "\n"; #define SHOW2(x) \ for (int j = 0; j < x.size(); j++) { \ SHOW(x[j]); \ } \ cout << "\n"; ll N, M; int N_MAX = 1e5 + 5; // int N_MAX = 30; vector<int> parent(N_MAX); vector<ll> treeSize(N_MAX, 1); int root(int x) { if (x == parent[x]) return x; parent[x] = root(parent[x]); return parent[x]; } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; if (treeSize[rx] >= treeSize[ry]) { parent[ry] = rx; treeSize[rx] += treeSize[ry]; treeSize[ry] = 0; } else { parent[rx] = ry; treeSize[ry] += treeSize[rx]; treeSize[rx] = 0; } } bool same(int x, int y) { return root(x) == root(y); } int main() { cin >> N >> M; vector<int> A(M); vector<int> B(M); for (int i = 0; i < M; i++) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<ll> ans(M); ans[M - 1] = N * (N - 1) / 2; for (int i = 0; i < N; i++) { parent[i] = i; } for (int i = M - 1; i > 0; i--) { if (same(A[i], B[i])) { ans[i - 1] = ans[i]; } else { ans[i - 1] = ans[i] - treeSize[parent[A[i]]] * treeSize[parent[B[i]]]; unite(A[i], B[i]); } } for (int i = 0; i < M; i++) { cout << ans[i] << "\n"; } return 0; }
[ "variable_declaration.type.change", "literal.number.change" ]
919,377
919,376
u339233484
cpp
p03108
#include <bits/stdc++.h> using namespace std; struct UnionFind { const int V; // par[x] := xのroot vector<int> par; // sz[x] := xを含む集合のサイズ vector<int> sz; UnionFind(const int V) : V(V), par(vector<int>(V)), sz(vector<int>(V, 1)) { for (int i = 0; i < V; ++i) par[i] = i; } bool unite(int x, int y) { x = root(x), y = root(y); if (same(x, y)) return false; if (y < x) swap(x, y); par[y] = x; sz[x] += sz[y]; return true; } int root(int x) { if (par[x] == x) return x; return (par[x] = root(par[x])); } bool same(int x, int y) { return (root(x) == root(y)); } int size(int x) { return sz[root(x)]; } }; int main() { int64_t n, m; cin >> n >> m; UnionFind uf(n); int64_t a[m], b[m], ans[m]; for (int i = 0; i < n; ++i) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } ans[m - 1] = n * (n - 1) / 2; for (int q = m - 2; q >= 0; --q) { ans[q] = ans[q + 1]; if (not uf.same(a[q + 1], b[q + 1])) ans[q] -= (int64_t)uf.size(a[q + 1]) * (int64_t)uf.size(b[q + 1]); uf.unite(a[q + 1], b[q + 1]); } for (int i = 0; i < m; ++i) cout << ans[i] << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; struct UnionFind { const int V; // par[x] := xのroot vector<int> par; // sz[x] := xを含む集合のサイズ vector<int> sz; UnionFind(const int V) : V(V), par(vector<int>(V)), sz(vector<int>(V, 1)) { for (int i = 0; i < V; ++i) par[i] = i; } bool unite(int x, int y) { x = root(x), y = root(y); if (same(x, y)) return false; if (y < x) swap(x, y); par[y] = x; sz[x] += sz[y]; return true; } int root(int x) { if (par[x] == x) return x; return (par[x] = root(par[x])); } bool same(int x, int y) { return (root(x) == root(y)); } int size(int x) { return sz[root(x)]; } }; // https://atcoder.jp/contests/abc120/tasks/abc120_d int main() { int64_t n, m; cin >> n >> m; UnionFind uf(n); int64_t a[m], b[m], ans[m]; for (int i = 0; i < m; ++i) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } ans[m - 1] = n * (n - 1) / 2; for (int q = m - 2; q >= 0; --q) { ans[q] = ans[q + 1]; if (not uf.same(a[q + 1], b[q + 1])) ans[q] -= (int64_t)uf.size(a[q + 1]) * (int64_t)uf.size(b[q + 1]); uf.unite(a[q + 1], b[q + 1]); } for (int i = 0; i < m; ++i) cout << ans[i] << "\n"; return 0; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
919,390
919,391
u918753189
cpp
p03108
#ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103L #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif // C++ #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <unordered_map> #include <unordered_set> #endif using namespace std; typedef long long ll; // typedef pair<int,int> Pint; typedef pair<ll, ll> P; // typedef pair<int, pair<int, int>> P; // typedef tuple<int,int,int> T; typedef vector<ll> vec; typedef vector<vec> mat; #define rep(i, n) for (ll i = 0; i < n; i++) #define revrep(i, n) for (ll i = n - 1; i >= 0; i--) ll INFL = 1LL << 60; // 10^18 = 2^60 int INF = 1 << 30; // 10^9 ll MOD = 1000000007; vector<int> dy = {0, 0, 1, -1}; vector<int> dx = {1, -1, 0, 0}; // vector<int> dy = {1, 1, 1, 0, -1, -1, -1, 0}; // vector<int> dx = {1, 0, -1, -1, -1, 0, 1, 1}; ll max(ll a, ll b) { return (a > b) ? a : b; } ll min(ll a, ll b) { return (a < b) ? a : b; } ll pow(ll x, ll k) { ll res = 1; while (k > 0) { if (k % 2) res *= x; x *= x; k /= 2; } return res; } ll pow_mod(ll x, ll k) { x %= MOD; x += MOD; x %= MOD; ll res = 1; while (k > 0) { if (k % 2) { res *= x; res %= MOD; } x *= x; x %= MOD; k /= 2; } return res; } ll inverse(ll x) { return pow_mod(x, MOD - 2); }; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } const ll MAX_V = 200010; ll par[MAX_V]; ll Rank[MAX_V]; ll child[MAX_V]; void init_UF(ll n) { for (ll i = 0; i < n; i++) { par[i] = i; Rank[i] = 1; child[i] = 1; } } ll find(ll x) { if (par[x] == x) return x; else { return par[x] = find(par[x]); } } bool same(ll x, ll y) { return find(x) == find(y); } void unite(ll x, ll y) { ll rx = find(x), ry = find(y); if (rx != ry) { if (Rank[rx] >= Rank[ry]) { par[ry] = rx; if (Rank[rx] == Rank[ry]) Rank[rx]++; child[x] += child[y]; } else { par[rx] = ry; child[y] += child[x]; } } } int main() { init_UF(200000); ll N, M; cin >> N >> M; vector<ll> A(M), B(M); rep(i, M) cin >> A[i] >> B[i]; vector<ll> ans(M); ll now = N * (N - 1) / 2; revrep(i, M) { ans[i] = now; ll a = A[i], b = B[i]; if (!same(a, b)) now -= child[find(a)] * child[find(b)]; unite(a, b); } rep(i, M) cout << ans[i] << endl; }
#ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #if __cplusplus >= 201103L #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif // C++ #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <unordered_map> #include <unordered_set> #endif using namespace std; typedef long long ll; // typedef pair<int,int> Pint; typedef pair<ll, ll> P; // typedef pair<int, pair<int, int>> P; // typedef tuple<int,int,int> T; typedef vector<ll> vec; typedef vector<vec> mat; #define rep(i, n) for (ll i = 0; i < n; i++) #define revrep(i, n) for (ll i = n - 1; i >= 0; i--) ll INFL = 1LL << 60; // 10^18 = 2^60 int INF = 1 << 30; // 10^9 ll MOD = 1000000007; vector<int> dy = {0, 0, 1, -1}; vector<int> dx = {1, -1, 0, 0}; // vector<int> dy = {1, 1, 1, 0, -1, -1, -1, 0}; // vector<int> dx = {1, 0, -1, -1, -1, 0, 1, 1}; ll max(ll a, ll b) { return (a > b) ? a : b; } ll min(ll a, ll b) { return (a < b) ? a : b; } ll pow(ll x, ll k) { ll res = 1; while (k > 0) { if (k % 2) res *= x; x *= x; k /= 2; } return res; } ll pow_mod(ll x, ll k) { x %= MOD; x += MOD; x %= MOD; ll res = 1; while (k > 0) { if (k % 2) { res *= x; res %= MOD; } x *= x; x %= MOD; k /= 2; } return res; } ll inverse(ll x) { return pow_mod(x, MOD - 2); }; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } const ll MAX_V = 200010; ll par[MAX_V]; ll Rank[MAX_V]; ll child[MAX_V]; void init_UF(ll n) { for (ll i = 0; i < n; i++) { par[i] = i; Rank[i] = 1; child[i] = 1; } } ll find(ll x) { if (par[x] == x) return x; else { return par[x] = find(par[x]); } } bool same(ll x, ll y) { return find(x) == find(y); } void unite(ll x, ll y) { ll rx = find(x), ry = find(y); if (rx != ry) { if (Rank[rx] >= Rank[ry]) { par[ry] = rx; if (Rank[rx] == Rank[ry]) Rank[rx]++; child[rx] += child[ry]; } else { par[rx] = ry; child[ry] += child[rx]; } } } int main() { init_UF(200000); ll N, M; cin >> N >> M; vector<ll> A(M), B(M); rep(i, M) cin >> A[i] >> B[i]; vector<ll> ans(M); ll now = N * (N - 1) / 2; revrep(i, M) { ans[i] = now; ll a = A[i], b = B[i]; if (!same(a, b)) now -= child[find(a)] * child[find(b)]; unite(a, b); } rep(i, M) cout << ans[i] << endl; }
[ "assignment.variable.change", "identifier.change", "variable_access.subscript.index.change", "assignment.value.change" ]
919,408
919,409
u633284019
cpp
p03108
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <stdio.h> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #define rep(i, a, n) for (ll i = (a); i < (n); ++i) #define urep(i, a, n) for (ll i = (a); i >= (n); --i) #define all(x) (x).begin(), (x).end() #define INF 1e18 const int mod = 1e9 + 7; typedef long long ll; using namespace std; ll dx[4] = {1, -1, 0, 0}; ll dy[4] = {0, 0, 1, -1}; ll N, M, X, Y, A, B, C, Q, K, R, W, H, P, L; string S, T; ll ans; ll x[101010]; ll y[101010]; ll a[201010]; ll b[101010]; ll c[101010]; ll t[101010]; ll p[101010]; ll n[101010]; ll l[101010]; ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } struct Edge { ll to, cost; Edge(ll to, ll cost) : to(to), cost(cost) {} }; typedef vector<vector<Edge>> AdjList; AdjList graph; vector<ll> dist; bool flag[100]; vector<ll> Prime{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31}; struct UnionFind { vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 vector<ll> size; UnionFind(ll N) : par(N), size(N) { //最初は全てが根であるとして初期化 for (ll i = 0; i < N; i++) par[i] = i; for (ll i = 0; i < N; i++) size[i] = 1; } ll root(ll x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } ll GetSize(ll x) { return size[root(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につける size[ry] += size[rx]; } bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す ll rx = root(x); ll ry = root(y); return rx == ry; } }; int main() { cin >> N >> M; vector<ll> tmp(N + 1); UnionFind UF(N); rep(i, 0, M) { cin >> a[i] >> b[i]; a[i]--, b[i]--; } tmp[M] = (N * N - N) / 2; urep(i, M - 1, 0) { if (!UF.same(a[i], b[i])) { tmp[i] = tmp[i + 1] - (UF.GetSize(a[i])) * (UF.GetSize(b[i])); UF.unite(a[i], b[i]); } else { tmp[i] = tmp[i + 1]; } } rep(i, 1, M + 1) { cout << tmp[i] << endl; } return 0; }
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <stdio.h> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #define rep(i, a, n) for (ll i = (a); i < (n); ++i) #define urep(i, a, n) for (ll i = (a); i >= (n); --i) #define all(x) (x).begin(), (x).end() #define INF 1e18 const int mod = 1e9 + 7; typedef long long ll; using namespace std; ll dx[4] = {1, -1, 0, 0}; ll dy[4] = {0, 0, 1, -1}; ll N, M, X, Y, A, B, C, Q, K, R, W, H, P, L; string S, T; ll ans; ll x[101010]; ll y[101010]; ll a[101010]; ll b[101010]; ll c[101010]; ll t[101010]; ll p[101010]; ll n[101010]; ll l[101010]; ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } struct Edge { ll to, cost; Edge(ll to, ll cost) : to(to), cost(cost) {} }; typedef vector<vector<Edge>> AdjList; AdjList graph; vector<ll> dist; bool flag[100]; vector<ll> Prime{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31}; struct UnionFind { vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 vector<ll> size; UnionFind(ll N) : par(N), size(N) { //最初は全てが根であるとして初期化 for (ll i = 0; i < N; i++) par[i] = i; for (ll i = 0; i < N; i++) size[i] = 1; } ll root(ll x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } ll GetSize(ll x) { return size[root(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につける size[ry] += size[rx]; } bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す ll rx = root(x); ll ry = root(y); return rx == ry; } }; int main() { cin >> N >> M; vector<ll> tmp(M + 1); UnionFind UF(N); rep(i, 0, M) { cin >> a[i] >> b[i]; a[i]--, b[i]--; } tmp[M] = (N * N - N) / 2; urep(i, M - 1, 0) { if (!UF.same(a[i], b[i])) { tmp[i] = tmp[i + 1] - (UF.GetSize(a[i])) * (UF.GetSize(b[i])); UF.unite(a[i], b[i]); } else { tmp[i] = tmp[i + 1]; } } rep(i, 1, M + 1) { cout << tmp[i] << endl; } return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
919,479
919,480
u406225550
cpp
p03108
#include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORE(i, a, b) for (int i = (a); i <= (b); ++i) #define FORR(i, a, b) for (int i = (b - 1); i >= (a); --i) #define FORRE(i, a, b) for (int i = (b); i >= (a); --i) #define rep(i, n) for (ll i = 0; i < (n); ++i) #define repe(i, n) for (int i = 0; i <= (n); ++i) #define repr(i, n) for (int i = (n - 1); i >= 0; --i) #define repre(i, n) for (int i = (n); i >= 0; --i) #define ALL(v) (v).begin(), (v).end() #define SP cout << fixed << setprecision(10) typedef pair<int, int> P; const int INF = (int)1e9; const int MOD = (int)1e9 + 7; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } #define MAX_N 100005 ll par[MAX_N]; ll level[MAX_N]; void init(ll n) { rep(i, n) { par[i] = i; level[i] = 0; } } ll find(ll x) { if (par[x] == x) return x; else return par[x] = find(par[x]); } void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; // if (level[x] < level[y]) par[x] = y; // else { // par[y] = x; // if (level[x] == level[y]) level[x]++; // } par[max(x, y)] = min(x, y); level[min(x, y)] = max(level[x], level[y]) + 1; par[min(x, y)] = min(x, y); } bool same(ll x, ll y) { return find(x) == find(y); } int main(void) { cin.tie(0); ios::sync_with_stdio(false); ll n, m; cin >> n >> m; vector<ll> a, b; rep(i, m) { ll ain, bin; cin >> ain >> bin; ain--, bin--; a.push_back(ain); b.push_back(bin); } reverse(ALL(a)); reverse(ALL(b)); init(n); vector<ll> ans; ans.push_back((n * (n - 1)) / 2); ll beforeans = (n * (n - 1)) / 2; rep(i, m - 1) { ll ai = a[i]; ll bi = b[i]; if (same(ai, bi)) { ans.push_back(beforeans); continue; } beforeans -= (level[find(ai)] + 1) * (level[find(bi)] + 1); ans.push_back(beforeans); unite(ai, bi); // rep(i, n) { // cout << par[i] << " "; // } // cout << endl; // rep(i, n) { // cout << level[i] << " "; // } // cout << endl; } reverse(ALL(ans)); for (auto &t : ans) { cout << t << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORE(i, a, b) for (int i = (a); i <= (b); ++i) #define FORR(i, a, b) for (int i = (b - 1); i >= (a); --i) #define FORRE(i, a, b) for (int i = (b); i >= (a); --i) #define rep(i, n) for (ll i = 0; i < (n); ++i) #define repe(i, n) for (int i = 0; i <= (n); ++i) #define repr(i, n) for (int i = (n - 1); i >= 0; --i) #define repre(i, n) for (int i = (n); i >= 0; --i) #define ALL(v) (v).begin(), (v).end() #define SP cout << fixed << setprecision(10) typedef pair<int, int> P; const int INF = (int)1e9; const int MOD = (int)1e9 + 7; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } #define MAX_N 100005 ll par[MAX_N]; ll level[MAX_N]; void init(ll n) { rep(i, n) { par[i] = i; level[i] = 0; } } ll find(ll x) { if (par[x] == x) return x; else return par[x] = find(par[x]); } void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; // if (level[x] < level[y]) par[x] = y; // else { // par[y] = x; // if (level[x] == level[y]) level[x]++; // } par[max(x, y)] = min(x, y); level[min(x, y)] = level[x] + level[y] + 1; par[min(x, y)] = min(x, y); } bool same(ll x, ll y) { return find(x) == find(y); } int main(void) { cin.tie(0); ios::sync_with_stdio(false); ll n, m; cin >> n >> m; vector<ll> a, b; rep(i, m) { ll ain, bin; cin >> ain >> bin; ain--, bin--; a.push_back(ain); b.push_back(bin); } reverse(ALL(a)); reverse(ALL(b)); init(n); vector<ll> ans; ans.push_back((n * (n - 1)) / 2); ll beforeans = (n * (n - 1)) / 2; rep(i, m - 1) { ll ai = a[i]; ll bi = b[i]; if (same(ai, bi)) { ans.push_back(beforeans); continue; } beforeans -= (level[find(ai)] + 1) * (level[find(bi)] + 1); ans.push_back(beforeans); unite(ai, bi); // rep(i, n) { // cout << par[i] << " "; // } // cout << endl; // rep(i, n) { // cout << level[i] << " "; // } // cout << endl; } reverse(ALL(ans)); for (auto &t : ans) { cout << t << endl; } return 0; }
[ "call.remove", "assignment.value.change", "call.arguments.change", "expression.operation.binary.change" ]
919,493
919,494
u995997203
cpp
p03108
// warm heart, wagging tail,and a smile just for you! // ███████████ // ███╬╬╬╬╬╬╬╬╬╬███ // ███╬╬╬╬╬████╬╬╬╬╬╬███ // ███████████ // ██╬╬╬╬╬████╬╬████╬╬╬╬╬██ // █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██ // ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██ // ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██ // ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██ // ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████ // █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████ // ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██ // ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███ // ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██ // ██████████████ // ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████ // ███████ █████ // ███████████████████ #include "bits/stdc++.h" using namespace std; #define MOD 1000000007 const double EPS = 1e-9; #define INF (1LL << 60) #define fs first #define sc second #define pb push_back #define int long long #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b - 1); i >= a; i--) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) #define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr) #define RITR(itr, mp) for (auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr) #define range(i, a, b) ((a) <= (i) && (i) < (b)) #define debug(x) cout << #x << " = " << (x) << endl; #define SP << " " << typedef pair<int, int> P; typedef vector<vector<P>> Graph; typedef vector<int> vec; typedef vector<vector<int>> mat; struct UnionFind { private: vector<int> child, tree, sum; public: UnionFind(int v) { tree.resize(v); sum.resize(v); REP(i, v) tree[i] = i, sum[i] = 1; } int root(int i) { if (i == tree[i]) { REP(j, child.size()) tree[child[j]] = i; child.clear(); return i; } else { child.push_back(i); return i = root(tree[i]); } } int tot(int i) { return sum[root(i)] * (sum[root(i)] - 1) / 2; } int unit(int x, int y) { x = root(x); y = root(y); sum[min(x, y)] += sum[max(x, y)]; tree[max(x, y)] = min(x, y); } bool isUnit(int x, int y) { return root(x) == root(y); } }; signed main() { ios::sync_with_stdio(false); cin.tie(0); //問題文を読む時間をケチらない!! //未定義動作に気を付ける!! // DPや二分探索の範囲に気をつける!! int n, m; cin >> n >> m; vec a(m), b(m); REP(i, m) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } UnionFind uf(n); vec ans(m, 0); ans[m - 1] = n * (n - 1) / 2; int cur = ans[m - 1]; RREP(i, m - 1) { if (!uf.isUnit(a[i], b[i])) { cur += uf.tot(a[i + 1]) + uf.tot(b[i + 1]); uf.unit(a[i + 1], b[i + 1]); cur -= uf.tot(a[i + 1]); } ans[i] = cur; } REP(i, m) cout << ans[i] << endl; return 0; }
// warm heart, wagging tail,and a smile just for you! // ███████████ // ███╬╬╬╬╬╬╬╬╬╬███ // ███╬╬╬╬╬████╬╬╬╬╬╬███ // ███████████ // ██╬╬╬╬╬████╬╬████╬╬╬╬╬██ // █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██ // ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██ // ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██ // ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██ // ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████ // █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████ // ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██ // ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███ // ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██ // ██████████████ // ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████ // ███████ █████ // ███████████████████ #include "bits/stdc++.h" using namespace std; #define MOD 1000000007 const double EPS = 1e-9; #define INF (1LL << 60) #define fs first #define sc second #define pb push_back #define int long long #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b - 1); i >= a; i--) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) #define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr) #define RITR(itr, mp) for (auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr) #define range(i, a, b) ((a) <= (i) && (i) < (b)) #define debug(x) cout << #x << " = " << (x) << endl; #define SP << " " << typedef pair<int, int> P; typedef vector<vector<P>> Graph; typedef vector<int> vec; typedef vector<vector<int>> mat; struct UnionFind { private: vector<int> child, tree, sum; public: UnionFind(int v) { tree.resize(v); sum.resize(v); REP(i, v) tree[i] = i, sum[i] = 1; } int root(int i) { if (i == tree[i]) { REP(j, child.size()) tree[child[j]] = i; child.clear(); return i; } else { child.push_back(i); return i = root(tree[i]); } } int tot(int i) { return sum[root(i)] * (sum[root(i)] - 1) / 2; } int unit(int x, int y) { x = root(x); y = root(y); sum[min(x, y)] += sum[max(x, y)]; tree[max(x, y)] = min(x, y); } bool isUnit(int x, int y) { return root(x) == root(y); } }; signed main() { ios::sync_with_stdio(false); cin.tie(0); //問題文を読む時間をケチらない!! //未定義動作に気を付ける!! // DPや二分探索の範囲に気をつける!! int n, m; cin >> n >> m; vec a(m), b(m); REP(i, m) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } UnionFind uf(n); vec ans(m, 0); ans[m - 1] = n * (n - 1) / 2; int cur = ans[m - 1]; RREP(i, m - 1) { if (!uf.isUnit(a[i + 1], b[i + 1])) { cur += uf.tot(a[i + 1]) + uf.tot(b[i + 1]); uf.unit(a[i + 1], b[i + 1]); cur -= uf.tot(a[i + 1]); } ans[i] = cur; } REP(i, m) cout << ans[i] << endl; return 0; }
[ "control_flow.branch.if.condition.change" ]
919,554
919,555
u239493918
cpp
p03108
#include <algorithm> #include <cmath> #include <iostream> #include <queue> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define ll long long int #define MAX 1000000007 using namespace std; struct UnionFind { int *par; ll *size; UnionFind(int n) { par = (int *)malloc(sizeof(int) * n); size = (ll *)malloc(sizeof(ll) * n); rep(i, n) par[i] = i; rep(i, n) size[i] = 1; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; par[ry] = rx; size[rx] += size[rx] * size[ry]; } bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } ll get_size(int x) { return size[root(x)]; } }; int main(void) { ll n, m; cin >> n >> m; pair<int, int> a[m]; rep(i, m) cin >> a[i].first >> a[i].second; UnionFind tree(n); ll ans[m]; ans[m - 1] = 0; rep(i, m - 1) { int x = a[m - 1 - i].first - 1, y = a[m - 1 - i].second - 1; if (!tree.same(x, y)) { ans[m - 2 - i] = ans[m - 1 - i] + tree.get_size(x) * tree.get_size(y); tree.unite(x, y); } else ans[m - 2 - i] = ans[m - i - 1]; } rep(i, m) cout << n * (n - 1) / 2 - ans[i] << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <queue> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define ll long long int #define MAX 1000000007 using namespace std; struct UnionFind { int *par; ll *size; UnionFind(int n) { par = (int *)malloc(sizeof(int) * n); size = (ll *)malloc(sizeof(ll) * n); rep(i, n) par[i] = i; rep(i, n) size[i] = 1; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; par[ry] = rx; size[rx] += size[ry]; } bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } ll get_size(int x) { return size[root(x)]; } }; int main(void) { ll n, m; cin >> n >> m; pair<int, int> a[m]; rep(i, m) cin >> a[i].first >> a[i].second; UnionFind tree(n); ll ans[m]; ans[m - 1] = 0; rep(i, m - 1) { int x = a[m - 1 - i].first - 1, y = a[m - 1 - i].second - 1; if (!tree.same(x, y)) { ans[m - 2 - i] = ans[m - 1 - i] + tree.get_size(x) * tree.get_size(y); tree.unite(x, y); } else ans[m - 2 - i] = ans[m - i - 1]; } rep(i, m) cout << n * (n - 1) / 2 - ans[i] << endl; return 0; }
[ "expression.operation.binary.remove" ]
919,610
919,611
u582848517
cpp
p03108
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (n); i++) #define REP1(i, n) for (int i = 1; i <= (n); i++) #define DO { #define END } typedef long long ll; #define MAXN 100000 ll f[MAXN]; ll weighted[MAXN]; ll init() { REP(i, MAXN) { f[i] = i; weighted[i] = 1; } } ll findu(ll a) { return a == f[a] ? (a) : (f[a] = findu(f[a])); } ll getNumu(ll id) { return weighted[findu(id)]; } ll unite(ll a, ll b) { ll fa = findu(a), fb = findu(b); if (fa != fb) { weighted[fb] += weighted[fa]; f[fa] = fb; } } ll printu() { REP(i, MAXN) cout << f[i] << " "; cout << endl; } ll n, m, a[MAXN], b[MAXN], res[MAXN + 1]; int main() { init(); cin >> n >> m; REP(i, m) cin >> a[i] >> b[i]; res[m] = n * (n - 1) >> 1; for (ll i = m - 1; i >= 0; i--) DO if (findu(a[i]) == findu(b[i])) res[i] = res[i + 1]; else DO ll anum = getNumu(a[i]), bnum = getNumu(b[i]); unite(a[i], b[i]); res[i] = res[i + 1] - anum * bnum; END END REP(i, m) cout << res[i] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (n); i++) #define REP1(i, n) for (int i = 1; i <= (n); i++) #define DO { #define END } typedef long long ll; #define MAXN 100000 ll f[MAXN]; ll weighted[MAXN]; ll init() { REP(i, MAXN) { f[i] = i; weighted[i] = 1; } } ll findu(ll a) { return a == f[a] ? (a) : (f[a] = findu(f[a])); } ll getNumu(ll id) { return weighted[findu(id)]; } void unite(ll a, ll b) { ll fa = findu(a), fb = findu(b); if (fa != fb) { weighted[fb] += weighted[fa]; f[fa] = fb; } } void printu() { REP(i, MAXN) cout << f[i] << " "; cout << endl; } ll n, m, a[MAXN], b[MAXN], res[MAXN + 1]; int main() { init(); cin >> n >> m; REP(i, m) cin >> a[i] >> b[i]; res[m] = n * (n - 1) >> 1; for (ll i = m - 1; i >= 0; i--) DO if (findu(a[i]) == findu(b[i])) res[i] = res[i + 1]; else DO ll anum = getNumu(a[i]), bnum = getNumu(b[i]); unite(a[i], b[i]); res[i] = res[i + 1] - anum * bnum; END END REP1(i, m) cout << res[i] << endl; return 0; }
[ "variable_declaration.name.change", "identifier.change" ]
919,653
919,654
u786318703
cpp
p03108
#include <bits/stdc++.h> using namespace std; #define INT(a) scanf("%d", &a) #define STR(a) scanf("%s", a) #define DBL(a) scanf("%lf", &a) #define LNG(a) scanf("%lld", &a) #define PI acos(-1) #define MX 100005 int u[MX], v[MX]; long long ans[MX]; long long cur; struct UF { int root[MX], SZ[MX]; UF() {} UF(int n) { for (int i = 0; i <= n; i++) root[i] = i, SZ[i] = 1; } int find(int n) { return n == root[n] ? n : root[n] = find(root[n]); } void unite(int x, int y) { int px = find(x); int py = find(y); if (px == py) return; // cout<<cur<<endl; cur -= SZ[px] * SZ[py] * 1LL; // cout<<SZ[px]<<SZ[py]<<cur<<endl; if (SZ[px] < SZ[py]) swap(px, py); root[py] = px; SZ[px] += SZ[py]; } }; int main() { int n, m; cin >> n >> m; UF uf(n); for (int i = 1; i <= m; i++) { cin >> u[i] >> v[i]; } cur = (n * (n - 1)) / 2; for (int i = m; i >= 1; i--) { ans[i] = cur; uf.unite(u[i], v[i]); } for (int i = 1; i <= m; i++) cout << ans[i] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define INT(a) scanf("%d", &a) #define STR(a) scanf("%s", a) #define DBL(a) scanf("%lf", &a) #define LNG(a) scanf("%lld", &a) #define PI acos(-1) #define MX 100005 int u[MX], v[MX]; long long ans[MX]; long long cur; struct UF { int root[MX], SZ[MX]; UF() {} UF(int n) { for (int i = 0; i <= n; i++) root[i] = i, SZ[i] = 1; } int find(int n) { return n == root[n] ? n : root[n] = find(root[n]); } void unite(int x, int y) { int px = find(x), py = find(y); if (px == py) return; // cout<<cur<<endl; cur -= SZ[px] * SZ[py] * 1LL; // cout<<SZ[px]<<SZ[py]<<cur<<endl; if (SZ[px] < SZ[py]) swap(px, py); root[py] = px; SZ[px] += SZ[py]; } }; int main() { int n, m; cin >> n >> m; UF uf(n); for (int i = 1; i <= m; i++) { cin >> u[i] >> v[i]; } cur = (n * (n - 1LL)) / 2; for (int i = m; i >= 1; i--) { ans[i] = cur; uf.unite(u[i], v[i]); } for (int i = 1; i <= m; i++) cout << ans[i] << endl; return 0; }
[ "literal.number.type.widen.change" ]
919,673
919,674
u402651318
cpp
p03108
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> P; typedef pair<ll, P> P1; #define fr first #define sc second #define mp make_pair #define pb push_back #define rep(i, x) for (ll i = 0; i < x; i++) #define rep1(i, x) for (ll i = 1; i <= x; i++) #define rrep(i, x) for (ll i = x - 1; i >= 0; i--) #define rrep1(i, x) for (ll i = x; i > 0; i--) #define sor(v) sort(v.begin(), v.end()) #define rev(s) reverse(s.begin(), s.end()) #define lb(vec, a) lower_bound(vec.begin(), vec.end(), a) #define ub(vec, a) upper_bound(vec.begin(), vec.end(), a) #define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end()) #define mp1(a, b, c) P1(a, P(b, c)) const ll INF = 100000000; const ll M = 100000000; const ll dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; const ll dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}}; /* ------------------------------------- */ const ll UF_SIZE = 100010; ll par[UF_SIZE]; // 親 ll siz[UF_SIZE]; // 木の深さ // n要素で初期化 void init(ll n) { for (ll i = 0; i < n; i++) { par[i] = i; siz[i] = 1; } } // 木の根を求める ll find(ll x) { if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } // xとyの属する集合を併合 void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (siz[x] < siz[y]) { par[x] = y; siz[y] += siz[x]; } else { par[y] = x; siz[x] += siz[y]; } } // xとyが同じ集合に属するか否か bool same(ll x, ll y) { return find(x) == find(y); } // xが属する集合の要素数 ll size(ll x) { return siz[find(x)]; } ll n, m, a[100010], b[100010]; int main() { scanf("%d%d", &n, &m); rep(i, m) scanf("%d%d", &a[i], &b[i]); rep(i, m) { a[i]--; b[i]--; } init(n); ll rets[100010]; rets[m] = n * (n - 1) / 2; rrep(i, m) { if (same(a[i], b[i])) { rets[i] = rets[i + 1]; } else { rets[i] = rets[i + 1] - size(a[i]) * size(b[i]); } unite(a[i], b[i]); } rep1(i, m) { printf("%d\n", rets[i]); } /* --------------------------------- */ printf("\n"); return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> P; typedef pair<ll, P> P1; #define fr first #define sc second #define mp make_pair #define pb push_back #define rep(i, x) for (ll i = 0; i < x; i++) #define rep1(i, x) for (ll i = 1; i <= x; i++) #define rrep(i, x) for (ll i = x - 1; i >= 0; i--) #define rrep1(i, x) for (ll i = x; i > 0; i--) #define sor(v) sort(v.begin(), v.end()) #define rev(s) reverse(s.begin(), s.end()) #define lb(vec, a) lower_bound(vec.begin(), vec.end(), a) #define ub(vec, a) upper_bound(vec.begin(), vec.end(), a) #define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end()) #define mp1(a, b, c) P1(a, P(b, c)) const ll INF = 100000000; const ll M = 100000000; const ll dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; const ll dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}}; /* ------------------------------------- */ const ll UF_SIZE = 100010; ll par[UF_SIZE]; // 親 ll siz[UF_SIZE]; // 木の深さ // n要素で初期化 void init(ll n) { for (ll i = 0; i < n; i++) { par[i] = i; siz[i] = 1; } } // 木の根を求める ll find(ll x) { if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } // xとyの属する集合を併合 void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (siz[x] < siz[y]) { par[x] = y; siz[y] += siz[x]; } else { par[y] = x; siz[x] += siz[y]; } } // xとyが同じ集合に属するか否か bool same(ll x, ll y) { return find(x) == find(y); } // xが属する集合の要素数 ll size(ll x) { return siz[find(x)]; } ll n, m, a[100010], b[100010]; int main() { scanf("%lld%lld", &n, &m); rep(i, m) scanf("%lld%lld", &a[i], &b[i]); rep(i, m) { a[i]--; b[i]--; } init(n); ll rets[100010]; rets[m] = n * (n - 1) / 2; rrep(i, m) { if (same(a[i], b[i])) { rets[i] = rets[i + 1]; } else { rets[i] = rets[i + 1] - size(a[i]) * size(b[i]); } unite(a[i], b[i]); } rep1(i, m) { printf("%lld\n", rets[i]); } /* --------------------------------- */ printf("\n"); return 0; }
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
919,776
919,777
u245366924
cpp
p03108
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <tuple> #include <utility> #include <vector> #define DEBUG(x) cout << #x << ": " << x << endl using namespace std; class UnionFind { public: vector<int> Parent; UnionFind(int N) { Parent = vector<int>(N, -1); } int root(int A) { if (Parent[A] < 0) return A; else return Parent[A] = root(Parent[A]); } int size(int A) { return -Parent[root(A)]; } bool connect(int A, int B) { A = root(A); B = root(B); if (A == B) return false; if (size(A) < size(B)) swap(A, B); Parent[A] += Parent[B]; Parent[B] = Parent[A]; return true; } }; int main() { int N, M; cin >> N >> M; vector<int> A(M), B(M); for (int i = 0; i < M; i++) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<long long> ans(M); ans[M - 1] = (long long)N * (N - 1) / 2; UnionFind Uni(N); for (int i = M - 1; i >= 1; i--) { ans[i - 1] = ans[i]; if (Uni.root(A[i]) != Uni.root(B[i])) { ans[i - 1] -= (long long)Uni.size(A[i]) * Uni.size(B[i]); Uni.connect(A[i], B[i]); } } for (int i = 0; i < M; i++) { cout << ans[i] << endl; } return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <tuple> #include <utility> #include <vector> #define DEBUG(x) cout << #x << ": " << x << endl using namespace std; class UnionFind { public: vector<int> Parent; UnionFind(int N) { Parent = vector<int>(N, -1); } int root(int A) { if (Parent[A] < 0) return A; else return Parent[A] = root(Parent[A]); } int size(int A) { return -Parent[root(A)]; } bool connect(int A, int B) { A = root(A); B = root(B); if (A == B) return false; if (size(A) < size(B)) swap(A, B); Parent[A] += Parent[B]; Parent[B] = A; return true; } }; int main() { int N, M; cin >> N >> M; vector<int> A(M), B(M); for (int i = 0; i < M; i++) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<long long> ans(M); ans[M - 1] = (long long)N * (N - 1) / 2; UnionFind Uni(N); for (int i = M - 1; i >= 1; i--) { ans[i - 1] = ans[i]; if (Uni.root(A[i]) != Uni.root(B[i])) { ans[i - 1] -= (long long)Uni.size(A[i]) * Uni.size(B[i]); Uni.connect(A[i], B[i]); } } for (int i = 0; i < M; i++) { cout << ans[i] << endl; } return 0; }
[]
919,778
919,779
u574045761
cpp
p03108
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <tuple> #include <utility> #include <vector> #define DEBUG(x) cout << #x << ": " << x << endl using namespace std; class UnionFind { public: vector<int> Parent; UnionFind(int N) { Parent = vector<int>(N, -1); } int root(int A) { if (Parent[A] < 0) return A; else return Parent[A] = root(Parent[A]); } int size(int A) { return -Parent[0]; } bool connect(int A, int B) { A = root(A); B = root(B); if (A == B) return false; if (size(A) < size(B)) swap(A, B); Parent[A] += Parent[B]; Parent[B] = A; return true; } }; int main() { int N, M; cin >> N >> M; vector<int> A(M), B(M); for (int i = 0; i < M; i++) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<long long> ans(M); ans[M - 1] = (long long)N * (N - 1) / 2; UnionFind Uni(N); for (int i = M - 1; i >= 1; i--) { ans[i - 1] = ans[i]; if (Uni.root(A[i]) != Uni.root(B[i])) { ans[i - 1] -= (long long)Uni.size(A[i]) * Uni.size(B[i]); Uni.connect(A[i], B[i]); } } for (int i = 0; i < M; i++) { cout << ans[i] << endl; } return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <tuple> #include <utility> #include <vector> #define DEBUG(x) cout << #x << ": " << x << endl using namespace std; class UnionFind { public: vector<int> Parent; UnionFind(int N) { Parent = vector<int>(N, -1); } int root(int A) { if (Parent[A] < 0) return A; else return Parent[A] = root(Parent[A]); } int size(int A) { return -Parent[root(A)]; } bool connect(int A, int B) { A = root(A); B = root(B); if (A == B) return false; if (size(A) < size(B)) swap(A, B); Parent[A] += Parent[B]; Parent[B] = A; return true; } }; int main() { int N, M; cin >> N >> M; vector<int> A(M), B(M); for (int i = 0; i < M; i++) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } vector<long long> ans(M); ans[M - 1] = (long long)N * (N - 1) / 2; UnionFind Uni(N); for (int i = M - 1; i >= 1; i--) { ans[i - 1] = ans[i]; if (Uni.root(A[i]) != Uni.root(B[i])) { ans[i - 1] -= (long long)Uni.size(A[i]) * Uni.size(B[i]); Uni.connect(A[i], B[i]); } } for (int i = 0; i < M; i++) { cout << ans[i] << endl; } return 0; }
[ "identifier.replace.add", "literal.replace.remove", "variable_access.subscript.index.change", "function.return_value.change", "call.arguments.add" ]
919,780
919,779
u574045761
cpp
p03108
/*********************** * Author: xuziyuan * ***********************/ #include <bits/stdc++.h> #define rt0 return 0 #define rep(i, n) for (int i = 0; i < n; i++) #define repn(i, n) for (int i = 1; i <= n; i++) #define replet(c) for (char c = 'a'; c <= 'z'; c++) #define LL long long #define pii pair<int, int> #define pb push_back #define fi first #define se second #define mpr make_pair #define sqr(a) ((a) * (a)) using namespace std; const LL MOD = 1e9 + 7; LL n, m, x, y, num[100010], par[100010]; vector<pii> v; vector<LL> ans; LL FIND(LL pos) { if (par[pos] != pos) par[pos] = FIND(par[pos]); return par[pos]; } void UNION(LL pos1, LL pos2) { num[FIND(pos2)] += num[FIND(pos1)]; par[FIND(pos1)] = FIND(pos2); } int main() { cin >> n >> m; rep(i, m) { scanf("%lld%lld", &x, &y); v.pb({x, y}); } reverse(v.begin(), v.end()); rep(i, 100005) par[i] = i, num[i] = 1; ans.pb(n * (n - 1) / 2); LL cnt = ans[0]; rep(i, m - 1) { if (FIND(v[i].fi) != FIND(v[i].se)) { // cout<<i<<endl; // cout<<v[i].fi<<' '<<FIND(v[i].fi)<<endl<<v[i].se<<' // '<<FIND(v[i].se)<<endl; cout<<num[FIND(v[i].fi)]<<' // '<<num[FIND(v[i].se)]<<'p'<<endl; cnt -= num[FIND(v[i].fi)] * num[FIND(v[i].se)]; UNION(v[i].fi, v[i].se); // cout<<v[i].fi<<' '<<FIND(v[i].fi)<<endl<<v[i].se<<' // '<<FIND(v[i].se)<<endl; } ans.pb(cnt); } reverse(ans.begin(), ans.end()); rep(i, m) printf("%lld", ans[i]); rt0; }
/*********************** * Author: xuziyuan * ***********************/ #include <bits/stdc++.h> #define rt0 return 0 #define rep(i, n) for (int i = 0; i < n; i++) #define repn(i, n) for (int i = 1; i <= n; i++) #define replet(c) for (char c = 'a'; c <= 'z'; c++) #define LL long long #define pii pair<int, int> #define pb push_back #define fi first #define se second #define mpr make_pair #define sqr(a) ((a) * (a)) using namespace std; const LL MOD = 1e9 + 7; LL n, m, x, y, num[100010], par[100010]; vector<pii> v; vector<LL> ans; LL FIND(LL pos) { if (par[pos] != pos) par[pos] = FIND(par[pos]); return par[pos]; } void UNION(LL pos1, LL pos2) { num[FIND(pos2)] += num[FIND(pos1)]; par[FIND(pos1)] = FIND(pos2); } int main() { cin >> n >> m; rep(i, m) { scanf("%lld%lld", &x, &y); v.pb({x, y}); } reverse(v.begin(), v.end()); rep(i, 100005) par[i] = i, num[i] = 1; ans.pb(n * (n - 1) / 2); LL cnt = ans[0]; rep(i, m - 1) { if (FIND(v[i].fi) != FIND(v[i].se)) { // cout<<i<<endl; // cout<<v[i].fi<<' '<<FIND(v[i].fi)<<endl<<v[i].se<<' // '<<FIND(v[i].se)<<endl; cout<<num[FIND(v[i].fi)]<<' // '<<num[FIND(v[i].se)]<<'p'<<endl; cnt -= num[FIND(v[i].fi)] * num[FIND(v[i].se)]; UNION(v[i].fi, v[i].se); // cout<<v[i].fi<<' '<<FIND(v[i].fi)<<endl<<v[i].se<<' // '<<FIND(v[i].se)<<endl; } ans.pb(cnt); } reverse(ans.begin(), ans.end()); rep(i, m) printf("%lld\n", ans[i]); rt0; }
[ "literal.string.change", "call.arguments.change", "io.output.change", "io.output.newline.add" ]
919,791
919,792
u977365687
cpp
p03108
#include <bits/stdc++.h> #define range(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, b) for (int i = 0; i < (b); i++) #define all(a) (a).begin(), (a).end() #define show(x) cerr << #x << " = " << (x) << endl; #define int long long using namespace std; template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); } template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) { is >> x; } return is; } template <typename T> class UnionFind { private: vector<int> par, depth; vector<T> sum; // 集合の重みの総和 public: vector<int> cnt; // その集合の頂点数 UnionFind() {} UnionFind(int n, vector<T> &c) { init(n, c); } void init(int n, vector<T> &c) { par = vector<int>(n); depth = vector<int>(n, 0); cnt = vector<int>(n, 1); sum = c; rep(i, n) { par[i] = i; } } 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 (depth[x] < depth[y]) { par[x] = y; cnt[y] += cnt[x]; sum[y] += sum[x]; } else { par[y] = x; cnt[x] += cnt[y]; sum[x] += sum[y]; if (depth[x] == depth[y]) depth[x]++; } } bool same(int x, int y) { return find(x) == find(y); } T weight(int x) { return sum[find(x)]; } }; int cul(int a) { return a * (a - 1) / 2; } signed main() { int n, m; cin >> n >> m; vector<int> a(m), b(m); rep(i, m) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } vector<int> t(n, 1); UnionFind<int> uni(n, t); vector<int> ans = {cul(n)}; for (int i = m - 1; i > 0; i--) { if (uni.same(a[i], b[i])) { ans.emplace_back(0); } else { int tmp = cul(uni.weight(a[i])) + cul(uni.weight(b[i])); // cout << cul(uni.weight(a[i])) << ' ' << cul(uni.weight(b[i])) << endl; // rep(j,n){ cout << uni.weight(j) << ' '; } cout << endl; uni.unite(a[i], b[i]); // show(cul(uni.weight(a[i]))) // show(ans.back()) ans.emplace_back(ans.back() + tmp - cul(uni.weight(a[i]))); } } reverse(all(ans)); for (auto i : ans) { cout << i << endl; } }
#include <bits/stdc++.h> #define range(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, b) for (int i = 0; i < (b); i++) #define all(a) (a).begin(), (a).end() #define show(x) cerr << #x << " = " << (x) << endl; #define int long long using namespace std; template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); } template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) { is >> x; } return is; } template <typename T> class UnionFind { private: vector<int> par, depth; vector<T> sum; // 集合の重みの総和 public: vector<int> cnt; // その集合の頂点数 UnionFind() {} UnionFind(int n, vector<T> &c) { init(n, c); } void init(int n, vector<T> &c) { par = vector<int>(n); depth = vector<int>(n, 0); cnt = vector<int>(n, 1); sum = c; rep(i, n) { par[i] = i; } } 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 (depth[x] < depth[y]) { par[x] = y; cnt[y] += cnt[x]; sum[y] += sum[x]; } else { par[y] = x; cnt[x] += cnt[y]; sum[x] += sum[y]; if (depth[x] == depth[y]) depth[x]++; } } bool same(int x, int y) { return find(x) == find(y); } T weight(int x) { return sum[find(x)]; } }; int cul(int a) { return a * (a - 1) / 2; } signed main() { int n, m; cin >> n >> m; vector<int> a(m), b(m); rep(i, m) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } vector<int> t(n, 1); UnionFind<int> uni(n, t); vector<int> ans = {cul(n)}; for (int i = m - 1; i > 0; i--) { if (uni.same(a[i], b[i])) { ans.emplace_back(ans.back()); } else { int tmp = cul(uni.weight(a[i])) + cul(uni.weight(b[i])); // cout << cul(uni.weight(a[i])) << ' ' << cul(uni.weight(b[i])) << endl; // rep(j,n){ cout << uni.weight(j) << ' '; } cout << endl; uni.unite(a[i], b[i]); // show(cul(uni.weight(a[i]))) // show(ans.back()) ans.emplace_back(ans.back() + tmp - cul(uni.weight(a[i]))); } } reverse(all(ans)); for (auto i : ans) { cout << i << endl; } }
[ "identifier.replace.add", "literal.replace.remove", "call.arguments.change", "call.add" ]
919,816
919,817
u526532903
cpp
p03108
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define repr(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--) #define all(v) (v).begin(), (v).end() #define pb push_back typedef long long ll; typedef vector<int> vint; typedef pair<int, int> pint; typedef pair<ll, ll> pll; typedef vector<pint> vpint; struct unionfind { vint root; vector<ll> group_size; unionfind(int n) { root.resize(n); group_size.resize(n); rep(i, n) root[i] = i; rep(i, n) group_size[i] = 1; } //ノードのグループ番号(親番号)を返す int find(int x) { return x == root[x] ? x : find(root[x]); } int size(int x) { x = find(x); return group_size[x]; } void unite(int x, int y) { x = find(x), y = find(y); int x2 = max(x, y); int y2 = min(x, y); group_size[x2] += group_size[y2]; root[y2] = x2; } }; int main() { int n, m; cin >> n >> m; vector<pint> road(m); vector<ll> ans(m); ll counter = n * (ll)((n - 1) / 2); unionfind uf(n); rep(i, m) { int a, b; cin >> a >> b; road[i].first = a - 1; road[i].second = b - 1; } repr(i, m) { ans[i] = counter; int x = road[i].first, y = road[i].second; if (uf.find(x) != uf.find(y)) { counter -= ll((ll)uf.size(x) * (ll)uf.size(y)); uf.unite(x, y); } } rep(i, m) cout << ans[i] << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define repr(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--) #define all(v) (v).begin(), (v).end() #define pb push_back typedef long long ll; typedef vector<int> vint; typedef pair<int, int> pint; typedef pair<ll, ll> pll; typedef vector<pint> vpint; struct unionfind { vint root; vector<ll> group_size; unionfind(int n) { root.resize(n); group_size.resize(n); rep(i, n) root[i] = i; rep(i, n) group_size[i] = 1; } //ノードのグループ番号(親番号)を返す int find(int x) { return x == root[x] ? x : find(root[x]); } int size(int x) { x = find(x); return group_size[x]; } void unite(int x, int y) { x = find(x), y = find(y); int x2 = max(x, y); int y2 = min(x, y); group_size[x2] += group_size[y2]; root[y2] = x2; } }; int main() { int n, m; cin >> n >> m; vector<pint> road(m); vector<ll> ans(m); ll counter = n * (ll)(n - 1) / 2; unionfind uf(n); rep(i, m) { int a, b; cin >> a >> b; road[i].first = a - 1; road[i].second = b - 1; } repr(i, m) { ans[i] = counter; int x = road[i].first, y = road[i].second; if (uf.find(x) != uf.find(y)) { counter -= ll((ll)uf.size(x) * (ll)uf.size(y)); uf.unite(x, y); } } rep(i, m) cout << ans[i] << endl; }
[ "call.arguments.change" ]
919,854
919,855
u943094398
cpp
p03108
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; class UnionFind { public: vector<int> par; UnionFind(int N) { par = vector<int>(N, -1); } int root(int x) { if (par[x] < 0) return x; return par[x] = root(par[x]); } int size(int x) { return -par[root(x)]; } bool unite(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (size(x) < size(y)) swap(x, y); par[x] += par[y]; par[y] = x; return true; } }; int main() { int N, M; cin >> N >> M; vector<int> A(M); vector<int> B(M); for (int i = 0; i < M; i++) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } UnionFind Bridges(M); vector<long long> inconvenience(M); inconvenience[M - 1] = (long long)(N * (N - 1) / 2); for (int i = M - 1; i >= 1; i--) { inconvenience[i - 1] = inconvenience[i]; if (Bridges.root(A[i]) != Bridges.root(B[i])) { inconvenience[i - 1] -= (long long)Bridges.size(A[i]) * Bridges.size(B[i]); Bridges.unite(A[i], B[i]); } } for (int i = 0; i < M; i++) { cout << inconvenience[i] << endl; } return 0; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; class UnionFind { public: vector<int> par; UnionFind(int N) { par = vector<int>(N, -1); } int root(int x) { if (par[x] < 0) return x; return par[x] = root(par[x]); } int size(int x) { return -par[root(x)]; } bool unite(int x, int y) { x = root(x); y = root(y); if (x == y) { return false; } if (size(x) < size(y)) swap(x, y); par[x] += par[y]; par[y] = x; return true; } }; int main() { int N, M; cin >> N >> M; vector<int> A(M); vector<int> B(M); for (int i = 0; i < M; i++) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } UnionFind Bridges(N); vector<long long> inconvenience(M); inconvenience[M - 1] = (long long)N * (N - 1) / 2; for (int i = M - 1; i >= 1; i--) { inconvenience[i - 1] = inconvenience[i]; if (Bridges.root(A[i]) != Bridges.root(B[i])) { inconvenience[i - 1] -= (long long)Bridges.size(A[i]) * Bridges.size(B[i]); Bridges.unite(A[i], B[i]); } } for (int i = 0; i < M; i++) { cout << inconvenience[i] << endl; } return 0; }
[]
919,881
919,882
u798944838
cpp
p03108
#include <algorithm> #include <iostream> using namespace std; static const int MAX_N = 100, MAX_M = 10e2; struct UnionFind { // MAX_N定義必要要素数 int Par[MAX_N]; //親は"-子供(自分含め)"を所持 int N; UnionFind(int n) { N = n; for (int i = 0; i < N; i++) Par[i] = -1; } bool unite(int a, int b) { int par_a = find(a); int par_b = find(b); if (par_a == par_b) return true; if (Par[par_a] > Par[par_b]) swap(par_a, par_b); Par[par_a] += Par[par_b]; Par[par_b] = par_a; return false; } int find(int a) { if (Par[a] < 0) return a; else return find(Par[a]); } long sizek(int a) { if (Par[a] < 0) return Par[a] * (-1); else return sizek(Par[a]); } }; /* UnionFind XX(頂点の数) XX.unite(a,b);a,b接続 既接続->true 新接続->false find(a)aの親の番号返却 sizek(a)aの群れの頂点の数返却 */ int A[MAX_M], B[MAX_M]; long ANS[MAX_M]; int main(void) { int N, M; cin >> N >> M; UnionFind uni(N); for (int i = 0; i < M; i++) cin >> A[i] >> B[i]; ANS[M - 1] = (long)N * (N - 1) / 2; for (int i = M - 1; i >= 1; i--) { A[i]--; B[i]--; int ba = uni.find(A[i]); int bb = uni.find(B[i]); if (ba == bb) { ANS[i - 1] = ANS[i]; continue; } long res = uni.sizek(A[i]); res *= (long)uni.sizek(B[i]); ANS[i - 1] = ANS[i] - res; uni.unite(A[i], B[i]); } for (int i = 0; i < M; i++) cout << ANS[i] << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; static const int MAX_N = 10e5, MAX_M = 10e5; struct UnionFind { // MAX_N定義必要要素数 int Par[MAX_N]; //親は"-子供(自分含め)"を所持 int N; UnionFind(int n) { N = n; for (int i = 0; i < N; i++) Par[i] = -1; } bool unite(int a, int b) { int par_a = find(a); int par_b = find(b); if (par_a == par_b) return true; if (Par[par_a] > Par[par_b]) swap(par_a, par_b); Par[par_a] += Par[par_b]; Par[par_b] = par_a; return false; } int find(int a) { if (Par[a] < 0) return a; else return find(Par[a]); } long sizek(int a) { if (Par[a] < 0) return Par[a] * (-1); else return sizek(Par[a]); } }; /* UnionFind XX(頂点の数) XX.unite(a,b);a,b接続 既接続->true 新接続->false find(a)aの親の番号返却 sizek(a)aの群れの頂点の数返却 */ int A[MAX_M], B[MAX_M]; long ANS[MAX_M]; int main(void) { int N, M; cin >> N >> M; UnionFind uni(N); for (int i = 0; i < M; i++) cin >> A[i] >> B[i]; ANS[M - 1] = (long)N * (N - 1) / 2; for (int i = M - 1; i >= 1; i--) { A[i]--; B[i]--; int ba = uni.find(A[i]); int bb = uni.find(B[i]); if (ba == bb) { ANS[i - 1] = ANS[i]; continue; } long res = uni.sizek(A[i]); res *= (long)uni.sizek(B[i]); ANS[i - 1] = ANS[i] - res; uni.unite(A[i], B[i]); } for (int i = 0; i < M; i++) cout << ANS[i] << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
919,885
919,886
u174265495
cpp
p03109
#include <bits/stdc++.h> using namespace std; int main() { int y, m, d; char a, b; cin >> y >> a >> m >> b >> d; if (m > 4) cout << "TBT" << endl; else cout << "Heisei" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int y, m, d; char a, b; cin >> y >> a >> m >> b >> d; if (m > 4) cout << "TBD" << endl; else cout << "Heisei" << endl; }
[ "literal.string.change", "io.output.change" ]
919,924
919,925
u995732479
cpp
p03109
#include <iostream> using namespace std; int main() { char s[10]; cin >> s; if (s[5] == 0 && s[6] <= '4') cout << "Heisei" << endl; else cout << "TBD" << endl; }
#include <iostream> using namespace std; int main() { char s[10]; cin >> s; if (s[5] == '0' && s[6] <= '4') cout << "Heisei" << endl; else cout << "TBD" << endl; }
[ "control_flow.branch.if.condition.change" ]
919,926
919,927
u043707543
cpp
p03109
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; if (s > "2019/04/30") { cout << "Heisei" << endl; } else { cout << "TBD" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; if (s <= "2019/04/30") { cout << "Heisei" << endl; } else { cout << "TBD" << endl; } }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
919,942
919,943
u758405447
cpp
p03109
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int Y = 0, M = 0; for (int i = 0; i < 4; i++) { Y *= 10; Y += S[i] - '0'; } for (int i = 4; i < 7; i++) { M *= 10; M += S[i] - '0'; } if (Y < 2019) { cout << "Heisei" << endl; } else if (M < 5 && Y == 2019) { cout << "Heisei" << endl; } else { cout << "TBD" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int Y = 0, M = 0; for (int i = 0; i < 4; i++) { Y *= 10; Y += S[i] - '0'; } for (int i = 5; i < 7; i++) { M *= 10; M += S[i] - '0'; } if (Y < 2019) { cout << "Heisei" << endl; } else if (M < 5 && Y == 2019) { cout << "Heisei" << endl; } else { cout << "TBD" << endl; } }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
919,958
919,959
u158290747
cpp
p03109
#include <bits/stdc++.h> #define rep0(i, n) for (int i = 0; i < (n); ++i) #define rep1(i, n) for (int i = 1; i <= (n); ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; typedef tuple<string, int, int> TU; typedef tuple<int, int, int> TI; int main() { string S; cin >> S; int year = atoi(S.substr(0, 4).c_str()); int month = atoi(S.substr(5, 7).c_str()); int day = atoi(S.substr(8, 10).c_str()); if (year < 2019) { cout << "Heisei" << endl; } else if (year == 2019 && month < 4) { cout << "Heisei" << endl; } else if (year == 2019 && month == 4 && day < 30) { cout << "Heisei" << endl; } else { cout << "TBD" << endl; } }
#include <bits/stdc++.h> #define rep0(i, n) for (int i = 0; i < (n); ++i) #define rep1(i, n) for (int i = 1; i <= (n); ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; typedef tuple<string, int, int> TU; typedef tuple<int, int, int> TI; int main() { string S; cin >> S; int year = atoi(S.substr(0, 4).c_str()); int month = atoi(S.substr(5, 7).c_str()); int day = atoi(S.substr(8, 10).c_str()); if (year < 2019) { cout << "Heisei" << endl; } else if (year == 2019 && month < 4) { cout << "Heisei" << endl; } else if (year == 2019 && month == 4 && day <= 30) { cout << "Heisei" << endl; } else { cout << "TBD" << endl; } }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
919,985
919,986
u290292036
cpp