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
p03045
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; using ll = long long; using vec = vector<ll>; using vect = vector<double>; using Graph = vector<vector<ll>>; #define loop(i, n) for (ll i = 0; i < n; i++) #define Loop(i, m, n) for (ll i = m; i < n; i++) #define pool(i, n) for (ll i = n; i >= 0; i--) #define Pool(i, m, n) for (ll i = n; i >= m; i--) #define mod 1000000007ll #define setbit bitset<8> #define flagcount __builtin_popcount #define flag(x) (1 << x) #define flagadd(bit, x) bit |= flag(x) #define flagpop(bit, x) bit &= ~flag(x) #define flagon(bit, i) bit &flag(i) #define flagoff(bit, i) !(bit & (1 << i)) #define all(v) v.begin(), v.end() #define low2way(v, x) lower_bound(all(v), x) #define high2way(v, x) upper_bound(all(v), x) #define count2way(v, x) high2way(v, x) - low2way(v, x) #define lower(v, x) \ low2way(v, x) - v.begin() // 1番左が0、もし見つから無いならnを出力 #define higher(v, x) \ high2way(v, x) - v.begin() - \ 1 // 1番左が0、もし見つからないならn-1を出力(注意) #define putout(a) cout << a << endl #define putout2(a, b) \ putout(a); \ putout(b) #define putout3(a, b, c) \ putout(a); \ putout(b); \ putout(c) #define putout4(a, b, c, d) \ putout(a); \ putout(b); \ putout(c); \ putout(d) #define putout5(a, b, c, d, e) \ putout(a); \ putout(b); \ putout(c); \ putout(d); \ putout(e) #define Gput(a, b) G[a].push_back(b) #define cin1(a) cin >> a #define cin2(a, b) cin >> a >> b #define cin3(a, b, c) cin >> a >> b >> c #define cin4(a, b, c, d) cin >> a >> b >> c >> d #define cin5(a, b, c, d, e) cin >> a >> b >> c >> d >> e #define Sum(v) accumulate(all(v), 0ll) #define gcd(x, y) __gcd(x, y) ll ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; } template <typename T> T lcm(T x, T y) { T z = gcd(x, y); return x * y / z; } template <typename T> bool primejudge(T n) { if (n < 2) return false; else if (n == 2) return true; else if (n % 2 == 0) return false; double sqrtn = sqrt(n); for (T i = 3; i < sqrtn + 1; i++) { if (n % i == 0) { return false; } i++; } return true; } template <typename T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } //場合によって使い分ける // const ll dx[4]={1,0,-1,0}; // const ll dy[4]={0,1,0,-1}; const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; //多次元配列の宣言法 // vector<vector<ll>> field(h, vector<ll>(w)); template <class T> inline void chmax(T &a, T b) { if (a < b) a = b; } template <class T> inline void chmin(T &a, T b) { if (a > b) a = b; } /* ライブラリをここに置いてコメントを削除 */ /* このunion_find木で出来ること 例)union_find tree(N);などで宣言(N:頂点数) tree.same(x,y):要素xと要素yが同じグループに属するか判定 tree.unite(x,y):要素xが属する木と要素yが属するグループの併合 tree.size(x,y):要素xが属する木の頂点数を返す ※グループの分割が出来ないことに注意! 計算量O(α(N))(ほぼO(1)) */ struct union_find { vector<long long> par; //親の番号  vector<long long> rank; //木の深さ(根のランクは0) vector<long long> siz; //要素xが根なら木の頂点数を格納する //初期化子リストを用いた初期化 union_find(long long N) : par(N), rank(N), siz(N) { for (long long i = 0; i < N; i++) { par[i] = i; rank[i] = 0; siz[i] = 1; } } //要素xが所属する木の根を再帰的に発見する long long root(long long x) { if (par[x] == x) return x; return par[x] = root(par[x]); //経路圧縮 } //要素xが属する木と要素yが属する木の併合 void unite(long long x, long long y) { long long rx = root(x); long long ry = root(y); if (rx == ry) return; //同じ木に属してたらそのまま if (rank[rx] < rank[ry]) { par[rx] = ry; //根がryの木に併合 siz[ry] = siz[rx] + siz[ry]; } else { par[ry] = rx; //根がrxの木に併合 siz[rx] = siz[rx] + siz[ry]; if (rank[rx] == rank[ry]) rank[rx]++; } } //要素xが属する木と要素yが属する木が同じならtrueを返す bool same(long long x, long long y) { return root(x) == root(y); } //要素xが属する木の頂点数を返す long long size(long long x) { return siz[root(x)]; } }; int main() { cout << fixed << setprecision(30); ll n, m; cin >> n >> m; union_find tree(n); loop(i, m) { ll x, y, z; cin >> x >> y >> z; tree.unite(x - 1, y - 1); } vector<bool> seen(n, false); ll ans = 0; loop(i, n) { if (seen[tree.par[i]]) continue; seen[tree.par[i]] = true; ans++; } putout(ans); return 0; }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; using ll = long long; using vec = vector<ll>; using vect = vector<double>; using Graph = vector<vector<ll>>; #define loop(i, n) for (ll i = 0; i < n; i++) #define Loop(i, m, n) for (ll i = m; i < n; i++) #define pool(i, n) for (ll i = n; i >= 0; i--) #define Pool(i, m, n) for (ll i = n; i >= m; i--) #define mod 1000000007ll #define setbit bitset<8> #define flagcount __builtin_popcount #define flag(x) (1 << x) #define flagadd(bit, x) bit |= flag(x) #define flagpop(bit, x) bit &= ~flag(x) #define flagon(bit, i) bit &flag(i) #define flagoff(bit, i) !(bit & (1 << i)) #define all(v) v.begin(), v.end() #define low2way(v, x) lower_bound(all(v), x) #define high2way(v, x) upper_bound(all(v), x) #define count2way(v, x) high2way(v, x) - low2way(v, x) #define lower(v, x) \ low2way(v, x) - v.begin() // 1番左が0、もし見つから無いならnを出力 #define higher(v, x) \ high2way(v, x) - v.begin() - \ 1 // 1番左が0、もし見つからないならn-1を出力(注意) #define putout(a) cout << a << endl #define putout2(a, b) \ putout(a); \ putout(b) #define putout3(a, b, c) \ putout(a); \ putout(b); \ putout(c) #define putout4(a, b, c, d) \ putout(a); \ putout(b); \ putout(c); \ putout(d) #define putout5(a, b, c, d, e) \ putout(a); \ putout(b); \ putout(c); \ putout(d); \ putout(e) #define Gput(a, b) G[a].push_back(b) #define cin1(a) cin >> a #define cin2(a, b) cin >> a >> b #define cin3(a, b, c) cin >> a >> b >> c #define cin4(a, b, c, d) cin >> a >> b >> c >> d #define cin5(a, b, c, d, e) cin >> a >> b >> c >> d >> e #define Sum(v) accumulate(all(v), 0ll) #define gcd(x, y) __gcd(x, y) ll ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; } template <typename T> T lcm(T x, T y) { T z = gcd(x, y); return x * y / z; } template <typename T> bool primejudge(T n) { if (n < 2) return false; else if (n == 2) return true; else if (n % 2 == 0) return false; double sqrtn = sqrt(n); for (T i = 3; i < sqrtn + 1; i++) { if (n % i == 0) { return false; } i++; } return true; } template <typename T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } //場合によって使い分ける // const ll dx[4]={1,0,-1,0}; // const ll dy[4]={0,1,0,-1}; const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; //多次元配列の宣言法 // vector<vector<ll>> field(h, vector<ll>(w)); template <class T> inline void chmax(T &a, T b) { if (a < b) a = b; } template <class T> inline void chmin(T &a, T b) { if (a > b) a = b; } /* ライブラリをここに置いてコメントを削除 */ /* このunion_find木で出来ること 例)union_find tree(N);などで宣言(N:頂点数) tree.same(x,y):要素xと要素yが同じグループに属するか判定 tree.unite(x,y):要素xが属する木と要素yが属するグループの併合 tree.size(x,y):要素xが属する木の頂点数を返す ※グループの分割が出来ないことに注意! 計算量O(α(N))(ほぼO(1)) */ struct union_find { vector<long long> par; //親の番号  vector<long long> rank; //木の深さ(根のランクは0) vector<long long> siz; //要素xが根なら木の頂点数を格納する //初期化子リストを用いた初期化 union_find(long long N) : par(N), rank(N), siz(N) { for (long long i = 0; i < N; i++) { par[i] = i; rank[i] = 0; siz[i] = 1; } } //要素xが所属する木の根を再帰的に発見する long long root(long long x) { if (par[x] == x) return x; return par[x] = root(par[x]); //経路圧縮 } //要素xが属する木と要素yが属する木の併合 void unite(long long x, long long y) { long long rx = root(x); long long ry = root(y); if (rx == ry) return; //同じ木に属してたらそのまま if (rank[rx] < rank[ry]) { par[rx] = ry; //根がryの木に併合 siz[ry] = siz[rx] + siz[ry]; } else { par[ry] = rx; //根がrxの木に併合 siz[rx] = siz[rx] + siz[ry]; if (rank[rx] == rank[ry]) rank[rx]++; } } //要素xが属する木と要素yが属する木が同じならtrueを返す bool same(long long x, long long y) { return root(x) == root(y); } //要素xが属する木の頂点数を返す long long size(long long x) { return siz[root(x)]; } }; int main() { cout << fixed << setprecision(30); ll n, m; cin >> n >> m; union_find tree(n); loop(i, m) { ll x, y, z; cin >> x >> y >> z; tree.unite(x - 1, y - 1); } vector<bool> seen(n, false); ll ans = 0; loop(i, n) { if (seen[tree.root(i)]) continue; seen[tree.root(i)] = true; ans++; } putout(ans); return 0; }
[ "variable_access.subscript.index.change", "control_flow.branch.if.condition.change", "assignment.variable.change" ]
863,451
863,452
u607229598
cpp
p03045
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define mod 1000000007 typedef long long ll; using namespace std; class UnionFind { public: vector<ll> par; vector<ll> siz; UnionFind(ll N) : par(N), siz(N, 1LL) { for (ll i = 0; i < N; ++i) par[i] = i; } void init(ll N) { par.resize(N); siz.assign(N, 1LL); for (ll i = 0; i < N; ++i) par[i] = i; } ll root(ll x) { while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } bool unite(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool same(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; UnionFind tree(N); for (int i = 0; i < M; i++) { ll X, Y, Z; cin >> X >> Y >> Z; X--; Y--; tree.unite(X, Y); } set<ll> st; for (int i = 0; i < N; i++) { st.insert(tree.par[i]); } cout << st.size() << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define mod 1000000007 typedef long long ll; using namespace std; class UnionFind { public: vector<ll> par; vector<ll> siz; UnionFind(ll N) : par(N), siz(N, 1LL) { for (ll i = 0; i < N; ++i) par[i] = i; } void init(ll N) { par.resize(N); siz.assign(N, 1LL); for (ll i = 0; i < N; ++i) par[i] = i; } ll root(ll x) { while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } bool unite(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool same(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; UnionFind tree(N); for (int i = 0; i < M; i++) { ll X, Y, Z; cin >> X >> Y >> Z; X--; Y--; tree.unite(X, Y); } set<ll> st; for (int i = 0; i < N; i++) { st.insert(tree.root(i)); } cout << st.size() << endl; return 0; }
[ "call.arguments.change" ]
863,457
863,458
u238205921
cpp
p03045
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <iostream> #include <queue> #include <set> #include <string> #include <tuple> #include <utility> #include <vector> #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define PRINT(V) cout << V << "\n" #define SORT(V) sort((V).begin(), (V).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) using namespace std; using ll = long long; 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; } template <typename T> vector<T> table(int n, T v) { return vector<T>(n, v); } template <class... Args> auto table(int n, Args... args) { auto val = table(args...); return vector<decltype(val)>(n, move(val)); } const ll INF = 1e17; const ll MOD = 1000000007; typedef pair<ll, ll> P; const ll MAX = 200005; class UnionFind { private: vector<ll> par; vector<ll> siz; public: UnionFind(ll sz) { par.resize(sz); siz.assign(sz, 1LL); rep(i, sz) par[i] = i; } 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 (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; } bool same(ll x, ll y) { return find(x) == find(y); } ll size(ll x) { return siz[find(x)]; } ll get() { ll res = 0; bool done[par.size()] = {0}; rep(i, par.size()) { if (done[find(i)] == 0) { res++; done[i] = 1; } } return res; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m, x, y, z; cin >> n >> m; UnionFind card(n); rep(i, m) { cin >> x >> y >> z; card.unite(x - 1, y - 1); } PRINT(card.get()); }
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <iostream> #include <queue> #include <set> #include <string> #include <tuple> #include <utility> #include <vector> #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define PRINT(V) cout << V << "\n" #define SORT(V) sort((V).begin(), (V).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) using namespace std; using ll = long long; 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; } template <typename T> vector<T> table(int n, T v) { return vector<T>(n, v); } template <class... Args> auto table(int n, Args... args) { auto val = table(args...); return vector<decltype(val)>(n, move(val)); } const ll INF = 1e17; const ll MOD = 1000000007; typedef pair<ll, ll> P; const ll MAX = 200005; class UnionFind { private: vector<ll> par; vector<ll> siz; public: UnionFind(ll sz) { par.resize(sz); siz.assign(sz, 1LL); rep(i, sz) par[i] = i; } 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 (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; } bool same(ll x, ll y) { return find(x) == find(y); } ll size(ll x) { return siz[find(x)]; } ll get() { ll res = 0; bool done[par.size()] = {0}; rep(i, par.size()) { if (done[find(i)] == 0) { res++; done[find(i)] = 1; } } return res; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m, x, y, z; cin >> n >> m; UnionFind card(n); rep(i, m) { cin >> x >> y >> z; card.unite(x - 1, y - 1); } PRINT(card.get()); }
[ "call.add", "call.arguments.change" ]
863,459
863,460
u892687772
cpp
p03045
#define _CRT_SECURE_NO_WARNINGS #include "bits/stdc++.h" using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define mp make_pair #define pb push_back #define dump(x) cerr << #x << " = " << (x) << endl; #define qp(f) [](auto i) { return f; } using LL = long long; using VI = vector<int>; using VL = vector<LL>; using VS = vector<string>; using VVI = vector<vector<int>>; using PII = pair<int, int>; const int inf = (int)1e9; const LL MOD = 1000000007; const double pi = acos(-1.0); const string Snum = "0123456789"; const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; template <class T> T Sort(T &a) { sort(a.begin(), a.end()); return a; } template <class T> T ReSort(T &a) { sort(a.rbegin(), a.rend()); return a; } template <class T> T Reverse(T &a) { reverse(a.begin(), a.end()); return a; } template <class T> void Unique(T &a) { a.erase(unique(a.begin(), a.end()), a.end()); } template <class T> auto Max(T a) { return *max_element(a.begin(), a.end()); } template <class T> auto Min(T a) { return *min_element(a.begin(), a.end()); } template <class T, class U> int Count(T a, U c) { return count(a.begin(), a.end(), c); } template <class T, class U> U Sum(T a, U init = 0) { return accumulate(a.begin(), a.end(), init); } template <class T> T Age(T a, T b) { return (a + b - 1) / b; } template <class T> T gcd(T n, T m) { return m == 0 ? n : gcd(m, n % m); } template <class T> T lcm(T n, T m) { return n / gcd(n, m) * m; } /* INPUT */ struct inputter_Str { vector<string> inputbuffer; string operator[](int n) { while (inputbuffer.size() <= n) { string s; cin >> s; inputbuffer.push_back(s); } return inputbuffer[n]; } operator string() { string s; cin >> s; inputbuffer.push_back(s); return s; } } in; struct inputter_Int { int operator[](int n) { return stoi(in[n]); } operator int() { return stoi(string(in)); } } ini; struct inputter_LL { LL operator[](int n) { return stoll(in[n]); } operator LL() { return stoll(string(in)); } } inl; struct inputter_Double { double operator[](int n) { return stod(in[n]); } operator double() { return stold(string(in)); } } ind; VI invi(int n, int m) { VI v(m); for (int i = 0; i < m; ++i) v[i] = ini[n + i]; return v; } VL invl(int n, int m) { VL v(m); for (int i = 0; i < m; ++i) v[i] = inl[n + i]; return v; } VS invs(int n, int m) { VS v(m); for (int i = 0; i < m; ++i) v[i] = in[n + i]; return v; } int Suminvi(int n, int m) { return Sum(invi(n, m), 0); } LL Suminvl(int n, int m) { return Sum(invl(n, m), 0LL); } int Maxinvi(int n, int m) { return Max(invi(n, m)); } LL Maxinvl(int n, int m) { return Max(invl(n, m)); } int Mininvi(int n, int m) { return Min(invi(n, m)); } LL Mininvl(int n, int m) { return Min(invl(n, m)); } /* OUTPUT */ struct boolswitch { string t, f; boolswitch(string tr, string fa) : t(tr), f(fa) {} } yes("yes", "no"), Yes("Yes", "No"), YES("YES", "NO"), Yay("Yay!", ":("); struct divizer { string s; divizer(string s_) : s(s_) {} } spc(" "), nosp(""); struct outputter { bool flag = false; boolswitch bs; divizer di; outputter(bool f, boolswitch b, divizer d) : flag(f), bs(b), di(d) {} template <class T> outputter operator,(T o) { if (flag) cout << di.s; cout << o; outputter t(true, bs, di); return t; } outputter operator,(double o) { if (flag) cout << di.s; printf("%.20f", o); outputter t(true, bs, di); return t; } outputter operator,(bool o) { if (flag) cout << di.s; cout << (o ? bs.t : bs.f); outputter t(true, bs, di); return t; } template <class T> outputter operator,(vector<T> o) { if (flag) cout << di.s; for (int i = 0; i < (int)o.size(); ++i) cout << o[i] << (i == (int)o.size() - 1 ? "" : di.s); outputter t(true, bs, di); return t; } template <class T, class U> outputter operator,(pair<T, U> o) { if (flag) cout << di.s; cout << "[" << o.first, ", " << o.second << "]"; outputter t(true, bs, di); return t; } outputter operator,(outputter o) { cout << '\n'; return o; } outputter operator,(boolswitch b) { outputter t(flag, b, di); return t; } outputter operator,(divizer d) { outputter t(flag, bs, d); return t; } } out(false, Yes, spc); /* ANSWER */ struct Answer { int mini = INT_MAX, maxi = INT_MIN, sumi = 0; LL minl = LLONG_MAX, maxl = LLONG_MIN, suml = 0LL; double mind = DBL_MAX, maxd = DBL_MIN, sumd = 0.; int count = 0; void operator=(int n) { mini = min(mini, n); maxi = max(maxi, n); sumi += n; count++; } void operator=(LL n) { minl = min(minl, n); maxl = max(maxl, n); suml += n; count++; } void operator=(double n) { mind = min(mind, n); maxd = max(maxd, n); sumd += n; count++; } } ans; /* SLICE */ struct IntNone { int val = 0; bool none = true; IntNone() : val(0), none(true){}; IntNone(int v) : val(v), none(false){}; operator int() { return val; } } None; struct Slicer { IntNone from_, to_, step_; Slicer(IntNone from, IntNone to, IntNone step) : from_(from), to_(to), step_(step) {} }; Slicer sp(int from, int to, int step = 1) { return Slicer(from, to, step); } Slicer sp(int from, IntNone to, int step = 1) { return Slicer(from, to, step); } Slicer sp(IntNone from, int to, int step = 1) { return Slicer(from, to, step); } Slicer sp(IntNone from, IntNone to, int step = 1) { return Slicer(from, to, step); } template <class T> decltype(auto) operator|(T v, Slicer s) { typedef typename T::iterator::value_type Ty; vector<Ty> ret; int size = (int)v.size(); if (s.from_.none) s.from_ = 0; if (s.to_.none) s.to_ = size; if (s.from_ < 0) s.from_ = size + s.from_; if (s.to_ < 0) s.to_ = size + s.to_; if (s.step_ > 0) for (int i = max(s.from_.val, 0); i < s.to_ && i < size && i >= 0; i += s.step_) ret.push_back(v[i]); else for (int i = min(s.from_.val, size - 1); i > s.to_ && i >= 0; i += s.step_) ret.push_back(v[i]); return ret; } /* MOD */ LL modpow(LL a, LL n, LL _MOD = MOD) { LL re = 1; while (n > 0) { if (n & 1) re = re * a % _MOD; a = a * a % _MOD; n >>= 1; } return re; } LL modinv(LL n, LL _MOD = MOD) { return modpow(n, _MOD - 2, _MOD); } struct Modl { LL val = 0; Modl(LL v = 0) noexcept : val(v % MOD) { if (val < 0) v += MOD; } operator LL() { return val; } }; Modl operator-(const Modl &a) { Modl r; r.val = a.val ? MOD - a.val : 0; return r; } Modl operator+(const Modl &a, const Modl &b) { Modl r(a.val + b.val); return r; } Modl operator-(const Modl &a, const Modl &b) { Modl r(a.val - b.val); return r; } Modl operator*(const Modl &a, const Modl &b) { Modl r(a.val * b.val); return r; } Modl operator/(const Modl &a, const Modl &b) { Modl r(a.val * modinv(b.val, MOD)); return r; } Modl operator+(const Modl &a, const int &b) { Modl r(a.val + LL(b)); return r; } Modl operator-(const Modl &a, const int &b) { Modl r(a.val - LL(b)); return r; } Modl operator*(const Modl &a, const int &b) { Modl r(a.val * LL(b)); return r; } Modl operator/(const Modl &a, const int &b) { Modl r(a.val * modinv(LL(b), MOD)); return r; } Modl operator+(const Modl &a, const LL &b) { Modl r(a.val + b); return r; } Modl operator-(const Modl &a, const LL &b) { Modl r(a.val - b); return r; } Modl operator*(const Modl &a, const LL &b) { Modl r(a.val * b); return r; } Modl operator/(const Modl &a, const LL &b) { Modl r(a.val * modinv(b, MOD)); return r; } Modl operator+(const int &a, const Modl &b) { Modl r(LL(a) + b.val); return r; } Modl operator-(const int &a, const Modl &b) { Modl r(LL(a) - b.val); return r; } Modl operator*(const int &a, const Modl &b) { Modl r(LL(a) * b.val); return r; } Modl operator/(const int &a, const Modl &b) { Modl r(LL(a) * modinv(b.val, MOD)); return r; } Modl operator+(const LL &a, const Modl &b) { Modl r(a + b.val); return r; } Modl operator-(const LL &a, const Modl &b) { Modl r(a - b.val); return r; } Modl operator*(const LL &a, const Modl &b) { Modl r(a * b.val); return r; } Modl operator/(const LL &a, const Modl &b) { Modl r(a * modinv(b.val, MOD)); return r; } Modl pow(Modl a, int n) { Modl r(modpow(a, n)); return r; } Modl pow(Modl a, LL n) { Modl r(modpow(a, n)); return r; } /* RANGE */ namespace RangeNS { template <class T> class Range { const T start_, stop_, step_; public: Range(const T &start, const T &stop, const T &step) : start_{start}, stop_{stop}, step_{step} { assert(!(step_ == 0 || (start_ > stop_ && step_ > 0) || (start_ < stop_ && step_ < 0))); } class iterator { T value_; const T start_, stop_, step_; public: iterator(T value, T step, T start, T stop) : value_{value}, step_{step}, start_{start}, stop_{stop} {} iterator operator++() { value_ = std::min(std::max(start_, stop_), std::max(std::min(start_, stop_), value_ + step_)); return *this; } T &operator*() { return value_; } const T *operator->() { return &value_; } bool operator==(const iterator &rhs) { return value_ == rhs.value_; } bool operator!=(const iterator &rhs) { return value_ != rhs.value_; } }; iterator begin() const { return iterator(start_, step_, start_, stop_); } iterator end() const { return iterator(stop_, step_, start_, stop_); } explicit operator vector<T>() const { vector<T> t; for (T i = start_; i < stop_; i += step_) t.push_back(i); return t; } }; template <class T, class Func, class FuncType> class Range2 { using Itr = class T::iterator; Itr begin_, end_; Func f_; public: Range2(T &v, Func f) : begin_{v.begin()}, end_{v.end()}, f_{f} {} class iterator { public: iterator(Itr itr, Func f) : itr_{itr}, f_{f} {} iterator operator++() { ++itr_; return *this; } FuncType operator*() { return f_(*itr_); } bool operator==(iterator rhs) { return rhs.itr_ == itr_; } bool operator!=(iterator rhs) { return rhs.itr_ != itr_; } private: Itr itr_; Func f_; }; iterator begin() const { return iterator(begin_, f_); } iterator end() const { return iterator(end_, f_); } operator vector<FuncType>() const { vector<FuncType> t; for (Itr i = begin_; i != end_; ++i) t.push_back(f_(*i)); return t; } }; } // namespace RangeNS template <class T> RangeNS::Range<T> range(const T &stop) { return RangeNS::Range<T>(T{0}, stop, T{1}); } template <class T> RangeNS::Range<T> range(const T &start, const T &stop) { return RangeNS::Range<T>(start, stop, T{1}); } template <class T> RangeNS::Range<T> range(const T &start, const T &stop, const T &step) { return RangeNS::Range<T>(start, stop, step); } template <class _T> ostream &operator<<(ostream &ostr, const vector<_T> &v) { if (v.size() == 0) { ostr << ""; return ostr; } ostr << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) ostr << " " << *itr; return ostr; } template <class T> ostream &operator<<(ostream &ostr, const RangeNS::Range<T> &r) { ostr << vector<T>(r); return ostr; } template <class T, class Func, class FuncType> ostream &operator<<(ostream &ostr, const RangeNS::Range2<T, Func, FuncType> &r) { ostr << vector<FuncType>(r); return ostr; } template <class T, class Func> auto operator|(T &v, Func f) { RangeNS::Range2<T, Func, decltype(f(*v.begin()))> r(v, f); return r; } template <class T, class Func> auto operator|(T &&v, Func f) { RangeNS::Range2<T, Func, decltype(f(*v.begin()))> r(v, f); return r; } /* age */ struct agel { LL val; agel(LL i) : val(i) {} }; agel operator"" age(unsigned long long i) { return agel(i); } LL operator/(const LL &a, const agel &b) { return Age(a, b.val); } class UnionFind { public: vector<int> par, sz; UnionFind(int n = 1) { init(n); } void init(int n) { par.resize(n); sz.resize(n); for (int i = 0; i < n; i++) par[i] = i, sz[i] = 1; } int root(int x) { if (par[x] == x) return x; else 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)]; } void unite(int x, int y) { x = root(x); y = root(y); if (x == y) return; par[y] = x; sz[x] += sz[y]; } }; int main() { int n, m; cin >> n >> m; UnionFind uf(n); rep(i, m) { int x, y, z; cin >> x >> y >> z; x--; y--; uf.unite(x, y); } set<int> aa; rep(i, n) aa.insert(uf.par[i]); out, sz(aa), out; }
#define _CRT_SECURE_NO_WARNINGS #include "bits/stdc++.h" using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define mp make_pair #define pb push_back #define dump(x) cerr << #x << " = " << (x) << endl; #define qp(f) [](auto i) { return f; } using LL = long long; using VI = vector<int>; using VL = vector<LL>; using VS = vector<string>; using VVI = vector<vector<int>>; using PII = pair<int, int>; const int inf = (int)1e9; const LL MOD = 1000000007; const double pi = acos(-1.0); const string Snum = "0123456789"; const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; template <class T> T Sort(T &a) { sort(a.begin(), a.end()); return a; } template <class T> T ReSort(T &a) { sort(a.rbegin(), a.rend()); return a; } template <class T> T Reverse(T &a) { reverse(a.begin(), a.end()); return a; } template <class T> void Unique(T &a) { a.erase(unique(a.begin(), a.end()), a.end()); } template <class T> auto Max(T a) { return *max_element(a.begin(), a.end()); } template <class T> auto Min(T a) { return *min_element(a.begin(), a.end()); } template <class T, class U> int Count(T a, U c) { return count(a.begin(), a.end(), c); } template <class T, class U> U Sum(T a, U init = 0) { return accumulate(a.begin(), a.end(), init); } template <class T> T Age(T a, T b) { return (a + b - 1) / b; } template <class T> T gcd(T n, T m) { return m == 0 ? n : gcd(m, n % m); } template <class T> T lcm(T n, T m) { return n / gcd(n, m) * m; } /* INPUT */ struct inputter_Str { vector<string> inputbuffer; string operator[](int n) { while (inputbuffer.size() <= n) { string s; cin >> s; inputbuffer.push_back(s); } return inputbuffer[n]; } operator string() { string s; cin >> s; inputbuffer.push_back(s); return s; } } in; struct inputter_Int { int operator[](int n) { return stoi(in[n]); } operator int() { return stoi(string(in)); } } ini; struct inputter_LL { LL operator[](int n) { return stoll(in[n]); } operator LL() { return stoll(string(in)); } } inl; struct inputter_Double { double operator[](int n) { return stod(in[n]); } operator double() { return stold(string(in)); } } ind; VI invi(int n, int m) { VI v(m); for (int i = 0; i < m; ++i) v[i] = ini[n + i]; return v; } VL invl(int n, int m) { VL v(m); for (int i = 0; i < m; ++i) v[i] = inl[n + i]; return v; } VS invs(int n, int m) { VS v(m); for (int i = 0; i < m; ++i) v[i] = in[n + i]; return v; } int Suminvi(int n, int m) { return Sum(invi(n, m), 0); } LL Suminvl(int n, int m) { return Sum(invl(n, m), 0LL); } int Maxinvi(int n, int m) { return Max(invi(n, m)); } LL Maxinvl(int n, int m) { return Max(invl(n, m)); } int Mininvi(int n, int m) { return Min(invi(n, m)); } LL Mininvl(int n, int m) { return Min(invl(n, m)); } /* OUTPUT */ struct boolswitch { string t, f; boolswitch(string tr, string fa) : t(tr), f(fa) {} } yes("yes", "no"), Yes("Yes", "No"), YES("YES", "NO"), Yay("Yay!", ":("); struct divizer { string s; divizer(string s_) : s(s_) {} } spc(" "), nosp(""); struct outputter { bool flag = false; boolswitch bs; divizer di; outputter(bool f, boolswitch b, divizer d) : flag(f), bs(b), di(d) {} template <class T> outputter operator,(T o) { if (flag) cout << di.s; cout << o; outputter t(true, bs, di); return t; } outputter operator,(double o) { if (flag) cout << di.s; printf("%.20f", o); outputter t(true, bs, di); return t; } outputter operator,(bool o) { if (flag) cout << di.s; cout << (o ? bs.t : bs.f); outputter t(true, bs, di); return t; } template <class T> outputter operator,(vector<T> o) { if (flag) cout << di.s; for (int i = 0; i < (int)o.size(); ++i) cout << o[i] << (i == (int)o.size() - 1 ? "" : di.s); outputter t(true, bs, di); return t; } template <class T, class U> outputter operator,(pair<T, U> o) { if (flag) cout << di.s; cout << "[" << o.first, ", " << o.second << "]"; outputter t(true, bs, di); return t; } outputter operator,(outputter o) { cout << '\n'; return o; } outputter operator,(boolswitch b) { outputter t(flag, b, di); return t; } outputter operator,(divizer d) { outputter t(flag, bs, d); return t; } } out(false, Yes, spc); /* ANSWER */ struct Answer { int mini = INT_MAX, maxi = INT_MIN, sumi = 0; LL minl = LLONG_MAX, maxl = LLONG_MIN, suml = 0LL; double mind = DBL_MAX, maxd = DBL_MIN, sumd = 0.; int count = 0; void operator=(int n) { mini = min(mini, n); maxi = max(maxi, n); sumi += n; count++; } void operator=(LL n) { minl = min(minl, n); maxl = max(maxl, n); suml += n; count++; } void operator=(double n) { mind = min(mind, n); maxd = max(maxd, n); sumd += n; count++; } } ans; /* SLICE */ struct IntNone { int val = 0; bool none = true; IntNone() : val(0), none(true){}; IntNone(int v) : val(v), none(false){}; operator int() { return val; } } None; struct Slicer { IntNone from_, to_, step_; Slicer(IntNone from, IntNone to, IntNone step) : from_(from), to_(to), step_(step) {} }; Slicer sp(int from, int to, int step = 1) { return Slicer(from, to, step); } Slicer sp(int from, IntNone to, int step = 1) { return Slicer(from, to, step); } Slicer sp(IntNone from, int to, int step = 1) { return Slicer(from, to, step); } Slicer sp(IntNone from, IntNone to, int step = 1) { return Slicer(from, to, step); } template <class T> decltype(auto) operator|(T v, Slicer s) { typedef typename T::iterator::value_type Ty; vector<Ty> ret; int size = (int)v.size(); if (s.from_.none) s.from_ = 0; if (s.to_.none) s.to_ = size; if (s.from_ < 0) s.from_ = size + s.from_; if (s.to_ < 0) s.to_ = size + s.to_; if (s.step_ > 0) for (int i = max(s.from_.val, 0); i < s.to_ && i < size && i >= 0; i += s.step_) ret.push_back(v[i]); else for (int i = min(s.from_.val, size - 1); i > s.to_ && i >= 0; i += s.step_) ret.push_back(v[i]); return ret; } /* MOD */ LL modpow(LL a, LL n, LL _MOD = MOD) { LL re = 1; while (n > 0) { if (n & 1) re = re * a % _MOD; a = a * a % _MOD; n >>= 1; } return re; } LL modinv(LL n, LL _MOD = MOD) { return modpow(n, _MOD - 2, _MOD); } struct Modl { LL val = 0; Modl(LL v = 0) noexcept : val(v % MOD) { if (val < 0) v += MOD; } operator LL() { return val; } }; Modl operator-(const Modl &a) { Modl r; r.val = a.val ? MOD - a.val : 0; return r; } Modl operator+(const Modl &a, const Modl &b) { Modl r(a.val + b.val); return r; } Modl operator-(const Modl &a, const Modl &b) { Modl r(a.val - b.val); return r; } Modl operator*(const Modl &a, const Modl &b) { Modl r(a.val * b.val); return r; } Modl operator/(const Modl &a, const Modl &b) { Modl r(a.val * modinv(b.val, MOD)); return r; } Modl operator+(const Modl &a, const int &b) { Modl r(a.val + LL(b)); return r; } Modl operator-(const Modl &a, const int &b) { Modl r(a.val - LL(b)); return r; } Modl operator*(const Modl &a, const int &b) { Modl r(a.val * LL(b)); return r; } Modl operator/(const Modl &a, const int &b) { Modl r(a.val * modinv(LL(b), MOD)); return r; } Modl operator+(const Modl &a, const LL &b) { Modl r(a.val + b); return r; } Modl operator-(const Modl &a, const LL &b) { Modl r(a.val - b); return r; } Modl operator*(const Modl &a, const LL &b) { Modl r(a.val * b); return r; } Modl operator/(const Modl &a, const LL &b) { Modl r(a.val * modinv(b, MOD)); return r; } Modl operator+(const int &a, const Modl &b) { Modl r(LL(a) + b.val); return r; } Modl operator-(const int &a, const Modl &b) { Modl r(LL(a) - b.val); return r; } Modl operator*(const int &a, const Modl &b) { Modl r(LL(a) * b.val); return r; } Modl operator/(const int &a, const Modl &b) { Modl r(LL(a) * modinv(b.val, MOD)); return r; } Modl operator+(const LL &a, const Modl &b) { Modl r(a + b.val); return r; } Modl operator-(const LL &a, const Modl &b) { Modl r(a - b.val); return r; } Modl operator*(const LL &a, const Modl &b) { Modl r(a * b.val); return r; } Modl operator/(const LL &a, const Modl &b) { Modl r(a * modinv(b.val, MOD)); return r; } Modl pow(Modl a, int n) { Modl r(modpow(a, n)); return r; } Modl pow(Modl a, LL n) { Modl r(modpow(a, n)); return r; } /* RANGE */ namespace RangeNS { template <class T> class Range { const T start_, stop_, step_; public: Range(const T &start, const T &stop, const T &step) : start_{start}, stop_{stop}, step_{step} { assert(!(step_ == 0 || (start_ > stop_ && step_ > 0) || (start_ < stop_ && step_ < 0))); } class iterator { T value_; const T start_, stop_, step_; public: iterator(T value, T step, T start, T stop) : value_{value}, step_{step}, start_{start}, stop_{stop} {} iterator operator++() { value_ = std::min(std::max(start_, stop_), std::max(std::min(start_, stop_), value_ + step_)); return *this; } T &operator*() { return value_; } const T *operator->() { return &value_; } bool operator==(const iterator &rhs) { return value_ == rhs.value_; } bool operator!=(const iterator &rhs) { return value_ != rhs.value_; } }; iterator begin() const { return iterator(start_, step_, start_, stop_); } iterator end() const { return iterator(stop_, step_, start_, stop_); } explicit operator vector<T>() const { vector<T> t; for (T i = start_; i < stop_; i += step_) t.push_back(i); return t; } }; template <class T, class Func, class FuncType> class Range2 { using Itr = class T::iterator; Itr begin_, end_; Func f_; public: Range2(T &v, Func f) : begin_{v.begin()}, end_{v.end()}, f_{f} {} class iterator { public: iterator(Itr itr, Func f) : itr_{itr}, f_{f} {} iterator operator++() { ++itr_; return *this; } FuncType operator*() { return f_(*itr_); } bool operator==(iterator rhs) { return rhs.itr_ == itr_; } bool operator!=(iterator rhs) { return rhs.itr_ != itr_; } private: Itr itr_; Func f_; }; iterator begin() const { return iterator(begin_, f_); } iterator end() const { return iterator(end_, f_); } operator vector<FuncType>() const { vector<FuncType> t; for (Itr i = begin_; i != end_; ++i) t.push_back(f_(*i)); return t; } }; } // namespace RangeNS template <class T> RangeNS::Range<T> range(const T &stop) { return RangeNS::Range<T>(T{0}, stop, T{1}); } template <class T> RangeNS::Range<T> range(const T &start, const T &stop) { return RangeNS::Range<T>(start, stop, T{1}); } template <class T> RangeNS::Range<T> range(const T &start, const T &stop, const T &step) { return RangeNS::Range<T>(start, stop, step); } template <class _T> ostream &operator<<(ostream &ostr, const vector<_T> &v) { if (v.size() == 0) { ostr << ""; return ostr; } ostr << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) ostr << " " << *itr; return ostr; } template <class T> ostream &operator<<(ostream &ostr, const RangeNS::Range<T> &r) { ostr << vector<T>(r); return ostr; } template <class T, class Func, class FuncType> ostream &operator<<(ostream &ostr, const RangeNS::Range2<T, Func, FuncType> &r) { ostr << vector<FuncType>(r); return ostr; } template <class T, class Func> auto operator|(T &v, Func f) { RangeNS::Range2<T, Func, decltype(f(*v.begin()))> r(v, f); return r; } template <class T, class Func> auto operator|(T &&v, Func f) { RangeNS::Range2<T, Func, decltype(f(*v.begin()))> r(v, f); return r; } /* age */ struct agel { LL val; agel(LL i) : val(i) {} }; agel operator"" age(unsigned long long i) { return agel(i); } LL operator/(const LL &a, const agel &b) { return Age(a, b.val); } class UnionFind { public: vector<int> par, sz; UnionFind(int n = 1) { init(n); } void init(int n) { par.resize(n); sz.resize(n); for (int i = 0; i < n; i++) par[i] = i, sz[i] = 1; } int root(int x) { if (par[x] == x) return x; else 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)]; } void unite(int x, int y) { x = root(x); y = root(y); if (x == y) return; par[y] = x; sz[x] += sz[y]; } }; int main() { int n, m; cin >> n >> m; UnionFind uf(n); rep(i, m) { int x, y, z; cin >> x >> y >> z; x--; y--; uf.unite(x, y); } set<int> aa; rep(i, n) aa.insert(uf.root(i)); out, sz(aa), out; }
[ "call.arguments.change" ]
863,461
863,462
u172873334
cpp
p03045
// ----------------------------------- // Author : MatsuTaku // Affiliation: Tokushima University // Country : Japan // Date : 04/09/2020 // ----------------------------------- #include <bits/stdc++.h> using namespace std; using ll = long long; struct UF { vector<int> vec; UF(int size) : vec(size) { iota(vec.begin(), vec.end(), 0); } int root(int a) { if (vec[a] == a) return a; return vec[a] = root(vec[a]); } void unite(int a, int b) { vec[root(b)] = root(a); } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; cin >> n >> m; UF uf(n); for (int i = 0; i < m; i++) { int x, y, z; cin >> x >> y >> x; x--; y--; uf.unite(x, y); } set<int> num; for (int i = 0; i < n; i++) num.insert(uf.root(i)); cout << num.size() << endl; return 0; }
// ----------------------------------- // Author : MatsuTaku // Affiliation: Tokushima University // Country : Japan // Date : 04/09/2020 // ----------------------------------- #include <bits/stdc++.h> using namespace std; using ll = long long; struct UF { vector<int> vec; UF(int size) : vec(size) { iota(vec.begin(), vec.end(), 0); } int root(int a) { if (vec[a] == a) return a; return vec[a] = root(vec[a]); } void unite(int a, int b) { vec[root(b)] = root(a); } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; cin >> n >> m; UF uf(n); for (int i = 0; i < m; i++) { int x, y, z; cin >> x >> y >> z; x--; y--; uf.unite(x, y); } set<int> num; for (int i = 0; i < n; i++) num.insert(uf.root(i)); cout << num.size() << endl; return 0; }
[ "identifier.change", "expression.operation.binary.change" ]
863,463
863,464
u500092662
cpp
p03045
/*input 6 5 1 2 1 2 3 2 1 3 3 4 5 4 5 6 5 */ #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 int long long #define pii pair<int, int> #define pb push_back #define f first #define s second #define FOR(i, n) for (int i = 0; i < n; i++) #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); int power(int x, int y, int mod = 2e18) { int ans = 1; x %= mod; while (y) { if (y & 1) ans = (x * ans) % mod; x = (x * x) % mod; y >>= 1; } return ans; } #ifndef ONLINE_JUDGE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " "; __f(comma + 1, args...); } #else #define trace(...) #endif // ifndef ONLINE_JUDGE template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < v.size(); ++i) os << v[i] << " "; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (auto it : v) os << it << " "; return os; } template <typename T, typename S> ostream &operator<<(ostream &os, const pair<T, S> &v) { os << v.first << " " << v.second; return os; } template <typename T, typename S> ostream &operator<<(ostream &os, const map<T, S> &v) { for (auto it : v) os << it.first << "=>" << it.second << "\n"; return os; } typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; int const MOD = 1e9 + 7; int const inf = 2e18; int const N = 2e5 + 10; vector<int> v[N]; bool vis[N]; void dfs(int i) { vis[i] = 1; for (auto x : v[i]) { if (!vis[x]) { dfs(x); } } } signed main() { IOS; int n, m; cin >> n >> m; FOR(i, m) { int x, y, z; cin >> x >> y >> z; v[x].pb(y); v[y].pb(x); } int ans = 0; FOR(i, n) { if (i != 0) { if (!vis[i]) { ans++; dfs(i); } } } cout << ans << endl; return 0; }
/*input 3 1 1 2 1 */ #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 int long long #define pii pair<int, int> #define pb push_back #define f first #define s second #define FOR(i, n) for (int i = 0; i < n; i++) #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); int power(int x, int y, int mod = 2e18) { int ans = 1; x %= mod; while (y) { if (y & 1) ans = (x * ans) % mod; x = (x * x) % mod; y >>= 1; } return ans; } #ifndef ONLINE_JUDGE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " "; __f(comma + 1, args...); } #else #define trace(...) #endif // ifndef ONLINE_JUDGE template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < v.size(); ++i) os << v[i] << " "; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (auto it : v) os << it << " "; return os; } template <typename T, typename S> ostream &operator<<(ostream &os, const pair<T, S> &v) { os << v.first << " " << v.second; return os; } template <typename T, typename S> ostream &operator<<(ostream &os, const map<T, S> &v) { for (auto it : v) os << it.first << "=>" << it.second << "\n"; return os; } typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; int const MOD = 1e9 + 7; int const inf = 2e18; int const N = 2e5 + 10; vector<int> v[N]; bool vis[N]; void dfs(int i) { vis[i] = 1; for (auto x : v[i]) { if (!vis[x]) { dfs(x); } } } signed main() { IOS; int n, m; cin >> n >> m; FOR(i, m) { int x, y, z; cin >> x >> y >> z; v[x].pb(y); v[y].pb(x); } int ans = 0; FOR(i, n + 1) { if (i != 0) { if (!vis[i]) { ans++; dfs(i); } } } cout << ans << endl; return 0; }
[ "expression.operation.binary.add" ]
863,477
863,478
u367694521
cpp
p03045
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #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; typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i) #define ALL(c) (c).begin(), (c).end() #define SIZE(v) ((int)v.size()) #define pb push_back #define mp make_pair #define mt make_tuple class UnionFind { public: UnionFind(){}; ~UnionFind(){}; void init(int num_entries) { num_entries_ = num_entries; par_.resize(num_entries_); rank_.resize(num_entries_, 0); member_num_.resize(num_entries_, 1); REP(i, num_entries_) { 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 (rank_[x] < rank_[y]) { par_[x] = y; member_num_[y] += member_num_[x]; member_num_[x] = 0; } else { par_[y] = x; member_num_[x] += member_num_[y]; member_num_[y] = 0; if (rank_[x] == rank_[y]) rank_[x]++; } } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return member_num_[this->find(x)]; } private: int num_entries_; std::vector<int> par_; std::vector<int> rank_; std::vector<int> member_num_; }; int main(void) { cin.sync_with_stdio(false); int N, M; cin >> N >> M; UnionFind uf; uf.init(N); REP(m, M) { int x, y, z; cin >> x >> y >> x; --x; --y; uf.unite(x, y); } set<int> s; REP(n, N) { s.insert(uf.find(n)); } cout << SIZE(s) << endl; return 0; }
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #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; typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i) #define ALL(c) (c).begin(), (c).end() #define SIZE(v) ((int)v.size()) #define pb push_back #define mp make_pair #define mt make_tuple class UnionFind { public: UnionFind(){}; ~UnionFind(){}; void init(int num_entries) { num_entries_ = num_entries; par_.resize(num_entries_); rank_.resize(num_entries_, 0); member_num_.resize(num_entries_, 1); REP(i, num_entries_) { 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 (rank_[x] < rank_[y]) { par_[x] = y; member_num_[y] += member_num_[x]; member_num_[x] = 0; } else { par_[y] = x; member_num_[x] += member_num_[y]; member_num_[y] = 0; if (rank_[x] == rank_[y]) rank_[x]++; } } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return member_num_[this->find(x)]; } private: int num_entries_; std::vector<int> par_; std::vector<int> rank_; std::vector<int> member_num_; }; int main(void) { cin.sync_with_stdio(false); int N, M; cin >> N >> M; UnionFind uf; uf.init(N); REP(m, M) { int x, y, z; cin >> x >> y >> z; --x; --y; uf.unite(x, y); } set<int> s; REP(n, N) { s.insert(uf.find(n)); } cout << SIZE(s) << endl; return 0; }
[ "identifier.change", "expression.operation.binary.change" ]
863,479
863,480
u810735437
cpp
p03045
#include <set> #include <stdio.h> using namespace std; int parent[100001]; int find(int u) { if (parent[u] == u) return u; return parent[u] = find(parent[u]); } void merge(int u, int v) { u = find(u), v = find(v); if (u == v) return; if (u < v) parent[v] = u; else parent[u] = v; } int main() { int N, M; scanf("%d %d", &N, &M); for (int i = 1; i <= N; ++i) parent[i] = i; for (int i = 0; i < M; ++i) { int X, Y, Z; scanf("%d %d %d", &X, &Y, &Z); merge(X, Y); } set<int> uniq; for (int i = 1; i <= N; ++i) uniq.insert(parent[i]); printf("%d\n", uniq.size()); return 0; }
#include <set> #include <stdio.h> using namespace std; int parent[100001]; int find(int u) { if (parent[u] == u) return u; return parent[u] = find(parent[u]); } void merge(int u, int v) { u = find(u), v = find(v); if (u == v) return; if (u < v) parent[v] = u; else parent[u] = v; } int main() { int N, M; scanf("%d %d", &N, &M); for (int i = 1; i <= N; ++i) parent[i] = i; for (int i = 0; i < M; ++i) { int X, Y, Z; scanf("%d %d %d", &X, &Y, &Z); merge(X, Y); } set<int> uniq; for (int i = 1; i <= N; ++i) uniq.insert(find(i)); printf("%d\n", uniq.size()); return 0; }
[ "call.arguments.change" ]
863,481
863,482
u328348656
cpp
p03045
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define SORT(c) sort((c).begin(), (c).end()) typedef long long ll; typedef pair<int, int> P; typedef vector<int> V; typedef map<int, int> M; constexpr ll INF = 1e18; constexpr ll MOD = 1e9 + 7; constexpr double PI = 3.14159265358979323846; constexpr int di[] = {0, 0, 1, -1}; constexpr int dj[] = {1, -1, 0, 0}; //##################### // Union-Find //##################### int uf_par[112345], uf_rnk[112345]; void uf_init(int size) { REP(i, size) { uf_par[i] = i; uf_rnk[i] = 0; } } int uf_find(int x) { if (uf_par[x] == x) return x; else return uf_par[x] = uf_find(uf_par[x]); } void uf_unite(int x, int y) { x = uf_find(x); y = uf_find(y); if (x == y) return; if (uf_rnk[x] < uf_rnk[y]) { uf_par[x] = y; } else { uf_par[y] = x; if (uf_rnk[x] == uf_rnk[y]) uf_rnk[x]++; } } bool uf_same(int x, int y) { return uf_find(x) == uf_find(y); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, x[112345], y[112345], z[112345]; cin >> n >> m; uf_init(n + 1); REP(i, m) { cin >> x[i] >> y[i] >> z[i]; z[i] = (z[i] % 2); uf_unite(x[i], y[i]); } set<int> st; REP(i, n) { st.insert(uf_par[i + 1]); } cout << st.size() << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define SORT(c) sort((c).begin(), (c).end()) typedef long long ll; typedef pair<int, int> P; typedef vector<int> V; typedef map<int, int> M; constexpr ll INF = 1e18; constexpr ll MOD = 1e9 + 7; constexpr double PI = 3.14159265358979323846; constexpr int di[] = {0, 0, 1, -1}; constexpr int dj[] = {1, -1, 0, 0}; //##################### // Union-Find //##################### int uf_par[112345], uf_rnk[112345]; void uf_init(int size) { REP(i, size) { uf_par[i] = i; uf_rnk[i] = 0; } } int uf_find(int x) { if (uf_par[x] == x) return x; else return uf_par[x] = uf_find(uf_par[x]); } void uf_unite(int x, int y) { x = uf_find(x); y = uf_find(y); if (x == y) return; if (uf_rnk[x] < uf_rnk[y]) { uf_par[x] = y; } else { uf_par[y] = x; if (uf_rnk[x] == uf_rnk[y]) uf_rnk[x]++; } } bool uf_same(int x, int y) { return uf_find(x) == uf_find(y); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, x[112345], y[112345], z[112345]; cin >> n >> m; uf_init(n + 1); REP(i, m) { cin >> x[i] >> y[i] >> z[i]; z[i] = (z[i] % 2); uf_unite(x[i], y[i]); } set<int> st; REP(i, n) { st.insert(uf_find(i + 1)); } cout << st.size() << endl; return 0; }
[ "call.arguments.change" ]
863,483
863,484
u423143252
cpp
p03045
#include <bits/stdc++.h> using namespace std; const int N = 100005; struct UnionFind { int parent[N], rnk[N]; UnionFind(int n) { for (int i = 0; i <= n; i++) { parent[i] = i; rnk[i] = 1; } } int root(int x) { if (parent[x] != x) parent[x] = root(parent[x]); return parent[x]; } void connect(int x, int y) { int rx = root(x), ry = root(y); if (rx == ry) return; if (rx > ry) { parent[ry] = rx; rnk[rx] += rnk[ry]; } if (rx <= ry) { parent[rx] = ry; rnk[ry] += rnk[rx]; } } }; set<int> s; int main() { int n, m; scanf("%d%d", &n, &m); UnionFind uf(n); for (int i = 1; i <= m; i++) { int x, y, z; scanf("%d%d%%d", &x, &y, &z); uf.connect(x, y); } for (int i = 1; i <= n; i++) s.insert(uf.root(i)); printf("%d\n", s.size()); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 100005; struct UnionFind { int parent[N], rnk[N]; UnionFind(int n) { for (int i = 0; i <= n; i++) { parent[i] = i; rnk[i] = 1; } } int root(int x) { if (parent[x] != x) parent[x] = root(parent[x]); return parent[x]; } void connect(int x, int y) { int rx = root(x), ry = root(y); if (rx == ry) return; if (rx > ry) { parent[ry] = rx; rnk[rx] += rnk[ry]; } if (rx <= ry) { parent[rx] = ry; rnk[ry] += rnk[rx]; } } }; set<int> s; int main() { int n, m; scanf("%d%d", &n, &m); UnionFind uf(n); for (int i = 1; i <= m; i++) { int x, y, z; scanf("%d%d%d", &x, &y, &z); uf.connect(x, y); } for (int i = 1; i <= n; i++) s.insert(uf.root(i)); printf("%d\n", s.size()); return 0; }
[ "literal.string.change", "call.arguments.change" ]
863,485
863,486
u407892169
cpp
p03045
#include <algorithm> #include <chrono> #include <cmath> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define pb push_back #define mod 1000000007 using ll = long long; using namespace std; vector<int> par; vector<int> rnk; vector<int> X; vector<int> Y; vector<int> Z; void init(int N) { rep(i, N) { par[i] = i; rnk[i] = 0; } } int root(int x) { return par[x] == x ? x : par[x] = root(par[x]); } bool same(int x, int y) { return root(x) == root(y); } void unite(int x, int y) { x = root(x); y = root(y); if (x == y) return; if (rnk[x] < rnk[y]) { par[x] = y; } else { par[y] = x; if (rnk[x] == rnk[y]) rnk[x]++; } } int main() { int N, M; cin >> N >> M; par.resize(N); rnk.resize(N); X.resize(M); Y.resize(M); Z.resize(M); rep(i, M) { cin >> X[i] >> Y[i] >> Z[i]; X[i]--; Y[i]--; Z[i] %= 2; } init(N); rep(i, M) { unite(X[i], Y[i]); } set<int> st; rep(i, N) { st.insert(par[i]); } cout << (int)st.size() << endl; return 0; }
#include <algorithm> #include <chrono> #include <cmath> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define pb push_back #define mod 1000000007 using ll = long long; using namespace std; vector<int> par; vector<int> rnk; vector<int> X; vector<int> Y; vector<int> Z; void init(int N) { rep(i, N) { par[i] = i; rnk[i] = 0; } } int root(int x) { return par[x] == x ? x : par[x] = root(par[x]); } bool same(int x, int y) { return root(x) == root(y); } void unite(int x, int y) { x = root(x); y = root(y); if (x == y) return; if (rnk[x] < rnk[y]) { par[x] = y; } else { par[y] = x; if (rnk[x] == rnk[y]) rnk[x]++; } } int main() { int N, M; cin >> N >> M; par.resize(N); rnk.resize(N); X.resize(M); Y.resize(M); Z.resize(M); rep(i, M) { cin >> X[i] >> Y[i] >> Z[i]; X[i]--; Y[i]--; Z[i] %= 2; } init(N); rep(i, M) { unite(X[i], Y[i]); } set<int> st; rep(i, N) { st.insert(par[root(i)]); } cout << (int)st.size() << endl; return 0; }
[ "call.add", "call.arguments.change" ]
863,491
863,492
u982234424
cpp
p03045
#include <algorithm> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <math.h> #include <queue> #include <regex> #include <set> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; using pii = pair<int, int>; using ll = long long; using ld = long double; #define pb push_back #define mp make_pair #define sc second #define fr first #define stpr setprecision #define cYES cout << "YES" << endl #define cNO cout << "NO" << endl #define cYes cout << "Yes" << endl #define cNo cout << "No" << endl #define rep(i, n) for (ll i = 0; i < (n); ++i) #define Rep(i, a, b) for (ll i = (a); i < (b); ++i) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define rRep(i, a, b) for (int i = a; i >= b; i--) #define crep(i) for (char i = 'a'; i <= 'z'; ++i) #define psortsecond(A, N) \ sort(A, A + N, \ [](const pii &a, const pii &b) { return a.second < b.second; }); #define ALL(x) (x).begin(), (x).end() #define debug(v) \ cout << #v << ":"; \ for (auto x : v) { \ cout << x << ' '; \ } \ cout << endl; #define endl '\n' int ctoi(const char c) { if ('0' <= c && c <= '9') return (c - '0'); return -1; } ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } constexpr ll MOD = 1000000007; constexpr ll INF = 1000000011; constexpr ll MOD2 = 998244353; constexpr ll LINF = 1001002003004005006ll; constexpr ld EPS = 10e-8; 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; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &&x : v) is >> x; return is; } template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first; is >> p.second; return is; } template <typename T, typename U> ostream &operator>>(ostream &os, const pair<T, U> &p) { os << p.first << ' ' << p.second; return os; } template <class T> ostream &operator<<(ostream &os, vector<T> &v) { for (auto i = begin(v); i != end(v); ++i) { if (i != begin(v)) os << ' '; os << *i; } return os; } class DisjointSet { public: vector<int> rank, p, sz; DisjointSet() {} //初期化 DisjointSet(int size) { rank.resize(size, 0); p.resize(size, 0); sz.resize(size, 1); rep(i, size) { makeSet(i); } } void makeSet(int x) { p[x] = x; rank[x] = 0; } bool same(int x, int y) { return findSet(x) == findSet(y); } void unite(int x, int y) { if (!same(x, y)) link(findSet(x), findSet(y)); } int size(int key) { return sz[findSet(key)]; } void link(int x, int y) { if (rank[x] > rank[y]) { p[y] = x; sz[x] += sz[y]; } else { p[x] = y; sz[y] += sz[x]; if (rank[x] == rank[y]) { rank[y]++; } } } int findSet(int x) { if (x != p[x]) { p[x] = findSet(p[x]); } return p[x]; } }; set<ll> S; int main() { ll N, M; cin >> N >> M; DisjointSet X; X = DisjointSet(N); ll A, B, C; rep(i, M) { cin >> A >> B >> C; X.unite(A - 1, B - 1); } rep(i, N) { S.insert(X.p[i]); } cout << S.size() << endl; }
#include <algorithm> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <math.h> #include <queue> #include <regex> #include <set> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; using pii = pair<int, int>; using ll = long long; using ld = long double; #define pb push_back #define mp make_pair #define sc second #define fr first #define stpr setprecision #define cYES cout << "YES" << endl #define cNO cout << "NO" << endl #define cYes cout << "Yes" << endl #define cNo cout << "No" << endl #define rep(i, n) for (ll i = 0; i < (n); ++i) #define Rep(i, a, b) for (ll i = (a); i < (b); ++i) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define rRep(i, a, b) for (int i = a; i >= b; i--) #define crep(i) for (char i = 'a'; i <= 'z'; ++i) #define psortsecond(A, N) \ sort(A, A + N, \ [](const pii &a, const pii &b) { return a.second < b.second; }); #define ALL(x) (x).begin(), (x).end() #define debug(v) \ cout << #v << ":"; \ for (auto x : v) { \ cout << x << ' '; \ } \ cout << endl; #define endl '\n' int ctoi(const char c) { if ('0' <= c && c <= '9') return (c - '0'); return -1; } ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } constexpr ll MOD = 1000000007; constexpr ll INF = 1000000011; constexpr ll MOD2 = 998244353; constexpr ll LINF = 1001002003004005006ll; constexpr ld EPS = 10e-8; 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; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &&x : v) is >> x; return is; } template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first; is >> p.second; return is; } template <typename T, typename U> ostream &operator>>(ostream &os, const pair<T, U> &p) { os << p.first << ' ' << p.second; return os; } template <class T> ostream &operator<<(ostream &os, vector<T> &v) { for (auto i = begin(v); i != end(v); ++i) { if (i != begin(v)) os << ' '; os << *i; } return os; } class DisjointSet { public: vector<int> rank, p, sz; DisjointSet() {} //初期化 DisjointSet(int size) { rank.resize(size, 0); p.resize(size, 0); sz.resize(size, 1); rep(i, size) { makeSet(i); } } void makeSet(int x) { p[x] = x; rank[x] = 0; } bool same(int x, int y) { return findSet(x) == findSet(y); } void unite(int x, int y) { if (!same(x, y)) link(findSet(x), findSet(y)); } int size(int key) { return sz[findSet(key)]; } void link(int x, int y) { if (rank[x] > rank[y]) { p[y] = x; sz[x] += sz[y]; } else { p[x] = y; sz[y] += sz[x]; if (rank[x] == rank[y]) { rank[y]++; } } } int findSet(int x) { if (x != p[x]) { p[x] = findSet(p[x]); } return p[x]; } }; set<ll> S; int main() { ll N, M; cin >> N >> M; DisjointSet X; X = DisjointSet(N); ll A, B, C; rep(i, M) { cin >> A >> B >> C; X.unite(A - 1, B - 1); } rep(i, N) { S.insert(X.findSet(i)); } cout << S.size() << endl; }
[ "call.arguments.change" ]
863,499
863,500
u008229752
cpp
p03045
#include <bits/stdc++.h> using namespace std; #define ll long long typedef pair<ll, ll> P; #define M 1000000007 #define all(a) (a).begin(), (a).end() #define rep(i, n) reps(i, 0, n) #define reps(i, m, n) for (int i = (m); i < (n); i++) // UnionFind #define MAXN 200010 ll par[MAXN]; // 親 ll deep[MAXN]; // 深さ // in要素で初期化 ll init(ll in) { for (int i = 0; i <= in; i++) { par[i] = i; deep[i] = 0; } } // 木の根を求める 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 (deep[x] < deep[y]) { par[x] = y; } else { par[y] = x; if (deep[x] == deep[y]) deep[x]++; } } // xとyが同じ集合に属するか否か bool same(ll x, ll y) { return find(x) == find(y); } int main() { int n, k; cin >> n >> k; init(n); rep(i, k) { int a, b, c; cin >> a >> b >> c; unite(a, b); } set<ll> s; reps(i, 1, n + 1) { s.insert(par[i]); } cout << s.size(); }
#include <bits/stdc++.h> using namespace std; #define ll long long typedef pair<ll, ll> P; #define M 1000000007 #define all(a) (a).begin(), (a).end() #define rep(i, n) reps(i, 0, n) #define reps(i, m, n) for (int i = (m); i < (n); i++) // UnionFind #define MAXN 200010 ll par[MAXN]; // 親 ll deep[MAXN]; // 深さ // in要素で初期化 ll init(ll in) { for (int i = 0; i <= in; i++) { par[i] = i; deep[i] = 0; } } // 木の根を求める 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 (deep[x] < deep[y]) { par[x] = y; } else { par[y] = x; if (deep[x] == deep[y]) deep[x]++; } } // xとyが同じ集合に属するか否か bool same(ll x, ll y) { return find(x) == find(y); } int main() { int n, k; cin >> n >> k; init(n); rep(i, k) { int a, b, c; cin >> a >> b >> c; unite(a, b); } set<ll> s; reps(i, 1, n + 1) { s.insert(find(i)); } cout << s.size(); }
[ "call.arguments.change" ]
863,501
863,502
u987476436
cpp
p03045
#include <bits/stdc++.h> using namespace std; using int64 = long long; #define int int64 #define rep(i, n) for (int i = 0; i < n; i++) #define FOR(i, a, b) for (int i = a; i < b; i++) #define SORT(x) sort(x.begin(), x.end()) #define GSORT(x) sort(x.begin(), x.end(), greater<int>()) #define mk make_pair #define fi first #define se second #define pb push_back #define All(x) x.begin(), x.end() #define V(T) vector<T> typedef pair<int, int> P; typedef pair<P, P> PP; typedef vector<int> vi; typedef vector<vi> vvi; int max(int a, int b) { if (b > a) return b; else return a; } int min(int a, int b) { if (b < a) return b; else return a; } struct UnionFind { vector<int> par; vector<int> rnk; UnionFind(int n) { par.assign(n, 0); rnk.assign(n, 1); for (int i = 0; i < n; i++) { par[i] = i; } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]) swap(x, y); rnk[x] += rnk[y]; par[y] = x; } int find(int x) { if (par[x] == x) return x; return par[x] = find(par[x]); } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return rnk[find(x)]; } }; signed main() { int n, m; cin >> n >> m; UnionFind uf(500050); vi xa(m), ya(m); rep(i, m) { int x, y, z; cin >> x >> y >> z; uf.unite(x, y); xa[i] = x; ya[i] = y; } vi cnts; V(bool) did(500050, false); rep(i, m) { if (!did[uf.find(xa[i])]) { cnts.pb(uf.size(xa[i])); did[uf.find(xa[i])] = true; } } int res = 0; int sum = 0; int i = 0; SORT(cnts); while (sum < n && i < cnts.size()) { sum += cnts[i++]; res++; } if (sum < n) res += n - res - 1; // cout << sum << endl; cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using int64 = long long; #define int int64 #define rep(i, n) for (int i = 0; i < n; i++) #define FOR(i, a, b) for (int i = a; i < b; i++) #define SORT(x) sort(x.begin(), x.end()) #define GSORT(x) sort(x.begin(), x.end(), greater<int>()) #define mk make_pair #define fi first #define se second #define pb push_back #define All(x) x.begin(), x.end() #define V(T) vector<T> typedef pair<int, int> P; typedef pair<P, P> PP; typedef vector<int> vi; typedef vector<vi> vvi; int max(int a, int b) { if (b > a) return b; else return a; } int min(int a, int b) { if (b < a) return b; else return a; } struct UnionFind { vector<int> par; vector<int> rnk; UnionFind(int n) { par.assign(n, 0); rnk.assign(n, 1); for (int i = 0; i < n; i++) { par[i] = i; } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]) swap(x, y); rnk[x] += rnk[y]; par[y] = x; } int find(int x) { if (par[x] == x) return x; return par[x] = find(par[x]); } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return rnk[find(x)]; } }; signed main() { int n, m; cin >> n >> m; UnionFind uf(500050); vi xa(m), ya(m); rep(i, m) { int x, y, z; cin >> x >> y >> z; uf.unite(x, y); xa[i] = x; ya[i] = y; } vi cnts; V(bool) did(500050, false); rep(i, m) { // cout << uf.size(xa[i]) << endl; if (!did[uf.find(xa[i])]) { cnts.pb(uf.size(xa[i])); did[uf.find(xa[i])] = true; } } int res = 0; int sum = 0; int i = 0; GSORT(cnts); while (sum < n && i < cnts.size()) { sum += cnts[i++]; res++; } if (sum < n) res += n - sum; cout << res << endl; return 0; }
[ "identifier.change", "call.function.change", "assignment.value.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
863,503
863,504
u703503553
cpp
p03045
#include <bits/stdc++.h> using namespace std; using int64 = long long; #define int int64 #define rep(i, n) for (int i = 0; i < n; i++) #define FOR(i, a, b) for (int i = a; i < b; i++) #define SORT(x) sort(x.begin(), x.end()) #define GSORT(x) sort(x.begin(), x.end(), greater<int>()) #define mk make_pair #define fi first #define se second #define pb push_back #define All(x) x.begin(), x.end() #define V(T) vector<T> typedef pair<int, int> P; typedef pair<P, P> PP; typedef vector<int> vi; typedef vector<vi> vvi; int max(int a, int b) { if (b > a) return b; else return a; } int min(int a, int b) { if (b < a) return b; else return a; } struct UnionFind { vector<int> par; vector<int> rnk; UnionFind(int n) { par.assign(n, 0); rnk.assign(n, 1); for (int i = 0; i < n; i++) { par[i] = i; } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]) swap(x, y); rnk[x] += rnk[y]; par[y] = x; } int find(int x) { if (par[x] == x) return x; return par[x] = find(par[x]); } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return rnk[find(x)]; } }; signed main() { int n, m; cin >> n >> m; UnionFind uf(100050); vi xa(m), ya(m); rep(i, m) { int x, y, z; cin >> x >> y >> z; uf.unite(x, y); xa[i] = x; ya[i] = y; } vi cnts; V(bool) did(100050, false); rep(i, m) { if (!did[uf.find(xa[i])]) { cnts.pb(uf.size(xa[i])); did[uf.find(xa[i])] = true; } } int res = 0; int sum = 0; int i = 0; SORT(cnts); while (sum < n && i < cnts.size()) { sum += cnts[i++]; res++; } if (sum < n) res += n - res - 1; // cout << sum << endl; cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using int64 = long long; #define int int64 #define rep(i, n) for (int i = 0; i < n; i++) #define FOR(i, a, b) for (int i = a; i < b; i++) #define SORT(x) sort(x.begin(), x.end()) #define GSORT(x) sort(x.begin(), x.end(), greater<int>()) #define mk make_pair #define fi first #define se second #define pb push_back #define All(x) x.begin(), x.end() #define V(T) vector<T> typedef pair<int, int> P; typedef pair<P, P> PP; typedef vector<int> vi; typedef vector<vi> vvi; int max(int a, int b) { if (b > a) return b; else return a; } int min(int a, int b) { if (b < a) return b; else return a; } struct UnionFind { vector<int> par; vector<int> rnk; UnionFind(int n) { par.assign(n, 0); rnk.assign(n, 1); for (int i = 0; i < n; i++) { par[i] = i; } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]) swap(x, y); rnk[x] += rnk[y]; par[y] = x; } int find(int x) { if (par[x] == x) return x; return par[x] = find(par[x]); } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return rnk[find(x)]; } }; signed main() { int n, m; cin >> n >> m; UnionFind uf(500050); vi xa(m), ya(m); rep(i, m) { int x, y, z; cin >> x >> y >> z; uf.unite(x, y); xa[i] = x; ya[i] = y; } vi cnts; V(bool) did(500050, false); rep(i, m) { // cout << uf.size(xa[i]) << endl; if (!did[uf.find(xa[i])]) { cnts.pb(uf.size(xa[i])); did[uf.find(xa[i])] = true; } } int res = 0; int sum = 0; int i = 0; GSORT(cnts); while (sum < n && i < cnts.size()) { sum += cnts[i++]; res++; } if (sum < n) res += n - sum; cout << res << endl; return 0; }
[ "literal.number.change", "call.arguments.change", "identifier.change", "call.function.change", "assignment.value.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
863,505
863,504
u703503553
cpp
p03045
#include <iostream> using namespace std; typedef pair<int, int> P; // Pでpair<-,->を表す。 typedef long long LL; /*ここから*/ // 10^6程度の扱いが可能 //縮約まで完了済み int V; //頂点の個数 int E; //辺の個数 P e[2000010]; //辺の組み int conn = 0; //連結数 int t[2000010]; //親情報の記録媒体 void Conn() { for (int i = 1; i <= V; i++) { t[i] = i; } for (int i = 0; i < E; i++) { int a, b; a = e[i].first; b = e[i].second; //同一連結成分か? while (t[a] != t[t[a]]) { t[a] = t[t[a]]; } while (t[b] != t[t[b]]) { t[b] = t[t[b]]; } if (t[a] != t[b]) { if (t[a] < t[b]) { t[t[b]] = t[a]; t[b] = t[a]; } else { t[t[a]] = t[b]; t[a] = t[b]; } } } for (int i = 1; i <= V; i++) { if (t[i] == i) { conn++; } } } /*ここまで*/ /*用例*/ int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; e[i].first = a; e[i].second = b; } V = n; E = m; Conn(); cout << conn << endl; //連結数 return 0; }
#include <iostream> using namespace std; typedef pair<int, int> P; // Pでpair<-,->を表す。 typedef long long LL; /*ここから*/ // 10^6程度の扱いが可能 //縮約まで完了済み int V; //頂点の個数 int E; //辺の個数 P e[2000010]; //辺の組み int conn = 0; //連結数 int t[2000010]; //親情報の記録媒体 void Conn() { for (int i = 1; i <= V; i++) { t[i] = i; } for (int i = 0; i < E; i++) { int a, b; a = e[i].first; b = e[i].second; //同一連結成分か? while (t[a] != t[t[a]]) { t[a] = t[t[a]]; } while (t[b] != t[t[b]]) { t[b] = t[t[b]]; } if (t[a] != t[b]) { if (t[a] < t[b]) { t[t[b]] = t[a]; t[b] = t[a]; } else { t[t[a]] = t[b]; t[a] = t[b]; } } } for (int i = 1; i <= V; i++) { if (t[i] == i) { conn++; } } } /*ここまで*/ /*用例*/ int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; e[i].first = a; e[i].second = b; } V = n; E = m; Conn(); cout << conn << endl; //連結数 return 0; }
[ "variable_declaration.add" ]
863,506
863,507
u992779443
cpp
p03045
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define rep2(i, n) for (int i = 0; i <= n; i++) #define repr(i, a, n) for (int i = a; i < n; i++) #define all(a) a.begin(), a.end() #define P pair<long long, long long> #define do long double 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; } int INF = 1e10; int MOD = 1e9 + 7; struct Union { vector<int> par; Union(int n) { par = vector<int>(n, -1); } int find(int x) { if (par[x] < 0) return x; else return par[x] = find(par[x]); } bool same(int a, int b) { return find(a) == find(b); } int Size(int a) { return -par[find(a)]; } void unite(int a, int b) { a = find(a); b = find(b); if (a == b) return; if (Size(b) > Size(a)) swap<int>(a, b); par[a] += par[b]; par[b] = a; } }; signed main() { int a, b; cin >> a >> b; int c[b][3]; rep(i, b) rep(j, 3) cin >> c[i][j]; Union d(a); rep(i, b) { d.unite(c[i][0] - 1, c[i][1] - 1); } vector<int> e(a); rep(i, b) { e[i] = d.find(i); } sort(all(e)); e.erase(unique(all(e)), e.end()); cout << e.size() << endl; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define rep2(i, n) for (int i = 0; i <= n; i++) #define repr(i, a, n) for (int i = a; i < n; i++) #define all(a) a.begin(), a.end() #define P pair<long long, long long> #define do long double 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; } int INF = 1e10; int MOD = 1e9 + 7; struct Union { vector<int> par; Union(int n) { par = vector<int>(n, -1); } int find(int x) { if (par[x] < 0) return x; else return par[x] = find(par[x]); } bool same(int a, int b) { return find(a) == find(b); } int Size(int a) { return -par[find(a)]; } void unite(int a, int b) { a = find(a); b = find(b); if (a == b) return; if (Size(b) > Size(a)) swap<int>(a, b); par[a] += par[b]; par[b] = a; } }; signed main() { int a, b; cin >> a >> b; int c[b][3]; rep(i, b) rep(j, 3) cin >> c[i][j]; Union d(a); rep(i, b) { d.unite(c[i][0] - 1, c[i][1] - 1); } vector<int> e(a); rep(i, a) { e[i] = d.find(i); } sort(all(e)); e.erase(unique(all(e)), e.end()); cout << e.size() << endl; }
[]
863,520
863,521
u341447450
cpp
p03045
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define fo(a, b) for (int a = 0; a < b; a++) #define Sort(a) sort(a.begin(), a.end()) #define rev(a) reverse(a.begin(), a.end()) #define fi first #define se second #define co(a) cout << a << endl #define sz size() #define bgn begin() #define en end() #define pb push_back #define pp() pop_back() #define V vector #define P pair #define V2(a, b, c) V<V<int>> a(b, V<int>(c)) #define V2a(a, b, c, d) V<V<int>> a(b, V<int>(c, d)) #define incin(a) \ int a; \ cin >> a #define yuko(a) setprecision(a) #define uni(a) a.erase(unique(a.begin(), a.end()), a.end()) #define pri priority_queue #define Pri priority_queue<int, vector<int>, greater<int>> #define ff fi.fi #define fs fi.se #define sf se.fi #define ss se.se #define all(a) (a).begin(), (a).end() #define Pi P<int, int> #define elif else if int low(V<int> a, int b) { decltype(a)::iterator c = lower_bound(a.begin(), a.end(), b); int d = c - a.bgn; return d; } int upp(V<int> a, int b) { decltype(a)::iterator c = upper_bound(a.begin(), a.end(), b); int d = c - a.bgn; return d; } template <class T> void cou(vector<vector<T>> a) { int b = a.size(); int c = a[0].size(); fo(i, b) { fo(j, c) { cout << a[i][j]; if (j == c - 1) cout << endl; else cout << ' '; } } } int wari(int a, int b) { if (a % b == 0) return a / b; else return a / b + 1; } int keta(int a) { double b = a; b = log10(b); int c = b; return c + 1; } int souwa(int a) { return a * (a + 1) / 2; } int gcm(int a, int b) { if (a % b == 0) return b; return gcm(b, a % b); } bool prime(int a) { if (a < 2) return false; else if (a == 2) return true; else if (a % 2 == 0) return false; double b = sqrt(a); for (int i = 3; i <= b; i += 2) { if (a % i == 0) { return false; } } return true; } struct Union { vector<int> par; Union(int a) { par = vector<int>(a, -1); } int find(int a) { if (par[a] < 0) return a; else return par[a] = find(par[a]); } bool same(int a, int b) { return find(a) == find(b); } int Size(int a) { return -par[find(a)]; } void unite(int a, int b) { a = find(a); b = find(b); if (a == b) return; if (Size(b) > Size(a)) swap<int>(a, b); par[a] += par[b]; par[b] = a; } }; int ketas(int a) { string b = to_string(a); int c = 0; fo(i, keta(a)) { c += b[i] - '0'; } return c; } int lcm(int a, int b) { return a / gcm(a, b) * b; } bool fe(int a, int b) { a %= 10; b %= 10; if (a == 0) a = 10; if (b == 0) b = 10; if (a > b) return true; else return false; } int INF = 1000000007; struct edge { int s, t, d; }; V<int> mojisyu(string a) { V<int> b(26, 0); fo(i, a.sz) { b[a[i] - 'a']++; } return b; } int wa2(int a) { if (a % 2 == 1) return a / 2; return a / 2 - 1; } /*signed main(){ int a,b,c; cin>>a>>b>>c; V<V<edge>> d(a); fo(i,b){ edge e; cin>>e.s>>e.t>>e.d; d[e.s].pb(e); } V<int> e(a,INF); e[c]=0; priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f; f.push({0,c}); int h=INF; while(!f.empty()){ P<int,int> g; g=f.top(); f.pop(); int v = g.second, i = g.first; for(edge l : d[v]){ if(e[l.t] > i + l.d){ e[l.t] = i + l.d; f.push({i+l.d , l.t}); } } } fo(i,a){ if(e[i]==INF) cout<<"INF"<<endl; else cout<<e[i]<<endl; } } ?*/ int nCr(int n, int r) { int a = 1; r = min(r, n - r); for (int i = n; i > n - r; i--) { a *= i; a /= n - i + 1; } return a; } /*void sea(int x,int y){ if(x<0||a<=x||y<0||b<=y||c[x][y]=='#') return; if(d[x][y]) return; d[x][y]++; sea(x+1,y); sea(x-1,y); sea(x,y+1); sea(x,y-1); }*/ int kaijou(int a) { int b = 1; fo(i, a) b *= i + 1; return b; } int nPr(int a, int b) { int c = 1; for (int i = a; i >= b; i--) c *= i; return c; } int MOD = INF; int fac[1000010], finv[1000010], inv[1000010]; // テーブルを作る前処理 //先にCOMinit()で前処理をする // ABC145D void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < 1000010; 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; } } // 二項係数計算 int COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int c[55], d[55]; int untiw(int a, int b) { if (a == 0) { if (b) return 1; return 0; } if (b <= 1) return 0; else if (b < c[a - 1] + 2) return untiw(a - 1, b - 1); else if (b == c[a - 1] + 2) return d[a - 1] + 1; else if (b == c[a]) return d[a]; return d[a - 1] + untiw(a - 1, b - c[a - 1] - 2) + 1; } signed main() { int a, b; cin >> a >> b; V<P<P<int, int>, int>> c(b); fo(i, b) cin >> c[i].ff >> c[i].fs >> c[i].se; Union d(a); fo(i, b) { d.unite(c[i].ff, c[i].fs); } V<int> e(a); fo(i, a) { e[i] == d.find(i); } Sort(e); uni(e); cout << e.sz << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define fo(a, b) for (int a = 0; a < b; a++) #define Sort(a) sort(a.begin(), a.end()) #define rev(a) reverse(a.begin(), a.end()) #define fi first #define se second #define co(a) cout << a << endl #define sz size() #define bgn begin() #define en end() #define pb push_back #define pp() pop_back() #define V vector #define P pair #define V2(a, b, c) V<V<int>> a(b, V<int>(c)) #define V2a(a, b, c, d) V<V<int>> a(b, V<int>(c, d)) #define incin(a) \ int a; \ cin >> a #define yuko(a) setprecision(a) #define uni(a) a.erase(unique(a.begin(), a.end()), a.end()) #define pri priority_queue #define Pri priority_queue<int, vector<int>, greater<int>> #define ff fi.fi #define fs fi.se #define sf se.fi #define ss se.se #define all(a) (a).begin(), (a).end() #define Pi P<int, int> #define elif else if int low(V<int> a, int b) { decltype(a)::iterator c = lower_bound(a.begin(), a.end(), b); int d = c - a.bgn; return d; } int upp(V<int> a, int b) { decltype(a)::iterator c = upper_bound(a.begin(), a.end(), b); int d = c - a.bgn; return d; } template <class T> void cou(vector<vector<T>> a) { int b = a.size(); int c = a[0].size(); fo(i, b) { fo(j, c) { cout << a[i][j]; if (j == c - 1) cout << endl; else cout << ' '; } } } int wari(int a, int b) { if (a % b == 0) return a / b; else return a / b + 1; } int keta(int a) { double b = a; b = log10(b); int c = b; return c + 1; } int souwa(int a) { return a * (a + 1) / 2; } int gcm(int a, int b) { if (a % b == 0) return b; return gcm(b, a % b); } bool prime(int a) { if (a < 2) return false; else if (a == 2) return true; else if (a % 2 == 0) return false; double b = sqrt(a); for (int i = 3; i <= b; i += 2) { if (a % i == 0) { return false; } } return true; } struct Union { vector<int> par; Union(int a) { par = vector<int>(a, -1); } int find(int a) { if (par[a] < 0) return a; else return par[a] = find(par[a]); } bool same(int a, int b) { return find(a) == find(b); } int Size(int a) { return -par[find(a)]; } void unite(int a, int b) { a = find(a); b = find(b); if (a == b) return; if (Size(b) > Size(a)) swap<int>(a, b); par[a] += par[b]; par[b] = a; } }; int ketas(int a) { string b = to_string(a); int c = 0; fo(i, keta(a)) { c += b[i] - '0'; } return c; } int lcm(int a, int b) { return a / gcm(a, b) * b; } bool fe(int a, int b) { a %= 10; b %= 10; if (a == 0) a = 10; if (b == 0) b = 10; if (a > b) return true; else return false; } int INF = 1000000007; struct edge { int s, t, d; }; V<int> mojisyu(string a) { V<int> b(26, 0); fo(i, a.sz) { b[a[i] - 'a']++; } return b; } int wa2(int a) { if (a % 2 == 1) return a / 2; return a / 2 - 1; } /*signed main(){ int a,b,c; cin>>a>>b>>c; V<V<edge>> d(a); fo(i,b){ edge e; cin>>e.s>>e.t>>e.d; d[e.s].pb(e); } V<int> e(a,INF); e[c]=0; priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f; f.push({0,c}); int h=INF; while(!f.empty()){ P<int,int> g; g=f.top(); f.pop(); int v = g.second, i = g.first; for(edge l : d[v]){ if(e[l.t] > i + l.d){ e[l.t] = i + l.d; f.push({i+l.d , l.t}); } } } fo(i,a){ if(e[i]==INF) cout<<"INF"<<endl; else cout<<e[i]<<endl; } } ?*/ int nCr(int n, int r) { int a = 1; r = min(r, n - r); for (int i = n; i > n - r; i--) { a *= i; a /= n - i + 1; } return a; } /*void sea(int x,int y){ if(x<0||a<=x||y<0||b<=y||c[x][y]=='#') return; if(d[x][y]) return; d[x][y]++; sea(x+1,y); sea(x-1,y); sea(x,y+1); sea(x,y-1); }*/ int kaijou(int a) { int b = 1; fo(i, a) b *= i + 1; return b; } int nPr(int a, int b) { int c = 1; for (int i = a; i >= b; i--) c *= i; return c; } int MOD = INF; int fac[1000010], finv[1000010], inv[1000010]; // テーブルを作る前処理 //先にCOMinit()で前処理をする // ABC145D void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < 1000010; 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; } } // 二項係数計算 int COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int c[55], d[55]; int untiw(int a, int b) { if (a == 0) { if (b) return 1; return 0; } if (b <= 1) return 0; else if (b < c[a - 1] + 2) return untiw(a - 1, b - 1); else if (b == c[a - 1] + 2) return d[a - 1] + 1; else if (b == c[a]) return d[a]; return d[a - 1] + untiw(a - 1, b - c[a - 1] - 2) + 1; } signed main() { int a, b; cin >> a >> b; V<P<P<int, int>, int>> c(b); fo(i, b) cin >> c[i].ff >> c[i].fs >> c[i].se; Union d(a); fo(i, b) { d.unite(c[i].ff - 1, c[i].fs - 1); } V<int> e(a); fo(i, a) { e[i] = d.find(i); } Sort(e); uni(e); cout << e.sz << endl; }
[ "expression.operation.compare.replace.remove", "assignment.replace.add", "misc.typo" ]
863,525
863,526
u322177979
cpp
p03045
#include <bits/stdc++.h> using namespace std; using ull = unsigned long long; using ll = long long; #define repi(n) for (int i = 0; i < (n); i++) #define repj(n) for (int j = 0; j < (n); j++) #define repk(n) for (int k = 0; k < (n); k++) #define repl(n) for (int l = 0; l < (n); l++) #define rep(i, n) for (int i = 0; (i) < (n); i++) #define repr(i, a, b) for (auto i = (a); i < (b); i++) #define repv(itr) for (auto &&v : (itr)) #define updatemax(t, v) (t = max((t), (v))) #define updatemin(t, v) (t = min((t), (v))) const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1}; const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1}; const double PI = atan(1.0) * 4; template <typename T> T minptr(T begin, T end) { T re = begin; for (T i = begin + 1; i != end; i++) { if (*i < *re) re = i; } return re; } template <typename T> T maxptr(T begin, T end) { T re = begin; for (T i = begin + 1; i != end; i++) { if (*i > *re) re = i; } return re; } int __vmax(int x) { return INT_MAX; } double __vmax(double x) { return 1e+300; } ll __vmax(ll x) { return LLONG_MAX; } int __vmin(int x) { return INT_MIN; } double __vmin(double x) { return -1e+300; } ll __vmin(ll x) { return LLONG_MIN; } template <typename T> T gcd(T a, T b) { return b == 0 ? a : b == 1 ? 1 : gcd(b, a % b); } template <typename T> T ib_binary_search(T begin, T end, function<bool(T)> f) { if (!f(end)) return end; while (abs(end - begin) > 1) { T m = (begin + end) / 2; if (f(m)) { end = m; } else { begin = m; } } return end; } ll modpow(ll a, ll b, ll m) { ll re = 1, k = 1; while (k <= b) { if (b & k) { re *= a; re %= m; } k = k << 1; a *= a; a %= m; } return re; } 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; } ll modbinomial(ll n, ll k, ll m) { k = min(k, n - k); if (k < 0) return 0; ll re = 1; for (ll i = 0; i < k; i++) { re *= n - i; re %= m; re *= modinv(i + 1, m); re %= m; } return re; } template <typename T> vector<T> lis(T begin, T end, bool allowequal = false, bool lds = false) { using V = typename iterator_traits<T>::value_type; int n = end - begin; vector<V> a(n, lds ? __vmin(*begin) : __vmax(*begin)); vector<int> id(n); if (lds && allowequal) { for (int i = 0; i < n; i++) { id[i] = n - 1 - (lower_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin()); a[id[i]] = begin[i]; } } else if (lds) { for (int i = 0; i < n; i++) { id[i] = n - 1 - (upper_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin()); a[id[i]] = begin[i]; } } else if (allowequal) { for (int i = 0; i < n; i++) { id[i] = upper_bound(a.begin(), a.end(), begin[i]) - a.begin(); a[id[i]] = begin[i]; } } else { for (int i = 0; i < n; i++) { id[i] = lower_bound(a.begin(), a.end(), begin[i]) - a.begin(); a[id[i]] = begin[i]; } } int m = *maxptr(id.begin(), id.end()); vector<T> re(m + 1); for (int i = n - 1; i >= 0; i--) { if (id[i] == m) re[m--] = begin + i; } return re; } template <typename T> class segtree { private: int n; function<T(T, T)> f; T e; vector<T> data; void _updateP(int i) { data[i] = f(data[i * 2 + 1], data[i * 2 + 2]); if (i) _updateP((i - 1) / 2); } T _calc(int begin, int end, int node, int nodeBegin, int nodeEnd) { if (end <= nodeBegin || nodeEnd <= begin) { return e; } else if (begin <= nodeBegin && nodeEnd <= end) { return data[node]; } else { int m = (nodeBegin + nodeEnd) / 2; T left = _calc(begin, end, node * 2 + 1, nodeBegin, m); T right = _calc(begin, end, node * 2 + 2, m, nodeEnd); return f(left, right); } } public: segtree(int n_, function<T(T, T)> f_, T e_, T fill) { n = pow(2, ceil(log2(n_))); f = f_; e = e_; data.resize(n * 2 - 1); for (int i = 0; i < n * 2 - 1; i++) data[i] = fill; } segtree(int n_, function<T(T, T)> f_, T e_) : segtree(n_, f_, e_, e_) {} T value(int i) { return data[n - 1 + i]; } void update(int i, T value) { data[n - 1 + i] = value; if (n) _updateP((n - 2 + i) / 2); } T calc(int begin, int end) { return _calc(begin, end, 0, 0, n); } static T max(T a, T b) { return std::max(a, b); } static T min(T a, T b) { return std::min(a, b); } static T sum(T a, T b) { return a + b; } }; int parent[100000]; int grp(int x) { if (parent[x] == x) return x; return parent[x] = grp(parent[x]); } void uni(int a, int b) { parent[a] = grp(b); } bool mm[100000]; int main() { int n, m; cin >> n >> m; repi(n) parent[i] = i; repi(m) { int x, y, z; cin >> x >> y >> z; x--; y--; uni(x, y); } int count = 0; repi(n) { int g = grp(i); if (!mm[g]) { mm[g] = true; count++; } } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; using ull = unsigned long long; using ll = long long; #define repi(n) for (int i = 0; i < (n); i++) #define repj(n) for (int j = 0; j < (n); j++) #define repk(n) for (int k = 0; k < (n); k++) #define repl(n) for (int l = 0; l < (n); l++) #define rep(i, n) for (int i = 0; (i) < (n); i++) #define repr(i, a, b) for (auto i = (a); i < (b); i++) #define repv(itr) for (auto &&v : (itr)) #define updatemax(t, v) (t = max((t), (v))) #define updatemin(t, v) (t = min((t), (v))) const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1}; const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1}; const double PI = atan(1.0) * 4; template <typename T> T minptr(T begin, T end) { T re = begin; for (T i = begin + 1; i != end; i++) { if (*i < *re) re = i; } return re; } template <typename T> T maxptr(T begin, T end) { T re = begin; for (T i = begin + 1; i != end; i++) { if (*i > *re) re = i; } return re; } int __vmax(int x) { return INT_MAX; } double __vmax(double x) { return 1e+300; } ll __vmax(ll x) { return LLONG_MAX; } int __vmin(int x) { return INT_MIN; } double __vmin(double x) { return -1e+300; } ll __vmin(ll x) { return LLONG_MIN; } template <typename T> T gcd(T a, T b) { return b == 0 ? a : b == 1 ? 1 : gcd(b, a % b); } template <typename T> T ib_binary_search(T begin, T end, function<bool(T)> f) { if (!f(end)) return end; while (abs(end - begin) > 1) { T m = (begin + end) / 2; if (f(m)) { end = m; } else { begin = m; } } return end; } ll modpow(ll a, ll b, ll m) { ll re = 1, k = 1; while (k <= b) { if (b & k) { re *= a; re %= m; } k = k << 1; a *= a; a %= m; } return re; } 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; } ll modbinomial(ll n, ll k, ll m) { k = min(k, n - k); if (k < 0) return 0; ll re = 1; for (ll i = 0; i < k; i++) { re *= n - i; re %= m; re *= modinv(i + 1, m); re %= m; } return re; } template <typename T> vector<T> lis(T begin, T end, bool allowequal = false, bool lds = false) { using V = typename iterator_traits<T>::value_type; int n = end - begin; vector<V> a(n, lds ? __vmin(*begin) : __vmax(*begin)); vector<int> id(n); if (lds && allowequal) { for (int i = 0; i < n; i++) { id[i] = n - 1 - (lower_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin()); a[id[i]] = begin[i]; } } else if (lds) { for (int i = 0; i < n; i++) { id[i] = n - 1 - (upper_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin()); a[id[i]] = begin[i]; } } else if (allowequal) { for (int i = 0; i < n; i++) { id[i] = upper_bound(a.begin(), a.end(), begin[i]) - a.begin(); a[id[i]] = begin[i]; } } else { for (int i = 0; i < n; i++) { id[i] = lower_bound(a.begin(), a.end(), begin[i]) - a.begin(); a[id[i]] = begin[i]; } } int m = *maxptr(id.begin(), id.end()); vector<T> re(m + 1); for (int i = n - 1; i >= 0; i--) { if (id[i] == m) re[m--] = begin + i; } return re; } template <typename T> class segtree { private: int n; function<T(T, T)> f; T e; vector<T> data; void _updateP(int i) { data[i] = f(data[i * 2 + 1], data[i * 2 + 2]); if (i) _updateP((i - 1) / 2); } T _calc(int begin, int end, int node, int nodeBegin, int nodeEnd) { if (end <= nodeBegin || nodeEnd <= begin) { return e; } else if (begin <= nodeBegin && nodeEnd <= end) { return data[node]; } else { int m = (nodeBegin + nodeEnd) / 2; T left = _calc(begin, end, node * 2 + 1, nodeBegin, m); T right = _calc(begin, end, node * 2 + 2, m, nodeEnd); return f(left, right); } } public: segtree(int n_, function<T(T, T)> f_, T e_, T fill) { n = pow(2, ceil(log2(n_))); f = f_; e = e_; data.resize(n * 2 - 1); for (int i = 0; i < n * 2 - 1; i++) data[i] = fill; } segtree(int n_, function<T(T, T)> f_, T e_) : segtree(n_, f_, e_, e_) {} T value(int i) { return data[n - 1 + i]; } void update(int i, T value) { data[n - 1 + i] = value; if (n) _updateP((n - 2 + i) / 2); } T calc(int begin, int end) { return _calc(begin, end, 0, 0, n); } static T max(T a, T b) { return std::max(a, b); } static T min(T a, T b) { return std::min(a, b); } static T sum(T a, T b) { return a + b; } }; int parent[100000]; int grp(int x) { if (parent[x] == x) return x; return parent[x] = grp(parent[x]); } void uni(int a, int b) { parent[grp(a)] = grp(b); } bool mm[100000]; int main() { int n, m; cin >> n >> m; repi(n) parent[i] = i; repi(m) { int x, y, z; cin >> x >> y >> z; x--; y--; uni(x, y); } int count = 0; repi(n) { int g = grp(i); if (!mm[g]) { mm[g] = true; count++; } } cout << count << endl; }
[ "call.add", "call.arguments.change" ]
863,533
863,534
u600091079
cpp
p03045
#include "bits/stdc++.h" using namespace std; #define Would #define you #define all(n) n.begin(), n.end() #define rall(n) n.rbegin(), n.rend() typedef long long ll; const ll INF = 1e18; const ll MOD = 1e9 + 7; const double EPS = 1e-10; const double pi = acos(-1); // 3.1415926535897932384626433832795028... const ll SIZE = 1 << 17; int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}, alp[30]; ll fac[200005], finv[200005], inv[200005]; vector<ll> dij; struct edge { ll to, cost; }; vector<vector<edge>> G; ll mod_pow(ll a, ll b) { ll res = 1, mul = a; for (int i = 0; i < 31; ++i) { if (b >> i & 1) { res *= mul; res %= MOD; } mul = (mul * mul) % MOD; } return res; } void addedge(int from, int to, int cost) { G[from].push_back({to, cost}); G[to].push_back({from, cost}); } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } template <typename T> void outp(vector<T> v) { for (int i = 0; i < v.size(); ++i) { cout << v[i]; if (i != v.size() - 1) { cout << " "; } } } double add(double a, double b) { if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; } return a + b; } int a, b, ans; bool visited[100005]; vector<int> v[100005]; void dfs(int n) { if (visited[n]) { return; } visited[n] = 1; for (auto i : v[n]) { dfs(i); } } int main() { cin >> a >> b; for (int i = 0; i < b; ++i) { int n, m, mm; cin >> n >> m >> mm; v[m].push_back(n), v[n].push_back(m); } for (int i = 0; i < a; ++i) { if (!visited[i]) { dfs(i); ++ans; } } cout << ans << endl; }
#include "bits/stdc++.h" using namespace std; #define Would #define you #define all(n) n.begin(), n.end() #define rall(n) n.rbegin(), n.rend() typedef long long ll; const ll INF = 1e18; const ll MOD = 1e9 + 7; const double EPS = 1e-10; const double pi = acos(-1); // 3.1415926535897932384626433832795028... const ll SIZE = 1 << 17; int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}, alp[30]; ll fac[200005], finv[200005], inv[200005]; vector<ll> dij; struct edge { ll to, cost; }; vector<vector<edge>> G; ll mod_pow(ll a, ll b) { ll res = 1, mul = a; for (int i = 0; i < 31; ++i) { if (b >> i & 1) { res *= mul; res %= MOD; } mul = (mul * mul) % MOD; } return res; } void addedge(int from, int to, int cost) { G[from].push_back({to, cost}); G[to].push_back({from, cost}); } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } template <typename T> void outp(vector<T> v) { for (int i = 0; i < v.size(); ++i) { cout << v[i]; if (i != v.size() - 1) { cout << " "; } } } double add(double a, double b) { if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; } return a + b; } int a, b, ans; bool visited[100005]; vector<int> v[100005]; void dfs(int n) { if (visited[n]) { return; } visited[n] = 1; for (auto i : v[n]) { dfs(i); } } int main() { cin >> a >> b; for (int i = 0; i < b; ++i) { int n, m, mm; cin >> n >> m >> mm; v[m].push_back(n), v[n].push_back(m); } for (int i = 1; i <= a; ++i) { if (!visited[i]) { dfs(i); ++ans; } } cout << ans << endl; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
863,541
863,542
u539402331
cpp
p03045
#include "bits/stdc++.h" using namespace std; #define Would #define you #define all(n) n.begin(), n.end() #define rall(n) n.rbegin(), n.rend() typedef long long ll; const ll INF = 1e18; const ll MOD = 1e9 + 7; const double EPS = 1e-10; const double pi = acos(-1); // 3.1415926535897932384626433832795028... const ll SIZE = 1 << 17; int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}, alp[30]; ll fac[200005], finv[200005], inv[200005]; vector<ll> dij; struct edge { ll to, cost; }; vector<vector<edge>> G; ll mod_pow(ll a, ll b) { ll res = 1, mul = a; for (int i = 0; i < 31; ++i) { if (b >> i & 1) { res *= mul; res %= MOD; } mul = (mul * mul) % MOD; } return res; } void addedge(int from, int to, int cost) { G[from].push_back({to, cost}); G[to].push_back({from, cost}); } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } template <typename T> void outp(vector<T> v) { for (int i = 0; i < v.size(); ++i) { cout << v[i]; if (i != v.size() - 1) { cout << " "; } } } double add(double a, double b) { if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; } return a + b; } int a, b, ans; bool visited[10005]; vector<int> v[10005]; void dfs(int n) { if (visited[n]) { return; } visited[n] = 1; for (auto i : v[n]) { dfs(i); } } int main() { cin >> a >> b; for (int i = 0; i < b; ++i) { int n, m, mm; cin >> n >> m >> mm; v[m].push_back(n), v[n].push_back(m); } for (int i = 0; i < a; ++i) { if (!visited[i]) { dfs(i); ++ans; } } cout << ans << endl; }
#include "bits/stdc++.h" using namespace std; #define Would #define you #define all(n) n.begin(), n.end() #define rall(n) n.rbegin(), n.rend() typedef long long ll; const ll INF = 1e18; const ll MOD = 1e9 + 7; const double EPS = 1e-10; const double pi = acos(-1); // 3.1415926535897932384626433832795028... const ll SIZE = 1 << 17; int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}, alp[30]; ll fac[200005], finv[200005], inv[200005]; vector<ll> dij; struct edge { ll to, cost; }; vector<vector<edge>> G; ll mod_pow(ll a, ll b) { ll res = 1, mul = a; for (int i = 0; i < 31; ++i) { if (b >> i & 1) { res *= mul; res %= MOD; } mul = (mul * mul) % MOD; } return res; } void addedge(int from, int to, int cost) { G[from].push_back({to, cost}); G[to].push_back({from, cost}); } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } template <typename T> void outp(vector<T> v) { for (int i = 0; i < v.size(); ++i) { cout << v[i]; if (i != v.size() - 1) { cout << " "; } } } double add(double a, double b) { if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; } return a + b; } int a, b, ans; bool visited[100005]; vector<int> v[100005]; void dfs(int n) { if (visited[n]) { return; } visited[n] = 1; for (auto i : v[n]) { dfs(i); } } int main() { cin >> a >> b; for (int i = 0; i < b; ++i) { int n, m, mm; cin >> n >> m >> mm; v[m].push_back(n), v[n].push_back(m); } for (int i = 1; i <= a; ++i) { if (!visited[i]) { dfs(i); ++ans; } } cout << ans << endl; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
863,543
863,542
u539402331
cpp
p03045
#include <bits/stdc++.h> using namespace std; struct DSU { int n; vector<int> ps; vector<int> rank; int num_components; DSU(int n) : n(n), ps(n), num_components(n) { for (int i = 0; i < n; ++i) { ps[i] = i; rank[i] = 0; } } int parent(int i) { if (ps[i] == i) { return i; } return ps[i] = parent(ps[i]); } int merge(int i, int j) { i = parent(i); j = parent(j); if (i != j) { if (rank[i] <= rank[j]) { swap(i, j); } if (rank[i] == rank[j]) { ++rank[i]; } ps[j] = i; --num_components; return true; } return false; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<int> ps(n); for (int i = 0; i < n; ++i) { ps[i] = i; } DSU dsu(n); for (int i = 0; i < m; ++i) { int x, y, z; cin >> x >> y >> z; --x; --y; dsu.merge(x, y); } cout << dsu.num_components << endl; return 0; }
#include <bits/stdc++.h> using namespace std; struct DSU { int n; vector<int> ps; vector<int> rank; int num_components; DSU(int n) : n(n), ps(n), num_components(n), rank(n) { for (int i = 0; i < n; ++i) { ps[i] = i; rank[i] = 0; } } int parent(int i) { if (ps[i] == i) { return i; } return ps[i] = parent(ps[i]); } int merge(int i, int j) { i = parent(i); j = parent(j); if (i != j) { if (rank[i] <= rank[j]) { swap(i, j); } if (rank[i] == rank[j]) { ++rank[i]; } ps[j] = i; --num_components; return true; } return false; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<int> ps(n); for (int i = 0; i < n; ++i) { ps[i] = i; } DSU dsu(n); for (int i = 0; i < m; ++i) { int x, y, z; cin >> x >> y >> z; --x; --y; dsu.merge(x, y); } cout << dsu.num_components << endl; return 0; }
[]
863,544
863,545
u813181182
cpp
p03045
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) typedef long long ll; typedef pair<ll, ll> P; using vi = vector<ll>; using vvi = vector<vector<ll>>; using vc = vector<char>; using vvc = vector<vector<char>>; const int inf = 1000000007; const int mod = 1000000007; const int max_n = 100000; void chmin(auto &a, auto b) { if (b < a) a = b; } void chmax(auto &a, auto b) { if (a < b) a = b; } vi parent(max_n); vi depth(max_n, 0); int root(int i) { if (parent[i] == i) return i; return root(parent[i]); } void heigou(int x, int y) { x = root(x); y = root(y); if (x == y) return; if (depth[x] < depth[y]) parent[x] = y; else if (depth[x] > depth[y]) parent[y] = x; else { parent[y] = x; depth[x]++; } } int main() { int n, m, ans = 0; cin >> n >> m; vi v; rep(i, parent.size()) parent[i] = i; rep(i, m) { int a, b, c; cin >> a >> b >> c; heigou(a, b); } rep(i, n) { v.push_back(root(i)); } sort(v.begin(), v.end()); rep(i, n - 1) { if (v[i] != v[i + 1]) ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) typedef long long ll; typedef pair<ll, ll> P; using vi = vector<ll>; using vvi = vector<vector<ll>>; using vc = vector<char>; using vvc = vector<vector<char>>; const int inf = 1000000007; const int mod = 1000000007; const int max_n = 100000; void chmin(auto &a, auto b) { if (b < a) a = b; } void chmax(auto &a, auto b) { if (a < b) a = b; } vi parent(max_n); vi depth(max_n, 0); int root(int i) { if (parent[i] == i) return i; return root(parent[i]); } void heigou(int x, int y) { x = root(x); y = root(y); if (x == y) return; if (depth[x] < depth[y]) parent[x] = y; else if (depth[x] > depth[y]) parent[y] = x; else { parent[y] = x; depth[x]++; } } int main() { int n, m, ans = 0; cin >> n >> m; vi v; rep(i, parent.size()) parent[i] = i; rep(i, m) { int a, b, c; cin >> a >> b >> c; heigou(a - 1, b - 1); } rep(i, n) { v.push_back(root(i)); } sort(v.begin(), v.end()); rep(i, n - 1) { if (v[i] != v[i + 1]) ans++; } cout << ans + 1 << endl; }
[ "expression.operation.binary.add" ]
863,561
863,562
u422633119
cpp
p03045
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; using Graph = vector<vector<int>>; using P = pair<int, int>; int main() { int N, M; cin >> N >> M; Graph edge(M); rep(i, M) { int x, y, z; cin >> x >> y >> z; --x; --y; edge[x].push_back(y); edge[y].push_back(x); } vector<bool> visited(N, false); int ans = 0; rep(i, N) { if (visited[i]) continue; visited[i] = true; ++ans; queue<int> q; q.push(i); while (!q.empty()) { int v = q.front(); q.pop(); for (auto nv : edge[v]) { if (visited[nv]) continue; visited[nv] = true; q.push(nv); } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; using Graph = vector<vector<int>>; using P = pair<int, int>; int main() { int N, M; cin >> N >> M; Graph edge(N); rep(i, M) { int x, y, z; cin >> x >> y >> z; --x; --y; edge[x].push_back(y); edge[y].push_back(x); } vector<bool> visited(N, false); int ans = 0; rep(i, N) { if (visited[i]) continue; visited[i] = true; ++ans; queue<int> q; q.push(i); while (!q.empty()) { int v = q.front(); q.pop(); for (auto nv : edge[v]) { if (visited[nv]) continue; visited[nv] = true; q.push(nv); } } } cout << ans << endl; return 0; }
[]
863,563
863,564
u104057163
cpp
p03045
#include <cstdlib> #include <iostream> #include <queue> #include <stdio.h> #include <vector> typedef struct _xyz { int x; int y; int z; } xyz; typedef struct _node { std::vector<int> nbr; // zero-based numbering (node_arr[nbr] } node; int main(void) { int n, m; scanf("%d%d", &n, &m); xyz *xyz_arr = (xyz *)std::malloc(sizeof(xyz) * m); for (int i = 0; i < m; ++i) { scanf("%d%d%d", &xyz_arr[i].x, &xyz_arr[i].y, &xyz_arr[i].z); } node *node_arr = (node *)std::malloc(sizeof(node) * n); for (int i = 0; i < m; i++) { node_arr[xyz_arr[i].x - 1].nbr.push_back(xyz_arr[i].y - 1); node_arr[xyz_arr[i].y - 1].nbr.push_back(xyz_arr[i].x - 1); } int count; std::vector<bool> memo(n); count = 0; for (int i = 0; i < m; ++i) { if (!memo[i]) { /* * BFS */ memo[i] = true; std::queue<int> q; // zero-based numbering q.push(i); while (!q.empty()) { int j = q.front(); q.pop(); for (auto itr = node_arr[j].nbr.begin(); itr != node_arr[j].nbr.end(); ++itr) { if (!memo[*itr]) { memo[*itr] = true; q.push(*itr); } else { continue; } } } count++; } else if (node_arr[i].nbr.empty()) { count++; } else { continue; } } std::cout << count << std::endl; return EXIT_SUCCESS; }
#include <cstdlib> #include <iostream> #include <queue> #include <stdio.h> #include <vector> typedef struct _xyz { int x; int y; int z; } xyz; typedef struct _node { std::vector<int> nbr; // zero-based numbering (node_arr[nbr] } node; int main(void) { int n, m; scanf("%d%d", &n, &m); xyz *xyz_arr = (xyz *)std::malloc(sizeof(xyz) * m); for (int i = 0; i < m; ++i) { scanf("%d%d%d", &xyz_arr[i].x, &xyz_arr[i].y, &xyz_arr[i].z); } node *node_arr = (node *)std::malloc(sizeof(node) * n); for (int i = 0; i < m; i++) { node_arr[xyz_arr[i].x - 1].nbr.push_back(xyz_arr[i].y - 1); node_arr[xyz_arr[i].y - 1].nbr.push_back(xyz_arr[i].x - 1); } int count; std::vector<bool> memo(n); count = 0; for (int i = 0; i < n; ++i) { if (!memo[i]) { /* * BFS */ memo[i] = true; std::queue<int> q; // zero-based numbering q.push(i); while (!q.empty()) { int j = q.front(); q.pop(); for (auto itr = node_arr[j].nbr.begin(); itr != node_arr[j].nbr.end(); ++itr) { if (!memo[*itr]) { memo[*itr] = true; q.push(*itr); } else { continue; } } } count++; } else if (node_arr[i].nbr.empty()) { count++; } else { continue; } } std::cout << count << std::endl; return EXIT_SUCCESS; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
863,568
863,569
u450601883
cpp
p03045
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define all(a) (a).begin(), (a).end() #define ll long long struct UnionFind { vector<int> par; UnionFind(int N) : par(N) { rep(i, N) par[i] = i; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; par[rx] = ry; } bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } }; int main() { int N, M; cin >> N >> M; vector<int> X(M), Y(M), Z(M); rep(i, M) cin >> X[i] >> Y[i] >> Z[i]; UnionFind tree(N + 1); rep(i, M) tree.unite(X[i], Y[i]); set<int> A; rep(i, N) A.insert(tree.root(i)); cout << A.size() - 1 << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define all(a) (a).begin(), (a).end() #define ll long long struct UnionFind { vector<int> par; UnionFind(int N) : par(N) { rep(i, N) par[i] = i; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; par[rx] = ry; } bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } }; int main() { int N, M; cin >> N >> M; vector<int> X(M), Y(M), Z(M); rep(i, M) cin >> X[i] >> Y[i] >> Z[i]; UnionFind tree(N + 1); rep(i, M) tree.unite(X[i], Y[i]); set<int> A; rep(i, N + 1) A.insert(tree.root(i)); cout << A.size() - 1 << endl; }
[ "expression.operation.binary.add" ]
863,576
863,577
u154756110
cpp
p03045
#include <bits/stdc++.h> using namespace std; #define int long long // #define double long double #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 REP(i, n) for (ll i = 0; i < (n); ++i) #define REPR(i, n) for (ll i = n; i >= 0; i--) #define FOREACH(x, a) for (auto &(x) : (a)) #define VECCIN(x) \ for (auto &youso_ : (x)) \ cin >> youso_ #define bitcnt __builtin_popcount #define SZ(x) ((ll)(x).size()) #define fi first #define se second #define All(a) (a).begin(), (a).end() #define rAll(a) (a).rbegin(), (a).rend() template <typename T = long long> inline T IN() { T x; cin >> x; return (x); } inline void CIN() {} template <class Head, class... Tail> inline void CIN(Head &&head, Tail &&...tail) { cin >> head; CIN(move(tail)...); } #define CCIN(...) \ char __VA_ARGS__; \ CIN(__VA_ARGS__) #define DCIN(...) \ double __VA_ARGS__; \ CIN(__VA_ARGS__) #define LCIN(...) \ ll __VA_ARGS__; \ CIN(__VA_ARGS__) #define SCIN(...) \ string __VA_ARGS__; \ CIN(__VA_ARGS__) #define Printv(v) \ { \ REP(x, v.size()) { cout << v[x] << (x == v.size() - 1 ? "\n" : " "); } \ } template <typename T = string> inline void eputs(T s) { cout << s << "\n"; exit(0); } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>; template <typename T> using PQ = priority_queue<T>; typedef long long ll; typedef pair<ll, ll> PL; typedef vector<PL> VPL; typedef vector<ll> VL; typedef vector<VL> VVL; typedef vector<double> VD; const int INF = 1e9; const int MOD = 1e9 + 7; const ll LINF = 1e18; const ll dx[] = {1, 0, -1, 0}; const ll dy[] = {0, 1, 0, -1}; #define PI 3.141592653589793238 // size用 struct UnionFind { vector<ll> par; vector<ll> sizes; UnionFind(ll n) : par(n), sizes(n, 1) { REP(i, n) par[i] = i; } ll find(ll x) { if (x == par[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 (sizes[x] < sizes[y]) swap(x, y); par[y] = x; sizes[x] += sizes[y]; sizes[y] = 0; } bool same(ll x, ll y) { return find(x) == find(y); } ll size(ll x) { return sizes[find(x)]; } }; set<ll> st; signed main() { LCIN(N, M); UnionFind uf(N); REP(i, M) { LCIN(X, Y, Z); X--, Y--; uf.unite(X, Y); } REP(i, N) { st.emplace(uf.par[i]); } cout << st.size() << "\n"; }
#include <bits/stdc++.h> using namespace std; #define int long long // #define double long double #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 REP(i, n) for (ll i = 0; i < (n); ++i) #define REPR(i, n) for (ll i = n; i >= 0; i--) #define FOREACH(x, a) for (auto &(x) : (a)) #define VECCIN(x) \ for (auto &youso_ : (x)) \ cin >> youso_ #define bitcnt __builtin_popcount #define SZ(x) ((ll)(x).size()) #define fi first #define se second #define All(a) (a).begin(), (a).end() #define rAll(a) (a).rbegin(), (a).rend() template <typename T = long long> inline T IN() { T x; cin >> x; return (x); } inline void CIN() {} template <class Head, class... Tail> inline void CIN(Head &&head, Tail &&...tail) { cin >> head; CIN(move(tail)...); } #define CCIN(...) \ char __VA_ARGS__; \ CIN(__VA_ARGS__) #define DCIN(...) \ double __VA_ARGS__; \ CIN(__VA_ARGS__) #define LCIN(...) \ ll __VA_ARGS__; \ CIN(__VA_ARGS__) #define SCIN(...) \ string __VA_ARGS__; \ CIN(__VA_ARGS__) #define Printv(v) \ { \ REP(x, v.size()) { cout << v[x] << (x == v.size() - 1 ? "\n" : " "); } \ } template <typename T = string> inline void eputs(T s) { cout << s << "\n"; exit(0); } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>; template <typename T> using PQ = priority_queue<T>; typedef long long ll; typedef pair<ll, ll> PL; typedef vector<PL> VPL; typedef vector<ll> VL; typedef vector<VL> VVL; typedef vector<double> VD; const int INF = 1e9; const int MOD = 1e9 + 7; const ll LINF = 1e18; const ll dx[] = {1, 0, -1, 0}; const ll dy[] = {0, 1, 0, -1}; #define PI 3.141592653589793238 // size用 struct UnionFind { vector<ll> par; vector<ll> sizes; UnionFind(ll n) : par(n), sizes(n, 1) { REP(i, n) par[i] = i; } ll find(ll x) { if (x == par[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 (sizes[x] < sizes[y]) swap(x, y); par[y] = x; sizes[x] += sizes[y]; sizes[y] = 0; } bool same(ll x, ll y) { return find(x) == find(y); } ll size(ll x) { return sizes[find(x)]; } }; set<ll> st; signed main() { LCIN(N, M); UnionFind uf(N); REP(i, M) { LCIN(X, Y, Z); X--, Y--; uf.unite(X, Y); } REP(i, N) { st.emplace(uf.find(i)); } cout << st.size() << "\n"; }
[ "call.arguments.change" ]
863,580
863,581
u139031151
cpp
p03045
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } /* attention long longのシフト演算には気をつけよう タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも sizeは(int)とキャストしよう ごちゃごちゃ場合分けを考える前に全探索は考えましたか? */ const ll mod = 1e9 + 7; void chmod(ll &M) { if (M >= mod) M %= mod; else if (M < 0) { M += (abs(M) / mod + 1) * mod; M %= mod; } } ll modpow(ll x, ll n) { if (n == 0) return 1; ll res = modpow(x, n / 2); if (n % 2 == 0) return res * res % mod; else return res * res % mod * x % mod; } ll power(ll x, ll n) { if (n == 0) return 1; ll res = power(x, n / 2); if (n % 2 == 0) return res * res; else return res * res * x; } int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; }; int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; }; /* <--------------------------------------------> */ class UnionFind { public: //親の番号を格納する。親だった場合はー(その集合のサイズ) vector<int> parents; //作る時はparentsを-1で初期化する //こうすることで全部ばらばらになる UnionFind(int n) { parents = vector<int>(n, -1); } // Aがどのグループにいるか調べる int root(int A) { if (parents[A] < 0) return A; return parents[A] = root(parents[A]); } //自分のいるグループの大きさを調べる int size(int A) { return -parents[root(A)]; } // AとBをくっつける bool connect(int A, int B) { // AとBを直接ではなく親同士をくっつける A = root(A); B = root(B); if (A == B) { return false; } //大きい方(A)に小さい方(B)をくっつけたい if (size(A) < size(B)) swap(A, B); parents[A] += parents[B]; parents[B] = A; return true; } }; typedef tuple<ll, ll, ll> T; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; UnionFind uni(n); for (int i = 0; i < m; ++i) { int x, y, z; cin >> x >> y >> x; --x; --y; uni.connect(x, y); } map<int, int> mp; for (int i = 0; i < n; ++i) ++mp[uni.root(i)]; cout << mp.size() << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } /* attention long longのシフト演算には気をつけよう タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも sizeは(int)とキャストしよう ごちゃごちゃ場合分けを考える前に全探索は考えましたか? */ const ll mod = 1e9 + 7; void chmod(ll &M) { if (M >= mod) M %= mod; else if (M < 0) { M += (abs(M) / mod + 1) * mod; M %= mod; } } ll modpow(ll x, ll n) { if (n == 0) return 1; ll res = modpow(x, n / 2); if (n % 2 == 0) return res * res % mod; else return res * res % mod * x % mod; } ll power(ll x, ll n) { if (n == 0) return 1; ll res = power(x, n / 2); if (n % 2 == 0) return res * res; else return res * res * x; } int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; }; int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; }; /* <--------------------------------------------> */ class UnionFind { public: //親の番号を格納する。親だった場合はー(その集合のサイズ) vector<int> parents; //作る時はparentsを-1で初期化する //こうすることで全部ばらばらになる UnionFind(int n) { parents = vector<int>(n, -1); } // Aがどのグループにいるか調べる int root(int A) { if (parents[A] < 0) return A; return parents[A] = root(parents[A]); } //自分のいるグループの大きさを調べる int size(int A) { return -parents[root(A)]; } // AとBをくっつける bool connect(int A, int B) { // AとBを直接ではなく親同士をくっつける A = root(A); B = root(B); if (A == B) { return false; } //大きい方(A)に小さい方(B)をくっつけたい if (size(A) < size(B)) swap(A, B); parents[A] += parents[B]; parents[B] = A; return true; } }; typedef tuple<ll, ll, ll> T; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; UnionFind uni(n); for (int i = 0; i < m; i++) { int x, y, z; cin >> x >> y >> z; --x; --y; uni.connect(x, y); } map<int, int> mp; for (int i = 0; i < n; i++) ++mp[uni.root(i)]; cout << mp.size() << endl; return 0; }
[ "identifier.change", "expression.operation.binary.change" ]
863,588
863,589
u052332717
cpp
p03045
/* オーダー 10**6 余裕を持って間に合う 10**7 おそらく間に合う 余裕を持って間に合う 10**8 非常にシンプルな処理でない限り厳しい おそらく間に合う 10**9 非常にシンプルな処理でない限り厳しい logn :OK n :10^7 nlogn :10^6 n**2 :10^4 n**3 :300 2**n :20 n! :10 // 各桁の和を計算する関数 int findSumOfDigits(int n) { int sum = 0; while (n > 0) { // n が 0 になるまで sum += n % 10; n /= 10; } return sum; } sort(a, a + N, greater<int>()); // a[0:N] を大きい順にソート int num[110] = {0}; // バケット for (int i = 0; i < N; ++i) { num[d[i]]++; // d[i] が 1 個増える } map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名 for (int i = 0; i < N; ++i) { auto itr = mp.find(s[i]); // s[i] が設定されているか? if(itr != mp.end() ) { mp[s[i]] += 1; } else { mp[s[i]] += 1 ; } } stack<int> s; //intをデータとするスタックを用意 s.push(1); //{} -> {1} printf("%d\n", s.top()); // 3 s.pop(); queue<int> que; //intをデータとするキューを用意 que.push(1); //{} -> {1} printf("%d\n", que.front()); // 1 que.pop(); */ #include <algorithm> #include <bitset> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string.h> #include <string> #include <vector> using namespace std; // #define for(i,a,b) for (int i=(a);i<(b);++i) typedef long long ll; typedef pair<ll, ll> P; #define REP(i, n) for (long long i = 0; i < (long long)(n); i++) #define pb push_back // vectorに要素追加 #define INF (ll)1e18 const int MAX_N = 1e5 + 1; ll par[MAX_N]; // 親 ll size_list[MAX_N]; // iを親とするグループのサイズ ll depth[MAX_N]; // 木の深さ // n要素の初期化 void init(ll n) { REP(i, n) { par[i] = i; depth[i] = 0; } } // 木の根を求める ll find(ll x) { if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } // xとyの属する集合を併合 void unit(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (depth[x] < depth[y]) { // xよりyが深いなら size_list[y] += size_list[par[x]]; par[x] = y; // xの親はy } else { size_list[x] += size_list[par[y]]; par[y] = x; if (depth[x] == depth[y]) depth[x]++; } } // xとyが同じ集合に属するか否か bool same(ll x, ll y) { return find(x) == find(y); } // xのグループの大きさ ll size(ll x) { return size_list[par[x]]; } int main() { // 入力 ll N, M; cin >> N >> M; ll X[M], Y[M], Z[M]; REP(i, M) { ll x, y, z; cin >> x >> y >> z; x--; y--; X[i] = x; Y[i] = y; Z[i] = z; } // 解法 init(N); // Union-Find木を初期化 REP(i, M) { unit(X[i], Y[i]); } // REP(i,N){ // printf("%lld: %lld\n", i, par[i]); // } set<ll> se; REP(i, N) se.insert(par[i]); printf("%lld\n", se.size()); // printf("%lld\n", 1); }
/* オーダー 10**6 余裕を持って間に合う 10**7 おそらく間に合う 余裕を持って間に合う 10**8 非常にシンプルな処理でない限り厳しい おそらく間に合う 10**9 非常にシンプルな処理でない限り厳しい logn :OK n :10^7 nlogn :10^6 n**2 :10^4 n**3 :300 2**n :20 n! :10 // 各桁の和を計算する関数 int findSumOfDigits(int n) { int sum = 0; while (n > 0) { // n が 0 になるまで sum += n % 10; n /= 10; } return sum; } sort(a, a + N, greater<int>()); // a[0:N] を大きい順にソート int num[110] = {0}; // バケット for (int i = 0; i < N; ++i) { num[d[i]]++; // d[i] が 1 個増える } map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名 for (int i = 0; i < N; ++i) { auto itr = mp.find(s[i]); // s[i] が設定されているか? if(itr != mp.end() ) { mp[s[i]] += 1; } else { mp[s[i]] += 1 ; } } stack<int> s; //intをデータとするスタックを用意 s.push(1); //{} -> {1} printf("%d\n", s.top()); // 3 s.pop(); queue<int> que; //intをデータとするキューを用意 que.push(1); //{} -> {1} printf("%d\n", que.front()); // 1 que.pop(); */ #include <algorithm> #include <bitset> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string.h> #include <string> #include <vector> using namespace std; // #define for(i,a,b) for (int i=(a);i<(b);++i) typedef long long ll; typedef pair<ll, ll> P; #define REP(i, n) for (long long i = 0; i < (long long)(n); i++) #define pb push_back // vectorに要素追加 #define INF (ll)1e18 const int MAX_N = 1e5 + 1; ll par[MAX_N]; // 親 ll size_list[MAX_N]; // iを親とするグループのサイズ ll depth[MAX_N]; // 木の深さ // n要素の初期化 void init(ll n) { REP(i, n) { par[i] = i; depth[i] = 0; } } // 木の根を求める ll find(ll x) { if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } // xとyの属する集合を併合 void unit(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (depth[x] < depth[y]) { // xよりyが深いなら size_list[y] += size_list[par[x]]; par[x] = y; // xの親はy } else { size_list[x] += size_list[par[y]]; par[y] = x; if (depth[x] == depth[y]) depth[x]++; } } // xとyが同じ集合に属するか否か bool same(ll x, ll y) { return find(x) == find(y); } // xのグループの大きさ ll size(ll x) { return size_list[par[x]]; } int main() { // 入力 ll N, M; cin >> N >> M; ll X[M], Y[M], Z[M]; REP(i, M) { ll x, y, z; cin >> x >> y >> z; x--; y--; X[i] = x; Y[i] = y; Z[i] = z; } // 解法 init(N); // Union-Find木を初期化 REP(i, M) { unit(X[i], Y[i]); } // REP(i,N){ // printf("%lld: %lld, %lld\n", i, par[i], depth[i]); // } set<ll> se; REP(i, N) se.insert(find(i)); printf("%lld\n", se.size()); // printf("%lld\n", 1); }
[ "call.arguments.change" ]
863,592
863,593
u757738907
cpp
p03045
#include <bits/stdc++.h> using namespace std; int num_groups, p[100000], n, m, a, b, c; int par(int x) { return (p[x] == x) ? x : p[x] = par(p[x]); } bool isSameGroup(int a, int b) { return par(a) == par(b); } void merge(int a, int b) { num_groups -= (!isSameGroup(a, b)); p[par(a)] = par(b); } int main() { cin >> n >> m; for (int i = 0; i < n; i++) p[i] = 1; num_groups = n; for (int i = 0; i < m; i++) { cin >> a >> b >> c; merge(a - 1, b - 1); } cout << num_groups; }
#include <bits/stdc++.h> using namespace std; int num_groups, p[100000], n, m, a, b, c; int par(int x) { return (p[x] == x) ? x : p[x] = par(p[x]); } bool isSameGroup(int a, int b) { return par(a) == par(b); } void merge(int a, int b) { num_groups -= (!isSameGroup(a, b)); p[par(a)] = par(b); } int main() { cin >> n >> m; for (int i = 0; i < n; i++) p[i] = i; num_groups = n; for (int i = 0; i < m; i++) { cin >> a >> b >> c; merge(a - 1, b - 1); } cout << num_groups; }
[ "assignment.value.change", "identifier.replace.add", "literal.replace.remove" ]
863,598
863,599
u913008467
cpp
p03045
#include <bits/stdc++.h> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) // const bool debug=true; const bool debug = false; #define DEBUG if (debug == true) using namespace std; typedef long long ll; typedef unsigned long long ull; const ll MOD = 1000000007; const int MAX = 200005; int parent[MAX]; void parinit(void) { rep(i, MAX) { parent[i] = i; } } int root(int a) { if (parent[a] == a) { return a; } return parent[a] = root(parent[a]); } void unite(int a, int b) { parent[a] = root(b); } int main(void) { int n, m; cin >> n >> m; parinit(); rep(i, m) { int x, y, z; cin >> x >> y >> z; unite(x, y); } set<int> roots; for (int i = 1; i <= n; i++) { roots.insert(root(i)); } cout << roots.size() << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) // const bool debug=true; const bool debug = false; #define DEBUG if (debug == true) using namespace std; typedef long long ll; typedef unsigned long long ull; const ll MOD = 1000000007; const int MAX = 200005; int parent[MAX]; void parinit(void) { rep(i, MAX) { parent[i] = i; } } int root(int a) { if (parent[a] == a) { return a; } return parent[a] = root(parent[a]); } void unite(int a, int b) { parent[root(a)] = root(b); } int main(void) { int n, m; cin >> n >> m; parinit(); rep(i, m) { int x, y, z; cin >> x >> y >> z; unite(x, y); } set<int> roots; for (int i = 1; i <= n; i++) { roots.insert(root(i)); } cout << roots.size() << endl; return 0; }
[ "call.add", "call.arguments.change" ]
863,600
863,601
u076566148
cpp
p03045
#include <iostream> using namespace std; int f[100001], cnt[100001], ans, n, m; int find(int x) { if (f[x] == x) return x; return f[x] = find(f[x]); } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { f[i] = i; } for (int i = 1; i <= m; i++) { int x, y, z; cin >> x >> y >> z; f[x] = y; } for (int i = 1; i <= n; i++) { if (!cnt[find(i)]) ans++; cnt[find(i)] = 1; } cout << ans; return 0; }
#include <iostream> using namespace std; int f[100001], cnt[100001], ans, n, m; int find(int x) { if (f[x] == x) return x; return f[x] = find(f[x]); } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { f[i] = i; } for (int i = 1; i <= m; i++) { int x, y, z; cin >> x >> y >> z; f[find(x)] = find(y); } for (int i = 1; i <= n; i++) { if (!cnt[find(i)]) ans++; cnt[find(i)] = 1; } cout << ans; return 0; }
[ "call.add", "call.arguments.change" ]
863,608
863,609
u875054522
cpp
p03045
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <string> #include <vector> using namespace std; int parent[100000]; void init(int N) { for (int i = 0; i < N; i++) { parent[i] = i; } } int find(int node) { int temp = parent[node]; if (temp == node) { return temp; } else { int newParent = find(temp); parent[node] = newParent; return newParent; } } void unite(int i, int j) { int pi = find(i); int pj = find(j); if (pi != pj) { parent[i] = pj; } } int main() { int N, M; cin >> N >> M; init(N); int X, Y, Z; for (int i = 0; i < M; i++) { cin >> X >> Y >> Z; unite(X - 1, Y - 1); } int ans = 0; for (int i = 0; i < N; i++) { if (parent[i] == i) { ans++; } } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <string> #include <vector> using namespace std; int parent[100000]; void init(int N) { for (int i = 0; i < N; i++) { parent[i] = i; } } int find(int node) { int temp = parent[node]; if (temp == node) { return temp; } else { int newParent = find(temp); parent[node] = newParent; return newParent; } } void unite(int i, int j) { int pi = find(i); int pj = find(j); if (pi != pj) { parent[pi] = pj; } } int main() { int N, M; cin >> N >> M; init(N); int X, Y, Z; for (int i = 0; i < M; i++) { cin >> X >> Y >> Z; unite(X - 1, Y - 1); } int ans = 0; for (int i = 0; i < N; i++) { if (parent[i] == i) { ans++; } } cout << ans << endl; return 0; }
[ "assignment.variable.change", "identifier.change", "variable_access.subscript.index.change" ]
863,614
863,615
u048945791
cpp
p03045
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 1; vector<int> nxt[MAXN]; bool vis[MAXN]; void dfs(int v) { vis[v] = 1; for (int w : nxt[v]) if (!vis[w]) dfs(w); } int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; nxt[x].push_back(y); nxt[y].push_back(x); } int ans = 0; for (int v = 1; v <= n; v++) { if (!vis[v]) { ans++; dfs(v); } } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 1; vector<int> nxt[MAXN]; bool vis[MAXN]; void dfs(int v) { vis[v] = 1; for (int w : nxt[v]) if (!vis[w]) dfs(w); } int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int x, y, z; cin >> x >> y >> z; nxt[x].push_back(y); nxt[y].push_back(x); } int ans = 0; for (int v = 1; v <= n; v++) { if (!vis[v]) { ans++; dfs(v); } } cout << ans << "\n"; return 0; }
[ "variable_declaration.add" ]
863,616
863,617
u939951826
cpp
p03045
#include <algorithm> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int MAX_N = 200000; int N; int parent[MAX_N]; int vrank[MAX_N]; void init_union_find() { for (int i = 0; i < N; ++i) { parent[i] = i; vrank[i] = 0; } } int find(int x) { if (parent[x] == x) { return x; } else { return parent[x] = find(parent[x]); } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (vrank[x] < vrank[y]) { parent[x] = y; } else { parent[y] = x; if (vrank[x] == vrank[y]) vrank[x]++; } } bool same(int x, int y) { return find(x) == find(y); } int main() { int M; cin >> N >> M; init_union_find(); for (int i = 0; i < M; i++) { int X, Y, Z; cin >> X >> Y >> Z; unite(X - 1, Y - 1); } unordered_set<int> s; for (int i = 0; i < N; i++) { s.insert(parent[i]); } cout << s.size() << endl; return 0; }
#include <algorithm> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int MAX_N = 200000; int N; int parent[MAX_N]; int vrank[MAX_N]; void init_union_find() { for (int i = 0; i < N; ++i) { parent[i] = i; vrank[i] = 0; } } int find(int x) { if (parent[x] == x) { return x; } else { return parent[x] = find(parent[x]); } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (vrank[x] < vrank[y]) { parent[x] = y; } else { parent[y] = x; if (vrank[x] == vrank[y]) vrank[x]++; } } bool same(int x, int y) { return find(x) == find(y); } int main() { int M; cin >> N >> M; init_union_find(); for (int i = 0; i < M; i++) { int X, Y, Z; cin >> X >> Y >> Z; unite(X - 1, Y - 1); } unordered_set<int> s; for (int i = 0; i < N; i++) { s.insert(find(i)); } cout << s.size() << endl; return 0; }
[ "call.arguments.change" ]
863,628
863,629
u194385557
cpp
p03045
#include <bits/stdc++.h> #define ll long long #define fornum(A, B, C) for (A = B; A < C; A++) #define mp make_pair #define pii pair<int, int> #define pll pair<ll, ll> using namespace std; ///////////////////////////////////////////////////// ll N, M; ll i, j, k, l; ll anss[101010], ans; ll mk[101010], mkr[101010]; ll fnd(ll a) { if (mk[a] == a) return a; return mk[a] = fnd(mk[a]); } ll rfnd(ll a) { if (mkr[a] == 0) return 0; return mkr[a] = fnd(mkr[a]); } int main() { scanf("%lld%lld", &N, &M); fornum(i, 0, N) { mk[i + 1] = i + 1; } fornum(i, 0, M) { ll x, y, z; scanf("%lld%lld%lld", &x, &y, &z); mk[x] = fnd(y); } /* fornum(i,0,N){ //printf("%lld %lld\n", mk[i + 1], mkr[i + 1]); mk[rfnd(i + 1)] = fnd(i + 1); }*/ /* fornum(i,0,N){ printf("%lld %lld\n", mk[i + 1], mkr[i + 1]); }*/ fornum(i, 0, N) { ll a = fnd(i + 1); if (anss[a] == 0) { ans++; anss[a]++; } } printf("%lld", ans); return 0; }
#include <bits/stdc++.h> #define ll long long #define fornum(A, B, C) for (A = B; A < C; A++) #define mp make_pair #define pii pair<int, int> #define pll pair<ll, ll> using namespace std; ///////////////////////////////////////////////////// ll N, M; ll i, j, k, l; ll anss[101010], ans; ll mk[101010], mkr[101010]; ll fnd(ll a) { if (mk[a] == a) return a; return mk[a] = fnd(mk[a]); } ll rfnd(ll a) { if (mkr[a] == 0) return 0; return mkr[a] = fnd(mkr[a]); } int main() { scanf("%lld%lld", &N, &M); fornum(i, 0, N) { mk[i + 1] = i + 1; } fornum(i, 0, M) { ll x, y, z; scanf("%lld%lld%lld", &x, &y, &z); mk[fnd(x)] = fnd(y); } /* fornum(i,0,N){ //printf("%lld %lld\n", mk[i + 1], mkr[i + 1]); mk[rfnd(i + 1)] = fnd(i + 1); }*/ /* fornum(i,0,N){ printf("%lld %lld\n", mk[i + 1], mkr[i + 1]); }*/ fornum(i, 0, N) { ll a = fnd(i + 1); if (anss[a] == 0) { ans++; anss[a]++; } } printf("%lld", ans); return 0; }
[ "call.add", "call.arguments.change" ]
863,638
863,639
u259396003
cpp
p03045
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; #define MAX 100010 int p[MAX] = {0}; int parent(int i) { if (p[i] == i) return i; return p[i] = parent(p[i]); } int main() { int n, m; int x, y, z; cin >> n >> m; int ans = n; for (int i = 1; i <= n; i++) { p[i] = i; } for (int i = 1; i <= n; i++) { cin >> x >> y >> z; int px = parent(p[x]); int py = parent(p[y]); if (px != py) { p[px] = py; ans--; } } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; #define MAX 100010 int p[MAX] = {0}; int parent(int i) { if (p[i] == i) return i; return p[i] = parent(p[i]); } int main() { int n, m; int x, y, z; cin >> n >> m; int ans = n; for (int i = 1; i <= n; i++) { p[i] = i; } for (int i = 1; i <= m; i++) { cin >> x >> y >> z; int px = parent(p[x]); int py = parent(p[y]); if (px != py) { p[px] = py; ans--; } } cout << ans << endl; return 0; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
863,642
863,643
u249988228
cpp
p03045
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; #define lli long long int #define ulli unsigned long long int #define ld long double #define fi first #define se second #define pb push_back #define mp make_pair #define loop(i, a, b) for (lli i = a; i < b; i++) #define initialize(array, size, value) \ for (lli i = 0; i < size; i++) \ array[i] = value #define couta(array, size) \ for (lli i = 0; i < size; i++) \ cout << array[i] << " " #define vl vector<lli> #define vp vector<pair<lli, lli>> #define sl set<lli> #define msp multiset<pair<long long, long long>> S; #define pll pair<lli, lli> #define mll \ map<lli, \ lli> // for( map<lli, lli>::iterator // i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl; #define mvl map<lli, vl> #define umll unordered_map<lli, lli> #define vt vector<pair<lli, pll>> #define vf vector<pair<pll, pll>> #define qu queue<lli> #define pq priority_queue<lli> #define dq deque<lli> #define ptr vector<lli>::iterator #define bs(array, x) \ binary_search(array.begin(), array.end(), \ x) // also valid for set and multiset #define lb(array, x) lower_bound(array.begin(), array.end(), x) #define ub(array, x) upper_bound(array.begin(), array.end(), x) #define nobw(array, i, j) \ upper_bound(array.begin(), array.end(), j) - \ lower_bound(array.begin(), array.end(), \ i) // number of numbers between i & j #define vc clear() #define endl '\n' #define sp system("pause"); #define INF 9223372036854775807 #define MINF -9223372036854775808 typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; lli par[100001]; lli siz[100001]; // vector<lli>k[200000]; //if memory limit exceed try to exclude it lli find(lli a) { if (a == par[a]) return a; return find(par[a]); } void unite(lli a, lli b) { a = find(a); b = find(b); if (siz[b] > siz[a]) swap(a, b); par[b] = a; siz[a] += siz[b]; } int main() { ios::sync_with_stdio(0); cin.tie(0); lli n, m; cin >> n >> m; lli a[m][3]; for (lli i = 0; i < m; i++) { cin >> a[i][0] >> a[i][1] >> a[i][2]; } loop(i, 1, n + 1) { par[i] = i; siz[i] = 1; // k[i].push_back(i); } for (lli i = 0; i < m; i++) { unite(a[i][0], a[i][1]); } lli te[n + 1]; for (lli i = 1; i <= n; i++) te[i] = 0; // for(lli i=1;i<=n;i++)cout<<par[i]; for (lli i = 1; i <= n; i++) te[par[i]]++; lli ans = 0; for (lli i = 1; i <= n; i++) if (te[i] != 0) ans++; cout << ans; /* for(lli i=m-1;i>=0;i--){ ans.pb(ans1); if(find(a[i][0])==find(a[i][1])){continue; } ans1=ans1-(k[find(a[i][0])].size()*k[find(a[i][1])].size()); //cout<<k[find(a[i][0])].size()<<" "<<k[find(a[i][1])].size()<<endl; unite(a[i][0],a[i][1]); } reverse(ans.begin(),ans.end()); for(lli i=0;i<ans.size();i++)cout<<ans[i]<<endl; /*loop(i,0,n-1) { lli a, b; cin >> a >> b; unite(a, b); }*/ // lli t=k[find(1)].size(); // for (lli i=0;i<t;i++)cout <<k[find(1)][i]<< " "; return 0; }
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; #define lli long long int #define ulli unsigned long long int #define ld long double #define fi first #define se second #define pb push_back #define mp make_pair #define loop(i, a, b) for (lli i = a; i < b; i++) #define initialize(array, size, value) \ for (lli i = 0; i < size; i++) \ array[i] = value #define couta(array, size) \ for (lli i = 0; i < size; i++) \ cout << array[i] << " " #define vl vector<lli> #define vp vector<pair<lli, lli>> #define sl set<lli> #define msp multiset<pair<long long, long long>> S; #define pll pair<lli, lli> #define mll \ map<lli, \ lli> // for( map<lli, lli>::iterator // i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl; #define mvl map<lli, vl> #define umll unordered_map<lli, lli> #define vt vector<pair<lli, pll>> #define vf vector<pair<pll, pll>> #define qu queue<lli> #define pq priority_queue<lli> #define dq deque<lli> #define ptr vector<lli>::iterator #define bs(array, x) \ binary_search(array.begin(), array.end(), \ x) // also valid for set and multiset #define lb(array, x) lower_bound(array.begin(), array.end(), x) #define ub(array, x) upper_bound(array.begin(), array.end(), x) #define nobw(array, i, j) \ upper_bound(array.begin(), array.end(), j) - \ lower_bound(array.begin(), array.end(), \ i) // number of numbers between i & j #define vc clear() #define endl '\n' #define sp system("pause"); #define INF 9223372036854775807 #define MINF -9223372036854775808 typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; lli par[100001]; lli siz[100001]; // vector<lli>k[200000]; //if memory limit exceed try to exclude it lli find(lli a) { if (a == par[a]) return a; return find(par[a]); } void unite(lli a, lli b) { a = find(a); b = find(b); if (siz[b] > siz[a]) swap(a, b); par[b] = a; siz[a] += siz[b]; } int main() { ios::sync_with_stdio(0); cin.tie(0); lli n, m; cin >> n >> m; lli a[m][3]; for (lli i = 0; i < m; i++) { cin >> a[i][0] >> a[i][1] >> a[i][2]; } loop(i, 1, n + 1) { par[i] = i; siz[i] = 1; // k[i].push_back(i); } for (lli i = 0; i < m; i++) { unite(a[i][0], a[i][1]); } lli te[n + 1]; for (lli i = 1; i <= n; i++) te[i] = 0; // for(lli i=1;i<=n;i++)cout<<par[i]; for (lli i = 1; i <= n; i++) te[find(i)]++; lli ans = 0; for (lli i = 1; i <= n; i++) if (te[i] != 0) ans++; cout << ans; /* for(lli i=m-1;i>=0;i--){ ans.pb(ans1); if(find(a[i][0])==find(a[i][1])){continue; } ans1=ans1-(k[find(a[i][0])].size()*k[find(a[i][1])].size()); //cout<<k[find(a[i][0])].size()<<" "<<k[find(a[i][1])].size()<<endl; unite(a[i][0],a[i][1]); } reverse(ans.begin(),ans.end()); for(lli i=0;i<ans.size();i++)cout<<ans[i]<<endl; /*loop(i,0,n-1) { lli a, b; cin >> a >> b; unite(a, b); }*/ // lli t=k[find(1)].size(); // for (lli i=0;i<t;i++)cout <<k[find(1)][i]<< " "; return 0; }
[ "variable_access.subscript.index.change" ]
863,644
863,645
u774144672
cpp
p03045
#include <algorithm> #include <iostream> #include <numeric> #include <unordered_set> #include <vector> using namespace std; int par[100000]; int rnk[100000]; int find(int x) { if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) { par[i] = i; rnk[i] = 0; } int x, y, z; for (int i = 0; i < m; ++i) { cin >> x >> y >> z; --x; --y; x = find(x); y = find(y); if (x == y) continue; if (rnk[x] < rnk[y]) { par[x] = y; } else { par[y] = x; if (rnk[x] == rnk[y]) ++rnk[x]; } } unordered_set<int> ans; for (int i = 0; i < n; ++i) { ans.insert(par[i]); } cout << ans.size() << endl; }
#include <algorithm> #include <iostream> #include <numeric> #include <unordered_set> #include <vector> using namespace std; int par[100000]; int rnk[100000]; int find(int x) { if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) { par[i] = i; rnk[i] = 0; } int x, y, z; for (int i = 0; i < m; ++i) { cin >> x >> y >> z; --x; --y; x = find(x); y = find(y); if (x == y) continue; if (rnk[x] < rnk[y]) { par[x] = y; } else { par[y] = x; if (rnk[x] == rnk[y]) ++rnk[x]; } } unordered_set<int> ans; for (int i = 0; i < n; ++i) { ans.insert(find(i)); } cout << ans.size() << endl; }
[ "call.arguments.change" ]
863,646
863,647
u550574002
cpp
p03045
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> typedef long long int lli; using namespace std; typedef pair<int, int> ii; typedef priority_queue<int, vector<int>, greater<int>> heapq; // #define int long long int class UnionFindWithSize { public: UnionFindWithSize(int N) : parent(N, -1) {} void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (parent[x] > parent[y]) swap(x, y); parent[x] += parent[y]; parent[y] = x; } int find(int x) { if (parent[x] < 0) return x; return parent[x] = find(parent[x]); } int size(int x) { return -parent[find(x)]; } private: vector<int> parent; }; signed main() { int N, M; cin >> N >> M; UnionFindWithSize ufws(N); for (int i = 0; i < M; i++) { int X, Y, Z; cin >> X >> Y >> Z; ufws.unite(X, Y); } map<int, int> m; for (int i = 1; i <= N; i++) { m[ufws.find(i)]++; } cout << m.size() << endl; return 0; }
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> typedef long long int lli; using namespace std; typedef pair<int, int> ii; typedef priority_queue<int, vector<int>, greater<int>> heapq; // #define int long long int class UnionFindWithSize { public: UnionFindWithSize(int N) : parent(N, -1) {} void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (parent[x] > parent[y]) swap(x, y); parent[x] += parent[y]; parent[y] = x; } int find(int x) { if (parent[x] < 0) return x; return parent[x] = find(parent[x]); } int size(int x) { return -parent[find(x)]; } private: vector<int> parent; }; signed main() { int N, M; cin >> N >> M; UnionFindWithSize ufws(N); for (int i = 0; i < M; i++) { int X, Y, Z; cin >> X >> Y >> Z; ufws.unite(X - 1, Y - 1); } map<int, int> m; for (int i = 0; i < N; i++) { m[ufws.find(i)]++; } cout << m.size() << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
863,648
863,649
u576106056
cpp
p03045
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mod = (int)1e9 + 7; const int INF = (int)100100100; struct UnionFind { vector<int> par; UnionFind(int N) : par(N) { for (int i = 0; i < N; i++) par[i] = i; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; par[rx] = ry; } bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } }; int main() { // ll N; cin >> N; ll N, M; cin >> N >> M; // string S; cin >> S; // ll H,W; cin >> H >> W; UnionFind tree(N); for (int i = 0; i < N; i++) { int x, y, z; cin >> x >> y >> z; tree.unite(x - 1, y - 1); } ll sum = 1; for (int i = 0; i < N; i++) { if (!tree.same(0, i)) { tree.unite(0, i); sum++; } } cout << sum << endl; } /* */
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mod = (int)1e9 + 7; const int INF = (int)100100100; struct UnionFind { vector<int> par; UnionFind(int N) : par(N) { for (int i = 0; i < N; i++) par[i] = i; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; par[rx] = ry; } bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } }; int main() { // ll N; cin >> N; ll N, M; cin >> N >> M; // string S; cin >> S; // ll H,W; cin >> H >> W; UnionFind tree(N); for (int i = 0; i < M; i++) { int x, y, z; cin >> x >> y >> z; tree.unite(x - 1, y - 1); } ll sum = 1; for (int i = 0; i < N; i++) { if (!tree.same(0, i)) { tree.unite(0, i); sum++; } } cout << sum << endl; } /* */
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
863,652
863,653
u593555034
cpp
p03045
#include <bits/stdc++.h> using namespace std; typedef vector<int> vi; const int maxn = 2e5 + 2; int n, m; struct UF { int sz; vi r, p; UF(int n) : r(n, 0), p(n, 0), sz(n) { iota(p.begin(), p.end(), 0); } int f(int x) { return (p[x] == x ? x : p[x] = f(p[x])); } void u(int i, int j) { int x = f(i), y = f(j); if (x == y) return; --sz; if (r[x] >= r[y]) { p[y] = x; if (r[x] == r[y]) r[x]++; } else p[x] = y; } bool s(int i, int j) { return f(i) == f(j); } }; int main() { cin >> n >> m; UF uf(n); for (int i = 0, x, y, z; i < n; ++i) { cin >> x >> y >> z; uf.u(x - 1, y - 1); } cout << uf.sz; }
#include <bits/stdc++.h> using namespace std; typedef vector<int> vi; const int maxn = 2e5 + 2; int n, m; struct UF { int sz; vi r, p; UF(int n) : r(n, 0), p(n, 0), sz(n) { iota(p.begin(), p.end(), 0); } int f(int x) { return (p[x] == x ? x : p[x] = f(p[x])); } void u(int i, int j) { int x = f(i), y = f(j); if (x == y) return; --sz; if (r[x] >= r[y]) { p[y] = x; if (r[x] == r[y]) r[x]++; } else p[x] = y; } bool s(int i, int j) { return f(i) == f(j); } }; int main() { cin >> n >> m; UF uf(n); for (int i = 0, x, y, z; i < m; ++i) { cin >> x >> y >> z; uf.u(x - 1, y - 1); } cout << uf.sz; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
863,658
863,659
u884136989
cpp
p03045
#include <algorithm> #include <cmath> #include <cstdlib> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <tuple> #include <vector> using namespace std; const long long mod = 1e9 + 7; const long long INF = 1LL << 60; int par[100010]; int urank[100010]; void init(int n) { for (int i = 0; i < n; i++) { par[i] = i; urank[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 (urank[x] < urank[y]) par[x] = y; else { par[y] = x; if (urank[x] == urank[y]) urank[x]++; } } bool same(int x, int y) { return find(x) == find(y); } int main() { int n, m; cin >> n >> m; vector<int> x(m), y(m), z(m); init(n); for (int i = 0; i < m; i++) { cin >> x[i] >> y[i] >> z[i]; x[i]--; y[i]--; unite(x[i], y[i]); } set<int> st; for (int i = 0; i < n; i++) { st.insert(par[i]); } cout << st.size() << endl; }
#include <algorithm> #include <cmath> #include <cstdlib> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <tuple> #include <vector> using namespace std; const long long mod = 1e9 + 7; const long long INF = 1LL << 60; int par[100010]; int urank[100010]; void init(int n) { for (int i = 0; i < n; i++) { par[i] = i; urank[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 (urank[x] < urank[y]) par[x] = y; else { par[y] = x; if (urank[x] == urank[y]) urank[x]++; } } bool same(int x, int y) { return find(x) == find(y); } int main() { int n, m; cin >> n >> m; vector<int> x(m), y(m), z(m); init(n); for (int i = 0; i < m; i++) { cin >> x[i] >> y[i] >> z[i]; x[i]--; y[i]--; unite(x[i], y[i]); } set<int> st; for (int i = 0; i < n; i++) { st.insert(find(i)); } cout << st.size() << endl; }
[ "call.arguments.change" ]
863,662
863,663
u553605501
cpp
p03045
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; struct unionfind { vector<int> par, rank; unionfind(int x) { par.resize(x); rank.resize(x); for (int i = 0; i < x; i++) par[i] = i, rank[i] = 0; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void uni(int x, int y) { x = root(x), y = root(y); if (x == y) return; if (rank[x] < rank[y]) par[x] = y; else { par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } bool same(int x, int y) { return root(x) == root(y); } }; int main() { int n, m; cin >> n >> m; unionfind uf(n); for (int i = 0; i < m; i++) { int x, y, z; cin >> x >> y >> z; uf.uni(x - 1, y - 1); } int ans; for (int i = 0; i < n; i++) { if (uf.par[i] == i) ans++; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; struct unionfind { vector<int> par, rank; unionfind(int x) { par.resize(x); rank.resize(x); for (int i = 0; i < x; i++) par[i] = i, rank[i] = 0; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void uni(int x, int y) { x = root(x), y = root(y); if (x == y) return; if (rank[x] < rank[y]) par[x] = y; else { par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } bool same(int x, int y) { return root(x) == root(y); } }; int main() { int n, m; cin >> n >> m; unionfind uf(n); for (int i = 0; i < m; i++) { int x, y, z; cin >> x >> y >> z; uf.uni(x - 1, y - 1); } int ans = 0; for (int i = 0; i < n; i++) { if (uf.par[i] == i) ans++; } cout << ans; return 0; }
[ "variable_declaration.value.change" ]
863,677
863,678
u129667379
cpp
p03045
#include <bits/stdc++.h> using namespace std; using pint = pair<int, int>; using ll = long long; using pll = pair<ll, ll>; #define FOR(i, begin, end) \ for (int i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define FI first #define SE second #define endl "\n" #define ciosup \ cin.tie(0); \ ios::sync_with_stdio(false); #define eb emplace_back constexpr ll INF = 1e9 + 7; constexpr ll MOD = 1e9 + 7; struct UnionFind { vector<int> par, rank; UnionFind(int N) : par(N), rank(N) { REP(i, N) { par[i] = i; // the parent of the node rank[i] = 0; // the rank of the tree } } int find(int x) { // Find the root of x if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } void unite(int x, int y) { // Unite (the set of x) and (the set of y) x = find(x); y = find(y); if (x == y) return; if (rank[x] < rank[y]) { // larger rank is above par[x] = y; } else { par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } bool same(int x, int y) { return find(x) == find(y); } }; int main() { int n, m; cin >> n >> m; UnionFind gp(n); int x[m], y[m], z[m]; REP(i, m) { int a, b, c; cin >> a >> b >> c; x[i] = a - 1; y[i] = b - 1; z[i] = c % 2; } REP(i, m) { gp.unite(x[i], y[i]); } set<int> parset; REP(i, n) { parset.insert(gp.par[i]); } cout << parset.size() << endl; }
#include <bits/stdc++.h> using namespace std; using pint = pair<int, int>; using ll = long long; using pll = pair<ll, ll>; #define FOR(i, begin, end) \ for (int i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define FI first #define SE second #define endl "\n" #define ciosup \ cin.tie(0); \ ios::sync_with_stdio(false); #define eb emplace_back constexpr ll INF = 1e9 + 7; constexpr ll MOD = 1e9 + 7; struct UnionFind { vector<int> par, rank; UnionFind(int N) : par(N), rank(N) { REP(i, N) { par[i] = i; // the parent of the node rank[i] = 0; // the rank of the tree } } int find(int x) { // Find the root of x if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } void unite(int x, int y) { // Unite (the set of x) and (the set of y) x = find(x); y = find(y); if (x == y) return; if (rank[x] < rank[y]) { // larger rank is above par[x] = y; } else { par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } bool same(int x, int y) { return find(x) == find(y); } }; int main() { int n, m; cin >> n >> m; UnionFind gp(n); int x[m], y[m], z[m]; REP(i, m) { int a, b, c; cin >> a >> b >> c; x[i] = a - 1; y[i] = b - 1; z[i] = c % 2; } REP(i, m) { gp.unite(x[i], y[i]); } set<int> parset; REP(i, n) { parset.insert(gp.find(i)); } cout << parset.size() << endl; }
[ "call.arguments.change" ]
863,681
863,682
u337054478
cpp
p03045
#include <bits/stdc++.h> using namespace std; using pint = pair<int, int>; using ll = long long; using pll = pair<ll, ll>; #define FOR(i, begin, end) \ for (int i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define FI first #define SE second #define endl "\n" #define ciosup \ cin.tie(0); \ ios::sync_with_stdio(false); #define eb emplace_back constexpr ll INF = 1e9 + 7; constexpr ll MOD = 1e9 + 7; struct UnionFind { vector<int> par, rank; UnionFind(int N) : par(N), rank(N) { REP(i, N) { par[i] = i; // the parent of the node rank[i] = 0; // the rank of the tree } } int find(int x) { // Find the root of x if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } void unite(int x, int y) { // Unite (the set of x) and (the set of y) x = find(x), y = find(y); if (x == y) return; if (rank[x] < rank[y]) { // larger rank is above par[x] = y; } else { par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } bool same(int x, int y) { return find(x) == find(y); } }; int main() { int n, m; cin >> n >> m; UnionFind gp(n); int x[m], y[m], z[m]; REP(i, m) { int a, b, c; cin >> a >> b >> c; x[i] = a - 1; y[i] = b - 1; z[i] = c % 2; } REP(i, m) { gp.unite(x[i], y[i]); } set<int> parset; REP(i, n) { // cout << "par " << gp.par[i] << endl; parset.insert(gp.par[i]); } cout << parset.size() << endl; }
#include <bits/stdc++.h> using namespace std; using pint = pair<int, int>; using ll = long long; using pll = pair<ll, ll>; #define FOR(i, begin, end) \ for (int i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define FI first #define SE second #define endl "\n" #define ciosup \ cin.tie(0); \ ios::sync_with_stdio(false); #define eb emplace_back constexpr ll INF = 1e9 + 7; constexpr ll MOD = 1e9 + 7; struct UnionFind { vector<int> par, rank; UnionFind(int N) : par(N), rank(N) { REP(i, N) { par[i] = i; // the parent of the node rank[i] = 0; // the rank of the tree } } int find(int x) { // Find the root of x if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } void unite(int x, int y) { // Unite (the set of x) and (the set of y) x = find(x); y = find(y); if (x == y) return; if (rank[x] < rank[y]) { // larger rank is above par[x] = y; } else { par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } bool same(int x, int y) { return find(x) == find(y); } }; int main() { int n, m; cin >> n >> m; UnionFind gp(n); int x[m], y[m], z[m]; REP(i, m) { int a, b, c; cin >> a >> b >> c; x[i] = a - 1; y[i] = b - 1; z[i] = c % 2; } REP(i, m) { gp.unite(x[i], y[i]); } set<int> parset; REP(i, n) { parset.insert(gp.find(i)); } cout << parset.size() << endl; }
[ "call.arguments.change" ]
863,683
863,682
u337054478
cpp
p03045
#include <bits/stdc++.h> #define X first #define Y second #define pb emplace_back #define FOR(i, a, b) for (int(i) = (a); i < (b); ++(i)) #define EFOR(i, a, b) for (int(i) = (a); i <= (b); ++(i)) #define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X)) #define REP rep #define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X)) #define all(X) (X).begin(), (X).end() #define eb emplace_back using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef ll LL; typedef pii PII; typedef pll PLL; const ll MOD = 1e9 + 7; #define rall(X) (X).rbegin(), (X).rend() #define UNIQUE(X) (X).erase(unique(all(X)), (X).end()) #define reps(X, S, Y) for (int(X) = S; (X) < (Y); ++(X)) #define rreps(X, S, Y) for (int(X) = (Y)-1; (X) >= (S); --(X)) template <class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; } template <class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; } int N; int M; bool used[114514]; vector<int> es[114514]; void dfs(int v) { used[v] = true; for (int u : es[v]) { if (used[u]) continue; dfs(u); } } signed main() { ios_base::sync_with_stdio(false); cout << fixed << setprecision(0); cin >> N >> M; rep(i, M) { int u, v; cin >> u >> v; --u; --v; es[u].eb(v); es[v].eb(u); } int ans = 0; rep(v, N) { if (!used[v]) { ans++; dfs(v); } } cout << ans << endl; }
#include <bits/stdc++.h> #define X first #define Y second #define pb emplace_back #define FOR(i, a, b) for (int(i) = (a); i < (b); ++(i)) #define EFOR(i, a, b) for (int(i) = (a); i <= (b); ++(i)) #define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X)) #define REP rep #define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X)) #define all(X) (X).begin(), (X).end() #define eb emplace_back using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef ll LL; typedef pii PII; typedef pll PLL; const ll MOD = 1e9 + 7; #define rall(X) (X).rbegin(), (X).rend() #define UNIQUE(X) (X).erase(unique(all(X)), (X).end()) #define reps(X, S, Y) for (int(X) = S; (X) < (Y); ++(X)) #define rreps(X, S, Y) for (int(X) = (Y)-1; (X) >= (S); --(X)) template <class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; } template <class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; } int N; int M; bool used[114514]; vector<int> es[114514]; void dfs(int v) { used[v] = true; for (int u : es[v]) { if (used[u]) continue; dfs(u); } } signed main() { ios_base::sync_with_stdio(false); cout << fixed << setprecision(0); cin >> N >> M; rep(i, M) { int u, v; int z; cin >> u >> v >> z; --u; --v; es[u].eb(v); es[v].eb(u); } int ans = 0; rep(v, N) { if (!used[v]) { ans++; dfs(v); } } cout << ans << endl; }
[ "variable_declaration.add" ]
863,684
863,685
u756607506
cpp
p03045
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define mod 1000000007 #define INF 1000000000000000000 typedef long long ll; vector<int> uni(100010, -1); int root(int a) { if (uni[a < 0]) return a; return uni[a] = root(uni[a]); } bool connect(int a, int b) { a = root(a); b = root(b); if (a == b) return false; if (uni[a] > uni[b]) swap(a, b); uni[a] += uni[b]; uni[b] = a; return true; } int main() { int n, m; cin >> n >> m; int x, y, z; rep(i, m) { cin >> x >> y >> z; x--; y--; connect(x, y); } int count = 0; rep(i, n) { if (uni[i] < 0) count++; } cout << count; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define mod 1000000007 #define INF 1000000000000000000 typedef long long ll; vector<int> uni(100010, -1); int root(int a) { if (uni[a] < 0) return a; return uni[a] = root(uni[a]); } bool connect(int a, int b) { a = root(a); b = root(b); if (a == b) return false; if (uni[a] > uni[b]) swap(a, b); uni[a] += uni[b]; uni[b] = a; return true; } int main() { int n, m; cin >> n >> m; int x, y, z; rep(i, m) { cin >> x >> y >> z; x--; y--; connect(x, y); } int count = 0; rep(i, n) if (uni[i] < 0) count++; cout << count; }
[ "control_flow.branch.if.condition.change" ]
863,688
863,689
u503870829
cpp
p03045
#include <algorithm> #include <cstdio> #include <iostream> #include <stdlib.h> #include <string.h> #include <string> using namespace std; #define MAX_N 200000 class union_find { private: int par[MAX_N]; int tree_rank[MAX_N]; int set_num; public: union_find(int n); // const int find(int x); void unite(int x, int y); bool same(int x, int y); int get_number_of_cluster(); int *get_par(); int *get_tree_rank(); }; union_find::union_find(int n) { set_num = n; for (int i = 0; i < n; i++) { par[i] = i; tree_rank[i] = 0; } } 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; if (tree_rank[x] < tree_rank[y]) { par[x] = y; } else { par[y] = x; if (tree_rank[x] == tree_rank[y]) tree_rank[x]++; } } bool union_find::same(int x, int y) { return find(x) == find(y); } int union_find::get_number_of_cluster() { int *memo = (int *)malloc(set_num * sizeof(int)); memset(memo, 0, set_num * sizeof(int)); int ret = 0; for (int i = 0; i < set_num; i++) { if (memo[par[i]] == 0) { ret++; memo[par[i]] = 1; } } free(memo); return ret; } int *union_find::get_par() { return par; } int *union_find::get_tree_rank() { return tree_rank; } int main() { int N, M, x, y, z; scanf("%d %d", &N, &M); union_find number_set(N); for (int i = 0; i < M; i++) { scanf("%d %d %d", &x, &y, &z); if (!number_set.same(x - 1, y - 1)) { number_set.unite(x - 1, y - 1); } } printf("%d\r\n", number_set.get_number_of_cluster()); fflush(stdout); }
#include <algorithm> #include <cstdio> #include <iostream> #include <stdlib.h> #include <string.h> #include <string> using namespace std; #define MAX_N 200000 class union_find { private: int par[MAX_N]; int tree_rank[MAX_N]; int set_num; public: union_find(int n); // const int find(int x); void unite(int x, int y); bool same(int x, int y); int get_number_of_cluster(); int *get_par(); int *get_tree_rank(); }; union_find::union_find(int n) { set_num = n; for (int i = 0; i < n; i++) { par[i] = i; tree_rank[i] = 0; } } 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; if (tree_rank[x] < tree_rank[y]) { par[x] = y; } else { par[y] = x; if (tree_rank[x] == tree_rank[y]) tree_rank[x]++; } } bool union_find::same(int x, int y) { return find(x) == find(y); } int union_find::get_number_of_cluster() { int *memo = (int *)malloc(set_num * sizeof(int)); memset(memo, 0, set_num * sizeof(int)); int ret = 0; for (int i = 0; i < set_num; i++) { if (memo[find(i)] == 0) { ret++; memo[find(i)] = 1; } } free(memo); return ret; } int *union_find::get_par() { return par; } int *union_find::get_tree_rank() { return tree_rank; } int main() { int N, M, x, y, z; scanf("%d %d", &N, &M); union_find number_set(N); for (int i = 0; i < M; i++) { scanf("%d %d %d", &x, &y, &z); if (!number_set.same(x - 1, y - 1)) { number_set.unite(x - 1, y - 1); } } printf("%d\r\n", number_set.get_number_of_cluster()); fflush(stdout); }
[ "control_flow.loop.for.condition.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change", "assignment.variable.change" ]
863,694
863,695
u594244257
cpp
p03045
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <set> #include <string> #include <vector> using namespace std; using ll = long long; const ll MOD = 1000000007; #define rep(i, a, b) for (ll i = a; i < b; i++) #define range(i) (i).begin(), (i).end() #define rrange(i) (i).rbegin(), (i).rend() inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } inline constexpr int intpow(ll a, ll b) { if (b == 0) return 1; ll ans = intpow(a, b / 2); return ans * ans * (b & 1 ? a : 1); } inline constexpr int modpow(ll a, ll b) { if (b == 0) return 1; ll ans = intpow(a, b / 2); return ans * ans % MOD * (b & 1 ? a : 1) % MOD; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll LINF = 0x1fffffffffffffff; struct unionfind { vector<ll> d; unionfind(ll x) : d(x, -1) {} ll root(ll x) { return d[x] < 0 ? x : d[x] = root(d[x]); } ll size(ll x) { return -d[root(x)]; }; bool unite(ll x, ll y) { x = root(x), y = root(y); if (x != y) { if (d[x] > d[y]) swap(x, y); d[x] += d[y]; d[y] = x; } return x != y; } bool find(ll x, ll y) { return root(x) == root(y); } }; int main() { ll n, m; cin >> n >> m; unionfind uf(n); ll ans = n; rep(i, 0, m) { ll x, y, z; cin >> x, y, z; ans -= uf.unite(x - 1, y - 1); } cout << ans; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <set> #include <string> #include <vector> using namespace std; using ll = long long; const ll MOD = 1000000007; #define rep(i, a, b) for (ll i = a; i < b; i++) #define range(i) (i).begin(), (i).end() #define rrange(i) (i).rbegin(), (i).rend() inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } inline constexpr int intpow(ll a, ll b) { if (b == 0) return 1; ll ans = intpow(a, b / 2); return ans * ans * (b & 1 ? a : 1); } inline constexpr int modpow(ll a, ll b) { if (b == 0) return 1; ll ans = intpow(a, b / 2); return ans * ans % MOD * (b & 1 ? a : 1) % MOD; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll LINF = 0x1fffffffffffffff; struct unionfind { vector<ll> d; unionfind(ll x) : d(x, -1) {} ll root(ll x) { return d[x] < 0 ? x : d[x] = root(d[x]); } ll size(ll x) { return -d[root(x)]; }; bool unite(ll x, ll y) { x = root(x), y = root(y); if (x != y) { if (d[x] > d[y]) swap(x, y); d[x] += d[y]; d[y] = x; } return x != y; } bool find(ll x, ll y) { return root(x) == root(y); } }; int main() { ll n, m; cin >> n >> m; unionfind uf(n); ll ans = n; rep(i, 0, m) { ll x, y, z; cin >> x >> y >> z; ans -= uf.unite(x - 1, y - 1); } cout << ans; }
[]
863,698
863,699
u356489231
cpp
p03045
#include <algorithm> #include <iostream> #include <vector> using namespace std; class unionFind { int nodeSize; vector<int> parent; public: unionFind(int n) : nodeSize(n) { parent = vector<int>(n + 1, -1); } int getRoot(int a) { if (parent[a] < 0) { return a; } return parent[a] = getRoot(a); } bool isSameParent(int a, int b) { return getRoot(a) == getRoot(b); } bool isRoot(int a) { if (parent[a] < 0) { return true; } return false; } void unite(int a, int b) { if (isSameParent(a, b)) { return; } int aParent = getRoot(a); int bParent = getRoot(b); if (abs(parent[aParent]) > abs(parent[bParent])) { parent[aParent] += parent[bParent]; parent[bParent] = aParent; } else { parent[bParent] += parent[bParent]; parent[aParent] = bParent; } } }; int main() { int n, m; cin >> n >> m; vector<int> x(m), y(m), z(m); for (int i = 0; i < m; i++) { cin >> x[i] >> y[i] >> z[i]; } unionFind uf(n); for (int i = 0; i < m; i++) { uf.unite(x[i], y[i]); } int ans = 0; for (int i = 1; i <= n; i++) { if (uf.isRoot(i)) { ans++; } } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; class unionFind { int nodeSize; vector<int> parent; public: unionFind(int n) : nodeSize(n) { parent = vector<int>(n + 1, -1); } int getRoot(int a) { if (parent[a] < 0) { return a; } return parent[a] = getRoot(parent[a]); } bool isSameParent(int a, int b) { return getRoot(a) == getRoot(b); } bool isRoot(int a) { if (parent[a] < 0) { return true; } return false; } void unite(int a, int b) { if (isSameParent(a, b)) { return; } int aParent = getRoot(a); int bParent = getRoot(b); if (abs(parent[aParent]) > abs(parent[bParent])) { parent[aParent] += parent[bParent]; parent[bParent] = aParent; } else { parent[bParent] += parent[aParent]; parent[aParent] = bParent; } } }; int main() { int n, m; cin >> n >> m; vector<int> x(m), y(m), z(m); for (int i = 0; i < m; i++) { cin >> x[i] >> y[i] >> z[i]; } unionFind uf(n); for (int i = 0; i < m; i++) { uf.unite(x[i], y[i]); } int ans = 0; for (int i = 1; i <= n; i++) { if (uf.isRoot(i)) { ans++; } } cout << ans << endl; return 0; }
[ "call.arguments.change", "function.return_value.change", "assignment.value.change", "identifier.change", "variable_access.subscript.index.change" ]
863,704
863,703
u369508054
cpp
p03045
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; int N, M; vector<int> adj[MAXN]; bool vis[MAXN]; void dfs(int cur) { if (vis[cur]) return; vis[cur] = true; for (int nxt : adj[cur]) { dfs(nxt); } } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> N >> M; for (int i = 0; i < M; i++) { int a, b, dummy; cin >> a >> b >> dummy; adj[a].push_back(b); adj[b].push_back(b); } int nComps = 0; for (int i = 1; i <= N; i++) { if (vis[i]) continue; nComps++; dfs(i); } cout << nComps << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; int N, M; vector<int> adj[MAXN]; bool vis[MAXN]; void dfs(int cur) { if (vis[cur]) return; vis[cur] = true; for (int nxt : adj[cur]) { dfs(nxt); } } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> N >> M; for (int i = 0; i < M; i++) { int a, b, dummy; cin >> a >> b >> dummy; adj[a].push_back(b); adj[b].push_back(a); } int nComps = 0; for (int i = 1; i <= N; i++) { if (vis[i]) continue; nComps++; dfs(i); } cout << nComps << endl; return 0; }
[ "identifier.change", "call.arguments.change" ]
863,705
863,706
u242534780
cpp
p03045
#include <algorithm> #include <cmath> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < n; i++) #define RREP(i, n) for (int i = n - 1; i >= 0; i--) #define ALL(v) v.begin(), v.end() #define pb push_back #define mp make_pair #define F first #define S second #define UNIQUE(v) \ do { \ sort(v.begin(), v.end()); \ v.erase(unique(v.begin(), v.end()), v.end()); \ } while (0) #define y0 y3487465 #define y1 y8687969 #define m0(x) memset(x, 0, sizeof(x)) #define m1(x) memset(x, 63, sizeof(x)) typedef long long ll; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pi> vpi; typedef vector<ll> vll; typedef vector<vll> vvll; double EPS = 1e-9; int INFi = 1000000005; long long INFll = 1000000000000000005ll; double PI = acos(-1); int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1}; ll MOD = 1000000007; ll N, M; const int MAX_M = 100000; ll X[MAX_M], Y[MAX_M], Z[MAX_M]; const int MAX_N = 100000; int par[MAX_N]; int depth[MAX_N]; void init(int n) { for (int i = 0; i < n; i++) { par[i] = i; depth[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 (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 find(x) == find(y); } int main() { cin >> N >> M; REP(i, M) cin >> X[i] >> Y[i] >> Z[i]; init(N); REP(i, M) { unite(X[i] - 1, Y[i] - 1); } set<int> s; REP(i, N) { s.insert(par[i]); } cout << s.size() << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < n; i++) #define RREP(i, n) for (int i = n - 1; i >= 0; i--) #define ALL(v) v.begin(), v.end() #define pb push_back #define mp make_pair #define F first #define S second #define UNIQUE(v) \ do { \ sort(v.begin(), v.end()); \ v.erase(unique(v.begin(), v.end()), v.end()); \ } while (0) #define y0 y3487465 #define y1 y8687969 #define m0(x) memset(x, 0, sizeof(x)) #define m1(x) memset(x, 63, sizeof(x)) typedef long long ll; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pi> vpi; typedef vector<ll> vll; typedef vector<vll> vvll; double EPS = 1e-9; int INFi = 1000000005; long long INFll = 1000000000000000005ll; double PI = acos(-1); int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1}; ll MOD = 1000000007; ll N, M; const int MAX_M = 100000; ll X[MAX_M], Y[MAX_M], Z[MAX_M]; const int MAX_N = 100000; int par[MAX_N]; int depth[MAX_N]; void init(int n) { for (int i = 0; i < n; i++) { par[i] = i; depth[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 (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 find(x) == find(y); } int main() { cin >> N >> M; REP(i, M) cin >> X[i] >> Y[i] >> Z[i]; init(N); REP(i, M) { unite(X[i] - 1, Y[i] - 1); } set<int> s; REP(i, N) { s.insert(find(i)); } cout << s.size() << endl; return 0; }
[ "call.arguments.change" ]
863,707
863,708
u505831576
cpp
p03045
#include <iostream> #include <map> #include <vector> using namespace std; struct UnionFind { vector<int> data; UnionFind(int sz) { data.assign(sz, -1); } bool unite(int x, int y) { x = find(x), y = find(y); if (x == y) return (false); if (data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return (true); } int find(int k) { if (data[k] < 0) return (k); return (data[k] = find(data[k])); } int size(int k) { return (-data[find(k)]); } }; int main() { int n, m; cin >> n >> m; UnionFind uf(n); for (int i = 0; i < m; i++) { int x, y, z; cin >> x >> y >> z; uf.unite(x, y); } map<int, bool> appeared; int ans = 0; for (int i = 0; i < n; i++) { if (!appeared[uf.find(i)]) { appeared[uf.find(i)] = true; ans++; } } cout << ans << endl; }
#include <iostream> #include <map> #include <vector> using namespace std; struct UnionFind { vector<int> data; UnionFind(int sz) { data.assign(sz, -1); } bool unite(int x, int y) { x = find(x), y = find(y); if (x == y) return (false); if (data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return (true); } int find(int k) { if (data[k] < 0) return (k); return (data[k] = find(data[k])); } int size(int k) { return (-data[find(k)]); } }; int main() { int n, m; cin >> n >> m; UnionFind uf(n); for (int i = 0; i < m; i++) { int x, y, z; cin >> x >> y >> z; uf.unite(x - 1, y - 1); } map<int, bool> appeared; int ans = 0; for (int i = 0; i < n; i++) { if (!appeared[uf.find(i)]) { appeared[uf.find(i)] = true; ans++; } } cout << ans << endl; }
[ "expression.operation.binary.add" ]
863,715
863,716
u672765904
cpp
p03043
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; double s = 0; for (int i = 1; i < N; i++) { double ss = 1; int b = i; while (b < K) { ss /= 2; b *= 2; } s += ss; } s /= N; cout << fixed << setprecision(10) << s << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; double s = 0; for (int i = 1; i < N + 1; i++) { double ss = 1; int b = i; while (b < K) { ss /= 2; b *= 2; } s += ss; } s /= N; cout << fixed << setprecision(10) << s << endl; }
[ "control_flow.loop.for.condition.change", "misc.off_by_one" ]
863,727
863,728
u973991908
cpp
p03043
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; double s = 0; for (int i = 1; i < N; i++) { double ss = 1; int b = i; while (b < K) { ss /= 2; b *= 2; } s += ss; } s /= 3; cout << fixed << setprecision(10) << s << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; double s = 0; for (int i = 1; i < N + 1; i++) { double ss = 1; int b = i; while (b < K) { ss /= 2; b *= 2; } s += ss; } s /= N; cout << fixed << setprecision(10) << s << endl; }
[ "control_flow.loop.for.condition.change", "misc.off_by_one", "assignment.value.change", "identifier.replace.add", "literal.replace.remove" ]
863,729
863,728
u973991908
cpp
p03043
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; double s = 0; for (int i = 1; i < N + 1; i++) { double ss = 1; int b = i; while (b < K) { ss /= 2; b *= 2; } s += ss; } s /= 3; cout << fixed << setprecision(10) << s << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; double s = 0; for (int i = 1; i < N + 1; i++) { double ss = 1; int b = i; while (b < K) { ss /= 2; b *= 2; } s += ss; } s /= N; cout << fixed << setprecision(10) << s << endl; }
[ "assignment.value.change", "identifier.replace.add", "literal.replace.remove" ]
863,730
863,728
u973991908
cpp
p03043
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define mp(a, b) make_pair(a, b) #define pb(a) push_back(a) #define boost \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define check(x) cout << #x << " : " << (x) << endl #define inf LLONG_MAX #define all(v) v.begin(), v.end() #define allr(v) v.rbegin(), v.rend() //#define endl '\n' #define mod 998244353 typedef long long ll; typedef unsigned long long ull; // using u64 = uint64_t; // using u128 = __uint128_t; typedef vector<ll> edge; typedef pair<ll, bool> mypair; typedef priority_queue<ll> max_heap; typedef priority_queue<ll, vector<ll>, greater<ll>> min_heap; const ll N = 1e5 + 20; int main() { boost; std::vector<double> po(32); po[0] = 1; for (ll i = 1; i < 32; i++) po[i] = po[i - 1] * 2; double ans = 0; ll n, k; cin >> n >> k; for (ll i = 1; i <= n; i++) { ans += ((double)1 / (*lower_bound(all(po), k / i))); } ans /= n; cout << fixed << setprecision(15) << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define mp(a, b) make_pair(a, b) #define pb(a) push_back(a) #define boost \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define check(x) cout << #x << " : " << (x) << endl #define inf LLONG_MAX #define all(v) v.begin(), v.end() #define allr(v) v.rbegin(), v.rend() //#define endl '\n' #define mod 998244353 typedef long long ll; typedef unsigned long long ull; // using u64 = uint64_t; // using u128 = __uint128_t; typedef vector<ll> edge; typedef pair<ll, bool> mypair; typedef priority_queue<ll> max_heap; typedef priority_queue<ll, vector<ll>, greater<ll>> min_heap; const ll N = 1e5 + 20; int main() { boost; std::vector<double> po(32); po[0] = 1; for (ll i = 1; i < 32; i++) po[i] = po[i - 1] * 2; double ans = 0; ll n, k; cin >> n >> k; for (ll i = 1; i <= n; i++) { ans += ((double)1 / (*lower_bound(all(po), (double)k / (double)i))); } ans /= n; cout << fixed << setprecision(15) << ans << endl; return 0; }
[ "type_conversion.add" ]
863,738
863,739
u202858603
cpp
p03043
#include <bits/stdc++.h> using namespace std; int main() { int n, k, now; double ans = 0.0; double one_n, temp; cin >> n >> k; one_n = 1.0 / n; for (int i = 1; i <= n; i++) { now = i; temp = one_n; while (now < k) { now *= 2.0; temp /= 2.0; } ans += temp; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k, now; double ans = 0.0; double one_n, temp; cin >> n >> k; one_n = 1.0 / n; for (int i = 1; i <= n; i++) { now = i; temp = one_n; while (now < k) { now *= 2.0; temp /= 2.0; } ans += temp; } cout << setprecision(15) << ans << endl; }
[ "io.output.change" ]
863,740
863,741
u745852541
cpp
p03043
#include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; using ll = long long; const int INF = 999999999; int main() { int N, K; cin >> N >> K; double ans = 0; for (int i = 1; i <= K; ++i) { double p = 1; int x = i; while (x < K) { x *= 2; p *= 0.5; } ans += p / N; } printf("%.9f\n", ans); }
#include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; using ll = long long; const int INF = 999999999; int main() { int N, K; cin >> N >> K; double ans = 0; for (int i = 1; i <= N; ++i) { double p = 1; int x = i; while (x < K) { x *= 2; p *= 0.5; } ans += p / N; } printf("%.9f\n", ans); }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
863,742
863,743
u239023686
cpp
p03043
#define _USE_MATH_DEFINES #include <algorithm> #include <cmath> #include <iostream> #include <map> #include <memory.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <vector> #define fio \ ios::sync_with_stdio(false); \ cin.tie(NULL); using namespace std; typedef long long ll; typedef pair<int, int> pii; /* int func(int x) { int i = 0; for (; x >> i; i++); int comp = 1 << (i-1); if (comp == x) return x; return comp << 1; } */ int n, k, dp[100'005] = { 1, }; double ans = 0; int func(int x) { int left = 0, right = 30; int res = 0; while (left <= right) { int mid = left + right >> 1; if (k < dp[mid] * x) { res = dp[mid]; right = mid - 1; } else { left = mid + 1; } } return res; } int main(void) { for (int i = 1; i <= 10000; i++) { dp[i] = dp[i - 1] * 2; } scanf("%d %d", &n, &k); for (int i = 1; i <= n; i++) { if (k <= i) ans += 1.0 / n; else ans += 1.0 / (n * func(i)); } printf("%.10lf\n", ans); return 0; }
#define _USE_MATH_DEFINES #include <algorithm> #include <cmath> #include <iostream> #include <map> #include <memory.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <vector> #define fio \ ios::sync_with_stdio(false); \ cin.tie(NULL); using namespace std; typedef long long ll; typedef pair<int, int> pii; /* int func(int x) { int i = 0; for (; x >> i; i++); int comp = 1 << (i-1); if (comp == x) return x; return comp << 1; } */ int n, k, dp[100'005] = { 1, }; double ans = 0; int func(int x) { int left = 0, right = 30; int res = 0; while (left <= right) { int mid = left + right >> 1; if (k <= dp[mid] * x) { res = dp[mid]; right = mid - 1; } else { left = mid + 1; } } return res; } int main(void) { for (int i = 1; i <= 10000; i++) { dp[i] = dp[i - 1] * 2; } scanf("%d %d", &n, &k); for (int i = 1; i <= n; i++) { if (k <= i) ans += 1.0 / n; else ans += 1.0 / (n * func(i)); } printf("%.12lf\n", ans); /* k = 10; int x; scanf("%d", &x); printf("%d\n", func(x)); */ return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "literal.string.change", "call.arguments.change", "io.output.change" ]
863,744
863,745
u716033247
cpp
p03043
//#pragma warning(disable:4996) #include <stdio.h> //#include <math.h> int main() { int n, k; scanf("%d %d", &n, &k); double answer = 0; for (int i = 1; i <= n; i++) { int a = 1; a *= n; int b = i; while (b <= k) { b *= 2; a *= 2; } answer += (double)1.0 / a; } printf("%lf", answer); // while (1); }
//#pragma warning(disable:4996) #include <stdio.h> //#include <math.h> int main() { int n, k; scanf("%d %d", &n, &k); double answer = 0; for (int i = 1; i <= n; i++) { int a = 1; a *= n; int b = i; while (b < k) { b *= 2; a *= 2; } answer += (double)1.0 / a; } printf("%.10lf", answer); // while (1); }
[ "expression.operator.compare.change", "control_flow.loop.condition.change", "literal.string.change", "call.arguments.change", "io.output.change" ]
863,746
863,747
u691912637
cpp
p03043
//#pragma warning(disable:4996) #include <stdio.h> //#include <math.h> int main() { int n, k; scanf("%d %d", &n, &k); double answer = 0; for (int i = 1; i <= n; i++) { int a = 1; a *= n; int b = i; while (b <= k) { b *= 2; a *= 2; } answer += (double)1 / a; } printf("%lf", answer); // while (1); }
//#pragma warning(disable:4996) #include <stdio.h> //#include <math.h> int main() { int n, k; scanf("%d %d", &n, &k); double answer = 0; for (int i = 1; i <= n; i++) { int a = 1; a *= n; int b = i; while (b < k) { b *= 2; a *= 2; } answer += (double)1.0 / a; } printf("%.10lf", answer); // while (1); }
[ "expression.operator.compare.change", "control_flow.loop.condition.change", "literal.number.change", "assignment.value.change", "expression.operation.binary.change", "literal.string.change", "call.arguments.change", "io.output.change" ]
863,748
863,747
u691912637
cpp
p03043
#include <iostream> #include <stdio.h> using namespace std; int main() { double n, k, ans; cin >> n >> k; for (int i = 1; i <= n; i++) { double t = i, temp = 1 / n; while (t < k) { t *= 2; temp /= 2; } ans += temp; } printf("%12f", ans); }
#include <iostream> #include <stdio.h> using namespace std; int main() { double n, k, ans = 0; cin >> n >> k; for (int i = 1; i <= n; i++) { double t = i, temp = 1 / n; while (t < k) { t *= 2; temp /= 2; } ans += temp; } printf("%.12f", ans); }
[ "variable_declaration.value.change", "literal.string.change", "call.arguments.change", "io.output.change" ]
863,771
863,772
u950603962
cpp
p03043
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <stdlib.h> #include <string> #include <vector> #define ll long long using namespace std; int main() { double N, K; cin >> N >> K; double k; double l; double keep = 0.000; double j; for (int i = 1; i <= N; i++) { j = 1.0; l = 1.0; k = 0.0; while (K - (i * j) >= 0) { // cout << N << i*j << endl; j *= 2.0; k++; } // cout << k << endl; // cout << l << endl; for (int p = 0; p < k; p++) { l /= 2.000; } keep += l / N; // cout << keep << endl; } cout << setprecision(12) << keep << endl; return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <stdlib.h> #include <string> #include <vector> #define ll long long using namespace std; int main() { double N, K; cin >> N >> K; int k; double l; double keep = 0.000; double j; for (int i = 1; i <= N; i++) { j = 1.0; l = 1.0; k = 0; while (K - (i * j) > 0) { j *= 2.0; k++; } for (int p = 0; p < k; p++) { l /= 2.0; } keep += l / N; // printf("%0.10lf\n",l/N); } cout << setprecision(12) << keep << endl; return 0; }
[ "variable_declaration.type.primitive.change", "literal.number.change", "assignment.value.change", "expression.operator.compare.change", "control_flow.loop.condition.change" ]
863,777
863,778
u468862268
cpp
p03043
/*coderanant*/ #include <bits/stdc++.h> using namespace std; #define int long long #define ll long long #define f1(i, a, b) for (i = a; i < b; i++) #define f2(i, a, b) for (i = a; i >= b; i--) #define endl '\n' #define pb push_back #define gp " " #define ff first #define ss second #define mp make_pair const int mod = 1000000007; int i, j; ll temp; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // #ifndef ONLINE_JUDGE // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); // #endif int n, k; cin >> n >> k; double ans = 0.0; f1(i, 1, n + 1) { double temp = 1.0 / n; int j = i; while (j < k) { temp *= (1.0 / 2.0); j *= 2; } ans += temp; } cout << ans; return 0; }
/*coderanant*/ #include <bits/stdc++.h> using namespace std; #define int long long #define ll long long #define f1(i, a, b) for (i = a; i < b; i++) #define f2(i, a, b) for (i = a; i >= b; i--) #define endl '\n' #define pb push_back #define gp " " #define ff first #define ss second #define mp make_pair const int mod = 1000000007; int i, j; ll temp; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // #ifndef ONLINE_JUDGE // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); // #endif int n, k; cin >> n >> k; double ans = 0.0; f1(i, 1, n + 1) { double temp = 1.0 / n; int j = i; while (j < k) { temp *= (1.0 / 2.0); j *= 2; } ans += temp; } cout << setprecision(12) << ans; return 0; }
[ "io.output.change" ]
863,781
863,782
u087436629
cpp
p03043
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; double kakuritu = 0.0; for (int i = 0; i < N; i++) { int tokuten = i + 1; int kai = 0; while (tokuten < K) { tokuten *= 2; kai++; } if (kai != 0) { kakuritu += ((1.0 / N) * (1 / pow(2, kai))); } else { kakuritu += (1.0 / N); } } cout << fixed << kakuritu << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; double kakuritu = 0.0; for (int i = 0; i < N; i++) { int tokuten = i + 1; int kai = 0; while (tokuten < K) { tokuten *= 2; kai++; } if (kai != 0) { kakuritu += ((1.0 / N) * (1 / pow(2, kai))); } else { kakuritu += (1.0 / N); } } cout << setprecision(13) << kakuritu << endl; }
[ "io.output.change", "call.arguments.add" ]
863,783
863,784
u120711599
cpp
p03043
/************************* author : coldbeer 2019-05-20 10:38:08 PM IST *************************/ #include <bits/stdc++.h> using namespace std; #define endl "\n" int main() { ios_base::sync_with_stdio(false); cin.tie(0); long double n; int k; cin >> n >> k; long double ans = 0; for (int i = 1; i < n + 1; i++) { int p = i; int d = 0; if (p <= k - 1) { while (p <= (k - 1)) p = 2 * p, d++; long double tmp = 0.5; ans += powl(tmp, d); } } ans = ans / n; cout << fixed << setprecision(12) << ans << endl; return 0; }
/************************* author : coldbeer 2019-05-20 10:38:08 PM IST *************************/ #include <bits/stdc++.h> using namespace std; #define endl "\n" int main() { ios_base::sync_with_stdio(false); cin.tie(0); long double n; int k; cin >> n >> k; long double ans = 0; for (int i = 1; i < n + 1; i++) { int p = i; int d = 0; if (p <= k - 1) { while (p <= (k - 1)) p = 2 * p, d++; } long double tmp = 0.5; ans += powl(tmp, d); } ans = ans / n; cout << fixed << setprecision(12) << ans << endl; return 0; }
[]
863,785
863,786
u257192613
cpp
p03043
/************************* author : coldbeer 2019-05-20 10:38:08 PM IST *************************/ #include <bits/stdc++.h> using namespace std; #define endl "\n" int main() { ios_base::sync_with_stdio(false); cin.tie(0); long double n, k; cin >> n >> k; long double ans = 0; for (int i = 1; i < n + 1; i++) { long double p = i; int d = 0; if (p <= k - 1) { while (p <= (k - 1)) p = 2 * p, d++; long double tmp = 0.5; ans += powl(tmp, d); } } ans = ans / n; cout << fixed << setprecision(12) << ans << endl; return 0; }
/************************* author : coldbeer 2019-05-20 10:38:08 PM IST *************************/ #include <bits/stdc++.h> using namespace std; #define endl "\n" int main() { ios_base::sync_with_stdio(false); cin.tie(0); long double n; int k; cin >> n >> k; long double ans = 0; for (int i = 1; i < n + 1; i++) { int p = i; int d = 0; if (p <= k - 1) { while (p <= (k - 1)) p = 2 * p, d++; } long double tmp = 0.5; ans += powl(tmp, d); } ans = ans / n; cout << fixed << setprecision(12) << ans << endl; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.narrow.change" ]
863,787
863,786
u257192613
cpp
p03043
/************************* author : coldbeer 2019-05-20 10:38:08 PM IST *************************/ #include <bits/stdc++.h> using namespace std; #define endl "\n" int main() { ios_base::sync_with_stdio(false); cin.tie(0); long double n, k; cin >> n >> k; long double ans = 0; for (int i = 1; i < n + 1; i++) { int p = i, d = 0; if (p <= k - 1) { while (p <= (k - 1)) p = 2 * p, d++; long double tmp = 0.5; ans += powl(tmp, d); } } ans = ans / n; cout << fixed << setprecision(12) << ans << endl; return 0; }
/************************* author : coldbeer 2019-05-20 10:38:08 PM IST *************************/ #include <bits/stdc++.h> using namespace std; #define endl "\n" int main() { ios_base::sync_with_stdio(false); cin.tie(0); long double n; int k; cin >> n >> k; long double ans = 0; for (int i = 1; i < n + 1; i++) { int p = i; int d = 0; if (p <= k - 1) { while (p <= (k - 1)) p = 2 * p, d++; } long double tmp = 0.5; ans += powl(tmp, d); } ans = ans / n; cout << fixed << setprecision(12) << ans << endl; return 0; }
[ "variable_declaration.type.change" ]
863,788
863,786
u257192613
cpp
p03043
#include <bits/stdc++.h> typedef long long ll; using namespace std; const int inf = 1e9; const ll linf = 1e18; const ll mod = 1e9 + 7; int main() { int N, K; cin >> N >> K; double ans = 0.; for (int i = 1; i <= N; i++) { int num = i; int cnt = 0; while (num < K) { num *= 2; cnt++; } ans += 1.0 / N * pow(0.5, cnt); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> typedef long long ll; using namespace std; const int inf = 1e9; const ll linf = 1e18; const ll mod = 1e9 + 7; int main() { int N, K; cin >> N >> K; double ans = 0.; for (int i = 1; i <= N; i++) { int num = i; int cnt = 0; while (num < K) { num *= 2; cnt++; } ans += 1.0 / N * pow(0.5, cnt); } cout << setprecision(10) << ans << endl; return 0; }
[ "io.output.change" ]
863,793
863,794
u394759653
cpp
p03043
#include <cmath> #include <iomanip> #include <iostream> using namespace std; int main() { int n, k; cin >> n >> k; double ans = 0; for (int i = 1; i <= n; i++) { int i_tmp = i; int count = 0; if (i_tmp < k) { while (i_tmp <= k) { i_tmp *= 2; count++; } } ans += pow(0.5, count); } ans /= n; cout << setprecision(12) << ans << endl; }
#include <cmath> #include <iomanip> #include <iostream> using namespace std; int main() { int n, k; cin >> n >> k; double ans = 0; for (int i = 1; i <= n; i++) { int i_tmp = i; int count = 0; if (i_tmp < k) { while (i_tmp < k) { i_tmp *= 2; count++; } } ans += pow(0.5, count); // cout << count << endl; } ans /= n; cout << setprecision(12) << ans << endl; }
[ "expression.operator.compare.change", "control_flow.loop.condition.change" ]
863,795
863,796
u675125216
cpp
p03043
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <string> using namespace std; int main() { int n, k; double ans = 0; cin >> n >> k; for (int i = 1; i <= n; ++i) { int temp = i; int count = 0; while (temp <= k) { temp <<= 1; count++; } ans += 1.0 / n * pow(1.0 / 2, count); } printf("%.12f", ans); }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <string> using namespace std; int main() { int n, k; double ans = 0; cin >> n >> k; for (int i = 1; i <= n; ++i) { int temp = i; int count = 0; while (temp < k) { temp <<= 1; count++; } ans += 1.0 / n * pow(1.0 / 2, count); } printf("%.12f", ans); }
[ "expression.operator.compare.change", "control_flow.loop.condition.change" ]
863,804
863,805
u163200127
cpp
p03043
#include <bits/stdc++.h> using namespace std; int main() { long double n, k, ans = 0; cin >> n >> k; for (long double i = 1; i <= n; i++) { long double temp = i, x = 0; while (temp < k) { temp *= 2; ++x; } long double ttmp = 1 / (pow((long double)2, x) * n); ans += ttmp; } cout << ans << setprecision(10) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long double n, k, ans = 0; cin >> n >> k; for (long double i = 1; i <= n; i++) { long double temp = i, x = 0; while (temp < k) { temp *= 2; ++x; } long double ttmp = 1 / (pow((long double)2, x) * n); ans += ttmp; } cout << fixed << setprecision(10) << ans << endl; return 0; }
[ "identifier.change", "io.output.change" ]
863,806
863,807
u592099403
cpp
p03043
#include <algorithm> #include <array> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdlib.h> #include <string.h> #include <string> #include <vector> using namespace std; int main() { int N, K; double a, ans = 0; cin >> N >> K; for (int i = 1; i < N + 1; i++) { a = 1 / N; if (i >= K) ans = ans + (double)1 / N; else { for (int k = i; k < K; k = k * 2) { a = a / 2; } ans = ans + a; } } cout << setprecision(11) << ans << endl; return 0; }
#include <algorithm> #include <array> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdlib.h> #include <string.h> #include <string> #include <vector> using namespace std; int main() { int N, K; double a, ans = 0; cin >> N >> K; for (int i = 1; i < N + 1; i++) { a = 1.0 / N; if (i >= K) ans = ans + (double)1 / N; else { for (int k = 1; k * i < K; k = k * 2) { a = a / 2; } ans = ans + a; } } cout << setprecision(11) << ans << endl; return 0; }
[ "literal.number.change", "assignment.value.change", "expression.operation.binary.change", "variable_declaration.value.change", "identifier.replace.remove", "literal.replace.add", "control_flow.loop.for.initializer.change", "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.c...
863,808
863,809
u531752502
cpp
p03043
#include <algorithm> #include <iomanip> #include <iostream> #include <math.h> #include <string.h> #include <vector> typedef long long ll; using namespace std; int main() { double N, K; double sum = 0, ans; double y = 0; cin >> N >> K; for (double i = 1; i <= N; i++) { double x = i; ans = 1.0; while (x <= K) { x *= 2; ans *= 1.0 / 2.0; // cout << ans << endl; } y += 1.0 / N * ans; } cout << setprecision(12) << y << endl; return 0; }
#include <algorithm> #include <iomanip> #include <iostream> #include <math.h> #include <string.h> #include <vector> typedef long long ll; using namespace std; int main() { double N, K; double sum = 0, ans; double y = 0; cin >> N >> K; for (double i = 1; i <= N; i++) { double x = i; ans = 1.0; while (x < K) { x *= 2.0; ans *= 1.0 / 2.0; // cout << ans << endl; } y += 1.0 / N * ans; } cout << setprecision(12) << y << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.condition.change", "literal.number.change", "assignment.value.change" ]
863,810
863,811
u831873811
cpp
p03043
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // conversion //------------------------------------------ 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(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define EXISTch(s, c) \ ((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1) #define SORT(c) sort((c).begin(), (c).end()) #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = (int)1000000007; const LL MOD = (LL)1000000007; // 10^9+7 const LL INF2 = (LL)100000000000000000; // 10^18 int main() { int n, k; cin >> n >> k; double ans = 0.0; for (int i = 1; i < n + 1; i++) { double x = i; double p = 1.0; while (x < k) { x *= 2; p *= 0.5; } ans += i * p / (double)n; } cout << fixed << setprecision(10) << ans << endl; return 0; }
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // conversion //------------------------------------------ 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(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define EXISTch(s, c) \ ((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1) #define SORT(c) sort((c).begin(), (c).end()) #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = (int)1000000007; const LL MOD = (LL)1000000007; // 10^9+7 const LL INF2 = (LL)100000000000000000; // 10^18 int main() { int n, k; cin >> n >> k; double ans = 0.0; for (int i = 1; i < n + 1; i++) { double x = i; double p = 1.0; while (x < k) { x *= 2; p *= 0.5; } ans += p / (double)n; } cout << fixed << setprecision(10) << ans << endl; return 0; }
[ "expression.operation.binary.remove" ]
863,812
863,813
u874996917
cpp
p03043
/** * Dont raise your voice, improve your argument. * --Desmond Tutu * * AND WATCH OUT FOR OFF BY ONE!!! */ #include <bits/stdc++.h> const bool unsyncedio = std::ios::sync_with_stdio(false); using namespace std; typedef unsigned int uint; typedef long long ll; #define fori(n) for (ll i = 0; i < (n); i++) #define forn(i, n) for (ll(i) = 0; (i) < (n); (i)++) int main() { int n, k; cin >> n >> k; double ans = 0.0; for (int i = 1; i <= n; i++) { /* add prob of winning if dice shows i. */ double p = 1.0; int x = i; while (x < k) { p /= 2; x *= 2; } ans += p; } ans /= n; cout << ans << endl; }
/** * Dont raise your voice, improve your argument. * --Desmond Tutu * * AND WATCH OUT FOR OFF BY ONE!!! */ #include <bits/stdc++.h> const bool unsyncedio = std::ios::sync_with_stdio(false); using namespace std; typedef unsigned int uint; typedef long long ll; #define fori(n) for (ll i = 0; i < (n); i++) #define forn(i, n) for (ll(i) = 0; (i) < (n); (i)++) int main() { int n, k; cin >> n >> k; double ans = 0.0; for (int i = 1; i <= n; i++) { /* add prob of winning if dice shows i. */ double p = 1.0; int x = i; while (x < k) { p /= 2; x *= 2; } ans += p; } ans /= n; cout << setprecision(12) << ans << endl; }
[ "io.output.change" ]
863,814
863,815
u014617387
cpp
p03043
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <set> #include <string> #include <vector> #define X first #define Y second #define vsort(v) sort(v.begin(), v.end()) #define vrev(v) reverse(v.begin(), v.end()) #define vmax_p(v) max_element(v.begin(), v.end()) #define vmin_p(v) min_element(v.begin(), v.end()) #define vmax_idx(v) distance(v.begin(), vmax_p(v)) #define vmin_idx(v) distance(v.begin(), vmin_p(v)) #define vcopy(src, dst) copy(src.begin(), src.end(), back_inserter(dst)) #define P pair // stoi(s): string to int // stod(s): string to double // INT_MAX // INT_MIN // LLONG_MAX // LLONG_MIN // DBL_MIN // DBL_MAX // LDBL_MIN // LDBL_MAX // A-Z: 65~90 // a-z: 97~122 // |a-z| = 26 // floor(x): truncate // 2進数変換 // string s = bitset<20>(x).to_string(); using namespace std; using ll = long long; int main(int argc, const char *argv[]) { int n, k; cin >> n >> k; double ans = 0; for (int i = 1; i <= n; i++) { int x = i; double y = 1; for (; x < k;) { x *= 2; y /= 2; } ans += 1.0 / n * y; } cout << setprecision(-9) << ans << endl; }
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <set> #include <string> #include <vector> #define X first #define Y second #define vsort(v) sort(v.begin(), v.end()) #define vrev(v) reverse(v.begin(), v.end()) #define vmax_p(v) max_element(v.begin(), v.end()) #define vmin_p(v) min_element(v.begin(), v.end()) #define vmax_idx(v) distance(v.begin(), vmax_p(v)) #define vmin_idx(v) distance(v.begin(), vmin_p(v)) #define vcopy(src, dst) copy(src.begin(), src.end(), back_inserter(dst)) #define P pair // stoi(s): string to int // stod(s): string to double // INT_MAX // INT_MIN // LLONG_MAX // LLONG_MIN // DBL_MIN // DBL_MAX // LDBL_MIN // LDBL_MAX // A-Z: 65~90 // a-z: 97~122 // |a-z| = 26 // floor(x): truncate // 2進数変換 // string s = bitset<20>(x).to_string(); using namespace std; using ll = long long; int main(int argc, const char *argv[]) { int n, k; cin >> n >> k; double ans = 0; for (int i = 1; i <= n; i++) { int x = i; double y = 1; for (; x < k;) { x *= 2; y /= 2; } ans += 1.0 / n * y; } cout << setprecision(9) << ans << endl; }
[ "expression.operation.unary.arithmetic.remove" ]
863,823
863,824
u493080913
cpp
p03043
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n, k; cin >> n >> k; double ans = 0; for (int i = 1; i <= n; i++) { int t = i, cnt = 0; while (t < k) { t *= 2; cnt++; } if (cnt) ans += (1.0 / (double)pow(2, cnt)) * (1.0 / (double)n); } printf("%.10f\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n, k; cin >> n >> k; double ans = 0; for (int i = 1; i <= n; i++) { int t = i, cnt = 0; while (t < k) { t *= 2; cnt++; } ans += (1.0 / (double)pow(2, cnt)) * (1.0 / (double)n); } printf("%.10f\n", ans); return 0; }
[]
863,838
863,839
u344122377
cpp
p03043
/* << IN THE NAME OF GOD >> */ #include <bits/stdc++.h> using namespace std; #define err(x) cerr << #x << " = " << x << '\n' #define out(x) cout << x << '\n' #define forp(i, r, l) for (int i = int(r); i < int(l); i++) #define forn(i, r, l) for (int i = int(r); i > int(l); i--) #define FAST \ ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int maxn = 1e5 + 120; double res; int main() { FAST; int n, k; cin >> n >> k; for (int i = 1, now; i <= n; i++) { double tmp = 1.0 / n; now = i; while (now < k) now = 1 << now, tmp /= 2; res += tmp; } cout << setprecision(12) << fixed << res << endl; return 0; }
/* << IN THE NAME OF GOD >> */ #include <bits/stdc++.h> using namespace std; #define err(x) cerr << #x << " = " << x << '\n' #define out(x) cout << x << '\n' #define forp(i, r, l) for (int i = int(r); i < int(l); i++) #define forn(i, r, l) for (int i = int(r); i > int(l); i--) #define FAST \ ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int maxn = 1e5 + 120; double res; int main() { FAST; int n, k; cin >> n >> k; for (int i = 1, now; i <= n; i++) { double tmp = 1.0 / n; now = i; while (now < k) now *= 2, tmp /= 2; res += tmp; } cout << setprecision(12) << fixed << res << endl; return 0; }
[ "assignment.change" ]
863,840
863,841
u085966074
cpp
p03043
#include <bits/stdc++.h> using namespace std; #define MD 1000000007 typedef long long int ll; typedef pair<ll, ll> P; template <typename T> std::string tostr(const T &t) { std::ostringstream os; os << t; return os.str(); } int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int main() { int n, k; cin >> n >> k; double ans = 0.0; for (int i = 1; i <= n; i++) { int tmp = i, cnt = 0; while (tmp < k) { tmp *= 2; cnt++; } double tmp2 = 0.5, tmp1 = 0.5; for (int j = 0; j < cnt - 1; j++) tmp1 *= tmp2; if (cnt == 0) tmp1 = 1.0; ans += ((double)1 / (double)n) * tmp1; } printf("%.8lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define MD 1000000007 typedef long long int ll; typedef pair<ll, ll> P; template <typename T> std::string tostr(const T &t) { std::ostringstream os; os << t; return os.str(); } int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int main() { int n, k; cin >> n >> k; double ans = 0.0; for (int i = 1; i <= n; i++) { int tmp = i, cnt = 0; while (tmp < k) { tmp *= 2; cnt++; } double tmp2 = 0.5, tmp1 = 0.5; for (int j = 0; j < cnt - 1; j++) tmp1 *= tmp2; if (cnt == 0) tmp1 = 1.0; ans += ((double)1 / (double)n) * tmp1; } printf("%.12lf\n", ans); return 0; }
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
863,844
863,845
u287060310
cpp
p03043
#include <bits/stdc++.h> #define rep(i, m) for (long long i = 0; i < m; i++) #define per(i, m) for (long long i = m - 1; i >= 0; i--) #define FOR(i, n, m) for (long long i = n; i < m; i++) #define ROF(i, n, m) for (long long i = m - 1; i >= n; i--) #define SORT(v, n) \ do { \ sort(v, v + n); \ reverse(v, v + n); \ } while (0) #define all(x) (x).begin(), (x).end() #define EPS (1e-7) #define INF (1e18) #define PI (acos(-1)) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; using namespace std; typedef long long ll; const ll MOD = 1000000007; typedef pair<ll, ll> LP; ll POW(ll x, ll n) { if (n == 0) return 1; if (n % 2 == 0) return POW(x * x, n / 2) % MOD; return x % MOD * POW(x, n - 1) % MOD; } ll POW2(ll x, ll n) { if (n == 0) return 1; if (n % 2 == 0) return POW2(x * x, n / 2); return x * POW2(x, n - 1); } ll gcd(ll u, ll v) { ll r; while (0 != v) { r = u % v; u = v; v = r; } return u; } ll lcm(ll u, ll v) { return u * v / gcd(u, v); } ll KAI(ll m) { if (m < 0) return 0; if (m == 0) return 1; return m * KAI(m - 1) % MOD; } ll KAI2(ll m) { if (m < 0) return 0; if (m == 0) return 1; return m * KAI2(m - 1); } ll extGCD(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1; y = 0; return a; } ll d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } inline ll mod(ll a, ll m) { return (a % m + m) % m; } ll modinv(ll a) { ll x, y; extGCD(a, MOD, x, y); return mod(x, MOD); } ll COM(ll m, ll n) { if (m < n) return 0; if (n < 0) return 0; if (n == 0) return 1; if (m == n) return 1; return KAI(m) % MOD * modinv(KAI(n) % MOD * KAI(m - n) % MOD) % MOD; } ll COM2(ll m, ll n) { if (m < n) return 0; if (n < 0) return 0; if (n == 0) return 1; if (m == n) return 1; return KAI2(m) / KAI2(n) / KAI2(m - n); } ll DEC(ll x, ll m, ll n) { return x % POW(m, n + 1) / POW(m, n); } ll keta(ll x, ll n) { if (x == 0) return 0; return keta(x / n, n) + 1; } ll DIV(ll x, ll n) { if (x == 0) return 0; return x / n + DIV(x / n, n); } ll ORD(ll x, ll n) { if (x == 0) return INF; if (x % n != 0) return 0; return 1 + ORD(x / n, n); } int main() { ll n, k, b[200000] = {}, t, m = 1; long double a, x = 0, q; cin >> n >> k; q = n; t = k - 1; while (k > 1) { while (t >= (k + 1) / 2) { b[t] = m; t--; } m++; k = (k + 1) / 2; } FOR(i, 1, n + 1) { a = POW(2, b[i]); a = 1 / a; x += a; } printf("%llf", x / q); }
#include <bits/stdc++.h> #define rep(i, m) for (long long i = 0; i < m; i++) #define per(i, m) for (long long i = m - 1; i >= 0; i--) #define FOR(i, n, m) for (long long i = n; i < m; i++) #define ROF(i, n, m) for (long long i = m - 1; i >= n; i--) #define SORT(v, n) \ do { \ sort(v, v + n); \ reverse(v, v + n); \ } while (0) #define all(x) (x).begin(), (x).end() #define EPS (1e-7) #define INF (1e18) #define PI (acos(-1)) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; using namespace std; typedef long long ll; const ll MOD = 1000000007; typedef pair<ll, ll> LP; ll POW(ll x, ll n) { if (n == 0) return 1; if (n % 2 == 0) return POW(x * x, n / 2) % MOD; return x % MOD * POW(x, n - 1) % MOD; } ll POW2(ll x, ll n) { if (n == 0) return 1; if (n % 2 == 0) return POW2(x * x, n / 2); return x * POW2(x, n - 1); } ll gcd(ll u, ll v) { ll r; while (0 != v) { r = u % v; u = v; v = r; } return u; } ll lcm(ll u, ll v) { return u * v / gcd(u, v); } ll KAI(ll m) { if (m < 0) return 0; if (m == 0) return 1; return m * KAI(m - 1) % MOD; } ll KAI2(ll m) { if (m < 0) return 0; if (m == 0) return 1; return m * KAI2(m - 1); } ll extGCD(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1; y = 0; return a; } ll d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } inline ll mod(ll a, ll m) { return (a % m + m) % m; } ll modinv(ll a) { ll x, y; extGCD(a, MOD, x, y); return mod(x, MOD); } ll COM(ll m, ll n) { if (m < n) return 0; if (n < 0) return 0; if (n == 0) return 1; if (m == n) return 1; return KAI(m) % MOD * modinv(KAI(n) % MOD * KAI(m - n) % MOD) % MOD; } ll COM2(ll m, ll n) { if (m < n) return 0; if (n < 0) return 0; if (n == 0) return 1; if (m == n) return 1; return KAI2(m) / KAI2(n) / KAI2(m - n); } ll DEC(ll x, ll m, ll n) { return x % POW(m, n + 1) / POW(m, n); } ll keta(ll x, ll n) { if (x == 0) return 0; return keta(x / n, n) + 1; } ll DIV(ll x, ll n) { if (x == 0) return 0; return x / n + DIV(x / n, n); } ll ORD(ll x, ll n) { if (x == 0) return INF; if (x % n != 0) return 0; return 1 + ORD(x / n, n); } int main() { ll n, k, b[200000] = {}, t, m = 1; double a, x = 0, q; cin >> n >> k; q = n; t = k - 1; while (k > 1) { while (t >= (k + 1) / 2) { b[t] = m; t--; } m++; k = (k + 1) / 2; } FOR(i, 1, n + 1) { a = POW(2, b[i]); a = 1 / a; x += a; } printf("% .16f", x / q); }
[ "variable_declaration.type.narrow.change", "literal.string.change", "call.arguments.change", "io.output.change" ]
863,846
863,847
u107995903
cpp
p03043
#include <bits/stdc++.h> #define rep(i, m) for (long long i = 0; i < m; i++) #define per(i, m) for (long long i = m - 1; i >= 0; i--) #define FOR(i, n, m) for (long long i = n; i < m; i++) #define ROF(i, n, m) for (long long i = m - 1; i >= n; i--) #define SORT(v, n) \ do { \ sort(v, v + n); \ reverse(v, v + n); \ } while (0) #define all(x) (x).begin(), (x).end() #define EPS (1e-7) #define INF (1e18) #define PI (acos(-1)) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; using namespace std; typedef long long ll; const ll MOD = 1000000007; typedef pair<ll, ll> LP; ll POW(ll x, ll n) { if (n == 0) return 1; if (n % 2 == 0) return POW(x * x, n / 2) % MOD; return x % MOD * POW(x, n - 1) % MOD; } ll POW2(ll x, ll n) { if (n == 0) return 1; if (n % 2 == 0) return POW2(x * x, n / 2); return x * POW2(x, n - 1); } ll gcd(ll u, ll v) { ll r; while (0 != v) { r = u % v; u = v; v = r; } return u; } ll lcm(ll u, ll v) { return u * v / gcd(u, v); } ll KAI(ll m) { if (m < 0) return 0; if (m == 0) return 1; return m * KAI(m - 1) % MOD; } ll KAI2(ll m) { if (m < 0) return 0; if (m == 0) return 1; return m * KAI2(m - 1); } ll extGCD(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1; y = 0; return a; } ll d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } inline ll mod(ll a, ll m) { return (a % m + m) % m; } ll modinv(ll a) { ll x, y; extGCD(a, MOD, x, y); return mod(x, MOD); } ll COM(ll m, ll n) { if (m < n) return 0; if (n < 0) return 0; if (n == 0) return 1; if (m == n) return 1; return KAI(m) % MOD * modinv(KAI(n) % MOD * KAI(m - n) % MOD) % MOD; } ll COM2(ll m, ll n) { if (m < n) return 0; if (n < 0) return 0; if (n == 0) return 1; if (m == n) return 1; return KAI2(m) / KAI2(n) / KAI2(m - n); } ll DEC(ll x, ll m, ll n) { return x % POW(m, n + 1) / POW(m, n); } ll keta(ll x, ll n) { if (x == 0) return 0; return keta(x / n, n) + 1; } ll DIV(ll x, ll n) { if (x == 0) return 0; return x / n + DIV(x / n, n); } ll ORD(ll x, ll n) { if (x == 0) return INF; if (x % n != 0) return 0; return 1 + ORD(x / n, n); } int main() { ll n, k, b[200000] = {}, t, m = 1; double a, x = 0, q; cin >> n >> k; q = n; t = k - 1; while (k > 1) { while (t >= (k + 1) / 2) { b[t] = m; t--; } m++; k = (k + 1) / 2; } FOR(i, 1, n + 1) { a = POW(2, b[i]); a = 1 / a; x += a; } printf("%lf", x / q); }
#include <bits/stdc++.h> #define rep(i, m) for (long long i = 0; i < m; i++) #define per(i, m) for (long long i = m - 1; i >= 0; i--) #define FOR(i, n, m) for (long long i = n; i < m; i++) #define ROF(i, n, m) for (long long i = m - 1; i >= n; i--) #define SORT(v, n) \ do { \ sort(v, v + n); \ reverse(v, v + n); \ } while (0) #define all(x) (x).begin(), (x).end() #define EPS (1e-7) #define INF (1e18) #define PI (acos(-1)) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; using namespace std; typedef long long ll; const ll MOD = 1000000007; typedef pair<ll, ll> LP; ll POW(ll x, ll n) { if (n == 0) return 1; if (n % 2 == 0) return POW(x * x, n / 2) % MOD; return x % MOD * POW(x, n - 1) % MOD; } ll POW2(ll x, ll n) { if (n == 0) return 1; if (n % 2 == 0) return POW2(x * x, n / 2); return x * POW2(x, n - 1); } ll gcd(ll u, ll v) { ll r; while (0 != v) { r = u % v; u = v; v = r; } return u; } ll lcm(ll u, ll v) { return u * v / gcd(u, v); } ll KAI(ll m) { if (m < 0) return 0; if (m == 0) return 1; return m * KAI(m - 1) % MOD; } ll KAI2(ll m) { if (m < 0) return 0; if (m == 0) return 1; return m * KAI2(m - 1); } ll extGCD(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1; y = 0; return a; } ll d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } inline ll mod(ll a, ll m) { return (a % m + m) % m; } ll modinv(ll a) { ll x, y; extGCD(a, MOD, x, y); return mod(x, MOD); } ll COM(ll m, ll n) { if (m < n) return 0; if (n < 0) return 0; if (n == 0) return 1; if (m == n) return 1; return KAI(m) % MOD * modinv(KAI(n) % MOD * KAI(m - n) % MOD) % MOD; } ll COM2(ll m, ll n) { if (m < n) return 0; if (n < 0) return 0; if (n == 0) return 1; if (m == n) return 1; return KAI2(m) / KAI2(n) / KAI2(m - n); } ll DEC(ll x, ll m, ll n) { return x % POW(m, n + 1) / POW(m, n); } ll keta(ll x, ll n) { if (x == 0) return 0; return keta(x / n, n) + 1; } ll DIV(ll x, ll n) { if (x == 0) return 0; return x / n + DIV(x / n, n); } ll ORD(ll x, ll n) { if (x == 0) return INF; if (x % n != 0) return 0; return 1 + ORD(x / n, n); } int main() { ll n, k, b[200000] = {}, t, m = 1; double a, x = 0, q; cin >> n >> k; q = n; t = k - 1; while (k > 1) { while (t >= (k + 1) / 2) { b[t] = m; t--; } m++; k = (k + 1) / 2; } FOR(i, 1, n + 1) { a = POW(2, b[i]); a = 1 / a; x += a; } printf("% .16f", x / q); }
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
863,848
863,847
u107995903
cpp
p03043
#include <bits/stdc++.h> using namespace std; #define YES cout << "YES" << endl; #define NO cout << "NO" << endl; #define Yes cout << "Yes" << endl; #define No cout << "No" << endl; #define INF INT_MAX #define MOD 1000000007 #define PI acos(-1) using ll = long long; using ull = unsigned long long; using Pii = pair<int, int>; using Pll = pair<ll, ll>; #define rep(i, n) for (ll i = 0; i < n; i++) int main(int argc, char *argv[]) { cin.tie(0); ios::sync_with_stdio(false); double N, K; cin >> N >> K; double ans = 0; for (int i = 1; i <= N; i++) { int j = i; double p = 1; while (K > j) { j *= 2; p *= 0.5; } ans += p; } ans /= N; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define YES cout << "YES" << endl; #define NO cout << "NO" << endl; #define Yes cout << "Yes" << endl; #define No cout << "No" << endl; #define INF INT_MAX #define MOD 1000000007 #define PI acos(-1) using ll = long long; using ull = unsigned long long; using Pii = pair<int, int>; using Pll = pair<ll, ll>; #define rep(i, n) for (ll i = 0; i < n; i++) int main(int argc, char *argv[]) { cin.tie(0); ios::sync_with_stdio(false); double N, K; cin >> N >> K; double ans = 0; for (int i = 1; i <= N; i++) { int j = i; double p = 1; while (K > j) { j *= 2; p *= 0.5; } ans += p; } ans /= N; cout << setprecision(10) << ans << endl; return 0; }
[ "io.output.change" ]
863,851
863,852
u458798873
cpp
p03043
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout.precision(12); cout.setf(ios_base::fixed, ios_base::floatfield); int n, k; cin >> n >> k; double ans = 0.0; for (int i = 1; i <= n; i++) { if (i >= k) ans += 1.0; for (int j = 1; j <= 60; j++) { int64_t m = 1LL << j; if (m * i >= k) { ans += 1.0 / m; break; } } } cout << ans / n << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout.precision(12); cout.setf(ios_base::fixed, ios_base::floatfield); int n, k; cin >> n >> k; double ans = 0.0; for (int i = 1; i <= n; i++) { if (i >= k) ans += 1.0; else { for (int j = 1; j <= 60; j++) { int64_t m = 1LL << j; if (m * i >= k) { ans += 1.0 / m; break; } } } } cout << ans / n << endl; return 0; }
[ "control_flow.branch.else.add" ]
863,860
863,861
u726604439
cpp
p03043
#include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <string> #include <vector> #define nummax 110000 using namespace std; int main() { double ans = 0.0, y, i, N, K, x; cin >> N >> K; for (i = 1; i <= N; i++) { x = 0; while (1) { if (i * pow(2, (double)x) >= K) break; x++; } x *= -1; y = pow(2, (double)x); ans += y; } ans /= N; // cout << ans << endl; printf("%f.12\n", ans); }
#include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <string> #include <vector> #define nummax 110000 using namespace std; int main() { double ans = 0.0, y, i, N, K, x; cin >> N >> K; for (i = 1; i <= N; i++) { x = 0; while (1) { if (i * pow(2, (double)x) >= K) break; x++; } x *= -1; y = pow(2, (double)x); ans += y; } ans /= N; // cout << ans << endl; printf("%.12f\n", ans); }
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
863,873
863,874
u541884637
cpp
p03043
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; int main() { int a, b; cin >> a >> b; double ret = 0; for (int i = 1; i <= 1; i++) { double tmp = 1.0 / a; int now = i; while (now < b) { now *= 2; tmp /= 2; } ret += tmp; } printf("%.12f\n", ret); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; int main() { int a, b; cin >> a >> b; double ret = 0; for (int i = 1; i <= a; i++) { double tmp = 1.0 / a; int now = i; while (now < b) { now *= 2; tmp /= 2; } ret += tmp; } printf("%.12f\n", ret); return 0; }
[ "identifier.replace.add", "literal.replace.remove", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
863,882
863,883
u568419568
cpp
p03045
#include <bits/stdc++.h> using namespace std; int root(int i, vector<int> &par) { if (par[i] == i) return i; return par[i] = root(par[i], par); } void unite(int i, int j, vector<int> &par) { int ri = root(i, par); int rj = root(j, par); par[rj] = ri; } int main(void) { int N, M; cin >> N >> M; vector<int> par(N); for (int i = 0; i < N; i++) par[i] = i; for (int i = 0; i < M; i++) { int X, Y, Z; cin >> X >> Y >> Z; unite(X - 1, Y - 1, par); } set<int> s; for (int i = 0; i < N; i++) s.insert(par[i]); cout << s.size() << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int root(int i, vector<int> &par) { if (par[i] == i) return i; return par[i] = root(par[i], par); } void unite(int i, int j, vector<int> &par) { int ri = root(i, par); int rj = root(j, par); par[rj] = ri; } int main(void) { int N, M; cin >> N >> M; vector<int> par(N); for (int i = 0; i < N; i++) par[i] = i; for (int i = 0; i < M; i++) { int X, Y, Z; cin >> X >> Y >> Z; unite(X - 1, Y - 1, par); } set<int> s; for (int i = 0; i < N; i++) s.insert(root(i, par)); cout << s.size() << endl; return 0; }
[ "call.arguments.change", "call.arguments.add" ]
864,068
864,069
u898331860
cpp
p03045
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define repp(i, l, r) for (int i = (l); i < (r); i++) #define per(i, n) for (int i = ((n)-1); i >= 0; i--) #define perr(i, l, r) for (int i = ((r)-1); i >= (l); i--) #define all(x) (x).begin(), (x).end() #define MOD 1000000007 #define IINF 1000000000 #define LINF 1000000000000000000 #define SP << " " << #define CYES cout << "Yes" << endl #define CNO cout << "No" << endl typedef long long LL; typedef long double LD; class UnionFind { private: vector<int> node; public: UnionFind(int n) { node = vector<int>(n); rep(i, n) node[i] = i; } int root(int x) { if (node[x] == x) return x; else node[x] = root(node[x]); } bool uni(int x, int y) { x = root(x); y = root(y); if (x == y) return false; node[y] = x; return true; } }; int main() { int n, m; cin >> n >> m; UnionFind uf(n); int x, y, z; int ans = n; rep(i, m) { cin >> x >> y >> z; if (uf.uni(x - 1, y - 1)) ans--; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define repp(i, l, r) for (int i = (l); i < (r); i++) #define per(i, n) for (int i = ((n)-1); i >= 0; i--) #define perr(i, l, r) for (int i = ((r)-1); i >= (l); i--) #define all(x) (x).begin(), (x).end() #define MOD 1000000007 #define IINF 1000000000 #define LINF 1000000000000000000 #define SP << " " << #define CYES cout << "Yes" << endl #define CNO cout << "No" << endl typedef long long LL; typedef long double LD; class UnionFind { private: vector<int> node; public: UnionFind(int n) { node = vector<int>(n); rep(i, n) node[i] = i; } int root(int x) { if (node[x] == x) return x; else return node[x] = root(node[x]); } bool uni(int x, int y) { x = root(x); y = root(y); if (x == y) return false; node[y] = x; return true; } }; int main() { int n, m; cin >> n >> m; UnionFind uf(n); int x, y, z; int ans = n; rep(i, m) { cin >> x >> y >> z; if (uf.uni(x - 1, y - 1)) ans--; } cout << ans << endl; return 0; }
[ "control_flow.return.add" ]
864,070
864,071
u405923605
cpp
p03047
#include <bits/stdc++.h> #define rep(i, N) for (int i = 0; i < (N); i++) #define rrep(i, n) for (int i = (int)n - 1; i >= 0; --i) #define FOR(i, a, b) for (int i = (a); i < (b); i++) using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e12; const int inf = 1e9; const int mod = 1e9 + 7; typedef long long ll; typedef pair<ll, int> P; typedef set<int> S; 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; } __attribute__((constructor)) void init() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(10); } ll gcd(ll a, ll b) { if (a < b) swap(a, b); if (a % b == 0) return b; else return gcd(b, a % b); } ll ngcd(vector<ll> a) { ll res; res = a[0]; for (int i = 1; i < a.size() && res != 1; i++) { res = gcd(a[i], res); } return res; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll nlcm(vector<ll> numbers) { ll res; res = numbers[0]; for (ll i = 1; i < numbers.size(); i++) { res = lcm(res, numbers[i]); } return res; } signed main() { ll n, k; cin >> n >> k; cout << k - n + 1 << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, N) for (int i = 0; i < (N); i++) #define rrep(i, n) for (int i = (int)n - 1; i >= 0; --i) #define FOR(i, a, b) for (int i = (a); i < (b); i++) using namespace std; const long long MOD = 1e9 + 7; const long long INF = 1e12; const int inf = 1e9; const int mod = 1e9 + 7; typedef long long ll; typedef pair<ll, int> P; typedef set<int> S; 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; } __attribute__((constructor)) void init() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(10); } ll gcd(ll a, ll b) { if (a < b) swap(a, b); if (a % b == 0) return b; else return gcd(b, a % b); } ll ngcd(vector<ll> a) { ll res; res = a[0]; for (int i = 1; i < a.size() && res != 1; i++) { res = gcd(a[i], res); } return res; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll nlcm(vector<ll> numbers) { ll res; res = numbers[0]; for (ll i = 1; i < numbers.size(); i++) { res = lcm(res, numbers[i]); } return res; } signed main() { ll n, k; cin >> n >> k; cout << n - k + 1 << endl; return 0; }
[ "expression.operation.binary.remove" ]
864,443
864,444
u418810472
cpp
p03047
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; cout << b - a + 1 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; cout << a - b + 1 << endl; }
[ "expression.operation.binary.remove" ]
864,445
864,446
u225777148
cpp
p03047
#include <stdio.h> int main() { int a, b; scanf("%d%d", &a, &b); printf("%d\n", a - b); }
#include <stdio.h> int main() { int a, b; scanf("%d%d", &a, &b); printf("%d\n", a - b + 1); }
[ "expression.operation.binary.add" ]
864,459
864,460
u561639627
cpp
p03047
#include <iostream> using namespace std; int main() { int n, k; cin >> n >> k; cout << min(n - k + 1, 0) << endl; }
#include <iostream> using namespace std; int main() { int n, k; cin >> n >> k; cout << max(n - k + 1, 0) << endl; }
[ "misc.opposites", "identifier.change", "call.function.change", "io.output.change" ]
864,475
864,476
u112318601
cpp
p03047
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N, K; cout << N - K + 1 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; cout << N - K + 1 << endl; }
[]
864,493
864,494
u280966279
cpp
p03047
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; cout << n + k - 1 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; cout << n - k + 1 << endl; }
[ "expression.operation.binary.remove" ]
864,507
864,508
u459105164
cpp
p03047
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define REP(i, d, n) for (int i = (d); i < (n); ++i) #define all(v) v.begin(), v.end() using ll = long long; using P = pair<int, int>; int main() { int n, k; cin >> n >> k; cout << n - k - 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define REP(i, d, n) for (int i = (d); i < (n); ++i) #define all(v) v.begin(), v.end() using ll = long long; using P = pair<int, int>; int main() { int n, k; cin >> n >> k; cout << n - k + 1 << endl; return 0; }
[ "misc.opposites", "expression.operator.arithmetic.change", "io.output.change" ]
864,513
864,514
u561143568
cpp
p03047
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define RFOR(i, a, b) for (int i = (a); i >= (b); i--) #define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++) #define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--) #define MOD 1000000007 #define INF 1000000000 // 2000000000 #define LINF 1000000000000000000 // 9000000000000000000 #define DINF 1000000000000000.0 #define PI 3.14159265358979 //.size()はunsigned int 0-1をするとオーバーフローする using namespace std; typedef long long int ll; typedef pair<long long int, long long int> P; int dy[5] = {-1, 0, 1, 0, 0}; int dx[5] = {0, -1, 0, 1, 0}; int main(void) { long long int n, k; cin >> n >> k; cout << n - k << endl; }
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define RFOR(i, a, b) for (int i = (a); i >= (b); i--) #define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++) #define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--) #define MOD 1000000007 #define INF 1000000000 // 2000000000 #define LINF 1000000000000000000 // 9000000000000000000 #define DINF 1000000000000000.0 #define PI 3.14159265358979 //.size()はunsigned int 0-1をするとオーバーフローする using namespace std; typedef long long int ll; typedef pair<long long int, long long int> P; int dy[5] = {-1, 0, 1, 0, 0}; int dx[5] = {0, -1, 0, 1, 0}; int main(void) { long long int n, k; cin >> n >> k; cout << n - k + 1 << endl; }
[ "expression.operation.binary.add" ]
864,515
864,516
u057611820
cpp
p03047
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; const int INF = 1000000007; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, K; cin >> N, K; cout << N - K + 1 << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; const int INF = 1000000007; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, K; cin >> N >> K; cout << N - K + 1 << endl; }
[]
864,526
864,527
u415916075
cpp
p03047
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int k, n; cin >> n >> k; cout << n - k << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int k, n; cin >> n >> k; cout << n - k + 1 << "\n"; return 0; }
[ "expression.operation.binary.add" ]
864,528
864,529
u211227348
cpp