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
p03043
#include <bits/stdc++.h> using namespace std; #define C continue; #define R return; #define D double #define ll long long #define ld long double #define ull unsigned long long #define pb push_back #define vi vector<int> #define vc vector<char> #define vs vector<string> #define vb vector<bool> #define vd vector<D> #define vll vector<ll> #define vull vector<ull> #define vvi vector<vector<int>> #define vvb vector<vector<bool>> #define vvc vector<vector<char>> #define vvll vector<vector<ll>> #define vvd vector<vector<D>> #define all(v) (v).begin(), (v).end() #define allrev(v) (v).rbegin(), (v).rend() #define pii pair<int, int> #define vpii vector<pii> #define F first #define S second #define mp make_pair #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define dist(a, b, p, q) sqrt((p - a) * (p - a) + (q - b) * (q - b)); #define mod 1000000007 #define pp(n) printf("%.12f", n); #define line cout << "\n"; const D pie = acos(-1); const D hpie = asin(1); const D qpie = atan2(-1, 1); const D tpie = 2 * pie; void solve(int test_case) { D n, k; cin >> n >> k; D dice = 1 / n; D ans = 0; D show; for (show = 1; show < min(k, n + 1); show++) { int P = ceil(log2(k / show)); D update = 1; for (int i = 0; i < P; i++) update *= 0.5; ans += update; } ans *= dice; if (show < n) ans += (n - show + 1) * dice; pp(ans); line } int main() { int t = 1; // cin>>t; for (int i = 0; i < t; i++) solve(i); return 0; }
#include <bits/stdc++.h> using namespace std; #define C continue; #define R return; #define D double #define ll long long #define ld long double #define ull unsigned long long #define pb push_back #define vi vector<int> #define vc vector<char> #define vs vector<string> #define vb vector<bool> #define vd vector<D> #define vll vector<ll> #define vull vector<ull> #define vvi vector<vector<int>> #define vvb vector<vector<bool>> #define vvc vector<vector<char>> #define vvll vector<vector<ll>> #define vvd vector<vector<D>> #define all(v) (v).begin(), (v).end() #define allrev(v) (v).rbegin(), (v).rend() #define pii pair<int, int> #define vpii vector<pii> #define F first #define S second #define mp make_pair #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define dist(a, b, p, q) sqrt((p - a) * (p - a) + (q - b) * (q - b)); #define mod 1000000007 #define pp(n) printf("%.12f", n); #define line cout << "\n"; const D pie = acos(-1); const D hpie = asin(1); const D qpie = atan2(-1, 1); const D tpie = 2 * pie; void solve(int test_case) { D n, k; cin >> n >> k; D dice = 1 / n; D ans = 0; D show; for (show = 1; show < min(k, n + 1); show++) { int P = ceil(log2(k / show)); D update = 1; for (int i = 0; i < P; i++) update *= 0.5; ans += update; } ans *= dice; if (show <= n) ans += (n - show + 1) * dice; pp(ans); line } int main() { int t = 1; // cin>>t; for (int i = 0; i < t; i++) solve(i); return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
862,517
862,518
u389438219
cpp
p03043
#include <assert.h> #include <bits/stdc++.h> #include <time.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // s.order_of_key(x); // gives order of x in the set #define For(i, x, n) for (long long i = x; i < n; i++) #define rFor(i, x, n) for (long long i = x; i >= n; i--) #define itFor(it, st) for (auto it = st.begin(); it != st.end(); it++) #define MOD 1000000007 #define PI 3.141592653589793 #define INF 999999999999999999 #define N 1000005 #define ll long long #define ld long double #define pb push_back #define mp make_pair #define fi first #define se second #define cont continue #define brk break #define deb1(x) cout << #x << ": " << x << endl #define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl #define deb3(x, y, z) \ cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define deb4(a, b, c, d) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define deb5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define deb6(a, b, c, d, e, f) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl using namespace std; void setprime(ll n = 15000002); ll choose(ll n, ll k); void showArray(ll a[], ll n); ll gcd(ll a, ll b); ld len(ld x1, ld y1, ld x2, ld y2); ld gcd_ld(ld x, ld y); ll power(ll x, ll n); ll power1(ll x, ll n); int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); cout << fixed; cout << setprecision(8); srand(time(NULL)); ll n, k; cin >> n >> k; ld ans = 0.00; For(i, 1, n + 1) { ld sp = (1.0) / n; ll start = i; if (start >= k) { ans += sp; continue; } while (start < k) { start *= 2; sp = sp * 0.5; } ans += sp; } cout << ans; // cout<<"\nTime used = // "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl; // - for // checking time used for a test case return 0; } // s1.substr(1,3) - return 3 characters starting from position 1 as substring of // string sz1. eg sz1="shreynumh" sz1.substr(2,5)="reyan" num = atoi(s.c_str()); // //convert string s to integer num n.erase(i,std::string::npos); //erase i th // position in string n , decreasing string size s.find(b)!= std::string::npos - // finds string b in string a - true if found cout<<"Time used = // "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl; // - for // checking time used for a test case void setprime(ll isprime[], ll n, ll cc = 0) { isprime[1] = 1; map<ll, ll> hm; ll i; for (i = 2; i * i <= 15000002; i++) if (isprime[i] == 0) { for (ll j = 2 * i; j <= 15000001; j += i) if (isprime[j] == 0) isprime[j] = i; isprime[i] = i; hm[i] = cc; cc++; } for (; i < 15000002; i++) if (isprime[i] == 0) isprime[i] = i, hm[i] = cc, cc++; } ll choose(ll n, ll k) { if (k == 0) return 1; return (n * choose(n - 1, k - 1)) / k; } void showArray(ll a[], ll n) { For(i, 0, n) { cout << a[i] << " "; } cout << endl; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ld len(ld x1, ld y1, ld x2, ld y2) { return sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2)); } ld gcd_ld(ld x, ld y) { ld eps = 0.0001; while (fabs(x) > eps && fabs(y) > eps) { if (x > y) x -= floor(x / y) * y; else y -= floor(y / x) * x; } return x + y; } ll power(ll x, ll n) { if (n == 0) return 1; else if (n % 2 == 0) // n is even return (power((x * x) % MOD, n / 2)) % MOD; else // n is bal return (x * power((x * x) % MOD, (n - 1) / 2)) % MOD; } ll power1(ll x, ll n) { ll num = 1; For(i, 0, n) { num = (num * x) % MOD; } return num; }
#include <assert.h> #include <bits/stdc++.h> #include <time.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // s.order_of_key(x); // gives order of x in the set #define For(i, x, n) for (long long i = x; i < n; i++) #define rFor(i, x, n) for (long long i = x; i >= n; i--) #define itFor(it, st) for (auto it = st.begin(); it != st.end(); it++) #define MOD 1000000007 #define PI 3.141592653589793 #define INF 999999999999999999 #define N 1000005 #define ll long long #define ld long double #define pb push_back #define mp make_pair #define fi first #define se second #define cont continue #define brk break #define deb1(x) cout << #x << ": " << x << endl #define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl #define deb3(x, y, z) \ cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define deb4(a, b, c, d) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define deb5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define deb6(a, b, c, d, e, f) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl using namespace std; void setprime(ll n = 15000002); ll choose(ll n, ll k); void showArray(ll a[], ll n); ll gcd(ll a, ll b); ld len(ld x1, ld y1, ld x2, ld y2); ld gcd_ld(ld x, ld y); ll power(ll x, ll n); ll power1(ll x, ll n); int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); cout << fixed; cout << setprecision(15); srand(time(NULL)); ll n, k; cin >> n >> k; ld ans = 0.00; For(i, 1, n + 1) { ld sp = (1.0) / n; ll start = i; if (start >= k) { ans += sp; continue; } while (start < k) { start *= 2; sp = sp * 0.5; } ans += sp; } cout << ans; // cout<<"\nTime used = // "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl; // - for // checking time used for a test case return 0; } // s1.substr(1,3) - return 3 characters starting from position 1 as substring of // string sz1. eg sz1="shreynumh" sz1.substr(2,5)="reyan" num = atoi(s.c_str()); // //convert string s to integer num n.erase(i,std::string::npos); //erase i th // position in string n , decreasing string size s.find(b)!= std::string::npos - // finds string b in string a - true if found cout<<"Time used = // "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl; // - for // checking time used for a test case void setprime(ll isprime[], ll n, ll cc = 0) { isprime[1] = 1; map<ll, ll> hm; ll i; for (i = 2; i * i <= 15000002; i++) if (isprime[i] == 0) { for (ll j = 2 * i; j <= 15000001; j += i) if (isprime[j] == 0) isprime[j] = i; isprime[i] = i; hm[i] = cc; cc++; } for (; i < 15000002; i++) if (isprime[i] == 0) isprime[i] = i, hm[i] = cc, cc++; } ll choose(ll n, ll k) { if (k == 0) return 1; return (n * choose(n - 1, k - 1)) / k; } void showArray(ll a[], ll n) { For(i, 0, n) { cout << a[i] << " "; } cout << endl; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ld len(ld x1, ld y1, ld x2, ld y2) { return sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2)); } ld gcd_ld(ld x, ld y) { ld eps = 0.0001; while (fabs(x) > eps && fabs(y) > eps) { if (x > y) x -= floor(x / y) * y; else y -= floor(y / x) * x; } return x + y; } ll power(ll x, ll n) { if (n == 0) return 1; else if (n % 2 == 0) // n is even return (power((x * x) % MOD, n / 2)) % MOD; else // n is bal return (x * power((x * x) % MOD, (n - 1) / 2)) % MOD; } ll power1(ll x, ll n) { ll num = 1; For(i, 0, n) { num = (num * x) % MOD; } return num; }
[ "literal.number.change", "io.output.change" ]
862,519
862,520
u375267383
cpp
p03043
#include <assert.h> #include <bits/stdc++.h> #include <time.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // s.order_of_key(x); // gives order of x in the set #define For(i, x, n) for (long long i = x; i < n; i++) #define rFor(i, x, n) for (long long i = x; i >= n; i--) #define itFor(it, st) for (auto it = st.begin(); it != st.end(); it++) #define MOD 1000000007 #define PI 3.141592653589793 #define INF 999999999999999999 #define N 1000005 #define ll long long #define ld long double #define pb push_back #define mp make_pair #define fi first #define se second #define cont continue #define brk break #define deb1(x) cout << #x << ": " << x << endl #define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl #define deb3(x, y, z) \ cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define deb4(a, b, c, d) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define deb5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define deb6(a, b, c, d, e, f) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl using namespace std; void setprime(ll n = 15000002); ll choose(ll n, ll k); void showArray(ll a[], ll n); ll gcd(ll a, ll b); ld len(ld x1, ld y1, ld x2, ld y2); ld gcd_ld(ld x, ld y); ll power(ll x, ll n); ll power1(ll x, ll n); int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); cout << fixed; cout << setprecision(3); srand(time(NULL)); ll n, k; cin >> n >> k; ld ans = 0.00; For(i, 1, n + 1) { ld sp = (1.0) / n; ll start = i; if (start >= k) { ans += sp; continue; } while (start < k) { start *= 2; sp = sp * 0.5; } ans += sp; } cout << ans; // cout<<"\nTime used = // "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl; // - for // checking time used for a test case return 0; } // s1.substr(1,3) - return 3 characters starting from position 1 as substring of // string sz1. eg sz1="shreynumh" sz1.substr(2,5)="reyan" num = atoi(s.c_str()); // //convert string s to integer num n.erase(i,std::string::npos); //erase i th // position in string n , decreasing string size s.find(b)!= std::string::npos - // finds string b in string a - true if found cout<<"Time used = // "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl; // - for // checking time used for a test case void setprime(ll isprime[], ll n, ll cc = 0) { isprime[1] = 1; map<ll, ll> hm; ll i; for (i = 2; i * i <= 15000002; i++) if (isprime[i] == 0) { for (ll j = 2 * i; j <= 15000001; j += i) if (isprime[j] == 0) isprime[j] = i; isprime[i] = i; hm[i] = cc; cc++; } for (; i < 15000002; i++) if (isprime[i] == 0) isprime[i] = i, hm[i] = cc, cc++; } ll choose(ll n, ll k) { if (k == 0) return 1; return (n * choose(n - 1, k - 1)) / k; } void showArray(ll a[], ll n) { For(i, 0, n) { cout << a[i] << " "; } cout << endl; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ld len(ld x1, ld y1, ld x2, ld y2) { return sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2)); } ld gcd_ld(ld x, ld y) { ld eps = 0.0001; while (fabs(x) > eps && fabs(y) > eps) { if (x > y) x -= floor(x / y) * y; else y -= floor(y / x) * x; } return x + y; } ll power(ll x, ll n) { if (n == 0) return 1; else if (n % 2 == 0) // n is even return (power((x * x) % MOD, n / 2)) % MOD; else // n is bal return (x * power((x * x) % MOD, (n - 1) / 2)) % MOD; } ll power1(ll x, ll n) { ll num = 1; For(i, 0, n) { num = (num * x) % MOD; } return num; }
#include <assert.h> #include <bits/stdc++.h> #include <time.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // s.order_of_key(x); // gives order of x in the set #define For(i, x, n) for (long long i = x; i < n; i++) #define rFor(i, x, n) for (long long i = x; i >= n; i--) #define itFor(it, st) for (auto it = st.begin(); it != st.end(); it++) #define MOD 1000000007 #define PI 3.141592653589793 #define INF 999999999999999999 #define N 1000005 #define ll long long #define ld long double #define pb push_back #define mp make_pair #define fi first #define se second #define cont continue #define brk break #define deb1(x) cout << #x << ": " << x << endl #define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl #define deb3(x, y, z) \ cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define deb4(a, b, c, d) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define deb5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define deb6(a, b, c, d, e, f) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl using namespace std; void setprime(ll n = 15000002); ll choose(ll n, ll k); void showArray(ll a[], ll n); ll gcd(ll a, ll b); ld len(ld x1, ld y1, ld x2, ld y2); ld gcd_ld(ld x, ld y); ll power(ll x, ll n); ll power1(ll x, ll n); int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); cout << fixed; cout << setprecision(15); srand(time(NULL)); ll n, k; cin >> n >> k; ld ans = 0.00; For(i, 1, n + 1) { ld sp = (1.0) / n; ll start = i; if (start >= k) { ans += sp; continue; } while (start < k) { start *= 2; sp = sp * 0.5; } ans += sp; } cout << ans; // cout<<"\nTime used = // "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl; // - for // checking time used for a test case return 0; } // s1.substr(1,3) - return 3 characters starting from position 1 as substring of // string sz1. eg sz1="shreynumh" sz1.substr(2,5)="reyan" num = atoi(s.c_str()); // //convert string s to integer num n.erase(i,std::string::npos); //erase i th // position in string n , decreasing string size s.find(b)!= std::string::npos - // finds string b in string a - true if found cout<<"Time used = // "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl; // - for // checking time used for a test case void setprime(ll isprime[], ll n, ll cc = 0) { isprime[1] = 1; map<ll, ll> hm; ll i; for (i = 2; i * i <= 15000002; i++) if (isprime[i] == 0) { for (ll j = 2 * i; j <= 15000001; j += i) if (isprime[j] == 0) isprime[j] = i; isprime[i] = i; hm[i] = cc; cc++; } for (; i < 15000002; i++) if (isprime[i] == 0) isprime[i] = i, hm[i] = cc, cc++; } ll choose(ll n, ll k) { if (k == 0) return 1; return (n * choose(n - 1, k - 1)) / k; } void showArray(ll a[], ll n) { For(i, 0, n) { cout << a[i] << " "; } cout << endl; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ld len(ld x1, ld y1, ld x2, ld y2) { return sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2)); } ld gcd_ld(ld x, ld y) { ld eps = 0.0001; while (fabs(x) > eps && fabs(y) > eps) { if (x > y) x -= floor(x / y) * y; else y -= floor(y / x) * x; } return x + y; } ll power(ll x, ll n) { if (n == 0) return 1; else if (n % 2 == 0) // n is even return (power((x * x) % MOD, n / 2)) % MOD; else // n is bal return (x * power((x * x) % MOD, (n - 1) / 2)) % MOD; } ll power1(ll x, ll n) { ll num = 1; For(i, 0, n) { num = (num * x) % MOD; } return num; }
[ "literal.number.change", "io.output.change" ]
862,521
862,520
u375267383
cpp
p03043
#include <assert.h> #include <bits/stdc++.h> #include <time.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // s.order_of_key(x); // gives order of x in the set #define For(i, x, n) for (long long i = x; i < n; i++) #define rFor(i, x, n) for (long long i = x; i >= n; i--) #define itFor(it, st) for (auto it = st.begin(); it != st.end(); it++) #define MOD 1000000007 #define PI 3.141592653589793 #define INF 999999999999999999 #define N 1000005 #define ll long long #define ld long double #define pb push_back #define mp make_pair #define fi first #define se second #define cont continue #define brk break #define deb1(x) cout << #x << ": " << x << endl #define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl #define deb3(x, y, z) \ cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define deb4(a, b, c, d) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define deb5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define deb6(a, b, c, d, e, f) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl using namespace std; void setprime(ll n = 15000002); ll choose(ll n, ll k); void showArray(ll a[], ll n); ll gcd(ll a, ll b); ld len(ld x1, ld y1, ld x2, ld y2); ld gcd_ld(ld x, ld y); ll power(ll x, ll n); ll power1(ll x, ll n); int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); cout << fixed; cout << setprecision(3); srand(time(NULL)); ll n, k; cin >> n >> k; ld ans = 0.00; For(i, 1, n + 1) { ld sp = (i * 1.0) / n; ll start = i; if (start >= k) { ans += sp; continue; } while (start < k) { start *= 2; sp = sp * 0.5; } ans += sp; } cout << ans; // cout<<"\nTime used = // "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl; // - for // checking time used for a test case return 0; } // s1.substr(1,3) - return 3 characters starting from position 1 as substring of // string sz1. eg sz1="shreynumh" sz1.substr(2,5)="reyan" num = atoi(s.c_str()); // //convert string s to integer num n.erase(i,std::string::npos); //erase i th // position in string n , decreasing string size s.find(b)!= std::string::npos - // finds string b in string a - true if found cout<<"Time used = // "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl; // - for // checking time used for a test case void setprime(ll isprime[], ll n, ll cc = 0) { isprime[1] = 1; map<ll, ll> hm; ll i; for (i = 2; i * i <= 15000002; i++) if (isprime[i] == 0) { for (ll j = 2 * i; j <= 15000001; j += i) if (isprime[j] == 0) isprime[j] = i; isprime[i] = i; hm[i] = cc; cc++; } for (; i < 15000002; i++) if (isprime[i] == 0) isprime[i] = i, hm[i] = cc, cc++; } ll choose(ll n, ll k) { if (k == 0) return 1; return (n * choose(n - 1, k - 1)) / k; } void showArray(ll a[], ll n) { For(i, 0, n) { cout << a[i] << " "; } cout << endl; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ld len(ld x1, ld y1, ld x2, ld y2) { return sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2)); } ld gcd_ld(ld x, ld y) { ld eps = 0.0001; while (fabs(x) > eps && fabs(y) > eps) { if (x > y) x -= floor(x / y) * y; else y -= floor(y / x) * x; } return x + y; } ll power(ll x, ll n) { if (n == 0) return 1; else if (n % 2 == 0) // n is even return (power((x * x) % MOD, n / 2)) % MOD; else // n is bal return (x * power((x * x) % MOD, (n - 1) / 2)) % MOD; } ll power1(ll x, ll n) { ll num = 1; For(i, 0, n) { num = (num * x) % MOD; } return num; }
#include <assert.h> #include <bits/stdc++.h> #include <time.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // s.order_of_key(x); // gives order of x in the set #define For(i, x, n) for (long long i = x; i < n; i++) #define rFor(i, x, n) for (long long i = x; i >= n; i--) #define itFor(it, st) for (auto it = st.begin(); it != st.end(); it++) #define MOD 1000000007 #define PI 3.141592653589793 #define INF 999999999999999999 #define N 1000005 #define ll long long #define ld long double #define pb push_back #define mp make_pair #define fi first #define se second #define cont continue #define brk break #define deb1(x) cout << #x << ": " << x << endl #define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl #define deb3(x, y, z) \ cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define deb4(a, b, c, d) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define deb5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define deb6(a, b, c, d, e, f) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl using namespace std; void setprime(ll n = 15000002); ll choose(ll n, ll k); void showArray(ll a[], ll n); ll gcd(ll a, ll b); ld len(ld x1, ld y1, ld x2, ld y2); ld gcd_ld(ld x, ld y); ll power(ll x, ll n); ll power1(ll x, ll n); int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); cout << fixed; cout << setprecision(15); srand(time(NULL)); ll n, k; cin >> n >> k; ld ans = 0.00; For(i, 1, n + 1) { ld sp = (1.0) / n; ll start = i; if (start >= k) { ans += sp; continue; } while (start < k) { start *= 2; sp = sp * 0.5; } ans += sp; } cout << ans; // cout<<"\nTime used = // "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl; // - for // checking time used for a test case return 0; } // s1.substr(1,3) - return 3 characters starting from position 1 as substring of // string sz1. eg sz1="shreynumh" sz1.substr(2,5)="reyan" num = atoi(s.c_str()); // //convert string s to integer num n.erase(i,std::string::npos); //erase i th // position in string n , decreasing string size s.find(b)!= std::string::npos - // finds string b in string a - true if found cout<<"Time used = // "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl; // - for // checking time used for a test case void setprime(ll isprime[], ll n, ll cc = 0) { isprime[1] = 1; map<ll, ll> hm; ll i; for (i = 2; i * i <= 15000002; i++) if (isprime[i] == 0) { for (ll j = 2 * i; j <= 15000001; j += i) if (isprime[j] == 0) isprime[j] = i; isprime[i] = i; hm[i] = cc; cc++; } for (; i < 15000002; i++) if (isprime[i] == 0) isprime[i] = i, hm[i] = cc, cc++; } ll choose(ll n, ll k) { if (k == 0) return 1; return (n * choose(n - 1, k - 1)) / k; } void showArray(ll a[], ll n) { For(i, 0, n) { cout << a[i] << " "; } cout << endl; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ld len(ld x1, ld y1, ld x2, ld y2) { return sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2)); } ld gcd_ld(ld x, ld y) { ld eps = 0.0001; while (fabs(x) > eps && fabs(y) > eps) { if (x > y) x -= floor(x / y) * y; else y -= floor(y / x) * x; } return x + y; } ll power(ll x, ll n) { if (n == 0) return 1; else if (n % 2 == 0) // n is even return (power((x * x) % MOD, n / 2)) % MOD; else // n is bal return (x * power((x * x) % MOD, (n - 1) / 2)) % MOD; } ll power1(ll x, ll n) { ll num = 1; For(i, 0, n) { num = (num * x) % MOD; } return num; }
[ "literal.number.change", "io.output.change", "expression.operation.binary.remove" ]
862,522
862,520
u375267383
cpp
p03043
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i) #define rep(i, n) REP(i, 0, n) typedef long long ll; typedef pair<int, int> pint; typedef pair<ll, int> pli; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 1e9 + 7; int m[100010]; int main() { long double n, k; cin >> n >> k; long double ans = 0; for (int i = 1; i <= n; i++) { long double temp = i; while (temp < k) { temp *= 2; } temp /= i; ans += 1.0 / temp; } cout << ans / n << endl; return 0; }
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i) #define rep(i, n) REP(i, 0, n) typedef long long ll; typedef pair<int, int> pint; typedef pair<ll, int> pli; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 1e9 + 7; int m[100010]; int main() { long double n, k; cin >> n >> k; long double ans = 0; for (int i = 1; i <= n; i++) { long double temp = i; while (temp < k) { temp *= 2; } temp /= i; ans += 1.0 / temp; } cout << setprecision(15) << ans / n << endl; return 0; }
[ "io.output.change" ]
862,523
862,524
u906208439
cpp
p03043
#include "algorithm" #include "bitset" #include "cassert" #include "climits" #include "cmath" #include "cstdio" #include "functional" #include "iomanip" #include "iostream" #include "list" #include "map" #include "numeric" #include "queue" #include "random" #include "set" #include "stack" #include "string" #include "unordered_map" #include "unordered_set" using namespace std; const long long int MOD = 1000000007; // const int MOD = 1000000007; // const int MOD = 998244353; // const long long int MOD = 998244353; long long int N, M, K, H, W, L, R; // int N, M, K, H, W, L, R; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> K; long double ans = 0; for (int i = 1; i <= N; i++) { int cnt = 0; int box = i; while (box < K) { box <<= 1; cnt++; } long double add = 1; for (int j = 0; j < cnt; j++) add /= 2; ans += add; } cout << setprecision(20) << ans << endl; return 0; }
#include "algorithm" #include "bitset" #include "cassert" #include "climits" #include "cmath" #include "cstdio" #include "functional" #include "iomanip" #include "iostream" #include "list" #include "map" #include "numeric" #include "queue" #include "random" #include "set" #include "stack" #include "string" #include "unordered_map" #include "unordered_set" using namespace std; const long long int MOD = 1000000007; // const int MOD = 1000000007; // const int MOD = 998244353; // const long long int MOD = 998244353; long long int N, M, K, H, W, L, R; // int N, M, K, H, W, L, R; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> K; long double ans = 0; for (int i = 1; i <= N; i++) { int cnt = 0; int box = i; while (box < K) { box <<= 1; cnt++; } long double add = 1; for (int j = 0; j < cnt; j++) add /= 2; ans += add; } ans /= N; cout << setprecision(20) << ans << endl; return 0; }
[ "assignment.add" ]
862,527
862,528
u468700753
cpp
p03043
#include <cmath> #include <iomanip> #include <iostream> #include <string> using namespace std; int main() { int n, k; cin >> n >> k; if (k <= 1) { cout << 100 << endl; return (0); } double a = 0; if (n >= k) { a = n - k + 1; } int b = a; double c = n; int d = 2; while (1) { int x = (k + 1) / 2; if (n >= x) { int w = n - x + 1; a = (a * 2) + (w - b); b = w; } c *= 2; d *= 2; if (x <= 1) { break; } k = x; } std::cout << std::fixed << std::setprecision(10); cout << a / c << endl; return (0); }
#include <cmath> #include <iomanip> #include <iostream> #include <string> using namespace std; int main() { int n, k; cin >> n >> k; if (k <= 1) { cout << 1 << endl; return (0); } double a = 0; if (n >= k) { a = n - k + 1; } int b = a; double c = n; int d = 2; while (1) { int x = (k + 1) / 2; if (n >= x) { int w = n - x + 1; a = (a * 2) + (w - b); b = w; } c *= 2; d *= 2; if (x <= 1) { break; } k = x; } std::cout << std::fixed << std::setprecision(10); cout << a / c << endl; return (0); }
[ "literal.number.change", "io.output.change" ]
862,529
862,530
u504696228
cpp
p03043
#include <bits/stdc++.h> using namespace std; int main() { double N, K; cin >> N >> K; double p = 0.0; for (int x = 1; x <= N; ++x) { for (int a = 0; a < 1000000; ++a) { if (x * pow(2, a) > K) { p += pow(0.5, a) / N; break; } } } cout << setprecision(10) << p << endl; }
#include <bits/stdc++.h> using namespace std; int main() { double N, K; cin >> N >> K; double p = 0.0; for (int x = 1; x <= N; ++x) { for (int a = 0; a < 1000000; ++a) { if (x * pow(2, a) >= K) { p += pow(0.5, a) / N; break; } } } cout << setprecision(10) << p << endl; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
862,531
862,532
u095136435
cpp
p03043
#include <bits/stdc++.h> using namespace std; int main() { double N, K; cin >> N >> K; double p = 0.0; for (int x = 1; x <= N; ++x) { for (int a = 0; a < 1000000; ++a) { if (x * pow(2, a) > K) { p += pow(0.5, a) / N; break; } } } cout << setprecision(12) << p << endl; }
#include <bits/stdc++.h> using namespace std; int main() { double N, K; cin >> N >> K; double p = 0.0; for (int x = 1; x <= N; ++x) { for (int a = 0; a < 1000000; ++a) { if (x * pow(2, a) >= K) { p += pow(0.5, a) / N; break; } } } cout << setprecision(10) << p << endl; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "literal.number.change", "io.output.change" ]
862,533
862,532
u095136435
cpp
p03043
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int num = 1; double pro = 0; for (int i = 1; i <= n; ++i) { double part_pro = 1.0 / n; int num = 1; for (; (num * i) <= k; num = (num << 1)) { part_pro *= 0.5; } pro += part_pro; } cout << setprecision(20) << pro << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int num = 1; double pro = 0; for (int i = 1; i <= n; ++i) { double part_pro = 1.0 / n; int num = 1; for (; (num * i) < k; num = (num << 1)) { part_pro *= 0.5; } pro += part_pro; } cout << setprecision(20) << pro << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
862,547
862,548
u627431737
cpp
p03043
#include <algorithm> #include <array> #include <bitset> #include <cmath> #include <functional> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <set> #include <string> #include <vector> #include <iomanip> #define pv(val) cerr << #val << '=' << (val) << endl #define pvn(name, val) cerr << name << '=' << (val) << endl #define pl cerr << '@' << __LINE__ << endl using namespace std; using ll = int64_t; #define rep(i, n) for (ll i = 0; i < (n); i++) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() template <class T> ostream &operator<<(ostream &os, vector<T> const &vec) { if (vec.empty()) { os << "{}"; } else { os << '{'; for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", "; os << vec.back() << '}'; } return os; } template <class T, size_t S> ostream &operator<<(ostream &os, array<T, S> const &arr) { if (arr.empty()) { os << "{}"; } else { os << '{'; for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", "; os << arr.back() << '}'; } return os; } template <class T, class U> ostream &operator<<(ostream &os, pair<T, U> const &p) { os << '(' << p.first << ", " << p.second << ')'; return os; } namespace math { ll gcd(ll u, ll v) { while (v != 0) { ll r = u % v; u = v; v = r; } return u; } ll lcm(ll m, ll n) { if ((0 == m) || (0 == n)) return 0; return ((m / math::gcd(m, n)) * n); } } // namespace math struct UnionFind { vector<ll> data; UnionFind(ll size) : data(size, -1) {} bool unionSet(ll x, ll y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool findSet(ll x, ll y) { return root(x) == root(y); } ll root(ll x) { return data[x] < 0 ? x : data[x] = root(data[x]); } ll size(ll x) { return -data[root(x)]; } }; template <class T, class U> pair<T, U> operator+(pair<T, U> const &a, pair<T, U> const &b) { return pair<T, U>(a.first + b.first, a.second + b.second); } template <class T, class U> pair<T, U> operator-(pair<T, U> const &a, pair<T, U> const &b) { return pair<T, U>(a.first - b.first, a.second - b.second); } ll bound(function<bool(ll)> f, ll ng, ll ok) { while (abs(ng - ok) > 1) { ll mid = (ng + ok) / 2; if (f(mid)) ok = mid; else ng = mid; } return ok; } bool goRight(vector<string> const &c, ll y) { rep(i, c[0].size()) if (c[y][i] == '#') return false; return true; } bool start(vector<string> const &c, int y, int sy, int sx, int dy, int dx) { vector<pair<ll, ll>> stk; stk.push_back({sy, sx}); vector<vector<bool>> visited(c.size(), vector<bool>(c[0].size(), false)); while (!stk.empty()) { auto const t = stk.back(); stk.pop_back(); if (t.first < 0 || t.first >= c.size() || t.second < 0 || t.second >= c[0].size()) continue; if (c[t.first][t.second] == '#') continue; if (visited[t.first][t.second]) continue; visited[t.first][t.second] = true; if (t.first == y) return true; stk.push_back({t.first + dy, t.second}); stk.push_back({t.first, t.second + dx}); } return false; } double prob(ll const N, ll const K, ll const n) { if (n >= K) return 1.0; double const X = ceil(log2(K / n)); return pow(0.5, X); } int main(void) { ll N, K; cin >> N >> K; double p = 0.0; for (ll n = 1; n <= N; n++) p += prob(N, K, n); p /= N; cout << setprecision(11); cout << p << endl; return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cmath> #include <functional> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <set> #include <string> #include <vector> #include <iomanip> #define pv(val) cerr << #val << '=' << (val) << endl #define pvn(name, val) cerr << name << '=' << (val) << endl #define pl cerr << '@' << __LINE__ << endl using namespace std; using ll = int64_t; #define rep(i, n) for (ll i = 0; i < (n); i++) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() template <class T> ostream &operator<<(ostream &os, vector<T> const &vec) { if (vec.empty()) { os << "{}"; } else { os << '{'; for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", "; os << vec.back() << '}'; } return os; } template <class T, size_t S> ostream &operator<<(ostream &os, array<T, S> const &arr) { if (arr.empty()) { os << "{}"; } else { os << '{'; for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", "; os << arr.back() << '}'; } return os; } template <class T, class U> ostream &operator<<(ostream &os, pair<T, U> const &p) { os << '(' << p.first << ", " << p.second << ')'; return os; } namespace math { ll gcd(ll u, ll v) { while (v != 0) { ll r = u % v; u = v; v = r; } return u; } ll lcm(ll m, ll n) { if ((0 == m) || (0 == n)) return 0; return ((m / math::gcd(m, n)) * n); } } // namespace math struct UnionFind { vector<ll> data; UnionFind(ll size) : data(size, -1) {} bool unionSet(ll x, ll y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool findSet(ll x, ll y) { return root(x) == root(y); } ll root(ll x) { return data[x] < 0 ? x : data[x] = root(data[x]); } ll size(ll x) { return -data[root(x)]; } }; template <class T, class U> pair<T, U> operator+(pair<T, U> const &a, pair<T, U> const &b) { return pair<T, U>(a.first + b.first, a.second + b.second); } template <class T, class U> pair<T, U> operator-(pair<T, U> const &a, pair<T, U> const &b) { return pair<T, U>(a.first - b.first, a.second - b.second); } ll bound(function<bool(ll)> f, ll ng, ll ok) { while (abs(ng - ok) > 1) { ll mid = (ng + ok) / 2; if (f(mid)) ok = mid; else ng = mid; } return ok; } bool goRight(vector<string> const &c, ll y) { rep(i, c[0].size()) if (c[y][i] == '#') return false; return true; } bool start(vector<string> const &c, int y, int sy, int sx, int dy, int dx) { vector<pair<ll, ll>> stk; stk.push_back({sy, sx}); vector<vector<bool>> visited(c.size(), vector<bool>(c[0].size(), false)); while (!stk.empty()) { auto const t = stk.back(); stk.pop_back(); if (t.first < 0 || t.first >= c.size() || t.second < 0 || t.second >= c[0].size()) continue; if (c[t.first][t.second] == '#') continue; if (visited[t.first][t.second]) continue; visited[t.first][t.second] = true; if (t.first == y) return true; stk.push_back({t.first + dy, t.second}); stk.push_back({t.first, t.second + dx}); } return false; } double prob(ll const N, ll const K, ll const n) { if (n >= K) return 1.0; double const X = ceil(log2((double)K / n)); return pow(0.5, X); } int main(void) { ll N, K; cin >> N >> K; double p = 0.0; for (ll n = 1; n <= N; n++) p += prob(N, K, n); p /= N; cout << setprecision(11); cout << p << endl; return 0; }
[ "type_conversion.add" ]
862,549
862,550
u967620300
cpp
p03043
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPr(i, n) for (int i = (n)-1; i >= 0; --i) #define FORq(i, m, n) for (int i = (m); i <= (n); ++i) #define FORqr(i, m, n) for (int i = (n); i >= (m); --i) #define PB push_back #define MP make_pair #define DEBUG printf("%s\n", "debug") #define fst first #define snd second #define SIN(x, S) (S.count(x) != 0) #define M0(x) memset(x, 0, sizeof(x)) #define FILL(x, y) memset(x, y, sizeof(x)) #define MM(x) memset(x, -1, sizeof(x)) #define ALL(x) (x).begin(), (x).end() using namespace std; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef long long ll; typedef long long integer; /////////////////////////////////////////////// const ll MOD = 1000000007; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } /////////////////////////////////////////////// /*(๑•﹏•๑`) */ int main() { // 2^(x-1) < K となる最大のx=e ll N, K; cin >> N >> K; double ans; vector<ll> domi; ll maxdom = 1; FORq(T, 1, N) { int e = 0; ll pow = T; if (pow >= K) { domi.PB(1); continue; } while (pow <= K) pow *= (ll)2, ++e; ll dom = 1; REP(i, e) { dom *= (ll)2; } domi.PB(dom); chmax(maxdom, dom); } ll bunsi = 0; REP(i, domi.size()) { bunsi += maxdom / domi[i]; } ans = (bunsi / (double)(maxdom)) / N; printf("%.20f", ans); }
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPr(i, n) for (int i = (n)-1; i >= 0; --i) #define FORq(i, m, n) for (int i = (m); i <= (n); ++i) #define FORqr(i, m, n) for (int i = (n); i >= (m); --i) #define PB push_back #define MP make_pair #define DEBUG printf("%s\n", "debug") #define fst first #define snd second #define SIN(x, S) (S.count(x) != 0) #define M0(x) memset(x, 0, sizeof(x)) #define FILL(x, y) memset(x, y, sizeof(x)) #define MM(x) memset(x, -1, sizeof(x)) #define ALL(x) (x).begin(), (x).end() using namespace std; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef long long ll; typedef long long integer; /////////////////////////////////////////////// const ll MOD = 1000000007; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } /////////////////////////////////////////////// /*(๑•﹏•๑`) */ int main() { // 2^(x-1) < K となる最大のx=e ll N, K; cin >> N >> K; double ans; vector<ll> domi; ll maxdom = 1; FORq(T, 1, N) { int e = 0; ll pow = T; if (pow >= K) { domi.PB(1); continue; } while (pow < K) pow *= (ll)2, ++e; ll dom = 1; REP(i, e) { dom *= (ll)2; } domi.PB(dom); chmax(maxdom, dom); } ll bunsi = 0; REP(i, domi.size()) { bunsi += maxdom / domi[i]; } ans = (bunsi / (double)(maxdom)) / N; printf("%.20f", ans); }
[ "expression.operator.compare.change", "control_flow.loop.condition.change" ]
862,596
862,597
u236433947
cpp
p03043
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPr(i, n) for (int i = (n)-1; i >= 0; --i) #define FORq(i, m, n) for (int i = (m); i <= (n); ++i) #define FORqr(i, m, n) for (int i = (n); i >= (m); --i) #define PB push_back #define MP make_pair #define DEBUG printf("%s\n", "debug") #define fst first #define snd second #define SIN(x, S) (S.count(x) != 0) #define M0(x) memset(x, 0, sizeof(x)) #define FILL(x, y) memset(x, y, sizeof(x)) #define MM(x) memset(x, -1, sizeof(x)) #define ALL(x) (x).begin(), (x).end() using namespace std; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef long long ll; typedef long long integer; /////////////////////////////////////////////// const ll MOD = 1000000007; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } /////////////////////////////////////////////// /*(๑•﹏•๑`) */ int main() { // 2^(x-1) < K となる最大のx=e ll N, K; cin >> N >> K; double ans; vector<ll> domi; ll maxdom = 1; FORq(T, 1, N) { int e = 0; ll pow = T; if (pow >= K) { domi.PB(1); continue; } while (pow <= K) pow *= (ll)2, ++e; ll dom = 1; REP(i, e) { dom *= (ll)2; } domi.PB(dom); chmax(maxdom, dom); } ll bunsi = 0; REP(i, domi.size()) { bunsi += maxdom / domi[i]; } ans = (bunsi / (double)(maxdom)) / N; printf("%.16f", ans); }
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPr(i, n) for (int i = (n)-1; i >= 0; --i) #define FORq(i, m, n) for (int i = (m); i <= (n); ++i) #define FORqr(i, m, n) for (int i = (n); i >= (m); --i) #define PB push_back #define MP make_pair #define DEBUG printf("%s\n", "debug") #define fst first #define snd second #define SIN(x, S) (S.count(x) != 0) #define M0(x) memset(x, 0, sizeof(x)) #define FILL(x, y) memset(x, y, sizeof(x)) #define MM(x) memset(x, -1, sizeof(x)) #define ALL(x) (x).begin(), (x).end() using namespace std; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef long long ll; typedef long long integer; /////////////////////////////////////////////// const ll MOD = 1000000007; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } /////////////////////////////////////////////// /*(๑•﹏•๑`) */ int main() { // 2^(x-1) < K となる最大のx=e ll N, K; cin >> N >> K; double ans; vector<ll> domi; ll maxdom = 1; FORq(T, 1, N) { int e = 0; ll pow = T; if (pow >= K) { domi.PB(1); continue; } while (pow < K) pow *= (ll)2, ++e; ll dom = 1; REP(i, e) { dom *= (ll)2; } domi.PB(dom); chmax(maxdom, dom); } ll bunsi = 0; REP(i, domi.size()) { bunsi += maxdom / domi[i]; } ans = (bunsi / (double)(maxdom)) / N; printf("%.20f", ans); }
[ "expression.operator.compare.change", "control_flow.loop.condition.change", "literal.string.change", "call.arguments.change", "io.output.change" ]
862,598
862,597
u236433947
cpp
p03043
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <string> #include <vector> using namespace std; using std::swap; double t = 0.0; int N, K; double che(int x) { int n = 1; while (1) { x *= 2; if (x >= K) break; ++n; } return n; } int main() { double p; cin >> N >> K; for (int i = 0; i < N; ++i) { if (i >= K) { t += 1.0 / N; } else { p = che(i + 1); t += pow(0.5, p) / N; } // printf("%.12f\n", pow(0.5, p)/N); // printf("%d %.12f\n",i+1,t); } printf("%.12f\n", t); return 0; }
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <string> #include <vector> using namespace std; using std::swap; double t = 0.0; double N, K; double che(int x) { double n = 1; while (1) { x *= 2; if (x >= K) break; ++n; } return n; } int main() { double p; cin >> N >> K; for (int i = 0; i < N; ++i) { if (i + 1 >= K) { t += 1.0 / N; } else { p = che(i + 1); t += pow(0.5, p) / N; } // printf("%.12f\n", pow(0.5, p)/N); // printf("%d %.12f\n",i+1,t); } printf("%.12f\n", t); return 0; }
[ "variable_declaration.type.primitive.change", "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "misc.off_by_one" ]
862,599
862,600
u196471026
cpp
p03043
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; typedef long long ll; typedef pair<int, ll> pll; vector<pll> g[N]; int n; ll d[N]; int a[N]; int main() { int n, k; cin >> n >> k; double ans = 0.0; for (int i = 1; i <= n; i++) { double pro = 1.0; int cur = i; while (cur <= k) { cur *= 2; pro = (pro * 0.5); } ans += pro * (1.0 / (double)n); } printf("%0.14lf\n", ans); }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; typedef long long ll; typedef pair<int, ll> pll; vector<pll> g[N]; int n; ll d[N]; int a[N]; int main() { int n, k; cin >> n >> k; double ans = 0.0; for (int i = 1; i <= n; i++) { double pro = 1.0; int cur = i; while (cur < k) { cur *= 2; pro = (pro * 0.5); } ans += pro * (1.0 / (double)n); } printf("%0.14lf\n", ans); }
[ "expression.operator.compare.change", "control_flow.loop.condition.change" ]
862,622
862,623
u208440216
cpp
p03043
#include <cmath> #include <iomanip> #include <iostream> using namespace std; int main() { int n, k; double win_p = 0; cin >> n >> k; for (int i = 1; i <= n; i++) { int e = 0; while (i * pow(2.0, e) <= k) { e++; } win_p += (1.0 / n) * pow((1.0 / 2), e); } cout << std::setprecision(12) << win_p << endl; }
#include <cmath> #include <iomanip> #include <iostream> using namespace std; int main() { int n, k; long double win_p = 0; cin >> n >> k; for (int i = 1; i <= n; i++) { int e = 0; while (i * pow(2.0, e) < k) { e++; } win_p += (1.0 / n) * pow((1.0 / 2), e); } cout << std::setprecision(12) << win_p << endl; }
[ "variable_declaration.type.widen.change", "expression.operator.compare.change", "control_flow.loop.condition.change" ]
862,633
862,634
u312025627
cpp
p03043
#include <cmath> #include <iomanip> #include <iostream> using namespace std; int main() { int n, k; double win_p = 0; cin >> n >> k; for (int i = 1; i <= n; i++) { int e = 0; while (i * pow(2.0, e) <= k) { e++; } win_p += (1.0 / n) * pow((1.0 / 2), e); } cout << std::setprecision(12) << win_p << endl; }
#include <cmath> #include <iomanip> #include <iostream> using namespace std; int main() { int n, k; double win_p = 0; cin >> n >> k; for (int i = 1; i <= n; i++) { int e = 0; while (i * pow(2.0, e) < k) { e++; } win_p += (1.0 / n) * pow((1.0 / 2), e); } cout << std::setprecision(12) << win_p << endl; }
[ "expression.operator.compare.change", "control_flow.loop.condition.change" ]
862,633
862,635
u312025627
cpp
p03043
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #define pb push_back #define mp make_pair #define M 1101 #define MOD 1000000007 #define fi first #define se second #define vi vector<int> #define vl vector<ll> #define all(v) v.begin(), v.end() #define repl(i, l, r) for (long long i = l; i <= r; ++i) #define rep(i, l, r) for (int i = l; i <= r; ++i) #define ins insert #define inf INT_MAX #define vp vector<pair<int, int>> int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; int x = min(k - 1, n); double sum = 0.0; for (int i = 1; i <= x; i++) { double p1 = (double)1 / n; int j = i * 2; int c = 0; while (j < k) { c++; j = j * 2; } double p2 = pow(0.5, c + 1); double p = p1 * p2; sum += p; } cout.precision(12); cout << fixed << sum << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #define pb push_back #define mp make_pair #define M 1101 #define MOD 1000000007 #define fi first #define se second #define vi vector<int> #define vl vector<ll> #define all(v) v.begin(), v.end() #define repl(i, l, r) for (long long i = l; i <= r; ++i) #define rep(i, l, r) for (int i = l; i <= r; ++i) #define ins insert #define inf INT_MAX #define vp vector<pair<int, int>> int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; int x = min(k - 1, n); double sum = 0.0; for (int i = 1; i <= n; i++) { double p1 = (double)1 / n; int j = i; int c = 0; while (j < k) { c++; j = j * 2; } double p2 = pow(0.5, c); double p = p1 * p2; sum += p; } cout.precision(12); cout << fixed << sum << "\n"; return 0; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
862,641
862,642
u456070059
cpp
p03043
#include <algorithm> #include <array> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; using lint = long long; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; double ans = 0; for (int i = 1; i <= n; i++) { double co = (double)1 / n; int mm = i; for (int j = 0; mm <= k; j++) { mm *= 2; co *= (double)(0.5); } ans += co; } cout << fixed << setprecision(16) << ans << endl; return 0; }
#include <algorithm> #include <array> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; using lint = long long; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; double ans = 0; for (int i = 1; i <= n; i++) { double co = (double)1 / n; int mm = i; for (int j = 0; mm < k; j++) { mm *= 2; co *= (double)(0.5); } ans += co; } cout << fixed << setprecision(16) << ans << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
862,647
862,648
u298980954
cpp
p03043
/* ID: Aman Raj LANG: C++ TASK: milk3 */ #include <iostream> #include <stdio.h> //#include<iostream> #include <algorithm> #include <vector> using namespace std; #include <math.h> typedef long long ll; #include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <iomanip> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> // setbase - cout << setbase (16); cout << 100 << endl; Prints 64 // setfill - cout << setfill ('x') << setw (5); cout << 77 << endl; prints // xxx77 setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx // cout.precision(x) cout<<fixed<<val; // prints x digits after decimal in val using namespace std; using namespace __gnu_pbds; #define f(i, a, b) for (i = a; i < b; i++) #define rep(i, n) f(i, 0, n) #define fd(i, a, b) for (i = a; i >= b; i--) #define pb push_back #define mp make_pair #define vi vector<int> #define vl vector<ll> #define ss second #define ff first //#define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define sz(a) a.size() #define inf (1000 * 1000 * 1000 + 5) #define all(a) a.begin(), a.end() #define tri pair<int, pii> #define vii vector<pii> #define vll vector<pll> #define viii vector<tri> #define mod (1000 * 1000 * 1000 + 7) #define pqueue priority_queue<int> #define pdqueue priority_queue<int, vi, greater<int>> //#define flush fflush(stdout) #define primeDEN 727999983 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #include <fstream> // find_by_order() // order_of_key typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; int main() { ifstream fin("milk3.in"); ofstream fout("milk3.out"); ll n, k; cin >> n >> k; cout << setprecision(12); double ans = 0.000000000; for (ll i = 1; i <= n; i++) { double p = 1.000000000000; ll j = i; if (j < k) { while (j <= k) { p *= (1.000000000000 / 2); j *= 2; } } ans += (1.000000000000 / n) * p; } cout << ans; return 0; }
/* ID: Aman Raj LANG: C++ TASK: milk3 */ #include <iostream> #include <stdio.h> //#include<iostream> #include <algorithm> #include <vector> using namespace std; #include <math.h> typedef long long ll; #include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <iomanip> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> // setbase - cout << setbase (16); cout << 100 << endl; Prints 64 // setfill - cout << setfill ('x') << setw (5); cout << 77 << endl; prints // xxx77 setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx // cout.precision(x) cout<<fixed<<val; // prints x digits after decimal in val using namespace std; using namespace __gnu_pbds; #define f(i, a, b) for (i = a; i < b; i++) #define rep(i, n) f(i, 0, n) #define fd(i, a, b) for (i = a; i >= b; i--) #define pb push_back #define mp make_pair #define vi vector<int> #define vl vector<ll> #define ss second #define ff first //#define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define sz(a) a.size() #define inf (1000 * 1000 * 1000 + 5) #define all(a) a.begin(), a.end() #define tri pair<int, pii> #define vii vector<pii> #define vll vector<pll> #define viii vector<tri> #define mod (1000 * 1000 * 1000 + 7) #define pqueue priority_queue<int> #define pdqueue priority_queue<int, vi, greater<int>> //#define flush fflush(stdout) #define primeDEN 727999983 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #include <fstream> // find_by_order() // order_of_key typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; int main() { ifstream fin("milk3.in"); ofstream fout("milk3.out"); ll n, k; cin >> n >> k; cout << setprecision(12); double ans = 0.000000000; for (ll i = 1; i <= n; i++) { double p = 1; ll j = i; if (j < k) { while (j < k) { p *= (1.000000000000 / 2); j *= 2; } } ans += (1.000000000000 / n) * p; } cout << ans; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "expression.operator.compare.change", "control_flow.loop.condition.change" ]
862,659
862,660
u756289568
cpp
p03043
/* ID: Aman Raj LANG: C++ TASK: milk3 */ #include <iostream> #include <stdio.h> //#include<iostream> #include <algorithm> #include <vector> using namespace std; #include <math.h> typedef long long ll; #include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <iomanip> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> // setbase - cout << setbase (16); cout << 100 << endl; Prints 64 // setfill - cout << setfill ('x') << setw (5); cout << 77 << endl; prints // xxx77 setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx // cout.precision(x) cout<<fixed<<val; // prints x digits after decimal in val using namespace std; using namespace __gnu_pbds; #define f(i, a, b) for (i = a; i < b; i++) #define rep(i, n) f(i, 0, n) #define fd(i, a, b) for (i = a; i >= b; i--) #define pb push_back #define mp make_pair #define vi vector<int> #define vl vector<ll> #define ss second #define ff first //#define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define sz(a) a.size() #define inf (1000 * 1000 * 1000 + 5) #define all(a) a.begin(), a.end() #define tri pair<int, pii> #define vii vector<pii> #define vll vector<pll> #define viii vector<tri> #define mod (1000 * 1000 * 1000 + 7) #define pqueue priority_queue<int> #define pdqueue priority_queue<int, vi, greater<int>> //#define flush fflush(stdout) #define primeDEN 727999983 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #include <fstream> // find_by_order() // order_of_key typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; int main() { ifstream fin("milk3.in"); ofstream fout("milk3.out"); ll n, k; cin >> n >> k; cout << setprecision(12); double ans = 0.000000000; for (ll i = 1; i <= n; i++) { double p = 1.000000000; ll j = i; if (j < k) { while (j <= k) { p *= (1.0000000000 / 2); j *= 2; } } ans += (1.000000000 / n) * p; } cout << ans; return 0; }
/* ID: Aman Raj LANG: C++ TASK: milk3 */ #include <iostream> #include <stdio.h> //#include<iostream> #include <algorithm> #include <vector> using namespace std; #include <math.h> typedef long long ll; #include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <iomanip> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> // setbase - cout << setbase (16); cout << 100 << endl; Prints 64 // setfill - cout << setfill ('x') << setw (5); cout << 77 << endl; prints // xxx77 setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx // cout.precision(x) cout<<fixed<<val; // prints x digits after decimal in val using namespace std; using namespace __gnu_pbds; #define f(i, a, b) for (i = a; i < b; i++) #define rep(i, n) f(i, 0, n) #define fd(i, a, b) for (i = a; i >= b; i--) #define pb push_back #define mp make_pair #define vi vector<int> #define vl vector<ll> #define ss second #define ff first //#define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define sz(a) a.size() #define inf (1000 * 1000 * 1000 + 5) #define all(a) a.begin(), a.end() #define tri pair<int, pii> #define vii vector<pii> #define vll vector<pll> #define viii vector<tri> #define mod (1000 * 1000 * 1000 + 7) #define pqueue priority_queue<int> #define pdqueue priority_queue<int, vi, greater<int>> //#define flush fflush(stdout) #define primeDEN 727999983 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #include <fstream> // find_by_order() // order_of_key typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; int main() { ifstream fin("milk3.in"); ofstream fout("milk3.out"); ll n, k; cin >> n >> k; cout << setprecision(12); double ans = 0.000000000; for (ll i = 1; i <= n; i++) { double p = 1; ll j = i; if (j < k) { while (j < k) { p *= (1.000000000000 / 2); j *= 2; } } ans += (1.000000000000 / n) * p; } cout << ans; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "expression.operator.compare.change", "control_flow.loop.condition.change", "assignment.value.change", "expression.operation.binary.change" ]
862,661
862,660
u756289568
cpp
p03043
#include <algorithm> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; int main() { int n, k; cin >> n >> k; double cnt = 0; for (int i = 1; i <= n; ++i) { if (i >= k) cnt += 1; else { int omote = ceil(log2(k / i)); cnt += 1 / pow(2, omote); } } cout << setprecision(18) << cnt / n << endl; return 0; }
#include <algorithm> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; int main() { int n, k; cin >> n >> k; double cnt = 0; for (int i = 1; i <= n; ++i) { if (i >= k) cnt += 1; else { int omote = ceil(log2(double(k) / i)); cnt += 1 / pow(2, omote); } } cout << setprecision(18) << cnt / n << endl; return 0; }
[ "call.add", "call.arguments.change" ]
862,662
862,663
u625725849
cpp
p03043
#include <bits/stdc++.h> using namespace std; double solve(int N, int K) { double res = 0; for (int i = 1; i <= N; i++) { int point = i; double ansd = 1; while (K > point) { ansd *= 0.50; point += point; } ansd *= (1.0 / N); res += ansd; } return res; } int main() { int N, K; cin >> N >> K; double ans = 0; double p = solve(N, K); ans = p; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; double solve(int N, int K) { double res = 0; for (int i = 1; i <= N; i++) { int point = i; double ansd = 1; while (K > point) { ansd *= 0.50; point += point; } ansd *= (1.0 / N); res += ansd; } return res; } int main() { int N, K; cin >> N >> K; double ans = 0; double p = solve(N, K); ans = p; cout << setprecision(12) << ans << endl; return 0; }
[ "io.output.change" ]
862,669
862,670
u845882023
cpp
p03043
#include <algorithm> #include <iostream> #include <map> #include <set> #include <string> #include <vector> #include <limits.h> #include <math.h> #include <stdlib.h> #include <string.h> using namespace std; int main() { long n, k, ret; long ii; long double sum = 0, one, div; cin >> n >> k; for (ii = 1; ii <= n; ii++) { one = 1.0 / n; ret = ii; div = 1; while (ret <= k) { ret *= 2; // one /= 2.0; div *= 2; } // div = ret; // cout << ret << endl; one /= div; // cout << one << endl; sum += one; } // cout << sum << endl; printf("%.12Lf\n", sum); return 0; }
#include <algorithm> #include <iostream> #include <map> #include <set> #include <string> #include <vector> #include <limits.h> #include <math.h> #include <stdlib.h> #include <string.h> using namespace std; int main() { long n, k, ret; long ii; long double sum = 0, one, div; cin >> n >> k; for (ii = 1; ii <= n; ii++) { one = 1.0 / n; ret = ii; div = 1; while (ret < k) { ret *= 2; // one /= 2.0; div *= 2; } // div = ret; // cout << ret << endl; one /= div; // cout << one << endl; sum += one; } // cout << sum << endl; printf("%.12Lf\n", sum); return 0; }
[ "expression.operator.compare.change", "control_flow.loop.condition.change" ]
862,680
862,681
u146847434
cpp
p03043
#include <algorithm> #include <iostream> #include <map> #include <set> #include <string> #include <vector> #include <limits.h> #include <math.h> #include <stdlib.h> #include <string.h> using namespace std; int main() { long n, k, ret; long ii; double sum = 0, one, div; cin >> n >> k; for (ii = 1; ii <= n; ii++) { one = 1.0 / n; ret = ii; div = 1; while (ret <= k) { ret *= 2; // one /= 2.0; div *= 2; } // div = ret; // cout << ret << endl; one /= div; // cout << one << endl; sum += one; } // cout << sum << endl; printf("%.12lf\n", sum); return 0; }
#include <algorithm> #include <iostream> #include <map> #include <set> #include <string> #include <vector> #include <limits.h> #include <math.h> #include <stdlib.h> #include <string.h> using namespace std; int main() { long n, k, ret; long ii; long double sum = 0, one, div; cin >> n >> k; for (ii = 1; ii <= n; ii++) { one = 1.0 / n; ret = ii; div = 1; while (ret < k) { ret *= 2; // one /= 2.0; div *= 2; } // div = ret; // cout << ret << endl; one /= div; // cout << one << endl; sum += one; } // cout << sum << endl; printf("%.12Lf\n", sum); return 0; }
[ "variable_declaration.type.widen.change", "expression.operator.compare.change", "control_flow.loop.condition.change", "literal.string.change", "literal.string.case.change", "call.arguments.change", "io.output.change" ]
862,682
862,681
u146847434
cpp
p03044
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; int N; int U[100010]; int V[100010]; int W[100010]; class UnionFindTree { private: // indexの数の親ノード(ある集合の親を見つけたいときはここを直接参照せず、findを使う) vector<int> par; // indexを根とする木のランク vector<int> rank; // 集合のサイズ vector<int> cnts; // 木の最大値 int treeSize; public: UnionFindTree(int initTreeSize = 1000) { // 引数で与えられた値を最大格納数とするUnionFindTreeの作成 treeSize = initTreeSize; init(initTreeSize); } void init(int sz) { par.clear(), rank.clear(), cnts.clear(); treeSize = sz; for (int i = 0; i < sz; i++) { par.push_back(i); rank.push_back(0); cnts.push_back(1); } } // 与えられた数が格納されている木のルートを探索 int find(int x) { if (par[x] == x) return x; else return par[x] = find(par[x]); } // 和集合をとる。ただしここでは各集合の親の付け替えは起こらない void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rank[x] < rank[y]) { par[x] = y; cnts[y] += cnts[x]; } else { par[y] = x; cnts[x] += cnts[y]; if (rank[y] == rank[x]) rank[x]++; } } // xの属する集合のサイズ int getCnt(int x) { return cnts[find(x)]; } bool same(int x, int y) { return find(x) == find(y); } }; set<int> G[100010]; UnionFindTree uft(100010); bool used[100010]; int cols[100010]; void dfs(int pos, int col) { used[pos] = true; cols[pos] = col; for (int to : G[pos]) { if (used[to]) continue; dfs(to, col ^ 1); } } int main() { cin >> N; for (int i = 0; i < N - 1; i++) { cin >> U[i] >> V[i] >> W[i]; U[i]--; V[i]--; if (W[i] % 2 == 0) { uft.unite(U[i], V[i]); } } int start = -1; for (int i = 0; i < N; i++) { int u = uft.find(U[i]); int v = uft.find(V[i]); if (u != v) { G[u].insert(v); G[v].insert(u); start = u; } } dfs(start, 0); for (int i = 0; i < N; i++) { cout << cols[uft.find(i)] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; int N; int U[100010]; int V[100010]; int W[100010]; class UnionFindTree { private: // indexの数の親ノード(ある集合の親を見つけたいときはここを直接参照せず、findを使う) vector<int> par; // indexを根とする木のランク vector<int> rank; // 集合のサイズ vector<int> cnts; // 木の最大値 int treeSize; public: UnionFindTree(int initTreeSize = 1000) { // 引数で与えられた値を最大格納数とするUnionFindTreeの作成 treeSize = initTreeSize; init(initTreeSize); } void init(int sz) { par.clear(), rank.clear(), cnts.clear(); treeSize = sz; for (int i = 0; i < sz; i++) { par.push_back(i); rank.push_back(0); cnts.push_back(1); } } // 与えられた数が格納されている木のルートを探索 int find(int x) { if (par[x] == x) return x; else return par[x] = find(par[x]); } // 和集合をとる。ただしここでは各集合の親の付け替えは起こらない void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rank[x] < rank[y]) { par[x] = y; cnts[y] += cnts[x]; } else { par[y] = x; cnts[x] += cnts[y]; if (rank[y] == rank[x]) rank[x]++; } } // xの属する集合のサイズ int getCnt(int x) { return cnts[find(x)]; } bool same(int x, int y) { return find(x) == find(y); } }; set<int> G[100010]; UnionFindTree uft(100010); bool used[100010]; int cols[100010]; void dfs(int pos, int col) { used[pos] = true; cols[pos] = col; for (int to : G[pos]) { if (used[to]) continue; dfs(to, col ^ 1); } } int main() { cin >> N; for (int i = 0; i < N - 1; i++) { cin >> U[i] >> V[i] >> W[i]; U[i]--; V[i]--; if (W[i] % 2 == 0) { uft.unite(U[i], V[i]); } } int start = -1; for (int i = 0; i < N; i++) { int u = uft.find(U[i]); int v = uft.find(V[i]); if (u != v) { G[u].insert(v); G[v].insert(u); } start = u; } dfs(start, 0); for (int i = 0; i < N; i++) { cout << cols[uft.find(i)] << endl; } return 0; }
[]
862,690
862,691
u489053642
cpp
p03044
#include <algorithm> #include <cstring> #include <iostream> #include <queue> #include <vector> struct nd { int to, w; nd(int t, int ww) : to(t), w(ww) {} }; std::vector<nd> vec[100005]; int drg[100005]; bool vis[100005]; bool col[100005]; int main() { int n; std::cin >> n; int u, v, w; for (int i = 1; i < n; ++i) { std::cin >> u >> v >> w; vec[u].push_back(nd(v, w)); vec[v].push_back(nd(u, w)); drg[u]++; drg[v]++; } std::queue<int> que; vis[1] = true; que.push(1); while (!que.empty()) { int it = que.front(); que.pop(); for (auto &ir : vec[it]) { if (!vis[ir.to]) { if (ir.w & 1) col[ir.to] = col[it]; else col[ir.to] = !col[it]; que.push(ir.to); vis[ir.to] = true; } } } for (int i = 1; i <= n; ++i) { std::cout << col[i] << std::endl; } }
#include <algorithm> #include <cstring> #include <iostream> #include <queue> #include <vector> struct nd { int to, w; nd(int t, int ww) : to(t), w(ww) {} }; std::vector<nd> vec[100005]; int drg[100005]; bool vis[100005]; bool col[100005]; int main() { int n; std::cin >> n; int u, v, w; for (int i = 1; i < n; ++i) { std::cin >> u >> v >> w; vec[u].push_back(nd(v, w)); vec[v].push_back(nd(u, w)); drg[u]++; drg[v]++; } std::queue<int> que; vis[1] = true; que.push(1); while (!que.empty()) { int it = que.front(); que.pop(); for (auto &ir : vec[it]) { if (!vis[ir.to]) { if (ir.w & 1) col[ir.to] = !col[it]; else col[ir.to] = col[it]; que.push(ir.to); vis[ir.to] = true; } } } for (int i = 1; i <= n; ++i) { std::cout << col[i] << std::endl; } }
[ "control_flow.branch.else.remove", "control_flow.branch.else_if.replace.remove", "control_flow.branch.if.replace.add", "assignment.add" ]
862,692
862,693
u750215086
cpp
p03044
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int N; int u, v, w; cin >> N; vector<int> ans(N, -1); vector<int> odd[100010]; vector<int> even[100010]; for (int i = 0; i < N - 1; i++) { cin >> u >> v >> w; if (w % 2 == 0) { even[u - 1].push_back(v - 1); even[v - 1].push_back(u - 1); } else { odd[u - 1].push_back(v - 1); odd[v - 1].push_back(u - 1); } } queue<int> q; q.push(0); ans[0] = 0; while (!q.empty()) { int now = q.front(); q.pop(); for (int i = 0; i < even[now].size(); i++) { if (ans[even[now][i]] != -1) continue; ans[even[now][i]] = ans[now]; q.push(even[now][i]); } for (int i = 0; i < odd[now].size(); i++) { if (ans[odd[now][i]] != -1) continue; ans[odd[now][i]] = ((ans[now] == 1) ? 0 : 1); q.push(even[now][i]); } } for (int i = 0; i < N; i++) { cout << ans[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int N; long u, v, w; cin >> N; vector<int> ans(N, -1); vector<int> odd[100010]; vector<int> even[100010]; for (int i = 0; i < N - 1; i++) { cin >> u >> v >> w; if (w % 2 == 0) { even[u - 1].push_back(v - 1); even[v - 1].push_back(u - 1); } else { odd[u - 1].push_back(v - 1); odd[v - 1].push_back(u - 1); } } queue<int> q; q.push(0); ans[0] = 0; while (!q.empty()) { int now = q.front(); q.pop(); for (int i = 0; i < even[now].size(); i++) { if (ans[even[now][i]] != -1) continue; ans[even[now][i]] = ans[now]; q.push(even[now][i]); } for (int i = 0; i < odd[now].size(); i++) { if (ans[odd[now][i]] != -1) continue; ans[odd[now][i]] = ((ans[now] == 1) ? 0 : 1); q.push(odd[now][i]); } } for (int i = 0; i < N; i++) { cout << ans[i] << endl; } return 0; }
[ "variable_declaration.type.primitive.change", "misc.opposites", "identifier.change", "call.arguments.change" ]
862,702
862,703
u854831509
cpp
p03044
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // #include <ext/pb_ds/assoc_container.hpp> //#include <boost/multiprecision/cpp_int.hpp> using namespace std; // using namespace boost::multiprecision; // using namespace __gnu_pbds; #define all(c) (c).begin(), (c).end() #define endl "\n" #define ff first #define ss second #define allr(c) (c).rbegin(), (c).rend() #define fr(x, in, n, r) for (ll x = in; x < n; x += r) #define ifr(x, n) for (ll x = 0; x < n; x++) #define dfr(x, n) for (ll x = n - 1; x >= 0; x--) #define pb(a) push_back(a) #define pf(a) push_front(a) #define pof(a) pop_front(a) #define pob(a) pop_back(a) #define eb(a) emplace_back(a) #define ef(a) emplace_front(a) typedef long long ll; typedef map<ll, ll> mll; typedef map<string, ll> msll; typedef vector<ll> vll; typedef pair<ll, ll> pll; typedef long double ld; #define mod 1000000007 vll v[100001]; bool vis[100001] = {0}; bool ans[100001]; map<pll, bool> m; void dfs(ll u) { vis[u] = 1; ifr(i, v[u].size()) { if (!vis[v[u][i]]) { ans[v[u][i]] = ans[u] ^ m[pll(u, v[u][i])]; dfs(v[u][i]); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen("input.txt","r",stdin); ll n; cin >> n; ll x, y, r; ifr(i, n - 1) { cin >> x >> y >> r; m[pll(x, y)] = r & 1; m[pll(y, r)] = r & 1; v[x].pb(y); v[y].pb(x); } ans[1] = 0; dfs(1); fr(i, 1, n + 1, 1) cout << ans[i] << endl; return 0; }
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // #include <ext/pb_ds/assoc_container.hpp> //#include <boost/multiprecision/cpp_int.hpp> using namespace std; // using namespace boost::multiprecision; // using namespace __gnu_pbds; #define all(c) (c).begin(), (c).end() #define endl "\n" #define ff first #define ss second #define allr(c) (c).rbegin(), (c).rend() #define fr(x, in, n, r) for (ll x = in; x < n; x += r) #define ifr(x, n) for (ll x = 0; x < n; x++) #define dfr(x, n) for (ll x = n - 1; x >= 0; x--) #define pb(a) push_back(a) #define pf(a) push_front(a) #define pof(a) pop_front(a) #define pob(a) pop_back(a) #define eb(a) emplace_back(a) #define ef(a) emplace_front(a) typedef long long ll; typedef map<ll, ll> mll; typedef map<string, ll> msll; typedef vector<ll> vll; typedef pair<ll, ll> pll; typedef long double ld; #define mod 1000000007 vll v[100001]; bool vis[100001] = {0}; bool ans[100001]; map<pll, bool> m; void dfs(ll u) { vis[u] = 1; ifr(i, v[u].size()) { if (!vis[v[u][i]]) { ans[v[u][i]] = ans[u] ^ m[pll(u, v[u][i])]; dfs(v[u][i]); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen("input.txt","r",stdin); ll n; cin >> n; ll x, y, r; ifr(i, n - 1) { cin >> x >> y >> r; m[pll(x, y)] = r & 1; m[pll(y, x)] = r & 1; v[x].pb(y); v[y].pb(x); } ans[1] = 0; dfs(1); fr(i, 1, n + 1, 1) cout << ans[i] << endl; return 0; }
[ "assignment.variable.change", "identifier.change", "variable_access.subscript.index.change", "call.arguments.change" ]
862,708
862,709
u906227026
cpp
p03044
#include <bits/stdc++.h> using namespace std; vector<unsigned long> ans; void dfs(unsigned long now, unsigned long prev, unsigned long col, const vector<vector<pair<unsigned long, unsigned long>>> &edge) { ans[now] = col; for (const auto &i : edge[now]) { if (i.first != prev) { dfs(i.first, now, col ^= i.second, edge); } } } int main() { unsigned long N; cin >> N; ans = vector<unsigned long>(N); vector<vector<pair<unsigned long, unsigned long>>> edge(N); for (unsigned long i = 1, a, b, c; i < N; ++i) { cin >> a >> b >> c; edge[--a].emplace_back(--b, c &= 1); edge[b].emplace_back(a, c); } dfs(0, 0, 0, edge); for (const auto i : ans) cout << i << endl; return 0; }
#include <bits/stdc++.h> using namespace std; vector<unsigned long> ans; void dfs(unsigned long now, unsigned long prev, unsigned long col, const vector<vector<pair<unsigned long, unsigned long>>> &edge) { ans[now] = col; for (const auto &i : edge[now]) { if (i.first != prev) { dfs(i.first, now, col ^ i.second, edge); } } } int main() { unsigned long N; cin >> N; ans = vector<unsigned long>(N); vector<vector<pair<unsigned long, unsigned long>>> edge(N); for (unsigned long i = 1, a, b, c; i < N; ++i) { cin >> a >> b >> c; edge[--a].emplace_back(--b, c &= 1); edge[b].emplace_back(a, c); } dfs(0, 0, 0, edge); for (const auto i : ans) cout << i << endl; return 0; }
[ "assignment.compound.bitwise.replace.remove", "expression.operator.bitwise.replace.add", "call.arguments.change" ]
862,719
862,720
u462437857
cpp
p03044
#include <bits/stdc++.h> using namespace std; vector<unsigned long> ans; void dfs(unsigned long now, unsigned long prev, unsigned long col, const vector<vector<pair<unsigned long, unsigned long>>> &edge) { ans[now] = col; for (const auto &i : edge[now]) { if (i.first != prev) { dfs(i.first, now, col ^= i.second, edge); } } } int main() { unsigned long N; cin >> N; ans = vector<unsigned long>(N); vector<vector<pair<unsigned long, unsigned long>>> edge(N); for (unsigned long i = 1, a, b, c; i < N; ++i) { cin >> a >> b >> c; edge[--a].emplace_back(--b, c &= 1); edge[b].emplace_back(a, c); } dfs(0, 0, 0, edge); for (const auto i : ans) cout << i << endl; return 0; }
#include <bits/stdc++.h> using namespace std; vector<unsigned long> ans; void dfs(unsigned long now, unsigned long prev, unsigned long col, const vector<vector<pair<unsigned long, unsigned long>>> &edge) { ans[now] = col; for (const auto &i : edge[now]) { if (i.first != prev) { dfs(i.first, now, col ^ i.second, edge); } } } int main() { unsigned long N; cin >> N; ans = vector<unsigned long>(N); vector<vector<pair<unsigned long, unsigned long>>> edge(N); for (unsigned long i = 1, a, b, c; i < N; ++i) { cin >> a >> b >> c; edge[--a].emplace_back(--b, c &= 1); edge[b].emplace_back(a, c); } dfs(0, 0, 0, edge); for (const auto i : ans) cout << i << endl; return 0; }
[ "assignment.compound.bitwise.replace.remove", "expression.operator.bitwise.replace.add", "call.arguments.change" ]
862,719
862,721
u462437857
cpp
p03044
//#include "bits/stdc++.h" #include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define int long long #define REP(i, l, r) REPEAT(i, l, r, true) // [l, r) #define rep(i, n) REP(i, 0, n) // [0, n) #define REPEAT(i, l, r, condition) \ for (int i = (condition) ? l : r - 1; (condition) ? i < r : i >= l; \ (condition) ? ++i : --i) // false<-[l, r)->true #define all(e) e.begin(), e.end() #define rall(e) e.rbegin(), e.rend() #define pb push_back #define fs first #define sc second #ifdef LOCAL #define show(...) \ cerr << #__VA_ARGS__ << " = "; \ _DEBUG(__VA_ARGS__) #define showlr(n, l, r) \ cerr << #n << " = "; \ for (int i = l; i < r; i++) { \ cerr << n[i] << ", "; \ } \ cerr << endl // [l, r) #else #define show(...) #define showlr(n, l, r) #endif #define YN(condition) puts((condition) ? "YES" : "NO") #define Yn(condition) puts((condition) ? "Yes" : "No") #define yn(condition) puts((condition) ? "yes" : "no") #define YES puts("YES") #define Yes puts("Yes") #define yes puts("yes") #define NO puts("NO") #define No puts("No") #define no puts("no") #define case (i) printf("Case #%lld: ", i) using namespace std; using vi = vector<int>; using pint = pair<int, int>; struct io { io() { cin.tie(0); ios::sync_with_stdio(false); cout.tie(0); cout << fixed << setprecision(20); } } io; template <class T> istream &operator>>(istream &is, vector<T> &v) { for (T &e : v) is >> e; return is; } template <class T> ostream &operator<<(ostream &os, vector<T> v) { os << "{"; for (T &e : v) os << e << (v.size() - (int)(&e - &v[0]) > 1 ? ", " : ""); os << "}"; return os; } void _DEBUG() {} template <typename H, typename... T> void _DEBUG(H a, T... b) { cerr << a << (sizeof...(b) ? "," : "\n"); _DEBUG(b...); } inline void in() {} template <typename H, typename... T> void in(H &a, T &...b) { cin >> a; in(b...); } inline void out() {} template <typename H, typename... T> void out(H a, T... b) { cout << a << (sizeof...(b) ? " " : "\n"); out(b...); } template <class T> void resz(int n, T &v) { v.resize(n); } template <class H, class... T> void resz(int n, H &a, T &...b) { a.resize(n); resz(n, b...); } template <typename V, typename H> void resize(vector<V> &v, const H a) { v.resize(a); } template <typename V, typename H, typename... T> void resize(vector<V> &v, const H &a, const T... b) { v.resize(a); for (auto &v : v) resize(v, b...); } const int INF = 1LL << 55; const int MOD = 1000000007; const double EPS = 1e-8; /*------------end of definitions------------*/ const int MAX_V = 1e5; vector<pint> G[MAX_V]; int V; vi color; vector<bool> visited; void dfs(int v, int c) { visited[v] = true; if (c & 1) color[v] = 1; rep(i, G[v].size()) { if (!visited[G[v][i].fs]) { dfs(G[v][i].fs, c + G[v][i].sc); } } } signed main() { in(V); visited.resize(V, false); color.resize(V); rep(i, V) { int u, v, w; in(u, v, w); u--; v--; G[u].pb({v, w}); G[v].pb({u, w}); } dfs(0, 0); for (auto e : color) { out(e); } return 0; }
//#include "bits/stdc++.h" #include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define int long long #define REP(i, l, r) REPEAT(i, l, r, true) // [l, r) #define rep(i, n) REP(i, 0, n) // [0, n) #define REPEAT(i, l, r, condition) \ for (int i = (condition) ? l : r - 1; (condition) ? i < r : i >= l; \ (condition) ? ++i : --i) // false<-[l, r)->true #define all(e) e.begin(), e.end() #define rall(e) e.rbegin(), e.rend() #define pb push_back #define fs first #define sc second #ifdef LOCAL #define show(...) \ cerr << #__VA_ARGS__ << " = "; \ _DEBUG(__VA_ARGS__) #define showlr(n, l, r) \ cerr << #n << " = "; \ for (int i = l; i < r; i++) { \ cerr << n[i] << ", "; \ } \ cerr << endl // [l, r) #else #define show(...) #define showlr(n, l, r) #endif #define YN(condition) puts((condition) ? "YES" : "NO") #define Yn(condition) puts((condition) ? "Yes" : "No") #define yn(condition) puts((condition) ? "yes" : "no") #define YES puts("YES") #define Yes puts("Yes") #define yes puts("yes") #define NO puts("NO") #define No puts("No") #define no puts("no") #define case (i) printf("Case #%lld: ", i) using namespace std; using vi = vector<int>; using pint = pair<int, int>; struct io { io() { cin.tie(0); ios::sync_with_stdio(false); cout.tie(0); cout << fixed << setprecision(20); } } io; template <class T> istream &operator>>(istream &is, vector<T> &v) { for (T &e : v) is >> e; return is; } template <class T> ostream &operator<<(ostream &os, vector<T> v) { os << "{"; for (T &e : v) os << e << (v.size() - (int)(&e - &v[0]) > 1 ? ", " : ""); os << "}"; return os; } void _DEBUG() {} template <typename H, typename... T> void _DEBUG(H a, T... b) { cerr << a << (sizeof...(b) ? "," : "\n"); _DEBUG(b...); } inline void in() {} template <typename H, typename... T> void in(H &a, T &...b) { cin >> a; in(b...); } inline void out() {} template <typename H, typename... T> void out(H a, T... b) { cout << a << (sizeof...(b) ? " " : "\n"); out(b...); } template <class T> void resz(int n, T &v) { v.resize(n); } template <class H, class... T> void resz(int n, H &a, T &...b) { a.resize(n); resz(n, b...); } template <typename V, typename H> void resize(vector<V> &v, const H a) { v.resize(a); } template <typename V, typename H, typename... T> void resize(vector<V> &v, const H &a, const T... b) { v.resize(a); for (auto &v : v) resize(v, b...); } const int INF = 1LL << 55; const int MOD = 1000000007; const double EPS = 1e-8; /*------------end of definitions------------*/ const int MAX_V = 1e5; vector<pint> G[MAX_V]; int V; vi color; vector<bool> visited; void dfs(int v, int c) { visited[v] = true; if (c & 1) color[v] = 1; rep(i, G[v].size()) { if (!visited[G[v][i].fs]) { dfs(G[v][i].fs, c + G[v][i].sc); } } } signed main() { in(V); visited.resize(V, false); color.resize(V); rep(i, V - 1) { int u, v, w; in(u, v, w); u--; v--; G[u].pb({v, w}); G[v].pb({u, w}); } dfs(0, 0); for (auto e : color) { out(e); } return 0; }
[ "expression.operation.binary.add" ]
862,726
862,727
u810724221
cpp
p03044
#include <bits/stdc++.h> using namespace std; #define ln '\n' #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 FORR(i, a, b) for (int i = (a); i >= (int)(b); --i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef pair<int, int> P; typedef pair<ll, ll> PL; typedef vector<P> VP; typedef vector<PL> VPL; typedef vector<string> VS; VI ans; void dfs(int i, bool is_black, vector<vector<P>> &edge) { if (ans[i] != -1) return; ans[i] = is_black ? 0 : 1; for (auto &adj : edge[i]) { int cost = adj.first; int to = adj.second; bool next_is_black = cost % 2 == 0 ? is_black : !is_black; dfs(to, next_is_black, edge); } } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; ans.resize(n, -1); // init vector<vector<P>> edge(n); // first: cost, second: to REP(i, n) { int u, v, w; cin >> u >> v >> w; u--; v--; edge[u].push_back(P(w, v)); edge[v].push_back(P(w, u)); } dfs(0, true, edge); REP(i, n) cout << ans[i] << ln; return 0; }
#include <bits/stdc++.h> using namespace std; #define ln '\n' #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 FORR(i, a, b) for (int i = (a); i >= (int)(b); --i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef pair<int, int> P; typedef pair<ll, ll> PL; typedef vector<P> VP; typedef vector<PL> VPL; typedef vector<string> VS; VI ans; void dfs(int i, bool is_black, vector<vector<P>> &edge) { if (ans[i] != -1) return; ans[i] = is_black ? 0 : 1; for (auto &adj : edge[i]) { int cost = adj.first; int to = adj.second; bool next_is_black = cost % 2 == 0 ? is_black : !is_black; dfs(to, next_is_black, edge); } } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; ans.resize(n, -1); // init vector<vector<P>> edge(n); // first: cost, second: to REP(i, n - 1) { int u, v, w; cin >> u >> v >> w; u--; v--; edge[u].push_back(P(w, v)); edge[v].push_back(P(w, u)); } dfs(0, true, edge); REP(i, n) cout << ans[i] << ln; return 0; }
[ "expression.operation.binary.add" ]
862,730
862,731
u991083615
cpp
p03044
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <vector> #define INF 4000000000000000000LL #define MOD 1000000007 #define ALL(x) std::begin(x), std::end(x) class edge_t { public: edge_t(int vv, int ww) : v(vv), w(ww){}; public: int v; int w; }; int N, a[111111]; std::vector<std::vector<edge_t>> G; bool visit[111111]; void dfs(int i, int j) { for (const auto &e : G[i]) { if (visit[e.v]) continue; visit[e.v] = true; int jj = j ^ (e.w & 1); dfs(e.v, a[e.v] = jj); } } int main(int argc, char **argv) { std::cin.tie(0); std::ios_base::sync_with_stdio(0); std::cout << std::fixed << std::setprecision(6); std::cerr << std::fixed << std::setprecision(6); std::cin >> N; G.resize(N); int u, v, w; for (int i = 0; i < N; i++) { std::cin >> u >> v >> w; u--; v--; G[u].emplace_back(v, w); G[v].emplace_back(u, w); } memset(a, -1, sizeof(a)); a[0] = 0; memset(visit, 0, sizeof(visit)); dfs(0, 0); for (int i = 0; i < N; i++) std::cout << a[i] << std::endl; return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <vector> #define INF 4000000000000000000LL #define MOD 1000000007 #define ALL(x) std::begin(x), std::end(x) class edge_t { public: edge_t(int vv, int ww) : v(vv), w(ww){}; public: int v; int w; }; int N, a[111111]; std::vector<std::vector<edge_t>> G; bool visit[111111]; void dfs(int i, int j) { for (const auto &e : G[i]) { if (visit[e.v]) continue; visit[e.v] = true; int jj = j ^ (e.w & 1); dfs(e.v, a[e.v] = jj); } } int main(int argc, char **argv) { std::cin.tie(0); std::ios_base::sync_with_stdio(0); std::cout << std::fixed << std::setprecision(6); std::cerr << std::fixed << std::setprecision(6); std::cin >> N; G.resize(N); int u, v, w; for (int i = 0; i < N - 1; i++) { std::cin >> u >> v >> w; u--; v--; G[u].emplace_back(v, w); G[v].emplace_back(u, w); } memset(a, -1, sizeof(a)); a[0] = 0; memset(visit, 0, sizeof(visit)); dfs(0, 0); for (int i = 0; i < N; i++) std::cout << a[i] << std::endl; return 0; }
[ "control_flow.loop.for.condition.change", "misc.off_by_one" ]
862,749
862,750
u629650917
cpp
p03044
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPr(i, n) for (int i = (n)-1; i >= 0; --i) #define FORq(i, m, n) for (int i = (m); i <= (n); ++i) #define FORqr(i, m, n) for (int i = (n); i >= (m); --i) #define PB push_back #define MP make_pair #define DEBUG printf("%s\n", "debug") #define fst first #define snd second #define SIN(x, S) (S.count(x) != 0) #define M0(x) memset(x, 0, sizeof(x)) #define FILL(x, y) memset(x, y, sizeof(x)) #define MM(x) memset(x, -1, sizeof(x)) #define ALL(x) (x).begin(), (x).end() using namespace std; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef long long ll; typedef long long integer; /////////////////////////////////////////////// const ll MOD = 1000000007; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } /////////////////////////////////////////////// /*(๑•﹏•๑`) */ struct Vertex { // edge information vector<int> edges_to; // to vertex number vector<ll> edges_cost; // edge cost // for dijkstra int done; // conform or not ll cost; // now cost int from; bool operator<(const Vertex &another) const { // priority --> min return another.cost < cost; // order(cost) } bool operator==(const Vertex &another) const { return another.cost == cost; // order(cost) } }; int main() { int N; cin >> N; static Vertex V[100002]; REP(i, N - 1) { int u, v, w; cin >> u >> v >> w; V[u].edges_to.PB(v); V[u].edges_cost.PB(w); V[v].edges_to.PB(u); V[v].edges_cost.PB(w); } queue<int> Q; Q.push(1); V[1].done = 1; while (!Q.empty()) { int now = Q.front(); Q.pop(); REP(i, V[now].edges_to.size()) { int next = V[now].edges_to[i]; if (V[next].done != 0) continue; int nextcost = V[now].edges_cost[i] % 2; if (nextcost == 0) { V[next].done = V[now].done; } else { V[next].done = (V[now].done + 1) % 2 + 2; } Q.push(next); } } FORq(i, 1, N) { cout << V[i].done - 1 << "\n"; } }
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPr(i, n) for (int i = (n)-1; i >= 0; --i) #define FORq(i, m, n) for (int i = (m); i <= (n); ++i) #define FORqr(i, m, n) for (int i = (n); i >= (m); --i) #define PB push_back #define MP make_pair #define DEBUG printf("%s\n", "debug") #define fst first #define snd second #define SIN(x, S) (S.count(x) != 0) #define M0(x) memset(x, 0, sizeof(x)) #define FILL(x, y) memset(x, y, sizeof(x)) #define MM(x) memset(x, -1, sizeof(x)) #define ALL(x) (x).begin(), (x).end() using namespace std; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef long long ll; typedef long long integer; /////////////////////////////////////////////// const ll MOD = 1000000007; ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } /////////////////////////////////////////////// /*(๑•﹏•๑`) */ struct Vertex { // edge information vector<int> edges_to; // to vertex number vector<ll> edges_cost; // edge cost // for dijkstra int done; // conform or not ll cost; // now cost int from; bool operator<(const Vertex &another) const { // priority --> min return another.cost < cost; // order(cost) } bool operator==(const Vertex &another) const { return another.cost == cost; // order(cost) } }; int main() { int N; cin >> N; static Vertex V[100002]; REP(i, N - 1) { int u, v, w; cin >> u >> v >> w; V[u].edges_to.PB(v); V[u].edges_cost.PB(w); V[v].edges_to.PB(u); V[v].edges_cost.PB(w); } queue<int> Q; Q.push(1); V[1].done = 1; while (!Q.empty()) { int now = Q.front(); Q.pop(); REP(i, V[now].edges_to.size()) { int next = V[now].edges_to[i]; if (V[next].done != 0) continue; int nextcost = V[now].edges_cost[i] % 2; if (nextcost == 0) { V[next].done = V[now].done; } else { V[next].done = (V[now].done + 1) % 2 + 2; } Q.push(next); } } FORq(i, 1, N) { cout << (V[i].done - 1) % 2 << "\n"; } }
[ "expression.operation.binary.add" ]
862,755
862,756
u236433947
cpp
p03044
#include <bits/stdc++.h> typedef long long ll; using namespace std; const int N = 2e5 + 10; typedef long double ldb; struct Edge { int to, nex, val; } e[N << 2]; int head[N], ecnt; void adde(int fr, int to, int v) { e[++ecnt] = (Edge){to, head[fr], v}; head[fr] = ecnt; } void addedge(int fr, int to, int v) { adde(fr, to, v); adde(to, fr, v); } int dep[N]; void dfs(int x, int par) { for (int j = head[x]; j; j = e[j].nex) if (e[j].to != par) { dep[e[j].to] ^= e[j].val; dfs(e[j].to, x); } } int n; int main() { cin >> n; for (int i = 1; i < n; i++) { int u, v, val; scanf("%d%d%d", &u, &v, &val); addedge(u, v, val & 1); } dfs(1, 0); for (int i = 1; i <= n; i++) printf("%d\n", dep[i]); return 0; }
#include <bits/stdc++.h> typedef long long ll; using namespace std; const int N = 2e5 + 10; typedef long double ldb; struct Edge { int to, nex, val; } e[N << 2]; int head[N], ecnt; void adde(int fr, int to, int v) { e[++ecnt] = (Edge){to, head[fr], v}; head[fr] = ecnt; } void addedge(int fr, int to, int v) { adde(fr, to, v); adde(to, fr, v); } int dep[N]; void dfs(int x, int par) { for (int j = head[x]; j; j = e[j].nex) if (e[j].to != par) { dep[e[j].to] = dep[x] ^ e[j].val; dfs(e[j].to, x); } } int n; int main() { cin >> n; for (int i = 1; i < n; i++) { int u, v, val; scanf("%d%d%d", &u, &v, &val); addedge(u, v, val & 1); } dfs(1, 0); for (int i = 1; i <= n; i++) printf("%d\n", dep[i]); return 0; }
[ "assignment.value.change", "assignment.change" ]
862,757
862,758
u076784075
cpp
p03044
#include <bits/stdc++.h> using namespace std; typedef long long ll; int col[100000]; struct edge { int to; ll w; }; vector<edge> G[100000]; void dfs(int u, bool c) { col[u] = c; for (int i = 0; i < G[u].size(); i++) { if (col[G[u][i].to] != -1) continue; ll dif; dif = G[u][i].w; if (dif % 2) dfs(G[u][i].to, !c); else dfs(G[u][i].to, c); } } int main() { fill(col, col + 100000, -1); int n; cin >> n; for (int i = 0; i < n; i++) { int u, v; ll w; cin >> u >> v >> w; u--, v--; G[u].push_back({v, w}); G[v].push_back({u, w}); } dfs(0, 0); for (int i = 0; i < n; i++) { cout << col[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int col[100000]; struct edge { int to; ll w; }; vector<edge> G[100000]; void dfs(int u, bool c) { col[u] = c; for (int i = 0; i < G[u].size(); i++) { if (col[G[u][i].to] != -1) continue; ll dif; dif = G[u][i].w; if (dif % 2) dfs(G[u][i].to, !c); else dfs(G[u][i].to, c); } } int main() { fill(col, col + 100000, -1); int n; cin >> n; for (int i = 0; i < n - 1; i++) { int u, v; ll w; cin >> u >> v >> w; u--, v--; G[u].push_back({v, w}); G[v].push_back({u, w}); } dfs(0, 0); for (int i = 0; i < n; i++) { cout << col[i] << endl; } return 0; }
[ "control_flow.loop.for.condition.change", "misc.off_by_one" ]
862,761
862,762
u853947407
cpp
p03044
// D - Even Relation #include <bits/stdc++.h> using namespace std; void dfs(const vector<vector<pair<int, int>>> &g, int u, int c, vector<int> &a, vector<int> &vi) { if (vi[u]) return; vi[u] = 1; a[u] = c; for (int i = 0; i < g[u].size(); i++) { int v = g[u][i].first; if (!vi[v]) dfs(g, v, g[u][i].second ? c ^ 1 : c, a, vi); } } int main(int argc, char *argv[]) { int n; cin >> n; vector<vector<pair<int, int>>> g(n); for (int i = 0; i < n; i++) { int u, v, w; cin >> u >> v >> w; u--; v--; g[u].push_back(make_pair(v, w % 2)); g[v].push_back(make_pair(u, w % 2)); } vector<int> a(n), vi(n); dfs(g, 0, 0, a, vi); for (int i = 0; i < n; i++) cout << a[i] << endl; return 0; }
// D - Even Relation #include <bits/stdc++.h> using namespace std; void dfs(const vector<vector<pair<int, int>>> &g, int u, int c, vector<int> &a, vector<int> &vi) { if (vi[u]) return; vi[u] = 1; a[u] = c; for (int i = 0; i < g[u].size(); i++) { int v = g[u][i].first; if (!vi[v]) dfs(g, v, g[u][i].second ? c ^ 1 : c, a, vi); } } int main(int argc, char *argv[]) { int n; cin >> n; vector<vector<pair<int, int>>> g(n); for (int i = 0; i < n - 1; i++) { int u, v, w; cin >> u >> v >> w; u--; v--; g[u].push_back(make_pair(v, w % 2)); g[v].push_back(make_pair(u, w % 2)); } vector<int> a(n), vi(n); dfs(g, 0, 0, a, vi); for (int i = 0; i < n; i++) cout << a[i] << endl; return 0; }
[ "control_flow.loop.for.condition.change", "misc.off_by_one" ]
862,765
862,766
u839953699
cpp
p03044
#include <bits/stdc++.h> using namespace std; #define int long long typedef int ll; typedef long double ld; const ll N = 100005; char en = '\n'; vector<pair<ll, ll>> adj[N]; ll color[N]; void dfs(ll curr, ll prev1 = -1, ll prevVal = -1) { if (prevVal == -1) color[curr] = 0; else color[curr] = 1 - prevVal; for (pair<ll, ll> &x : adj[curr]) { if (prev1 == x.first) continue; if (x.second == 0) { dfs(x.first, curr, -1); } else { dfs(x.first, curr, color[curr]); } } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; for (ll i = 1; i < n; i++) { ll u, v, w; cin >> u >> v >> w; w &= 1; adj[u].push_back({v, w}); adj[v].push_back({u, w}); } dfs(1); for (ll i = 1; i <= n; i++) cout << color[i] << en; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long typedef int ll; typedef long double ld; const ll N = 100005; char en = '\n'; vector<pair<ll, ll>> adj[N]; ll color[N]; void dfs(ll curr, ll prev1 = -1, ll prevVal = -1) { if (prevVal == -1) color[curr] = 0; else color[curr] = 1 - prevVal; for (pair<ll, ll> &x : adj[curr]) { if (prev1 == x.first) continue; if (x.second == 0) { dfs(x.first, curr, 1 - color[curr]); } else { dfs(x.first, curr, color[curr]); } } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; for (ll i = 1; i < n; i++) { ll u, v, w; cin >> u >> v >> w; w &= 1; adj[u].push_back({v, w}); adj[v].push_back({u, w}); } dfs(1); for (ll i = 1; i <= n; i++) cout << color[i] << en; return 0; }
[ "expression.operation.unary.arithmetic.remove" ]
862,773
862,774
u401416019
cpp
p03044
#include <bits/stdc++.h> const int MOD = 1000000007; const int INF = 1000000000; using namespace std; typedef long long ll; typedef tuple<ll, int, int> tup; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef vector<pair<int, int>> vp; bool visited[100005]; vp g[100005]; int colors[100005]; void dfs(int s) { visited[s] = true; for (int i = 0; i < int(g[s].size()); i++) { int to = g[s][i].first; int len = g[s][i].second; if (visited[to]) continue; else { if (len % 2 == 0) { colors[to] = colors[s]; dfs(to); } else { colors[to] = (colors[s] + 1) % 2; dfs(to); } } } } int main(int argc, char const *argv[]) { int N; memset(visited, false, sizeof(visited)); colors[1] = 0; cin >> N; for (int i = 0; i < N - 1; i++) { int u, v, w; cin >> u >> v >> w; g[u].push_back(pii(v, w)); g[v].push_back(pii(w, v)); } dfs(1); for (int i = 1; i <= N; i++) { cout << colors[i] << endl; } return 0; }
#include <bits/stdc++.h> const int MOD = 1000000007; const int INF = 1000000000; using namespace std; typedef long long ll; typedef tuple<ll, int, int> tup; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef vector<pair<int, int>> vp; bool visited[100005]; vp g[100005]; int colors[100005]; void dfs(int s) { visited[s] = true; for (int i = 0; i < int(g[s].size()); i++) { int to = g[s][i].first; int len = g[s][i].second; if (visited[to]) continue; else { if (len % 2 == 0) { colors[to] = colors[s]; dfs(to); } else { colors[to] = (colors[s] + 1) % 2; dfs(to); } } } } int main(int argc, char const *argv[]) { int N; memset(visited, false, sizeof(visited)); colors[1] = 0; cin >> N; for (int i = 0; i < N - 1; i++) { int u, v, w; cin >> u >> v >> w; g[u].push_back(pii(v, w)); g[v].push_back(pii(u, w)); } dfs(1); for (int i = 1; i <= N; i++) { cout << colors[i] << endl; } return 0; }
[ "identifier.change", "call.arguments.change" ]
862,777
862,778
u945017646
cpp
p03044
#include <iomanip> #include <iostream> //#include<cstdio> #include <algorithm> #include <cassert> #include <cmath> #include <map> #include <queue> #include <vector> using namespace std; typedef long long ll; const int Nmax = 1e5; int N, U[Nmax], V[Nmax]; ll W[Nmax]; void dfs(int v, vector<vector<pair<int, int>>> &graph, vector<int> &ans) { // cout << v << endl; for (auto p : graph[v]) { if (ans[p.first] >= 0) continue; if (p.second == 0) { ans[p.first] = ans[v]; } else { ans[p.first] = 1 - ans[v]; } dfs(p.first, graph, ans); } } int main() { cin >> N; for (int i = 0; i < N; i++) { cin >> U[i] >> V[i] >> W[i]; U[i]--; V[i]--; } vector<vector<pair<int, int>>> graph(N); for (int i = 0; i < N; i++) { graph[U[i]].push_back({V[i], W[i] % 2}); graph[V[i]].push_back({U[i], W[i] % 2}); } vector<int> ans(N, -1); ans[0] = 0; dfs(0, graph, ans); for (int i = 0; i < N; i++) { cout << ans[i] << endl; } return 0; }
#include <iomanip> #include <iostream> //#include<cstdio> #include <algorithm> #include <cassert> #include <cmath> #include <map> #include <queue> #include <vector> using namespace std; typedef long long ll; const int Nmax = 1e5; int N, U[Nmax], V[Nmax]; ll W[Nmax]; void dfs(int v, vector<vector<pair<int, int>>> &graph, vector<int> &ans) { // cout << v << endl; for (auto p : graph[v]) { if (ans[p.first] >= 0) continue; if (p.second == 0) { ans[p.first] = ans[v]; } else { ans[p.first] = 1 - ans[v]; } dfs(p.first, graph, ans); } } int main() { cin >> N; for (int i = 0; i < N - 1; i++) { cin >> U[i] >> V[i] >> W[i]; U[i]--; V[i]--; } vector<vector<pair<int, int>>> graph(N); for (int i = 0; i < N - 1; i++) { // cout << U[i] << " " << V[i] << endl; graph[U[i]].push_back({V[i], W[i] % 2}); graph[V[i]].push_back({U[i], W[i] % 2}); } vector<int> ans(N, -1); ans[0] = 0; dfs(0, graph, ans); for (int i = 0; i < N; i++) { cout << ans[i] << endl; } return 0; }
[ "control_flow.loop.for.condition.change", "misc.off_by_one" ]
862,781
862,782
u534998883
cpp
p03044
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <vector> #define INF 1001001001 #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; using namespace std; int main() { int n; cin >> n; vector<vector<int>> to(n), cost(n); rep(i, n - 1) { int u, v, w; cin >> u >> v >> w; u--; v--; w--; to[u].push_back(v); to[v].push_back(u); cost[u].push_back(w); cost[v].push_back(w); } vector<int> ans(n, -1); //-1で初期化 ans[0] = 0; queue<int> q; q.push(0); while (!q.empty()) { int v = q.front(); q.pop(); for (int i = 0; i < to[v].size(); i++) { int u = to[v][i]; int w = cost[v][i]; if (ans[u] != -1) continue; if (w % 2 == 0) { ans[u] = ans[v]; } else { ans[u] = 1 ^ ans[v]; } q.push(u); } } rep(i, n) { cout << ans[i] << endl; } }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <vector> #define INF 1001001001 #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; using namespace std; int main() { int n; cin >> n; vector<vector<int>> to(n), cost(n); rep(i, n - 1) { int u, v, w; cin >> u >> v >> w; u--; v--; to[u].push_back(v); to[v].push_back(u); cost[u].push_back(w); cost[v].push_back(w); } vector<int> ans(n, -1); //-1で初期化 ans[0] = 0; queue<int> q; q.push(0); while (!q.empty()) { int v = q.front(); q.pop(); for (int i = 0; i < to[v].size(); i++) { int u = to[v][i]; int w = cost[v][i]; if (ans[u] != -1) continue; if (w % 2 == 0) { ans[u] = ans[v]; } else { ans[u] = 1 ^ ans[v]; } q.push(u); } } rep(i, n) { cout << ans[i] << endl; } }
[ "expression.unary.arithmetic.remove" ]
862,796
862,797
u971166345
cpp
p03044
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; /* index=0を白として、そこからDFSしていき距離が偶数なら同じ色、距離が奇数なら違う色を割り当てていく。 dfsにはtreeとどの色を割り当てたかを記録していく必要がある。 あと、どこを訪れたか、これは割り当てた色を使えば大丈夫そう。未:-1, 白: 0, 黒: 1 みたいに */ void dfs(vector<vector<pair<int, int>>> &tree, vector<int> &colors, int index) { for (auto node : tree[index]) { if (colors[node.first] != -1) continue; int weight = node.second; colors[node.first] = (weight % 2 == 0) ? colors[index] : colors[index] ^ 1; dfs(tree, colors, node.first); } } int main() { int n; cin >> n; vector<vector<pair<int, int>>> tree(n); for (int i = 0; i < n; i++) { int v1, v2, w; cin >> v1 >> v2 >> w; v1--; v2--; tree[v1].emplace_back(v2, w); tree[v2].emplace_back(v1, w); } vector<int> colors(n, -1); colors[0] = 0; dfs(tree, colors, 0); for (int i = 0; i < n; i++) { cout << colors[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; /* index=0を白として、そこからDFSしていき距離が偶数なら同じ色、距離が奇数なら違う色を割り当てていく。 dfsにはtreeとどの色を割り当てたかを記録していく必要がある。 あと、どこを訪れたか、これは割り当てた色を使えば大丈夫そう。未:-1, 白: 0, 黒: 1 みたいに */ void dfs(vector<vector<pair<int, int>>> &tree, vector<int> &colors, int index) { for (auto node : tree[index]) { if (colors[node.first] != -1) continue; int weight = node.second; colors[node.first] = (weight % 2 == 0) ? colors[index] : colors[index] ^ 1; dfs(tree, colors, node.first); } } int main() { int n; cin >> n; vector<vector<pair<int, int>>> tree(n); for (int i = 0; i < n - 1; i++) { int v1, v2, w; cin >> v1 >> v2 >> w; v1--; v2--; tree[v1].emplace_back(v2, w); tree[v2].emplace_back(v1, w); } vector<int> colors(n, -1); colors[0] = 0; dfs(tree, colors, 0); for (int i = 0; i < n; i++) { cout << colors[i] << endl; } return 0; }
[ "control_flow.loop.for.condition.change", "misc.off_by_one" ]
862,821
862,822
u917793793
cpp
p03044
// include //------------------------------------------ #include <bits/stdc++.h> using namespace std; // typedef //------------------------------------------ typedef long long LL; typedef vector<LL> VL; typedef vector<VL> VVL; typedef vector<string> VS; typedef pair<LL, LL> PLL; // 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 SORT(c) sort((c).begin(), (c).end()) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int MOD = 1000000007; // MOD //-------------------------------------------- #define MUL(a, b) (((a) % MOD) * ((b) % MOD)) % MOD // grid //-------------------------------------------- VL dx = {0, 1, 0, -1}; VL dy = {1, 0, -1, 0}; VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1}; VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1}; // debug //-------------------------------------------- #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; // IO accelerate //-------------------------------------------- struct InitIO { InitIO() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(30); } } init_io; // main code LL n; VL ans, visited; vector<vector<pair<LL, LL>>> tree; // 木のもう片方とコスト void dfs(LL v, LL cost) { visited[v]++; if (cost % 2 == 0) { ans[v] = 0; } else { ans[v] = 1; } for (LL i = 0; i < tree[v].size(); i++) { if (visited[tree[v][i].first] == 0) { dfs(tree[v][i].first, cost + tree[v][i].second); } } return; } int main(int argc, char const *argv[]) { cin >> n; ans = VL(n, 0); visited = VL(n, 0); tree = vector<vector<PLL>>(n); for (LL i = 0; i < n; i++) { LL u, v, w; cin >> u >> v >> w; u--; v--; tree[u].push_back(make_pair(v, w)); tree[v].push_back(make_pair(u, w)); } dfs(0, 0); for (LL i = 0; i < n; i++) { cout << ans[i] << endl; } return 0; }
// include //------------------------------------------ #include <bits/stdc++.h> using namespace std; // typedef //------------------------------------------ typedef long long LL; typedef vector<LL> VL; typedef vector<VL> VVL; typedef vector<string> VS; typedef pair<LL, LL> PLL; // 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 SORT(c) sort((c).begin(), (c).end()) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int MOD = 1000000007; // MOD //-------------------------------------------- #define MUL(a, b) (((a) % MOD) * ((b) % MOD)) % MOD // grid //-------------------------------------------- VL dx = {0, 1, 0, -1}; VL dy = {1, 0, -1, 0}; VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1}; VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1}; // debug //-------------------------------------------- #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; // IO accelerate //-------------------------------------------- struct InitIO { InitIO() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(30); } } init_io; // main code LL n; VL ans, visited; vector<vector<pair<LL, LL>>> tree; // 木のもう片方とコスト void dfs(LL v, LL cost) { visited[v]++; if (cost % 2 == 0) { ans[v] = 0; } else { ans[v] = 1; } for (LL i = 0; i < tree[v].size(); i++) { if (visited[tree[v][i].first] == 0) { dfs(tree[v][i].first, cost + tree[v][i].second); } } return; } int main(int argc, char const *argv[]) { cin >> n; ans = VL(n, 0); visited = VL(n, 0); tree = vector<vector<PLL>>(n); for (LL i = 0; i < n - 1; i++) { LL u, v, w; cin >> u >> v >> w; u--; v--; tree[u].push_back(make_pair(v, w)); tree[v].push_back(make_pair(u, w)); } dfs(0, 0); for (LL i = 0; i < n; i++) { cout << ans[i] << endl; } return 0; }
[ "control_flow.loop.for.condition.change", "misc.off_by_one" ]
862,841
862,842
u150376070
cpp
p03044
#include <bits/stdc++.h> using namespace std; /*#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/ struct fast_ios { fast_ios() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; #define FOR(i, begin, end) for (int i = (begin); i < (end); i++) #define REP(i, n) FOR(i, 0, n) #define IFOR(i, begin, end) for (int i = (end)-1; i >= (begin); i--) #define IREP(i, n) IFOR(i, 0, n) #define Sort(v) sort(v.begin(), v.end()) #define Reverse(v) reverse(v.begin(), v.end()) #define all(v) v.begin(), v.end() #define SZ(v) ((int)v.size()) #define Lower_bound(v, x) \ distance(v.begin(), lower_bound(v.begin(), v.end(), x)) #define Upper_bound(v, x) \ distance(v.begin(), upper_bound(v.begin(), v.end(), x)) #define Max(a, b) a = max(a, b) #define Min(a, b) a = min(a, b) #define bit(n) (1LL << (n)) #define bit_exist(x, n) ((x >> n) & 1) #define debug(x) cout << #x << "=" << x << endl; #define vdebug(v) \ cout << #v << "=" << endl; \ REP(i_debug, v.size()) { cout << v[i_debug] << ","; } \ cout << endl; #define mdebug(m) \ cout << #m << "=" << endl; \ REP(i_debug, m.size()) { \ REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; } \ cout << endl; \ } #define pb push_back #define f first #define s second #define int long long #define INF 1000000000000000000 template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { for (int i = 0; i < v.size(); i++) { cout << v[i]; if (i != v.size() - 1) cout << endl; }; return os; } template <typename T> void Out(T x) { cout << x << endl; } template <typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if (f) Out(y); else Out(n); } using vec = vector<int>; using mat = vector<vec>; using Pii = pair<int, int>; using PiP = pair<int, Pii>; using PPi = pair<Pii, int>; using bools = vector<bool>; using pairs = vector<Pii>; // int dx[4] = {1,0,-1,0}; // int dy[4] = {0,1,0,-1}; // char d[4] = {'D','R','U','L'}; const int mod = 1000000007; // const int mod = 998244353; //#define Add(x, y) x = (x + (y)) % mod //#define Mult(x, y) x = (x * (y)) % mod struct edge { int to, cost, id; }; class Graph { public: int N; vector<vector<edge>> G; Graph(int N) : N(N) { G = vector<vector<edge>>(N, vector<edge>(0)); } void add_Directed_edge(int from, int to, int cost = 1, int id = 0) { G[from].push_back(edge({to, cost, id})); } void add_Undirected_edge(int v1, int v2, int cost = 1, int id = 0) { add_Directed_edge(v1, v2, cost, id); add_Directed_edge(v2, v1, cost, id); } //二部グラフ判定 vector<int> color; bool is_bipartite() { color = vec(N, -1); REP(i, N) if (color[i] == -1) { if (!dfs_for_check_bipartite(i, 0)) return false; } return true; } bool dfs_for_check_bipartite(int v, int c) { if (color[v] != -1) { if (color[v] == c) return true; else return false; } color[v] = c; for (auto e : G[v]) if (!dfs_for_check_bipartite(e.to, 1 - c)) return false; return true; } }; signed main() { int N; cin >> N; Graph G(2 * N); REP(i, N - 1) { int u, v, w; cin >> u >> v >> w; u--; v--; if (w % 2) G.add_Undirected_edge(u, v); else { G.add_Undirected_edge(u, N + i); G.add_Undirected_edge(N + i, u); } } G.is_bipartite(); REP(i, N) Out(G.color[i]); return 0; }
#include <bits/stdc++.h> using namespace std; /*#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/ struct fast_ios { fast_ios() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; #define FOR(i, begin, end) for (int i = (begin); i < (end); i++) #define REP(i, n) FOR(i, 0, n) #define IFOR(i, begin, end) for (int i = (end)-1; i >= (begin); i--) #define IREP(i, n) IFOR(i, 0, n) #define Sort(v) sort(v.begin(), v.end()) #define Reverse(v) reverse(v.begin(), v.end()) #define all(v) v.begin(), v.end() #define SZ(v) ((int)v.size()) #define Lower_bound(v, x) \ distance(v.begin(), lower_bound(v.begin(), v.end(), x)) #define Upper_bound(v, x) \ distance(v.begin(), upper_bound(v.begin(), v.end(), x)) #define Max(a, b) a = max(a, b) #define Min(a, b) a = min(a, b) #define bit(n) (1LL << (n)) #define bit_exist(x, n) ((x >> n) & 1) #define debug(x) cout << #x << "=" << x << endl; #define vdebug(v) \ cout << #v << "=" << endl; \ REP(i_debug, v.size()) { cout << v[i_debug] << ","; } \ cout << endl; #define mdebug(m) \ cout << #m << "=" << endl; \ REP(i_debug, m.size()) { \ REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; } \ cout << endl; \ } #define pb push_back #define f first #define s second #define int long long #define INF 1000000000000000000 template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { for (int i = 0; i < v.size(); i++) { cout << v[i]; if (i != v.size() - 1) cout << endl; }; return os; } template <typename T> void Out(T x) { cout << x << endl; } template <typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if (f) Out(y); else Out(n); } using vec = vector<int>; using mat = vector<vec>; using Pii = pair<int, int>; using PiP = pair<int, Pii>; using PPi = pair<Pii, int>; using bools = vector<bool>; using pairs = vector<Pii>; // int dx[4] = {1,0,-1,0}; // int dy[4] = {0,1,0,-1}; // char d[4] = {'D','R','U','L'}; const int mod = 1000000007; // const int mod = 998244353; //#define Add(x, y) x = (x + (y)) % mod //#define Mult(x, y) x = (x * (y)) % mod struct edge { int to, cost, id; }; class Graph { public: int N; vector<vector<edge>> G; Graph(int N) : N(N) { G = vector<vector<edge>>(N, vector<edge>(0)); } void add_Directed_edge(int from, int to, int cost = 1, int id = 0) { G[from].push_back(edge({to, cost, id})); } void add_Undirected_edge(int v1, int v2, int cost = 1, int id = 0) { add_Directed_edge(v1, v2, cost, id); add_Directed_edge(v2, v1, cost, id); } //二部グラフ判定 vector<int> color; bool is_bipartite() { color = vec(N, -1); REP(i, N) if (color[i] == -1) { if (!dfs_for_check_bipartite(i, 0)) return false; } return true; } bool dfs_for_check_bipartite(int v, int c) { if (color[v] != -1) { if (color[v] == c) return true; else return false; } color[v] = c; for (auto e : G[v]) if (!dfs_for_check_bipartite(e.to, 1 - c)) return false; return true; } }; signed main() { int N; cin >> N; Graph G(2 * N); REP(i, N - 1) { int u, v, w; cin >> u >> v >> w; u--; v--; if (w % 2) G.add_Undirected_edge(u, v); else { G.add_Undirected_edge(u, N + i); G.add_Undirected_edge(N + i, v); } } G.is_bipartite(); REP(i, N) Out(G.color[i]); return 0; }
[ "identifier.change", "call.arguments.change" ]
862,846
862,847
u434231045
cpp
p03044
#include <algorithm> #include <cassert> #include <cmath> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <vector> using ll = long long; using namespace std; // const int INF = 7+(1e+9); ll GCD(ll x, ll y) { if (y == 0) { return x; } else { return GCD(y, x % y); } } ll LCM(ll x, ll y) { return x / GCD(x, y) * y; } vector<int> color; vector<vector<int>> vec; void dfs(int x, int Color, int prev) { color[x] = Color; // cout<<x<<" "<<Color<<endl; for (int i = 0; i < vec[x].size(); i++) { if (prev != vec[x][i] && prev != -vec[x][i] && Color != -1) { if (vec[x][i] > 0) { // cout<<"偶数"<<x<<"to"<<i<<endl; dfs(vec[x][i], Color, x); } else { // cout<<vec[x][i]<<endl; // cout<<"奇数"<<x<<"to"<<i<<endl; dfs(-vec[x][i], 1 - Color, x); } } } return; } int main() { int n; cin >> n; color.resize(n); for (int i = 0; i < n; i++) { color[i] = -1; } vec.resize(n); for (int i = 0; i < n - 1; i++) { int u, v, w; cin >> u >> v >> w; u--; v--; // cout<<u<<" "<<v<<" "<<w<<endl; if (w % 2 == 0) { vec[u].push_back(v); vec[v].push_back(u); } else { vec[u].push_back(-v); vec[v].push_back(-u); } } for (int i = 0; i < n; i++) { if (color[i] == -1) { // cout<<i<<endl; dfs(i, 0, -1); } } for (int i = 0; i < n; i++) { cout << color[i] << endl; } }
#include <algorithm> #include <cassert> #include <cmath> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <vector> using ll = long long; using namespace std; // const int INF = 7+(1e+9); ll GCD(ll x, ll y) { if (y == 0) { return x; } else { return GCD(y, x % y); } } ll LCM(ll x, ll y) { return x / GCD(x, y) * y; } vector<int> color; vector<vector<int>> vec; void dfs(int x, int Color, int prev) { color[x] = Color; // cout<<x<<" "<<Color<<endl; for (int i = 0; i < vec[x].size(); i++) { if (prev != vec[x][i] && prev != -vec[x][i] && Color != -1) { if (vec[x][i] > 0) { // cout<<"偶数"<<x<<"to"<<i<<endl; dfs(vec[x][i], Color, x); } else { // cout<<vec[x][i]<<endl; // cout<<"奇数"<<x<<"to"<<i<<endl; dfs(-vec[x][i], 1 - Color, x); } } } return; } int main() { int n; cin >> n; color.resize(n); for (int i = 0; i < n; i++) { color[i] = -1; } vec.resize(n); for (int i = 0; i < n - 1; i++) { int u, v, w; cin >> u >> v >> w; u--; v--; // cout<<u<<" "<<v<<" "<<w<<endl; if (w % 2 == 0) { vec[u].push_back(v); vec[v].push_back(u); } else { vec[u].push_back(-v); vec[v].push_back(-u); } } for (int i = 0; i < n; i++) { if (color[i] == -1) { // cout<<i<<endl; dfs(i, 0, 0); } } for (int i = 0; i < n; i++) { cout << color[i] << endl; } }
[ "literal.number.change", "call.arguments.change" ]
862,850
862,851
u759162415
cpp
p03044
#include <bits/stdc++.h> #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define ll long long #define pii std::pair<int, int> #define pli std::pair<ll, int> #define pil std::pair<int, ll> #define psi std::pair<string, int> #define pll std::pair<ll, ll> #define pci std::pair<char, int> #define sll(x) scanf("%lld", &x) #define prll(x) printf("%lld ", x) #define pri(x) printf("%d ", x) #define si(x) scanf("%d", &x) #define pb push_back #define vll std::vector<ll> #define vpi std::vector<std::pair<int, int>> #define vi std::vector<int> #define vvi std::vector<std::vector<int>> #define vvpil std::vector<std::vector<std::pair<int, ll>>> #define vlpii std::vector<std::list<pii>> #define vlpil std::vector<std::list<pil>> #define li std::list<int> #define lpil std::list<pil> #define Endl printf("\n") #define vli vector<list<int>> #define vvll vector<vector<ll>> #define mp make_pair #define x first #define y second #define ull uint64_t #define ma 100000000 #define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " const ll INF = 10000000000000; const ll mod = 1e9 + 7; using namespace std; void add(ll &a, ll b) { a += b; if (a >= mod) a -= mod; } ll mul(ll a, ll b) { return (a * b) % mod; } ll Pow(ll a, ll b) { if (b == 0) return 1; ll c = Pow(a, b / 2); if (b % 2) return (a * ((c * c) % mod)) % mod; return (c * c) % mod; } vector<int> col; vector<vector<pll>> adj; vector<bool> visited; void dfs(int u, ll dist) { visited[u] = true; for (pll i : adj[u]) { if (!visited[i.x]) { if (dist % 2) col[i.x] = 1; else col[i.x] = 0; dfs(i.x, dist + i.y); } } } // check modulo int main() { IOS; cout.precision(30); int n; cin >> n; adj.resize(n); visited.resize(n); col.resize(n); int u, v; ll w; for (int i = 0; i < n - 1; i++) { cin >> u >> v >> w; u--; v--; adj[u].pb(mp(v, w)); adj[v].pb(mp(u, w)); } col[0] = 0; dfs(0, 0); for (int i = 0; i < n; i++) cout << col[i] << "\n"; return 0; }
#include <bits/stdc++.h> #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define ll long long #define pii std::pair<int, int> #define pli std::pair<ll, int> #define pil std::pair<int, ll> #define psi std::pair<string, int> #define pll std::pair<ll, ll> #define pci std::pair<char, int> #define sll(x) scanf("%lld", &x) #define prll(x) printf("%lld ", x) #define pri(x) printf("%d ", x) #define si(x) scanf("%d", &x) #define pb push_back #define vll std::vector<ll> #define vpi std::vector<std::pair<int, int>> #define vi std::vector<int> #define vvi std::vector<std::vector<int>> #define vvpil std::vector<std::vector<std::pair<int, ll>>> #define vlpii std::vector<std::list<pii>> #define vlpil std::vector<std::list<pil>> #define li std::list<int> #define lpil std::list<pil> #define Endl printf("\n") #define vli vector<list<int>> #define vvll vector<vector<ll>> #define mp make_pair #define x first #define y second #define ull uint64_t #define ma 100000000 #define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " const ll INF = 10000000000000; const ll mod = 1e9 + 7; using namespace std; void add(ll &a, ll b) { a += b; if (a >= mod) a -= mod; } ll mul(ll a, ll b) { return (a * b) % mod; } ll Pow(ll a, ll b) { if (b == 0) return 1; ll c = Pow(a, b / 2); if (b % 2) return (a * ((c * c) % mod)) % mod; return (c * c) % mod; } vector<int> col; vector<vector<pll>> adj; vector<bool> visited; void dfs(int u, ll dist) { visited[u] = true; for (pll i : adj[u]) { if (!visited[i.x]) { if ((dist + i.y) % 2) col[i.x] = 1; else col[i.x] = 0; dfs(i.x, dist + i.y); } } } // check modulo int main() { IOS; cout.precision(30); int n; cin >> n; adj.resize(n); visited.resize(n); col.resize(n); int u, v; ll w; for (int i = 0; i < n - 1; i++) { cin >> u >> v >> w; u--; v--; adj[u].pb(mp(v, w)); adj[v].pb(mp(u, w)); } col[0] = 0; dfs(0, 0); for (int i = 0; i < n; i++) cout << col[i] << "\n"; return 0; }
[ "control_flow.branch.if.condition.change" ]
862,874
862,875
u752814744
cpp
p03044
#include <bits/stdc++.h> #define x first #define y second using namespace std; const int sz = 1e5 + 9; int n, f, t, w; vector<pair<int, int>> v[sz]; int c[sz]; void dfs(int i, int p = 1) { int myv; if (i == p) myv = 0; else myv = c[p]; for (auto u : v[i]) { int nxt = u.x; int val = u.y; if (nxt == p) continue; if (val) c[nxt] = !myv; else c[nxt] = myv; dfs(nxt, i); } } int main() { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); scanf("%d", &n); for (int i = 0; i < n - 1; i++) { scanf("%d %d %d", &f, &t, &w); w &= 1; v[t].push_back(make_pair(f, w)); v[f].push_back(make_pair(t, w)); } dfs(1); for (int i = 1; i <= n; i++) printf("%d\n", c[i]); return 0; }
#include <bits/stdc++.h> #define x first #define y second using namespace std; const int sz = 1e5 + 9; int n, f, t, w; vector<pair<int, int>> v[sz]; int c[sz]; void dfs(int i, int p = 1) { int myv; if (i == p) myv = 0; else myv = c[i]; for (auto u : v[i]) { int nxt = u.x; int val = u.y; if (nxt == p) continue; if (val) c[nxt] = !myv; else c[nxt] = myv; dfs(nxt, i); } } int main() { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); scanf("%d", &n); for (int i = 0; i < n - 1; i++) { scanf("%d %d %d", &f, &t, &w); w &= 1; v[t].push_back(make_pair(f, w)); v[f].push_back(make_pair(t, w)); } dfs(1); for (int i = 1; i <= n; i++) printf("%d\n", c[i]); return 0; }
[ "assignment.value.change", "identifier.change", "variable_access.subscript.index.change" ]
862,904
862,905
u353783395
cpp
p03044
#include <algorithm> #include <assert.h> #include <bitset> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <functional> #include <iostream> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <utility> #include <vector> using namespace std; static const double EPS = 1e-9; template <class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; } template <class T> void amin(T &a, T v) { if (a > v) a = v; } template <class T> void amax(T &a, T v) { if (a < v) a = v; } int ROUND(double x) { return (int)(x + 0.5); } bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; } bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); } double SQSUM(double x, double y) { return x * x + y * y; } #define PI (acos(-1)) #define ARRAY_NUM(a) (sizeof(a) / sizeof(a[0])) #define NG (-1) #define BIG ((int)1e9 + 10) #define BIGLL ((ll)4e18) #define SZ(a) ((int)(a).size()) #define SQ(a) ((a) * (a)) typedef unsigned long long ull; typedef long long ll; vector<int> colors; void dfs(const vector<vector<pair<int, ll>>> &adj, int now, int col) { colors[now] = col; for (const auto &p : adj[now]) { if (colors[p.first] == NG) { if (p.second % 2 == 0) { dfs(adj, p.first, col); } else { dfs(adj, p.first, 1 - col); } } } } int main() { int N; cin >> N; vector<vector<pair<int, ll>>> adj( N); // adj[x] = { (y0, w0), (y1, w1), (y2, w2)... } colors.resize(N); fill(colors.begin(), colors.end(), NG); for (int i = 0; i < N; ++i) { int x, y; ll w; cin >> x >> y >> w; x--; y--; adj[x].push_back(make_pair(y, w)); adj[y].push_back(make_pair(x, w)); } dfs(adj, 0, 0); for (int i = 0; i < N; ++i) { cout << colors[i] << endl; } return 0; }
#include <algorithm> #include <assert.h> #include <bitset> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <functional> #include <iostream> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <utility> #include <vector> using namespace std; static const double EPS = 1e-9; template <class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; } template <class T> void amin(T &a, T v) { if (a > v) a = v; } template <class T> void amax(T &a, T v) { if (a < v) a = v; } int ROUND(double x) { return (int)(x + 0.5); } bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; } bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); } double SQSUM(double x, double y) { return x * x + y * y; } #define PI (acos(-1)) #define ARRAY_NUM(a) (sizeof(a) / sizeof(a[0])) #define NG (-1) #define BIG ((int)1e9 + 10) #define BIGLL ((ll)4e18) #define SZ(a) ((int)(a).size()) #define SQ(a) ((a) * (a)) typedef unsigned long long ull; typedef long long ll; vector<int> colors; void dfs(const vector<vector<pair<int, ll>>> &adj, int now, int col) { colors[now] = col; for (const auto &p : adj[now]) { if (colors[p.first] == NG) { if (p.second % 2 == 0) { dfs(adj, p.first, col); } else { dfs(adj, p.first, 1 - col); } } } } int main() { int N; cin >> N; vector<vector<pair<int, ll>>> adj( N); // adj[x] = { (y0, w0), (y1, w1), (y2, w2)... } colors.resize(N); fill(colors.begin(), colors.end(), NG); for (int i = 0; i < N - 1; ++i) { int x, y; ll w; cin >> x >> y >> w; x--; y--; adj[x].push_back(make_pair(y, w)); adj[y].push_back(make_pair(x, w)); } dfs(adj, 0, 0); for (int i = 0; i < N; ++i) { cout << colors[i] << endl; } return 0; }
[ "control_flow.loop.for.condition.change", "misc.off_by_one" ]
862,936
862,937
u922299738
cpp
p03044
#include <iostream> #include <queue> #include <utility> #include <vector> using namespace std; int main() { int n; cin >> n; vector<pair<int, int>> e[n]; // to,weight for (int k = 0; k < n - 1; k++) { int i, j, w; cin >> i >> j >> w; pair<int, int> edge1(j - 1, w); e[i - 1].push_back(edge1); pair<int, int> edge2(i - 1, w); e[j - 1].push_back(edge2); } int ans[n] = {0}; queue<pair<int, int>> que; // from,now pos pair<int, int> start(0, 0); que.push(start); while (!que.empty()) { pair<int, int> now = que.front(); que.pop(); for (auto p = e[now.second].begin(); p != e[now.second].end(); p++) { if ((*p).first != now.first) { if ((*p).second % 2 == 0) ans[(*p).first] = ans[now.second]; else if (ans[now.second] == 0) ans[(*p).first] = 1; else ans[(*p).first] = 0; pair<int, int> next(now.second, (*p).first); que.push(next); } } } for (int i = 0; i < n; i++) { cout << ans[i]; } cout << endl; return 0; }
#include <iostream> #include <queue> #include <utility> #include <vector> using namespace std; int main() { int n; cin >> n; vector<pair<int, int>> e[n]; // to,weight for (int k = 0; k < n - 1; k++) { int i, j, w; cin >> i >> j >> w; pair<int, int> edge1(j - 1, w); e[i - 1].push_back(edge1); pair<int, int> edge2(i - 1, w); e[j - 1].push_back(edge2); } int ans[n] = {0}; queue<pair<int, int>> que; // from,now pos pair<int, int> start(0, 0); que.push(start); while (!que.empty()) { pair<int, int> now = que.front(); que.pop(); for (auto p = e[now.second].begin(); p != e[now.second].end(); p++) { if ((*p).first != now.first) { if ((*p).second % 2 == 0) ans[(*p).first] = ans[now.second]; else if (ans[now.second] == 0) ans[(*p).first] = 1; else ans[(*p).first] = 0; pair<int, int> next(now.second, (*p).first); que.push(next); } } } for (int i = 0; i < n; i++) { cout << ans[i] << endl; ; } return 0; }
[]
862,971
862,972
u102334466
cpp
p03044
#include <bits/stdc++.h> using namespace std; using ll = long long; enum COLOR { BLACK, WHITE, NONE }; ll N; vector<vector<pair<ll, ll>>> G; vector<COLOR> color; void dfs(ll u, ll sum_w) { for (ll i = 0; i < (ll)G[u].size(); i++) { pair<ll, ll> _v = G[u][i]; ll v = _v.first; ll w = _v.second; if (color[v] != NONE) continue; if ((sum_w + w) % 2LL == 0LL) { color[v] = BLACK; } else { color[v] = WHITE; } dfs(v, (sum_w + w) % 2LL); } } int main(void) { ll N; cin >> N; G = vector<vector<pair<ll, ll>>>(N); // (dest, weight) color = vector<COLOR>(N, NONE); for (ll i = 0; i < N; i++) { ll u, v, w; cin >> u >> v >> w; u--; v--; G[u].push_back(make_pair(v, w)); G[v].push_back(make_pair(u, w)); } color[0] = BLACK; dfs(0, 0); for (ll i = 0; i < (ll)color.size(); i++) { cout << color[i] << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; enum COLOR { BLACK, WHITE, NONE }; ll N; vector<vector<pair<ll, ll>>> G; vector<COLOR> color; void dfs(ll u, ll sum_w) { for (ll i = 0; i < (ll)G[u].size(); i++) { pair<ll, ll> _v = G[u][i]; ll v = _v.first; ll w = _v.second; if (color[v] != NONE) continue; if ((sum_w + w) % 2LL == 0LL) { color[v] = BLACK; } else { color[v] = WHITE; } dfs(v, (sum_w + w) % 2LL); } } int main(void) { ll N; cin >> N; G = vector<vector<pair<ll, ll>>>(N); // (dest, weight) color = vector<COLOR>(N, NONE); for (ll i = 1; i < N; i++) { ll u, v, w; cin >> u >> v >> w; u--; v--; G[u].push_back(make_pair(v, w)); G[v].push_back(make_pair(u, w)); } color[0] = BLACK; dfs(0, 0); for (ll i = 0; i < (ll)color.size(); i++) { cout << color[i] << endl; } }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
862,981
862,982
u251945221
cpp
p03044
// khodaya khodet komak kon #include <bits/stdc++.h> #define pb push_back #define ers erase #define ins insert #define F first #define S second #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << " = " << x << endl #define kill(x) return cout << x, 0; #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #pragma GCC optimize("Ofast") using namespace std; typedef long long ll; typedef long double ld; typedef string str; typedef pair<ll, ll> pll; typedef vector<ll> vl; typedef vector<pll> vpl; const ld Pi = 3.14159265359; const ll MOD = 1000 * 1000 * 1000 + 7; const ll N = 2e5 + 10; const ll INF = 1e18; const ll LOG = 20; vpl G[N]; ll C[N], n, v, u; void DFS(ll v, ll p = 0, ll c = 0) { C[v] = c; for (auto u : G[v]) { if (u.F == p) continue; if (u.F % 2 == 0) { DFS(u.F, v, c); } else { DFS(u.F, v, 1 - c); } } return; } int main() { IOS; cin >> n; for (int i = 0; i < n - 1; i++) { ll w; cin >> v >> u >> w; G[v].pb({u, w}); G[u].pb({v, w}); } DFS(1); for (int i = 1; i <= n; i++) { cout << C[i] << '\n'; } return 0; } /* ,---, ___ ,--, ' .' \ ,--.'|_ ,--.'| ,--, / ; '. | | :,' | | : ,--.'| ,---. ,---, : : \ : : ' : : : ' .--.--. | |, ' ,'\ ,-+-. / | : | /\ \ .;__,' / ,--.--. | ' | ,--.--. / / ' `--'_ / / | ,--.'|' | | : ' ;. : | | | / \ ' | | / \ | : /`./ ,' ,'| . ; ,. :| | ,"' | | | ;/ \ \:__,'| : .--. .-. || | : .--. .-. | | : ;_ ' | | ' | |: :| | / | | ' : | \ \ ,' ' : |__ \__\/: . .' : |__ \__\/: . . \ \ `. | | : ' | .; :| | | | | | | ' '--' | | '.'| ," .--.; || | '.'| ," .--.; | `----. \' : |_| : || | | |/ | : : ; : ;/ / ,. |; : ;/ / ,. | / /`--' /| | '.'\ \ / | | |--' | | ,' | , /; : .' \ , /; : .' \'--'. / ; : ;`----' | |/ `--'' ---`-' | , .-./---`-' | , .-./ `--'---' | , / '---' `--`---' `--`---' ---`-' */
// khodaya khodet komak kon #include <bits/stdc++.h> #define pb push_back #define ers erase #define ins insert #define F first #define S second #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << " = " << x << endl #define kill(x) return cout << x, 0; #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #pragma GCC optimize("Ofast") using namespace std; typedef long long ll; typedef long double ld; typedef string str; typedef pair<ll, ll> pll; typedef vector<ll> vl; typedef vector<pll> vpl; const ld Pi = 3.14159265359; const ll MOD = 1000 * 1000 * 1000 + 7; const ll N = 2e5 + 10; const ll INF = 1e18; const ll LOG = 20; vpl G[N]; ll C[N], n, v, u; void DFS(ll v, ll p = 0, ll c = 0) { C[v] = c; for (auto u : G[v]) { if (u.F == p) continue; if (u.S % 2 == 0) { DFS(u.F, v, c); } else { DFS(u.F, v, 1 - c); } } return; } int main() { IOS; cin >> n; for (int i = 0; i < n - 1; i++) { ll w; cin >> v >> u >> w; G[v].pb({u, w}); G[u].pb({v, w}); } DFS(1); for (int i = 1; i <= n; i++) { cout << C[i] << '\n'; } return 0; } /* ,---, ___ ,--, ' .' \ ,--.'|_ ,--.'| ,--, / ; '. | | :,' | | : ,--.'| ,---. ,---, : : \ : : ' : : : ' .--.--. | |, ' ,'\ ,-+-. / | : | /\ \ .;__,' / ,--.--. | ' | ,--.--. / / ' `--'_ / / | ,--.'|' | | : ' ;. : | | | / \ ' | | / \ | : /`./ ,' ,'| . ; ,. :| | ,"' | | | ;/ \ \:__,'| : .--. .-. || | : .--. .-. | | : ;_ ' | | ' | |: :| | / | | ' : | \ \ ,' ' : |__ \__\/: . .' : |__ \__\/: . . \ \ `. | | : ' | .; :| | | | | | | ' '--' | | '.'| ," .--.; || | '.'| ," .--.; | `----. \' : |_| : || | | |/ | : : ; : ;/ / ,. |; : ;/ / ,. | / /`--' /| | '.'\ \ / | | |--' | | ,' | , /; : .' \ , /; : .' \'--'. / ; : ;`----' | |/ `--'' ---`-' | , .-./---`-' | , .-./ `--'---' | , / '---' `--`---' `--`---' ---`-' */
[ "control_flow.branch.if.condition.change" ]
862,994
862,995
u349705898
cpp
p03044
#include <bits/stdc++.h> using namespace std; #define sd(x) scanf("%d", &x) #define slld(x) scanf("%lld", &x) #define all(x) x.begin(), x.end() #define For(i, st, en) for (ll i = st; i < en; i++) #define tr(x) for (auto it = x.begin(); it != x.end(); it++) #define fast \ std::ios::sync_with_stdio(false); \ cin.tie(NULL); #define pb push_back #define ll long long #define int long long #define mp make_pair #define F first #define S second typedef pair<int, int> pii; #define MOD 1000000007 #define INF 1000000000000000007 #define MAXN 100005 // it's swapnil07 ;) vector<pii> adj[MAXN]; int color[MAXN]; bool vis[MAXN]; void dfs(int node, int weight, int clr) { if (weight % 2 == 0) { color[node] = clr; } else { color[node] = 1 - clr; } vis[node] = true; for (auto p : adj[node]) { int n = p.F; if (vis[n]) { continue; } int wt = weight + p.S; dfs(n, wt, color[node]); } } signed main() { fast #ifdef SWAPNIL07 freopen("/home/swapnil/Desktop/c++/input.txt", "r", stdin); freopen("/home/swapnil/Desktop/c++/output.txt", "w", stdout); #endif int n; cin >> n; For(i, 0, n - 1) { int u, v, w; cin >> u >> v >> w; adj[u].pb({v, w}); adj[v].pb({u, w}); } dfs(1, 0, 0); For(i, 1, n + 1) { cout << color[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define sd(x) scanf("%d", &x) #define slld(x) scanf("%lld", &x) #define all(x) x.begin(), x.end() #define For(i, st, en) for (ll i = st; i < en; i++) #define tr(x) for (auto it = x.begin(); it != x.end(); it++) #define fast \ std::ios::sync_with_stdio(false); \ cin.tie(NULL); #define pb push_back #define ll long long #define int long long #define mp make_pair #define F first #define S second typedef pair<int, int> pii; #define MOD 1000000007 #define INF 1000000000000000007 #define MAXN 100005 // it's swapnil07 ;) vector<pii> adj[MAXN]; int color[MAXN]; bool vis[MAXN]; void dfs(int node, int weight, int clr) { if (weight % 2 == 0) { color[node] = 0; } else { color[node] = 1; } vis[node] = true; for (auto p : adj[node]) { int n = p.F; if (vis[n]) { continue; } int wt = weight + p.S; dfs(n, wt, color[node]); } } signed main() { fast #ifdef SWAPNIL07 freopen("/home/swapnil/Desktop/c++/input.txt", "r", stdin); freopen("/home/swapnil/Desktop/c++/output.txt", "w", stdout); #endif int n; cin >> n; For(i, 0, n - 1) { int u, v, w; cin >> u >> v >> w; adj[u].pb({v, w}); adj[v].pb({u, w}); } dfs(1, 0, 0); For(i, 1, n + 1) { cout << color[i] << endl; } return 0; }
[ "assignment.value.change", "identifier.replace.remove", "literal.replace.add", "expression.operation.binary.remove" ]
863,002
863,003
u623300886
cpp
p03044
#include <bits/stdc++.h> #define f first #define s second #define mp make_pair #define pb push_back #define lp(i, a, n) for (int i = a; i <= n; ++i) #define lpd(i, a, n) for (int i = a; i >= n; --i) #define mem(a, b) memset(a, b, sizeof a) #define all(v) v.begin(), v.end() #define println(a) cout << (a) << endl #define sz(x) ((int)(x).size()) #define readi(x) scanf("%d", &x) #define read2i(x, y) scanf("%d%d", &x, &y) #define read3i(x, y, z) scanf("%d%d%d", &x, &y, &z) #define mod 1000000007 #define eps 1e-9 #define infi 1000000000 #define infll 1000000000000000000ll using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; typedef set<int> si; typedef map<int, int> mii; const int N = 100002; int n; vector<pii> g[N]; bool ans[N]; void dfs(int i, int p, int c) { ans[i] = c & 1; for (pii j : g[i]) if (j.f != p) dfs(j.s, i, (c + j.s) % 2); } int main() { readi(n); lp(i, 1, n - 1) { int a, b, c; read3i(a, b, c); g[a].pb({b, c}); g[b].pb({a, c}); } dfs(1, 1, 0); lp(i, 1, n) println(ans[i]); } /* uniform_int_distribution<type>(l, r)(rng) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); */
#include <bits/stdc++.h> #define f first #define s second #define mp make_pair #define pb push_back #define lp(i, a, n) for (int i = a; i <= n; ++i) #define lpd(i, a, n) for (int i = a; i >= n; --i) #define mem(a, b) memset(a, b, sizeof a) #define all(v) v.begin(), v.end() #define println(a) cout << (a) << endl #define sz(x) ((int)(x).size()) #define readi(x) scanf("%d", &x) #define read2i(x, y) scanf("%d%d", &x, &y) #define read3i(x, y, z) scanf("%d%d%d", &x, &y, &z) #define mod 1000000007 #define eps 1e-9 #define infi 1000000000 #define infll 1000000000000000000ll using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vll; typedef set<int> si; typedef map<int, int> mii; const int N = 100002; int n; vector<pii> g[N]; bool ans[N]; void dfs(int i, int p, int c) { ans[i] = c; for (pii j : g[i]) if (j.f != p) dfs(j.f, i, (c + j.s) % 2); } int main() { readi(n); lp(i, 1, n - 1) { int a, b, c; read3i(a, b, c); g[a].pb({b, c}); g[b].pb({a, c}); } dfs(1, 1, 0); lp(i, 1, n) println(ans[i]); } /* uniform_int_distribution<type>(l, r)(rng) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); */
[ "expression.operation.binary.remove", "call.arguments.change" ]
863,016
863,017
u527876446
cpp
p03044
#include <algorithm> #include <cctype> #include <cstdint> #include <cstdio> #include <deque> #include <queue> #include <string> #include <tuple> #include <utility> #include <vector> template <class Tp> constexpr Tp inf = Tp(1) << (8 * sizeof(Tp) - 3); template <class Tp, class Compare> using priority_queue = std::priority_queue<Tp, std::deque<Tp>, Compare>; template <class Weight> struct edge { using value_type = Weight; size_t src, dst; value_type cost; edge(size_t src, size_t dst, value_type cost = 1) : src(src), dst(dst), cost(cost) {} bool operator<(const edge<value_type> &rhs) const { if (cost != rhs.cost) return cost < rhs.cost; if (src != rhs.src) return src < rhs.src; return dst < rhs.dst; } }; template <class Weight> struct graph : public std::vector<std::vector<edge<Weight>>> { using value_type = Weight; graph(size_t n) : std::vector<std::vector<edge<value_type>>>(n) {} void connect_with(size_t src, size_t dst, value_type cost = 1) { (*this)[src].emplace_back(src, dst, cost); (*this)[dst].emplace_back(dst, src, cost); } void connect_to(size_t src, size_t dst, value_type cost = 1) { (*this)[src].emplace_back(src, dst, cost); } }; template <class Weight> std::vector<Weight> shortest(const graph<Weight> &g, size_t s) { // based on Dijkstra algorithm std::vector<Weight> res(g.size(), inf<Weight>); priority_queue<std::pair<Weight, size_t>, std::greater<>> q; res[s] = 0; q.emplace(0, s); while (!q.empty()) { Weight w; size_t v; std::tie(w, v) = q.top(); q.pop(); if (w > res[v]) continue; for (const auto &e : g[v]) { if (res[e.dst] > w + e.cost) { res[e.dst] = w + e.cost; q.emplace(res[e.dst], e.dst); } } } return res; } int main() { size_t N; scanf("%zu", &N); graph<int> g(N); for (size_t i = 0; i < N; ++i) { size_t u, v; int w; scanf("%zu %zu %d", &u, &v, &w); --u; --v; w &= 1; g.connect_with(u, v, w); } auto dist = shortest(g, 0); for (size_t i = 0; i < N; ++i) printf("%d\n", dist[i] & 1); }
#include <algorithm> #include <cctype> #include <cstdint> #include <cstdio> #include <deque> #include <queue> #include <string> #include <tuple> #include <utility> #include <vector> template <class Tp> constexpr Tp inf = Tp(1) << (8 * sizeof(Tp) - 3); template <class Tp, class Compare> using priority_queue = std::priority_queue<Tp, std::deque<Tp>, Compare>; template <class Weight> struct edge { using value_type = Weight; size_t src, dst; value_type cost; edge(size_t src, size_t dst, value_type cost = 1) : src(src), dst(dst), cost(cost) {} bool operator<(const edge<value_type> &rhs) const { if (cost != rhs.cost) return cost < rhs.cost; if (src != rhs.src) return src < rhs.src; return dst < rhs.dst; } }; template <class Weight> struct graph : public std::vector<std::vector<edge<Weight>>> { using value_type = Weight; graph(size_t n) : std::vector<std::vector<edge<value_type>>>(n) {} void connect_with(size_t src, size_t dst, value_type cost = 1) { (*this)[src].emplace_back(src, dst, cost); (*this)[dst].emplace_back(dst, src, cost); } void connect_to(size_t src, size_t dst, value_type cost = 1) { (*this)[src].emplace_back(src, dst, cost); } }; template <class Weight> std::vector<Weight> shortest(const graph<Weight> &g, size_t s) { // based on Dijkstra algorithm std::vector<Weight> res(g.size(), inf<Weight>); priority_queue<std::pair<Weight, size_t>, std::greater<>> q; res[s] = 0; q.emplace(0, s); while (!q.empty()) { Weight w; size_t v; std::tie(w, v) = q.top(); q.pop(); if (w > res[v]) continue; for (const auto &e : g[v]) { if (res[e.dst] > w + e.cost) { res[e.dst] = w + e.cost; q.emplace(res[e.dst], e.dst); } } } return res; } int main() { size_t N; scanf("%zu", &N); graph<int> g(N); for (size_t i = 1; i < N; ++i) { size_t u, v; int w; scanf("%zu %zu %d", &u, &v, &w); --u; --v; w &= 1; g.connect_with(u, v, w); } auto dist = shortest(g, 0); for (size_t i = 0; i < N; ++i) printf("%d\n", dist[i] & 1); }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
863,022
863,023
u352499693
cpp
p03044
#include <bits/stdc++.h> using namespace std; typedef long long int LL; typedef long long int ll; typedef pair<long long int, long long int> pii; typedef pair<double, double> pdd; #define SORT(c) sort((c).begin(), (c).end()) #define BACKSORT(c) sort((c).begin(), (c).end(), std::greater<LL>()) #define FOR(i, a, b) for (LL i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define SP << " " << LL mod = 1000000007; int main() { cin.tie(0); ios::sync_with_stdio(false); LL N; cin >> N; vector<vector<pii>> graph(N); REP(i, N - 1) { LL u, v, w; cin >> u >> v >> w; u--; v--; graph[u].push_back({v, w}); graph[v].push_back({u, w}); } vector<bool> ans(N); vector<bool> otozureta(N, false); queue<LL> q; q.push(0); otozureta[0] = true; ans[0] = false; while (!q.empty()) { LL a = q.front(); q.pop(); REP(i, graph[a].size()) { LL b = graph[a][i].first; if (!otozureta[b]) { otozureta[b] = true; ans[b] = (graph[a][i].second % 2 != 0) ^ ans[i]; q.push(b); } } } REP(i, N) { if (ans[i]) { cout << 1 << endl; } else { cout << 0 << endl; } } }
#include <bits/stdc++.h> using namespace std; typedef long long int LL; typedef long long int ll; typedef pair<long long int, long long int> pii; typedef pair<double, double> pdd; #define SORT(c) sort((c).begin(), (c).end()) #define BACKSORT(c) sort((c).begin(), (c).end(), std::greater<LL>()) #define FOR(i, a, b) for (LL i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define SP << " " << LL mod = 1000000007; int main() { cin.tie(0); ios::sync_with_stdio(false); LL N; cin >> N; vector<vector<pii>> graph(N); REP(i, N - 1) { LL u, v, w; cin >> u >> v >> w; u--; v--; graph[u].push_back({v, w}); graph[v].push_back({u, w}); } vector<bool> ans(N); vector<bool> otozureta(N, false); queue<LL> q; q.push(0); otozureta[0] = true; ans[0] = false; while (!q.empty()) { LL a = q.front(); q.pop(); REP(i, graph[a].size()) { LL b = graph[a][i].first; if (!otozureta[b]) { otozureta[b] = true; ans[b] = (graph[a][i].second % 2 != 0) ^ ans[a]; q.push(b); } } } REP(i, N) { if (ans[i]) { cout << 1 << endl; } else { cout << 0 << endl; } } }
[ "assignment.value.change", "identifier.change", "variable_access.subscript.index.change", "expression.operation.binary.change" ]
863,028
863,029
u944838431
cpp
p03044
#include <bits/stdc++.h> using namespace std; #define ll long long #define FOR(i, n, m) for (int i = (n); i < (m); i++) #define REP(i, n) for (int i = 0; i < (n); i++) #define REPR(i, n) for (int i = (n); i >= 0; i--) #define all(vec) vec.begin(), vec.end() using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using P = pair<ll, ll>; using PP = pair<ll, P>; using vp = vector<P>; using vpp = vector<PP>; using vs = vector<string>; #define fi first #define se second #define pb push_back template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { is >> p.fi >> p.se; return is; } template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { os << "(" << p.fi << "," << p.se << ")"; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &t) { REP(i, t.size()) is >> t[i]; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &t) { os << "{"; REP(i, t.size()) { if (i) os << ","; os << t[i]; } cout << "}"; return os; } const ll MOD = 1000000007LL; const int INF = 1 << 30; const ll LINF = 1LL << 60; int main() { int n; cin >> n; struct edge { int to, cost; }; vector<vector<edge>> G(n); REP(i, n - 1) { int a, b, c; cin >> a >> b >> c; a--; b--; G[a].pb({b, c}); G[b].pb({a, c}); } queue<int> que; que.push(0); vi d(n, INF); d[0] = 0; while (que.size()) { int t = que.front(); que.pop(); REP(i, G[t].size()) { int u = G[t][i].to; if (d[u] == INF) { que.push(u); d[u] = d[t] + G[t][i].cost; } } } REP(i, n) { cout << d[i] % 2 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define FOR(i, n, m) for (int i = (n); i < (m); i++) #define REP(i, n) for (int i = 0; i < (n); i++) #define REPR(i, n) for (int i = (n); i >= 0; i--) #define all(vec) vec.begin(), vec.end() using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using P = pair<ll, ll>; using PP = pair<ll, P>; using vp = vector<P>; using vpp = vector<PP>; using vs = vector<string>; #define fi first #define se second #define pb push_back template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { is >> p.fi >> p.se; return is; } template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { os << "(" << p.fi << "," << p.se << ")"; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &t) { REP(i, t.size()) is >> t[i]; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &t) { os << "{"; REP(i, t.size()) { if (i) os << ","; os << t[i]; } cout << "}"; return os; } const ll MOD = 1000000007LL; const int INF = 1 << 30; const ll LINF = 1LL << 60; int main() { int n; cin >> n; struct edge { int to, cost; }; vector<vector<edge>> G(n); REP(i, n - 1) { int a, b, c; cin >> a >> b >> c; a--; b--; G[a].pb({b, c}); G[b].pb({a, c}); } queue<int> que; que.push(0); vl d(n, -1); d[0] = 0; while (que.size()) { int t = que.front(); que.pop(); REP(i, G[t].size()) { int u = G[t][i].to; if (d[u] == -1) { que.push(u); d[u] = d[t] + G[t][i].cost; } } } REP(i, n) { cout << d[i] % 2 << endl; } return 0; }
[ "variable_declaration.type.change", "call.arguments.change", "identifier.replace.remove", "literal.replace.add", "control_flow.branch.if.condition.change" ]
863,038
863,039
u437391064
cpp
p03044
//ライブラリ #include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string.h> #include <string> #include <sys/time.h> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; //ユーティリティ #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i) #define rrep(i, n) for (int i = n - 1; i >= 0; --i) #define rreps(i, n) for (int i = n; i > 0; --i) #define vmax(v) *max_element(all(v)) #define vmin(v) *min_element(all(v)) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end()) template <class T> bool chmax(T &former, const T &b) { if (former < b) { former = b; return true; } return false; } template <class T> bool chmin(T &former, const T &b) { if (former > b) { former = b; return true; } return false; } //型 //型 typedef long long int ll; typedef long long unsigned int ull; typedef pair<int, int> pairi; typedef pair<ull, ull> pairull; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ull> vull; typedef priority_queue<int, vi> pq; typedef priority_queue<int, vi, greater<int>> rpq; //定数 #define INF (1e9 + 9) #define MOD (1e9 + 7); const double pi = (acos(-1)); const double eps = 1e-8; //セグメント木 //データ構造 template <typename Monoid> struct SegmentTree { using F = function<Monoid(Monoid, Monoid)>; int sz; vector<Monoid> seg; const F f; const Monoid M1; SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) { sz = 1; while (sz < n) sz <<= 1; seg.assign(2 * sz, M1); } void set(int k, const Monoid &x) { seg[k + sz] = x; } void build() { for (int k = sz - 1; k > 0; k--) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } void update(int k, const Monoid &x) { k += sz; seg[k] = x; while (k >>= 1) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, seg[a++]); if (b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } }; //グラフ template <typename T> struct edge { int src, to; T cost; edge(int to, T cost) : src(-1), to(to), cost(cost) {} edge(int src, int to, T cost) : src(src), to(to), cost(cost) {} edge &operator=(const int &x) { to = x; return *this; } operator int() const { return to; } }; template <typename T> using Edges = vector<edge<T>>; template <typename T> using WeightedGraph = vector<Edges<T>>; using UnWeightedGraph = vector<vector<int>>; template <typename T> using Matrix = vector<vector<T>>; template <typename T> void warshall_floyd(Matrix<T> &g, T inf) { for (int k = 0; k < g.size(); k++) { for (int i = 0; i < g.size(); i++) { for (int j = 0; j < g.size(); j++) { if (g[i][k] == inf || g[k][j] == inf) continue; g[i][j] = min(g[i][j], g[i][k] + g[k][j]); } } } } /* // 法の元の演算 // modを維持しながらべき乗。 ll mod_pow(ll x, ll n) { ll res = 1; while (n > 0) { if (n & 1) res = (res * x) % mod; x = (x * x) % mod; n >>= 1; } return res; } // 逆元。オイラーの定理から? // 有限体上での割り算に利用 // 3/4 = 3*(1/4) = 3x(4の逆数) = 3x3 mod 11 // 4の逆数はかけると1になるので、この場合は3 ll mod_inverse(ll x) { return mod_pow(x, mod-2); } const int fact_max_n = 1000000; ll fact[fact_max_n]; ll fact_inv[fact_max_n]; void calc_fact() { fact[0] = 1; //階乗の算出。かける度にmodを取る。 for (ll i = 1; i < fact_max_n; i++) fact[i] = (fact[i-1] * i) % mod; //階乗の逆元の算出。 //1*2*3 => 1/(1*2*3) //1*2 => 1/(1*2*3)*3 fact_inv[fact_max_n-1] = mod_inverse(fact[fact_max_n-1]); for (ll i = fact_max_n-2; i >= 0; i--) fact_inv[i] = (fact_inv[i+1] * (i+1)) % mod; } //mod付き組み合わせ // nCk= n!/(n-k)!k! を、modをかませながら演算 ll mod_comb(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; return (fact[n] * fact_inv[k] % mod) * fact_inv[n-k] % mod; } */ // GCD int gcd(int a, int b) { while (1) { if (a < b) swap(a, b); if (!b) break; a %= b; } return a; } int gcd(const vector<int> &list) { int a = list[0]; for (auto i = 1; i < list.size(); i++) { a = gcd(a, list[i]); } return a; } //どこに、コストいくつで行けるか? int N; vector<vector<pairi>> edges; vi colors; void input() { cin >> N; cin.ignore(); edges = vector<vector<pairi>>(N); colors = vi(N); rep(i, N - 1) { int u, v, w; cin >> u >> v >> w; cin.ignore(); edges[u - 1].push_back(pairi(v - 1, w)); edges[v - 1].push_back(pairi(u - 1, w)); } } // 今訪れているノードをcolorにし、偶数で行けるところを同色、奇数で行けるところを別の色にする void dfs(int current, int parent, int color) { colors[current] = color; vector<pairi> edge = edges[current]; for (auto it = edge.begin(); it != edge.end(); it++) { int next = (*it).first; int cost = (*it).second; if (next == parent) return; if (cost % 2 == 0) { dfs(next, current, color); } else { dfs(next, current, 1 - color); } } } void solve() { dfs(0, -1, 0); rep(i, N) { cout << colors[i] << endl; } } int main() { input(); // cout << "inputed" << endl; solve(); // cout << solve() << endl; }
//ライブラリ #include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string.h> #include <string> #include <sys/time.h> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; //ユーティリティ #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i) #define rrep(i, n) for (int i = n - 1; i >= 0; --i) #define rreps(i, n) for (int i = n; i > 0; --i) #define vmax(v) *max_element(all(v)) #define vmin(v) *min_element(all(v)) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end()) template <class T> bool chmax(T &former, const T &b) { if (former < b) { former = b; return true; } return false; } template <class T> bool chmin(T &former, const T &b) { if (former > b) { former = b; return true; } return false; } //型 //型 typedef long long int ll; typedef long long unsigned int ull; typedef pair<int, int> pairi; typedef pair<ull, ull> pairull; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ull> vull; typedef priority_queue<int, vi> pq; typedef priority_queue<int, vi, greater<int>> rpq; //定数 #define INF (1e9 + 9) #define MOD (1e9 + 7); const double pi = (acos(-1)); const double eps = 1e-8; //セグメント木 //データ構造 template <typename Monoid> struct SegmentTree { using F = function<Monoid(Monoid, Monoid)>; int sz; vector<Monoid> seg; const F f; const Monoid M1; SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) { sz = 1; while (sz < n) sz <<= 1; seg.assign(2 * sz, M1); } void set(int k, const Monoid &x) { seg[k + sz] = x; } void build() { for (int k = sz - 1; k > 0; k--) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } void update(int k, const Monoid &x) { k += sz; seg[k] = x; while (k >>= 1) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, seg[a++]); if (b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } }; //グラフ template <typename T> struct edge { int src, to; T cost; edge(int to, T cost) : src(-1), to(to), cost(cost) {} edge(int src, int to, T cost) : src(src), to(to), cost(cost) {} edge &operator=(const int &x) { to = x; return *this; } operator int() const { return to; } }; template <typename T> using Edges = vector<edge<T>>; template <typename T> using WeightedGraph = vector<Edges<T>>; using UnWeightedGraph = vector<vector<int>>; template <typename T> using Matrix = vector<vector<T>>; template <typename T> void warshall_floyd(Matrix<T> &g, T inf) { for (int k = 0; k < g.size(); k++) { for (int i = 0; i < g.size(); i++) { for (int j = 0; j < g.size(); j++) { if (g[i][k] == inf || g[k][j] == inf) continue; g[i][j] = min(g[i][j], g[i][k] + g[k][j]); } } } } /* // 法の元の演算 // modを維持しながらべき乗。 ll mod_pow(ll x, ll n) { ll res = 1; while (n > 0) { if (n & 1) res = (res * x) % mod; x = (x * x) % mod; n >>= 1; } return res; } // 逆元。オイラーの定理から? // 有限体上での割り算に利用 // 3/4 = 3*(1/4) = 3x(4の逆数) = 3x3 mod 11 // 4の逆数はかけると1になるので、この場合は3 ll mod_inverse(ll x) { return mod_pow(x, mod-2); } const int fact_max_n = 1000000; ll fact[fact_max_n]; ll fact_inv[fact_max_n]; void calc_fact() { fact[0] = 1; //階乗の算出。かける度にmodを取る。 for (ll i = 1; i < fact_max_n; i++) fact[i] = (fact[i-1] * i) % mod; //階乗の逆元の算出。 //1*2*3 => 1/(1*2*3) //1*2 => 1/(1*2*3)*3 fact_inv[fact_max_n-1] = mod_inverse(fact[fact_max_n-1]); for (ll i = fact_max_n-2; i >= 0; i--) fact_inv[i] = (fact_inv[i+1] * (i+1)) % mod; } //mod付き組み合わせ // nCk= n!/(n-k)!k! を、modをかませながら演算 ll mod_comb(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; return (fact[n] * fact_inv[k] % mod) * fact_inv[n-k] % mod; } */ // GCD int gcd(int a, int b) { while (1) { if (a < b) swap(a, b); if (!b) break; a %= b; } return a; } int gcd(const vector<int> &list) { int a = list[0]; for (auto i = 1; i < list.size(); i++) { a = gcd(a, list[i]); } return a; } //どこに、コストいくつで行けるか? int N; vector<vector<pairi>> edges; vi colors; void input() { cin >> N; cin.ignore(); edges = vector<vector<pairi>>(N); colors = vi(N); rep(i, N - 1) { int u, v, w; cin >> u >> v >> w; cin.ignore(); edges[u - 1].push_back(pairi(v - 1, w)); edges[v - 1].push_back(pairi(u - 1, w)); } } // 今訪れているノードをcolorにし、偶数で行けるところを同色、奇数で行けるところを別の色にする void dfs(int current, int parent, int color) { colors[current] = color; vector<pairi> edge = edges[current]; for (auto it = edge.begin(); it != edge.end(); it++) { int next = (*it).first; int cost = (*it).second; if (next == parent) continue; if (cost % 2 == 0) { dfs(next, current, color); } else { dfs(next, current, 1 - color); } } } void solve() { dfs(0, -1, 0); rep(i, N) { cout << colors[i] << endl; } } int main() { input(); // cout << "inputed" << endl; solve(); // cout << solve() << endl; }
[ "control_flow.return.remove", "control_flow.continue.add" ]
863,073
863,074
u823871776
cpp
p03044
#include <bits/stdc++.h> using namespace std; #define ll long long int #define fr(i, a, n) for (ll i = a; i < n; i++) int main() { ll n; cin >> n; vector<pair<ll, ll>> a[n]; ll x, y, z; fr(i, 0, n - 1) { cin >> x >> y >> z; a[x].push_back(make_pair(y, z)); a[y].push_back(make_pair(x, z)); } ll dist[n + 1]; queue<int> q; q.push(1); bool visited[n + 1]; fr(i, 1, n + 1) visited[i] = false; visited[1] = true; dist[1] = 0; while (!q.empty()) { ll w = q.front(); q.pop(); fr(i, 0, a[w].size()) { if (visited[a[w][i].first] == false) { visited[a[w][i].first] = true; dist[a[w][i].first] = dist[w] + a[w][i].second; q.push(a[w][i].first); } } } fr(i, 1, n + 1) { if (dist[i] % 2 == 0) cout << '1' << endl; else cout << '0' << endl; } }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define fr(i, a, n) for (ll i = a; i < n; i++) int main() { ll n; cin >> n; vector<pair<ll, ll>> a[n + 1]; ll x, y, z; fr(i, 0, n - 1) { cin >> x >> y >> z; a[x].push_back(make_pair(y, z)); a[y].push_back(make_pair(x, z)); } ll dist[n + 1]; queue<int> q; q.push(1); bool visited[n + 1]; fr(i, 1, n + 1) visited[i] = false; visited[1] = true; dist[1] = 0; while (!q.empty()) { ll w = q.front(); q.pop(); fr(i, 0, a[w].size()) { if (visited[a[w][i].first] == false) { visited[a[w][i].first] = true; dist[a[w][i].first] = dist[w] + a[w][i].second; q.push(a[w][i].first); } } } fr(i, 1, n + 1) { if (dist[i] % 2 == 0) cout << '0' << endl; else cout << '1' << endl; } }
[ "literal.string.change", "io.output.change" ]
863,092
863,093
u339112743
cpp
p03044
#include <bits/stdc++.h> using namespace std; #define ll long long int #define fr(i, a, n) for (ll i = a; i < n; i++) int main() { ll n; cin >> n; vector<pair<ll, ll>> a[n]; ll x, y, z; fr(i, 0, n) { cin >> x >> y >> z; a[x].push_back(make_pair(y, z)); a[y].push_back(make_pair(x, z)); } ll dist[n + 1]; queue<int> q; q.push(1); bool visited[n + 1]; fr(i, 1, n + 1) visited[i] = false; visited[1] = true; dist[1] = 0; while (!q.empty()) { ll w = q.front(); q.pop(); fr(i, 0, a[w].size()) { if (visited[a[w][i].first] == false) { visited[a[w][i].first] = true; dist[a[w][i].first] = dist[w] + a[w][i].second; q.push(a[w][i].first); } } } fr(i, 1, n + 1) { if (dist[i] % 2 == 0) cout << '1' << endl; else cout << '0' << endl; } }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define fr(i, a, n) for (ll i = a; i < n; i++) int main() { ll n; cin >> n; vector<pair<ll, ll>> a[n + 1]; ll x, y, z; fr(i, 0, n - 1) { cin >> x >> y >> z; a[x].push_back(make_pair(y, z)); a[y].push_back(make_pair(x, z)); } ll dist[n + 1]; queue<int> q; q.push(1); bool visited[n + 1]; fr(i, 1, n + 1) visited[i] = false; visited[1] = true; dist[1] = 0; while (!q.empty()) { ll w = q.front(); q.pop(); fr(i, 0, a[w].size()) { if (visited[a[w][i].first] == false) { visited[a[w][i].first] = true; dist[a[w][i].first] = dist[w] + a[w][i].second; q.push(a[w][i].first); } } } fr(i, 1, n + 1) { if (dist[i] % 2 == 0) cout << '0' << endl; else cout << '1' << endl; } }
[ "literal.string.change", "io.output.change" ]
863,094
863,093
u339112743
cpp
p03044
// Standard I/O #include <cstdio> #include <iostream> #include <sstream> // Standard Library #include <cmath> #include <cstdlib> #include <cstring> #include <ctime> // Template Class #include <complex> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> // Container Control #include <algorithm> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) #define irep(i, n) for (int i = n - 1; i >= 0; --i) #define reep(i, s, n) for (int i = s; i < n; ++i) #define ireep(i, n, s) for (int i = n - 1; i >= s; --i) #define foreach(itr, x) \ for (typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr) #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back #define all(v) v.begin(), v.end() #define fs first #define sc second #define vc vector // for visualizer.html double SCALE = 1.0; double OFFSET_X = 0.0; double OFFSET_Y = 0.0; #define LINE(x, y, a, b) \ cerr << "line(" << SCALE * (x) + OFFSET_X << "," << SCALE * (y) + OFFSET_Y \ << "," << SCALE * (a) + OFFSET_X << "," << SCALE * (b) + OFFSET_Y \ << ")" << endl; #define CIRCLE(x, y, r) \ cerr << "circle(" << SCALE * (x) + OFFSET_X << "," << SCALE * (y) + OFFSET_Y \ << "," << SCALE * (r) << ")" << endl; typedef long long ll; typedef complex<double> Point; typedef pair<int, int> pii; typedef pair<int, pii> ipii; typedef vector<int> vi; typedef vector<double> vd; typedef vector<vector<int>> vii; typedef vector<vector<double>> vdd; typedef vector<int>::iterator vi_itr; const int IINF = 1 << 28; const int MOD = 1e9 + 7; const double INF = 1e30; const double EPS = 1e-10; const double PI = acos(-1.0); // Direction : L U R D const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1}; struct Node { vector<pii> dist; }; Node node[100010]; int color[100010]; void dfs(int x, ll d, bool used[100010]) { if (used[x]) return; used[x] = true; rep(i, node[x].dist.size()) { if (used[node[x].dist[i].fs]) continue; if ((d + node[x].dist[i].sc) % 2 == 0) color[node[x].dist[i].fs] = color[x]; else color[node[x].dist[i].fs] = (color[x] + 1) % 2; dfs(node[x].dist[i].fs, d + node[x].dist[i].sc, used); } } int main() { int n; cin >> n; rep(i, n - 1) { int u, v, w; cin >> u >> v >> w; --u; --v; node[u].dist.emplace_back(v, w); node[v].dist.emplace_back(u, w); } bool used[100010] = {}; color[0] = 0; dfs(0, 0, used); rep(i, n) cout << color[i] << endl; }
// Standard I/O #include <cstdio> #include <iostream> #include <sstream> // Standard Library #include <cmath> #include <cstdlib> #include <cstring> #include <ctime> // Template Class #include <complex> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> // Container Control #include <algorithm> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) #define irep(i, n) for (int i = n - 1; i >= 0; --i) #define reep(i, s, n) for (int i = s; i < n; ++i) #define ireep(i, n, s) for (int i = n - 1; i >= s; --i) #define foreach(itr, x) \ for (typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr) #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back #define all(v) v.begin(), v.end() #define fs first #define sc second #define vc vector // for visualizer.html double SCALE = 1.0; double OFFSET_X = 0.0; double OFFSET_Y = 0.0; #define LINE(x, y, a, b) \ cerr << "line(" << SCALE * (x) + OFFSET_X << "," << SCALE * (y) + OFFSET_Y \ << "," << SCALE * (a) + OFFSET_X << "," << SCALE * (b) + OFFSET_Y \ << ")" << endl; #define CIRCLE(x, y, r) \ cerr << "circle(" << SCALE * (x) + OFFSET_X << "," << SCALE * (y) + OFFSET_Y \ << "," << SCALE * (r) << ")" << endl; typedef long long ll; typedef complex<double> Point; typedef pair<int, int> pii; typedef pair<int, pii> ipii; typedef vector<int> vi; typedef vector<double> vd; typedef vector<vector<int>> vii; typedef vector<vector<double>> vdd; typedef vector<int>::iterator vi_itr; const int IINF = 1 << 28; const int MOD = 1e9 + 7; const double INF = 1e30; const double EPS = 1e-10; const double PI = acos(-1.0); // Direction : L U R D const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1}; struct Node { vector<pii> dist; }; Node node[100010]; int color[100010]; void dfs(int x, ll d, bool used[100010]) { if (used[x]) return; used[x] = true; rep(i, node[x].dist.size()) { if (used[node[x].dist[i].fs]) continue; if ((d + node[x].dist[i].sc) % 2 == 0) color[node[x].dist[i].fs] = color[0]; else color[node[x].dist[i].fs] = (color[0] + 1) % 2; dfs(node[x].dist[i].fs, d + node[x].dist[i].sc, used); } } int main() { int n; cin >> n; rep(i, n - 1) { int u, v, w; cin >> u >> v >> w; --u; --v; node[u].dist.emplace_back(v, w); node[v].dist.emplace_back(u, w); } bool used[100010] = {}; color[0] = 0; dfs(0, 0, used); rep(i, n) cout << color[i] << endl; }
[ "assignment.value.change", "identifier.replace.remove", "literal.replace.add", "variable_access.subscript.index.change", "expression.operation.binary.change" ]
863,127
863,128
u540438381
cpp
p03044
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep1(i, n) for (ll i = 1; i < (ll)(n); i++) const ll mo = 1000000007; const ll INF = 1LL << 60; // MAX 9223372036854775807 int main() { int ans[100010] = {}; queue<ll> q; ll n; cin >> n; vector<pair<ll, ll>> G[n]; ans[0] = 1; rep(i, n - 1) { ll a, b, c; cin >> a >> b >> c; G[a - 1].push_back(pair<ll, ll>(b - 1, c)); G[b - 1].push_back(pair<ll, ll>(a - 1, c)); } q.push(0); while (!q.empty()) { ll aa = q.front(); // cout << "aa"<<aa+1 << endl; q.pop(); rep(i, G[aa].size()) { if (ans[G[aa][i].first] > 0) continue; q.push(G[aa][i].first); if (G[aa][i].second % 2 == 0) ans[G[aa][i].first] = ans[aa]; else ans[G[aa][i].first] = ((ans[aa] + 1) % 2) + 1; } } rep(i, n) { cout << ans[i] - 1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep1(i, n) for (ll i = 1; i < (ll)(n); i++) const ll mo = 1000000007; const ll INF = 1LL << 60; // MAX 9223372036854775807 int main() { int ans[100010] = {}; queue<ll> q; ll n; cin >> n; vector<pair<ll, ll>> G[n]; ans[0] = 1; rep(i, n - 1) { ll a, b, c; cin >> a >> b >> c; G[a - 1].push_back(pair<ll, ll>(b - 1, c)); G[b - 1].push_back(pair<ll, ll>(a - 1, c)); } q.push(0); while (!q.empty()) { ll aa = q.front(); // cout << "aa"<<aa+1 << endl; q.pop(); rep(i, G[aa].size()) { if (ans[G[aa][i].first] > 0) continue; q.push(G[aa][i].first); if (G[aa][i].second % 2 == 0) ans[G[aa][i].first] = ans[aa]; else ans[G[aa][i].first] = ((ans[aa]) % 2) + 1; } } rep(i, n) { cout << ans[i] - 1 << endl; } return 0; }
[ "expression.operation.binary.remove" ]
863,129
863,130
u419307948
cpp
p03044
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep1(i, n) for (ll i = 1; i < (ll)(n); i++) const ll mo = 1000000007; const ll INF = 1LL << 60; // MAX 9223372036854775807 int main() { int ans[100010] = {}; queue<ll> q; ll n; cin >> n; vector<pair<ll, ll>> G[n]; ans[0] = 1; rep(i, n - 1) { ll a, b, c; cin >> a >> b >> c; G[a - 1].push_back(pair<ll, ll>(b - 1, c)); G[b - 1].push_back(pair<ll, ll>(a - 1, c)); } q.push(0); while (!q.empty()) { ll aa = q.front(); // cout << "aa"<<aa+1 << endl; q.pop(); rep(i, G[aa].size()) { if (ans[G[aa][i].first] > 0) continue; q.push(G[aa][i].first); if (G[aa][i].second % 2 == 0) ans[G[aa][i].first] = ans[aa]; else ans[G[aa][i].first] = (ans[aa] + 1) % 2 + 2; } } rep(i, n) { cout << ans[i] - 1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep1(i, n) for (ll i = 1; i < (ll)(n); i++) const ll mo = 1000000007; const ll INF = 1LL << 60; // MAX 9223372036854775807 int main() { int ans[100010] = {}; queue<ll> q; ll n; cin >> n; vector<pair<ll, ll>> G[n]; ans[0] = 1; rep(i, n - 1) { ll a, b, c; cin >> a >> b >> c; G[a - 1].push_back(pair<ll, ll>(b - 1, c)); G[b - 1].push_back(pair<ll, ll>(a - 1, c)); } q.push(0); while (!q.empty()) { ll aa = q.front(); // cout << "aa"<<aa+1 << endl; q.pop(); rep(i, G[aa].size()) { if (ans[G[aa][i].first] > 0) continue; q.push(G[aa][i].first); if (G[aa][i].second % 2 == 0) ans[G[aa][i].first] = ans[aa]; else ans[G[aa][i].first] = ((ans[aa]) % 2) + 1; } } rep(i, n) { cout << ans[i] - 1 << endl; } return 0; }
[ "expression.operation.binary.remove", "literal.number.change", "assignment.value.change", "expression.operation.binary.change" ]
863,131
863,130
u419307948
cpp
p03044
#include <iostream> #include <vector> using namespace std; int N; vector<int> ans; using Edge = pair<int, int>; using Graph = vector<vector<Edge>>; Graph G; void dfs(int v, int p, int c) { ans[v] = c; for (auto e : G[v]) { if (e.first == p) continue; if (e.second & 1) dfs(e.first, v, 1 - c); else dfs(e.first, v, 1 - c); } } int main() { cin >> N; G.assign(N, vector<Edge>()); for (int i = 0; i < N - 1; i++) { int u, v, w; cin >> u >> v >> w; u--; v--; G[u].push_back(Edge(v, w)); G[v].push_back(Edge(u, w)); } ans.assign(N, 0); dfs(0, -1, 0); for (auto a : ans) cout << a << endl; return 0; }
#include <iostream> #include <vector> using namespace std; int N; vector<int> ans; using Edge = pair<int, int>; using Graph = vector<vector<Edge>>; Graph G; void dfs(int v, int p, int c) { ans[v] = c; for (auto e : G[v]) { if (e.first == p) continue; if (e.second & 1) dfs(e.first, v, 1 - c); else dfs(e.first, v, c); } } int main() { cin >> N; G.assign(N, vector<Edge>()); for (int i = 0; i < N - 1; i++) { int u, v, w; cin >> u >> v >> w; u--; v--; G[u].push_back(Edge(v, w)); G[v].push_back(Edge(u, w)); } ans.assign(N, 0); dfs(0, -1, 0); for (auto a : ans) cout << a << endl; return 0; }
[ "expression.operation.binary.remove" ]
863,151
863,152
u806800460
cpp
p03044
#include <bits/stdc++.h> #define foreach(i, v) \ for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i) #define BETWEEN(a, x, b) (a <= x && x < b) using namespace std; typedef long long ll; int n; // 頂点-頂点-距離 vector<pair<int, int>> g[100005]; int vis[100005]; void solve(int u, int c) { for (int i = 0; i < g[u].size(); i++) { auto kv = g[u][i]; int v = kv.first; int w = kv.second; if (vis[v]) continue; if (w % 2 == 0) vis[v] = c; else vis[v] = (3 - c); solve(v, c); } } int main(int argc, char *argv[]) { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n; for (int i = 0; i < n - 1; i++) { int u, v, w; cin >> u >> v >> w; u--; v--; g[u].push_back({v, w}); g[v].push_back({u, w}); } vis[0] = 1; solve(0, 1); for (int i = 0; i < n; i++) cout << (vis[i] - 1) << endl; return 0; }
#include <bits/stdc++.h> #define foreach(i, v) \ for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i) #define BETWEEN(a, x, b) (a <= x && x < b) using namespace std; typedef long long ll; int n; // 頂点-頂点-距離 vector<pair<int, int>> g[100005]; int vis[100005]; void solve(int u, int c) { for (int i = 0; i < g[u].size(); i++) { auto kv = g[u][i]; int v = kv.first; int w = kv.second; if (vis[v]) continue; if (w % 2 == 0) vis[v] = c; else vis[v] = (3 - c); solve(v, vis[v]); } } int main(int argc, char *argv[]) { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n; for (int i = 0; i < n - 1; i++) { int u, v, w; cin >> u >> v >> w; u--; v--; g[u].push_back({v, w}); g[v].push_back({u, w}); } vis[0] = 1; solve(0, 1); for (int i = 0; i < n; i++) cout << (vis[i] - 1) << endl; return 0; }
[ "call.arguments.change" ]
863,182
863,183
u440032761
cpp
p03044
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define inf 2147483647 #define rep(i, a, b) for (int i = a; i < b; i++) #define rr read() #define ll long long #define repb(i, a, b) for (int i = a; i <= b; i++) #define CloseIo ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0) using namespace std; int read() { char ch = getchar(); int x = 0, f = 1; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while ('0' <= ch && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } struct node { int v; ll w; node(ll sw, int sv) { w = sw; v = sv; } }; const int N = 2e5 + 5; vector<node> v[2 * N + 1]; int vis[N] = {0}; void dfs(int u, int p, ll d) { for (int i = 0; i < v[u].size(); i++) { int vv = v[u][i].v; if (vv == p) continue; if (d + v[u][i].w % 2) vis[vv] = 1; dfs(vv, u, d + v[u][i].w); } } int main() { int n = rr; memset(vis, 0, sizeof(vis)); rep(i, 0, n - 1) { int x = rr, y = rr; ll w; cin >> w; v[x].push_back(node(w, y)); v[y].push_back(node(w, x)); } dfs(1, 0, 0); for (int i = 1; i <= n; i++) printf("%d\n", vis[i]); }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define inf 2147483647 #define rep(i, a, b) for (int i = a; i < b; i++) #define rr read() #define ll long long #define repb(i, a, b) for (int i = a; i <= b; i++) #define CloseIo ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0) using namespace std; int read() { char ch = getchar(); int x = 0, f = 1; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while ('0' <= ch && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } struct node { int v; ll w; node(ll sw, int sv) { w = sw; v = sv; } }; const int N = 2e5 + 5; vector<node> v[2 * N + 1]; int vis[N] = {0}; void dfs(int u, int p, ll d) { for (int i = 0; i < v[u].size(); i++) { int vv = v[u][i].v; if (vv == p) continue; if ((d + v[u][i].w) % 2) vis[vv] = 1; dfs(vv, u, d + v[u][i].w); } } int main() { int n = rr; memset(vis, 0, sizeof(vis)); rep(i, 0, n - 1) { int x = rr, y = rr; ll w; cin >> w; v[x].push_back(node(w, y)); v[y].push_back(node(w, x)); } dfs(1, 0, 0); for (int i = 1; i <= n; i++) printf("%d\n", vis[i]); }
[ "control_flow.branch.if.condition.change" ]
863,205
863,206
u680195439
cpp
p03044
#include <iostream> #include <queue> #include <vector> using namespace std; int main() { int N, u, v, w; cin >> N; vector<vector<pair<int, int>>> tree(N); for (int i = 0; i < N; ++i) { cin >> u >> v >> w; tree[--u].push_back(make_pair(--v, w & 1)); tree[v].push_back(make_pair(u, w & 1)); } vector<int> ans(N, -1); ans[0] = 0; queue<int> que; for (que.push(0); !que.empty(); que.pop()) { int tmp = que.front(); for (int i = 0; i < tree[tmp].size(); ++i) { if (ans[tree[tmp][i].first] >= 0) continue; // 既に色を塗った ans[tree[tmp][i].first] = ans[tmp] ^ tree[tmp][i].second; que.push(tree[tmp][i].first); } } for (int i = 0; i < N; ++i) cout << ans[i] << endl; return 0; }
#include <iostream> #include <queue> #include <vector> using namespace std; int main() { int N, u, v, w; cin >> N; vector<vector<pair<int, int>>> tree(N); for (int i = 1; i < N; ++i) { cin >> u >> v >> w; tree[--u].push_back(make_pair(--v, w & 1)); tree[v].push_back(make_pair(u, w & 1)); } vector<int> ans(N, -1); ans[0] = 0; queue<int> que; for (que.push(0); !que.empty(); que.pop()) { int tmp = que.front(); for (int i = 0; i < tree[tmp].size(); ++i) { if (ans[tree[tmp][i].first] >= 0) continue; // 既に色を塗った ans[tree[tmp][i].first] = ans[tmp] ^ tree[tmp][i].second; que.push(tree[tmp][i].first); } } for (int i = 0; i < N; ++i) cout << ans[i] << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
863,231
863,232
u550314572
cpp
p03044
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define mod 1000000007 #define all(v) v.begin(), v.end() #define pb push_back ll power(ll a, ll x) { if (x == 0) return 1; ll y = power(a, x / 2); ll ans = (y * y) % mod; if (x % 2) ans = (ans * a) % mod; return ans; } ll inv(ll a) { return power(a, mod - 2); } #define N 100005 vector<pair<ll, ll>> adj[N]; ll color[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n; cin >> n; for (int i = 1; i < n; i++) { ll u, v, w; cin >> u >> v >> w; adj[u].pb({v, w}); adj[v].pb({u, w}); } queue<ll> q; ll vis[n + 1]; for (int i = 1; i <= n; i++) vis[i] = -1; vis[1] = 0; color[1] = 0; q.push(1); while (!q.empty()) { ll k = q.front(); ll u = k; q.pop(); for (auto i : adj[u]) { ll v = i.first; ll w = i.second; if (vis[v] == -1) { vis[v] = vis[u] + w; if ((vis[v]) % 2 == 0) { color[v] = color[u]; } else color[v] = 1 - color[u]; q.push(v); } } } for (int i = 1; i <= n; i++) { // cout<<vis[i]<<endl; cout << color[i] << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define mod 1000000007 #define all(v) v.begin(), v.end() #define pb push_back ll power(ll a, ll x) { if (x == 0) return 1; ll y = power(a, x / 2); ll ans = (y * y) % mod; if (x % 2) ans = (ans * a) % mod; return ans; } ll inv(ll a) { return power(a, mod - 2); } #define N 100005 vector<pair<ll, ll>> adj[N]; ll color[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n; cin >> n; for (int i = 1; i < n; i++) { ll u, v, w; cin >> u >> v >> w; adj[u].pb({v, w}); adj[v].pb({u, w}); } queue<ll> q; ll vis[n + 1]; for (int i = 1; i <= n; i++) vis[i] = -1; vis[1] = 0; color[1] = 0; q.push(1); while (!q.empty()) { ll k = q.front(); ll u = k; q.pop(); for (auto i : adj[u]) { ll v = i.first; ll w = i.second; if (vis[v] == -1) { vis[v] = vis[u] + w; if (w % 2 == 0) { color[v] = color[u]; } else color[v] = 1 - color[u]; q.push(v); } } } for (int i = 1; i <= n; i++) { // cout<<vis[i]<<endl; cout << color[i] << endl; } }
[ "control_flow.branch.if.condition.change" ]
863,248
863,249
u742642200
cpp
p03044
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) using namespace std; using ll = long long; ll N; vector<vector<int>> uvw; vector<vector<pair<int, int>>> graph; vector<int> black; void solve(int i) { for (auto x : graph[i]) { if (black[x.first] == -1) { if (x.second % 2 == 0) { black[x.first] = black[i]; } else { if (black[i] == 1) { black[x.first] = 0; } else { black[x.first] = 1; } } solve(x.first); } } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; uvw.assign(N, vector<int>(3)); graph.assign(N, vector<pair<int, int>>()); black.assign(N, -1); for (int i = 0; i < N - 1; i++) { for (int j = 0; j < 3; j++) { cin >> uvw[i][j]; } } for (int i = 0; i < N - 1; i++) { graph[uvw[i][0] - 1].push_back(make_pair(uvw[i][1] - 1, uvw[i][2])); graph[uvw[i][1] - 1].push_back(make_pair(uvw[0][1] - 1, uvw[i][2])); } black[0] = 0; solve(0); for (int i = 0; i < N; i++) { cout << black[i] << endl; } return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) using namespace std; using ll = long long; ll N; vector<vector<int>> uvw; vector<vector<pair<int, int>>> graph; vector<int> black; void solve(int i) { for (auto x : graph[i]) { // cout << x.first << endl; if (black[x.first] == -1) { if (x.second % 2 == 0) { black[x.first] = black[i]; } else { if (black[i] == 1) { black[x.first] = 0; } else { black[x.first] = 1; } } // cout << x.first << ' ' << black[x.first] << endl; solve(x.first); } } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; uvw.assign(N, vector<int>(3)); graph.assign(N, vector<pair<int, int>>()); black.assign(N, -1); for (int i = 0; i < N - 1; i++) { for (int j = 0; j < 3; j++) { cin >> uvw[i][j]; } } for (int i = 0; i < N - 1; i++) { graph[uvw[i][0] - 1].push_back(make_pair(uvw[i][1] - 1, uvw[i][2])); graph[uvw[i][1] - 1].push_back(make_pair(uvw[i][0] - 1, uvw[i][2])); } black[0] = 0; solve(0); for (int i = 0; i < N; i++) { cout << black[i] << endl; } return 0; }
[ "identifier.replace.add", "literal.replace.remove", "variable_access.subscript.index.change", "call.arguments.change", "expression.operation.binary.change", "literal.number.change" ]
863,279
863,280
u520129469
cpp
p03044
#include <bits/stdc++.h> using namespace std; template <class Abel> struct UnionFind { vector<long long> par; vector<long long> rank; vector<Abel> diff_weight; UnionFind(long long n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); } void init(long long n = 1, Abel SUM_UNITY = 0) { par.resize(n); rank.resize(n); diff_weight.resize(n); for (long long i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY; } long long root(long long x) { if (par[x] == x) { return x; } else { long long r = root(par[x]); diff_weight[x] += diff_weight[par[x]]; return par[x] = r; } } Abel weight(long long x) { root(x); return diff_weight[x]; } bool issame(long long x, long long y) { return root(x) == root(y); } bool merge(long long x, long long y, Abel w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y), w = -w; if (rank[x] == rank[y]) ++rank[x]; par[y] = x; diff_weight[y] = w; return true; } Abel diff(long long x, long long y) { return weight(y) - weight(x); } }; int main() { long long n, i; cin >> n; UnionFind<long long> uf(n); for (long long i = 0; i < n - 1; ++i) { long long l, r, d; cin >> l >> r >> d; --l, --r; if (uf.issame(l, r)) { } else { uf.merge(l, r, d); } } for (i = 0; i < n - 1; i++) { cout << uf.diff(0, i) % 2 << endl; } cout << uf.diff(0, n - 1) % 2; }
#include <bits/stdc++.h> using namespace std; template <class Abel> struct UnionFind { vector<long long> par; vector<long long> rank; vector<Abel> diff_weight; UnionFind(long long n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); } void init(long long n = 1, Abel SUM_UNITY = 0) { par.resize(n); rank.resize(n); diff_weight.resize(n); for (long long i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY; } long long root(long long x) { if (par[x] == x) { return x; } else { long long r = root(par[x]); diff_weight[x] += diff_weight[par[x]]; return par[x] = r; } } Abel weight(long long x) { root(x); return diff_weight[x]; } bool issame(long long x, long long y) { return root(x) == root(y); } bool merge(long long x, long long y, Abel w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y), w = -w; if (rank[x] == rank[y]) ++rank[x]; par[y] = x; diff_weight[y] = w; return true; } Abel diff(long long x, long long y) { return weight(y) - weight(x); } }; int main() { long long n, i; cin >> n; UnionFind<long long> uf(n); for (long long i = 0; i < n - 1; ++i) { long long l, r, d; cin >> l >> r >> d; --l, --r; if (uf.issame(l, r)) { } else { uf.merge(l, r, d); } } for (i = 0; i < n - 1; i++) { cout << abs(uf.diff(0, i)) % 2 << endl; } cout << abs(uf.diff(0, n - 1)) % 2; }
[ "call.add", "call.arguments.change" ]
863,281
863,282
u451256159
cpp
p03045
#include <algorithm> #include <bitset> #include <cmath> #include <iostream> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <vector> using namespace std; ///////////////////////////////////////////////////////////////////////////////////////////// using namespace std; typedef long long ll; #define rep(i, s, n) for (ll i = s; i < n; i++) #define repe(i, s, n) for (ll i = s; i <= n; i++) // initial : call init_uf(); // unite x and y : unite(ll x, ll y) // same x and y : uf(x) == uf(y); // size s[uf(a)]; static const ll MAX_N = 100001; ll p[MAX_N] = {}; // i: node ID, p[i]: root node id ll s[MAX_N] = {}; // i: node ID, s[i]: size of group which has node i ll v[MAX_N] = {}; // i: node ID, p[i]: root node id ll uf(ll i) { return (p[i] == i) ? i : p[i] = uf(p[i]); } void init_uf() { rep(i, 1, MAX_N) { p[i] = i; s[i] = 1; } } void unite(ll x, ll y) { x = uf(x); y = uf(y); if (x == y) return; if (p[x] > p[y]) swap(x, y); // merge technique s[x] += s[y]; p[y] = x; } int main() { init_uf(); ll n, m; cin >> n >> m; rep(i, 0, m) { ll x, y, z; cin >> x >> y >> z; unite(x, y); v[x] = 1; v[y] = 1; } set<int> s; int a = 0; repe(i, 1, n) { if (v[i]) s.insert(p[i]); if (!v[i]) a++; } cout << s.size() + a << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <iostream> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <vector> using namespace std; ///////////////////////////////////////////////////////////////////////////////////////////// using namespace std; typedef long long ll; #define rep(i, s, n) for (ll i = s; i < n; i++) #define repe(i, s, n) for (ll i = s; i <= n; i++) // initial : call init_uf(); // unite x and y : unite(ll x, ll y) // same x and y : uf(x) == uf(y); // size s[uf(a)]; static const ll MAX_N = 100001; ll p[MAX_N] = {}; // i: node ID, p[i]: root node id ll s[MAX_N] = {}; // i: node ID, s[i]: size of group which has node i ll v[MAX_N] = {}; ll uf(ll i) { return (p[i] == i) ? i : p[i] = uf(p[i]); } void init_uf() { rep(i, 1, MAX_N) { p[i] = i; s[i] = 1; } } void unite(ll x, ll y) { x = uf(x); y = uf(y); if (x == y) return; if (p[x] > p[y]) swap(x, y); // merge technique s[x] += s[y]; p[y] = x; } int main() { init_uf(); ll n, m; cin >> n >> m; rep(i, 0, m) { ll x, y, z; cin >> x >> y >> z; unite(x, y); v[x] = 1; v[y] = 1; } set<int> s; int a = 0; repe(i, 1, n) { if (v[i]) s.insert(uf(i)); if (!v[i]) a++; } cout << s.size() + a << endl; return 0; }
[ "call.arguments.change" ]
863,283
863,284
u873041360
cpp
p03045
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; typedef pair<int, int> P; const int MAX_N = 100005; int ran[MAX_N], par[MAX_N]; set<int> s; void init() { rep(i, MAX_N) { ran[i] = 1; par[i] = i; } } int find(int x) { if (par[x] == x) return x; return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (ran[x] > ran[y]) swap(x, y); par[x] = y; ran[y]++; return; } int main() { init(); int N, M; cin >> N >> M; rep(i, M) { int x, y, z; cin >> x >> y >> z; x--; y--; unite(x, y); } rep(i, N) { s.insert(par[i]); } cout << s.size() << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; typedef pair<int, int> P; const int MAX_N = 100005; int ran[MAX_N], par[MAX_N]; set<int> s; void init() { rep(i, MAX_N) { ran[i] = 1; par[i] = i; } } int find(int x) { if (par[x] == x) return x; return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (ran[x] > ran[y]) swap(x, y); par[x] = y; ran[y]++; return; } int main() { init(); int N, M; cin >> N >> M; rep(i, M) { int x, y, z; cin >> x >> y >> z; x--; y--; unite(x, y); } rep(i, N) { s.insert(find(i)); } cout << s.size() << endl; return 0; }
[ "call.arguments.change" ]
863,293
863,294
u352969025
cpp
p03045
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int mod = 1000000007; vector<int> g[100005]; int z[100005]; void dfs(int x, int p) { for (int i : g[x]) if (i != p) { z[i] = 1; dfs(i, x); } } int main() { ios::sync_with_stdio(false); int n, m, u, v, w, y = 0; cin >> n >> m; for (int i = 1; i <= m; i++) cin >> u >> v >> w, w %= 2, g[u].push_back(v), g[v].push_back(u); for (int i = 1; i <= n; i++) if (!z[i]) z[i] = 1, dfs(i, i), y++; cout << y; }
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int mod = 1000000007; vector<int> g[100005]; int z[100005]; void dfs(int x, int p) { for (int i : g[x]) if (i != p && !z[i]) { z[i] = 1; dfs(i, x); } } int main() { ios::sync_with_stdio(false); int n, m, u, v, w, y = 0; cin >> n >> m; for (int i = 1; i <= m; i++) cin >> u >> v >> w, w %= 2, g[u].push_back(v), g[v].push_back(u); for (int i = 1; i <= n; i++) if (!z[i]) z[i] = 1, dfs(i, i), y++; cout << y; }
[ "control_flow.branch.if.condition.change" ]
863,297
863,298
u151855078
cpp
p03045
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; struct UnionFind { vector<int> par; // par[i]:= iの親の番号 vector<int> siz; // siz[i]:= iの属する連結成分の大きさ UnionFind(int N) { par.resize(N); for (int i = 0; i < N; ++i) { par[i] = i; } siz.resize(N, 1); } int root(int x) { // xが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; else return par[x] = root(par[x]); } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す return root(x) == root(y); } bool unite(int x, int y) { // xとyの木を併合 x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); // merge technique 小を大にくっつける siz[x] += siz[y]; par[y] = x; return true; } int size(int x) { // xの属する木の大きさを得る return siz[root(x)]; } }; 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> st; rep(i, N) { st.insert(uf.par[i]); } int ans = st.size(); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; struct UnionFind { vector<int> par; // par[i]:= iの親の番号 vector<int> siz; // siz[i]:= iの属する連結成分の大きさ UnionFind(int N) { par.resize(N); for (int i = 0; i < N; ++i) { par[i] = i; } siz.resize(N, 1); } int root(int x) { // xが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; else return par[x] = root(par[x]); } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す return root(x) == root(y); } bool unite(int x, int y) { // xとyの木を併合 x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); // merge technique 小を大にくっつける siz[x] += siz[y]; par[y] = x; return true; } int size(int x) { // xの属する木の大きさを得る return siz[root(x)]; } }; 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> st; rep(i, N) { st.insert(uf.root(i)); } int ans = st.size(); cout << ans << endl; return 0; }
[ "call.arguments.change" ]
863,305
863,306
u115838990
cpp
p03045
#include <algorithm> #include <bitset> #include <fstream> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; // typedef pair<ll, ll> P; // typedef pair<ll, P> T; #define rep(i, n) for (ll i = 0; i < (n); i++) #define revrep(i, n) for (ll i = (n)-1; i >= 0; i--) #define f first #define s second #define pb push_back ll mod = 1000000007; const ll INF = 100000000000010000; // const ull B = 998244353; // ll bit[200010]; // ll kai[3010]; // ll Cnt[10010]; // void pres(double A, ll x = 20) { printf("%.20f\n", x); } vector<ll> dx = {0, 1, 0, -1, 1, -1, 1, -1, 0}; vector<ll> dy = {1, 0, -1, 0, 1, 1, -1, -1, 0}; void chmin(ll &x, ll y) { x = min(x, y); } void chmax(ll &x, ll y) { x = max(x, y); } /*ll sum(ll i) { i += 1; ll t = 0; while (i > 0) { t += bit[i]; i -= i & -i; } return t; } void add(ll i, ll x) { i += 1; while (i <= 200005) { bit[i] += x; i += i & -i; } }*/ /*`ll SAIKI(ll S) { for (ll T = S; ; T = (T - 1) & S) { } }*/ void test() { cout << "888888888888888888888888" << endl; } ll gcd(ll x, ll y) { if (y == 0) return x; return gcd(y, x % y); } ll pow_mod(ll x, ll k) { x %= mod; ll res = 1; while (k > 0) { if (k % 2) { res *= x; res %= mod; } x *= x; x %= mod; k /= 2; } return res; } ll div_mod(ll x) { return pow_mod(x, mod - 2); } vector<ll> par; // 各元の親を表す配列 vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化) void init_u(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); // resize だとなぜか初期化されなかった for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; // x の親の親を x の親とする } return x; } // Union(Unite, Merge) bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; // merge technique(データ構造をマージするテク.小を大にくっつける) if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { // 連結判定 return root(x) == root(y); } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } //コンビネーション const int MAXcomb = 1000010; ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb]; // facはn!,finvは1/n! // invは逆元 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAXcomb; 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; } } ll comb(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * finv[k] % mod * finv[n - k] % mod; } /*map<ll, ll> pres; ll ct; void makePrimeList(ll x) { ll X = x; for (ll j = 2; j * j <= x; j++) { ll cnt = 0; while (X % j == 0) { cnt++; X /= j; } if (cnt) { if (pres[j] == 0) { ct++; pres[j] = ct; } Cnt[pres[j]] += cnt; } } if (X != 1) { if (pres[X] == 0) { ct++; pres[X] = ct; } Cnt[pres[X]] += 1; } }*/ ll N, M; ll X[100010], Y[100010], Z[100010]; ll ans; void solve() { cin >> N >> M; init_u(N + 1); ans = N; rep(i, M) { cin >> X[i] >> Y[i] >> X[i]; if (!issame(X[i], Y[i])) { ans--; merge(X[i], Y[i]); } } cout << ans << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll T = 1; // cin >> T; rep(i, T) solve(); ll N; cin >> N; }
#include <algorithm> #include <bitset> #include <fstream> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; // typedef pair<ll, ll> P; // typedef pair<ll, P> T; #define rep(i, n) for (ll i = 0; i < (n); i++) #define revrep(i, n) for (ll i = (n)-1; i >= 0; i--) #define f first #define s second #define pb push_back ll mod = 1000000007; const ll INF = 100000000000010000; // const ull B = 998244353; // ll bit[200010]; // ll kai[3010]; // ll Cnt[10010]; // void pres(double A, ll x = 20) { printf("%.20f\n", x); } vector<ll> dx = {0, 1, 0, -1, 1, -1, 1, -1, 0}; vector<ll> dy = {1, 0, -1, 0, 1, 1, -1, -1, 0}; void chmin(ll &x, ll y) { x = min(x, y); } void chmax(ll &x, ll y) { x = max(x, y); } /*ll sum(ll i) { i += 1; ll t = 0; while (i > 0) { t += bit[i]; i -= i & -i; } return t; } void add(ll i, ll x) { i += 1; while (i <= 200005) { bit[i] += x; i += i & -i; } }*/ /*`ll SAIKI(ll S) { for (ll T = S; ; T = (T - 1) & S) { } }*/ void test() { cout << "888888888888888888888888" << endl; } ll gcd(ll x, ll y) { if (y == 0) return x; return gcd(y, x % y); } ll pow_mod(ll x, ll k) { x %= mod; ll res = 1; while (k > 0) { if (k % 2) { res *= x; res %= mod; } x *= x; x %= mod; k /= 2; } return res; } ll div_mod(ll x) { return pow_mod(x, mod - 2); } vector<ll> par; // 各元の親を表す配列 vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化) void init_u(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); // resize だとなぜか初期化されなかった for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; // x の親の親を x の親とする } return x; } // Union(Unite, Merge) bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; // merge technique(データ構造をマージするテク.小を大にくっつける) if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { // 連結判定 return root(x) == root(y); } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } //コンビネーション const int MAXcomb = 1000010; ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb]; // facはn!,finvは1/n! // invは逆元 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAXcomb; 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; } } ll comb(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * finv[k] % mod * finv[n - k] % mod; } /*map<ll, ll> pres; ll ct; void makePrimeList(ll x) { ll X = x; for (ll j = 2; j * j <= x; j++) { ll cnt = 0; while (X % j == 0) { cnt++; X /= j; } if (cnt) { if (pres[j] == 0) { ct++; pres[j] = ct; } Cnt[pres[j]] += cnt; } } if (X != 1) { if (pres[X] == 0) { ct++; pres[X] = ct; } Cnt[pres[X]] += 1; } }*/ ll N, M; ll X[100010], Y[100010], Z[100010]; ll ans; void solve() { cin >> N >> M; init_u(N + 1); ans = N; rep(i, M) { cin >> X[i] >> Y[i] >> Z[i]; if (!issame(X[i], Y[i])) { ans--; merge(X[i], Y[i]); } } cout << ans << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll T = 1; // cin >> T; rep(i, T) solve(); ll N; cin >> N; }
[ "identifier.change", "expression.operation.binary.change" ]
863,312
863,313
u475007080
cpp
p03045
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; vector<int> ve(N, 0); vector<stack<int>> ed(N); for (int i = 0; i < N; i++) { int X, Y, Z; cin >> X >> Y >> Z; ve[X - 1] = 1; ve[Y - 1] = 1; ed[X - 1].push(Y - 1); ed[Y - 1].push(X - 1); } int ans = 0; for (int i = 0; i < N; i++) { if (ve[i] == 0) ans++; else if (ve[i] == 1) { ans++; queue<int> q; q.push(i); while (q.empty() != true) { int p = q.front(); q.pop(); ve[p] = 2; while (ed[p].empty() != true) { if (ve[ed[p].top()] == 1) q.push(ed[p].top()); ed[p].pop(); } } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; vector<int> ve(N, 0); vector<stack<int>> ed(N); for (int i = 0; i < M; i++) { int X, Y, Z; cin >> X >> Y >> Z; ve[X - 1] = 1; ve[Y - 1] = 1; ed[X - 1].push(Y - 1); ed[Y - 1].push(X - 1); } int ans = 0; for (int i = 0; i < N; i++) { if (ve[i] == 0) ans++; else if (ve[i] == 1) { ans++; queue<int> q; q.push(i); while (q.empty() != true) { int p = q.front(); q.pop(); ve[p] = 2; while (ed[p].empty() != true) { if (ve[ed[p].top()] == 1) q.push(ed[p].top()); ed[p].pop(); } } } } cout << ans << endl; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
863,325
863,326
u182791129
cpp
p03045
#include <bits/stdc++.h> using namespace std; class UnionFind { public: vector<int> parent; vector<int> rank; UnionFind(int n) { parent.resize(n); rank.resize(n); for (int i = 0; i < n; i++) { parent[i] = i; rank[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 (rank[x] < rank[y]) { parent[x] = y; } else { parent[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 uf = UnionFind(N); for (int i = 0; i < M; i++) { int x, y, z; cin >> x >> y >> z; uf.unite(x - 1, y - 1); } set<int> s; for (int i = 0; i < N; i++) { s.insert(uf.parent[i]); } cout << s.size() << endl; return 0; }
#include <bits/stdc++.h> using namespace std; class UnionFind { public: vector<int> parent; vector<int> rank; UnionFind(int n) { parent.resize(n); rank.resize(n); for (int i = 0; i < n; i++) { parent[i] = i; rank[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 (rank[x] < rank[y]) { parent[x] = y; } else { parent[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 uf = UnionFind(N); for (int i = 0; i < M; i++) { int x, y, z; cin >> x >> y >> z; uf.unite(x - 1, y - 1); } set<int> s; for (int i = 0; i < N; i++) { s.insert(uf.find(i)); } cout << s.size() << endl; return 0; }
[ "call.arguments.change" ]
863,327
863,328
u188117876
cpp
p03045
#include <bits/stdc++.h> using namespace std; #define CPP_STR(x) CPP_STR_I(x) #define CPP_CAT(x, y) CPP_CAT_I(x, y) #define CPP_STR_I(args...) #args #define CPP_CAT_I(x, y) x##y using i8 = int8_t; using u8 = uint8_t; using i16 = int16_t; using u16 = uint16_t; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; using f32 = float; using f64 = double; #define FOR(i, start, end) \ for (i64 i = (start), CPP_CAT(i, xxxx_end) = (end); \ i < CPP_CAT(i, xxxx_end); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(f, c, ...) \ (([&](decltype((c)) cccc) { \ return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); \ })(c)) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); #define pb push_back #define mp make_pair #define F first #define S second 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 C> i64 SIZE(const C &c) { return static_cast<i64>(c.size()); } template <typename T, size_t N> i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); } struct ProconInit { static constexpr int IOS_PREC = 15; static constexpr bool AUTOFLUSH = false; ProconInit() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(IOS_PREC); if (AUTOFLUSH) cout << unitbuf; } } PROCON_INIT; #define MAX_N 100000 i64 parent[MAX_N]; i64 rank__[MAX_N]; void init(i64 n) { REP(i, n) { parent[i] = i; rank__[i] = 0; } } i64 find(i64 x) { if (parent[x] == x) { return x; } else { return parent[x] = find(parent[x]); } } void unite(i64 x, i64 y) { x = find(x); y = find(y); if (x == y) return; if (rank__[x] < rank__[y]) { parent[x] = y; } else { parent[y] = x; if (rank__[x] == rank__[y]) { rank__[x]++; } } } bool same(i64 x, i64 y) { return find(x) == find(y); } i64 N, M; int main() { cin >> N >> M; init(N); i64 x, y, z; REP(i, M) { cin >> x >> y >> z; unite(x - 1, y - 1); // 1-origin to 0-origin } set<i64> unique_parent; REP(i, N) { unique_parent.insert(parent[i]); } cout << SIZE(unique_parent) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define CPP_STR(x) CPP_STR_I(x) #define CPP_CAT(x, y) CPP_CAT_I(x, y) #define CPP_STR_I(args...) #args #define CPP_CAT_I(x, y) x##y using i8 = int8_t; using u8 = uint8_t; using i16 = int16_t; using u16 = uint16_t; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; using f32 = float; using f64 = double; #define FOR(i, start, end) \ for (i64 i = (start), CPP_CAT(i, xxxx_end) = (end); \ i < CPP_CAT(i, xxxx_end); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(f, c, ...) \ (([&](decltype((c)) cccc) { \ return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); \ })(c)) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); #define pb push_back #define mp make_pair #define F first #define S second 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 C> i64 SIZE(const C &c) { return static_cast<i64>(c.size()); } template <typename T, size_t N> i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); } struct ProconInit { static constexpr int IOS_PREC = 15; static constexpr bool AUTOFLUSH = false; ProconInit() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(IOS_PREC); if (AUTOFLUSH) cout << unitbuf; } } PROCON_INIT; #define MAX_N 100000 i64 parent[MAX_N]; i64 rank__[MAX_N]; void init(i64 n) { REP(i, n) { parent[i] = i; rank__[i] = 0; } } i64 find(i64 x) { if (parent[x] == x) { return x; } else { return parent[x] = find(parent[x]); } } void unite(i64 x, i64 y) { x = find(x); y = find(y); if (x == y) return; if (rank__[x] < rank__[y]) { parent[x] = y; } else { parent[y] = x; if (rank__[x] == rank__[y]) { rank__[x]++; } } } bool same(i64 x, i64 y) { return find(x) == find(y); } i64 N, M; int main() { cin >> N >> M; init(N); i64 x, y, z; REP(i, M) { cin >> x >> y >> z; unite(x - 1, y - 1); // 1-origin to 0-origin } set<i64> unique_parent; REP(i, N) { unique_parent.insert(find(i)); } cout << SIZE(unique_parent) << endl; return 0; }
[ "call.arguments.change" ]
863,329
863,330
u461336793
cpp
p03045
#include <cstdio> #include <iostream> #include <vector> using namespace std; int n, m; vector<int> ve[100005]; int cnt; bool v[100005]; void dfs(int p) { if (v[p]) return; v[p] = true; for (int i = 0; i < ve[p].size(); i++) { dfs(ve[p][i]); } } int main() { scanf("%d%d", &n, &m); while (m--) { int t1, t2; scanf("%d%d%d", &t1, &t2); ve[t1].push_back(t2); ve[t2].push_back(t1); } for (int i = 1; i <= n; i++) { if (!v[i]) dfs(i), cnt++; } printf("%d", cnt); return 0; }
#include <cstdio> #include <iostream> #include <vector> using namespace std; int n, m; vector<int> ve[100005]; int cnt; bool v[100005]; void dfs(int p) { if (v[p]) return; v[p] = true; for (int i = 0; i < ve[p].size(); i++) { dfs(ve[p][i]); } } int main() { scanf("%d%d", &n, &m); while (m--) { int t1, t2; scanf("%d%d%*d", &t1, &t2); ve[t1].push_back(t2); ve[t2].push_back(t1); } for (int i = 1; i <= n; i++) { if (!v[i]) dfs(i), cnt++; } printf("%d", cnt); return 0; }
[ "literal.string.change", "call.arguments.change" ]
863,336
863,337
u307227472
cpp
p03045
#include <algorithm> #include <atomic> #include <cmath> #include <future> #include <iomanip> #include <iostream> #include <map> #include <mutex> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <thread> #include <time.h> #include <vector> #define double long double #define int long long #define low lower_bound #define upp upper_bound #define mod (int)1e9 + 7 #define inf (int)1e16 #define rep(i, n) for (int i = 0; i < n; i++) #define Rep(i, n) for (int i = n; i >= 0; i--) #define all(vec) vec.begin(), vec.end() #define vsort(vec) sort(all(vec)) #define vrever(vec) reverse(all(vec)); #define vunsort(vec) \ vsort(vec); \ vrever(vec); #define cend cout << endl; #define P pair<int, int> #define prique priority_queue<P, vector<P>, greater<P>> struct edge { int to, cost; }; using namespace std; int n, m; int par[100010], ranked[100010], sizeth[100010]; set<int> st; void init(int n) { rep(i, n) { par[i] = i; ranked[i] = 0; sizeth[i] = 1; } } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } bool same(int x, int y) { return root(x) == root(y); } void unite(int x, int y) { x = root(x); y = root(y); if (x == y) return; if (ranked[x] < ranked[y]) { par[x] = y; sizeth[y] += sizeth[x]; } else { par[y] = x; if (ranked[x] == ranked[y]) ranked[x]++; sizeth[x] += sizeth[y]; } } signed main() { cin >> n >> m; init(n); rep(i, m) { int x, y, z; cin >> x >> y >> z; x--; y--; unite(x, y); } rep(i, n) st.insert(par[i]); cout << st.size() << endl; }
#include <algorithm> #include <atomic> #include <cmath> #include <future> #include <iomanip> #include <iostream> #include <map> #include <mutex> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <thread> #include <time.h> #include <vector> #define double long double #define int long long #define low lower_bound #define upp upper_bound #define mod (int)1e9 + 7 #define inf (int)1e16 #define rep(i, n) for (int i = 0; i < n; i++) #define Rep(i, n) for (int i = n; i >= 0; i--) #define all(vec) vec.begin(), vec.end() #define vsort(vec) sort(all(vec)) #define vrever(vec) reverse(all(vec)); #define vunsort(vec) \ vsort(vec); \ vrever(vec); #define cend cout << endl; #define P pair<int, int> #define prique priority_queue<P, vector<P>, greater<P>> struct edge { int to, cost; }; using namespace std; int n, m; int par[100010], ranked[100010], sizeth[100010]; set<int> st; void init(int n) { rep(i, n) { par[i] = i; ranked[i] = 0; sizeth[i] = 1; } } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } bool same(int x, int y) { return root(x) == root(y); } void unite(int x, int y) { x = root(x); y = root(y); if (x == y) return; if (ranked[x] < ranked[y]) { par[x] = y; sizeth[y] += sizeth[x]; } else { par[y] = x; if (ranked[x] == ranked[y]) ranked[x]++; sizeth[x] += sizeth[y]; } } signed main() { cin >> n >> m; init(n); rep(i, m) { int x, y, z; cin >> x >> y >> z; x--; y--; unite(x, y); } rep(i, n) st.insert(root(i)); cout << st.size() << endl; }
[ "call.arguments.change" ]
863,340
863,341
u054475353
cpp
p03045
#define _GLIBCXX_DEBUG #include <algorithm> //next_permutation #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define all(v) v.begin(), v.end() #define dec(n) cout << fixed << setprecision(n); #define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ" #define small "abcdefghijklmnopqrstuvwxyz" using namespace std; using ll = long long; using P = pair<ll, ll>; using vl = vector<ll>; using vvl = vector<vl>; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } const ll MOD = 1000000007; const ll MAX = 2000001; ll mod(ll a) { return a % MOD; } ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } ll fac[MAX], finv[MAX], inv[MAX]; void nCrprep() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll nCr(ll n, ll r) { if (n < r) return 0; if (n < 0 || r < 0) return 0; return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD; } ll nCrcheep(ll n, ll r) { if (r == 0) return 1; else if (r == 1) return n; else return nCrcheep(n - 1, r - 1) * n / r; } vector<pair<ll, ll>> prime_factorize(ll n) { vector<pair<ll, ll>> res; for (ll i = 2; i * i <= n; i++) { if (n % i != 0) continue; ll ex = 0; while (n % i == 0) { ex++; n /= i; } res.push_back({i, ex}); } if (n != 1) res.push_back({n, 1}); return res; } struct UnionFind { //自身が親であれば、その集合に属する頂点数に-1を掛けたもの //そうでなければ親のid vector<int> r; UnionFind(int N) { r = vector<int>(N, -1); } int root(int x) { if (r[x] < 0) return x; return r[x] = root(r[x]); } bool unite(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (r[x] > r[y]) swap(x, y); r[x] += r[y]; r[y] = x; return true; } int size(int x) { return -r[root(x)]; } }; int main() { ll n, m; cin >> n >> m; UnionFind UF(n); rep(i, m) { ll a, b, z; cin >> a >> b >> z; a--; b--; UF.unite(a, b); } set<ll> al_cnt; ll cnt = 0; rep(i, n) { if (!al_cnt.count(UF.root(i))) { cnt++; al_cnt.insert(i); } } cout << cnt << endl; }
#define _GLIBCXX_DEBUG #include <algorithm> //next_permutation #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define all(v) v.begin(), v.end() #define dec(n) cout << fixed << setprecision(n); #define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ" #define small "abcdefghijklmnopqrstuvwxyz" using namespace std; using ll = long long; using P = pair<ll, ll>; using vl = vector<ll>; using vvl = vector<vl>; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } const ll MOD = 1000000007; const ll MAX = 2000001; ll mod(ll a) { return a % MOD; } ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } ll fac[MAX], finv[MAX], inv[MAX]; void nCrprep() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll nCr(ll n, ll r) { if (n < r) return 0; if (n < 0 || r < 0) return 0; return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD; } ll nCrcheep(ll n, ll r) { if (r == 0) return 1; else if (r == 1) return n; else return nCrcheep(n - 1, r - 1) * n / r; } vector<pair<ll, ll>> prime_factorize(ll n) { vector<pair<ll, ll>> res; for (ll i = 2; i * i <= n; i++) { if (n % i != 0) continue; ll ex = 0; while (n % i == 0) { ex++; n /= i; } res.push_back({i, ex}); } if (n != 1) res.push_back({n, 1}); return res; } struct UnionFind { //自身が親であれば、その集合に属する頂点数に-1を掛けたもの //そうでなければ親のid vector<int> r; UnionFind(int N) { r = vector<int>(N, -1); } int root(int x) { if (r[x] < 0) return x; return r[x] = root(r[x]); } bool unite(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (r[x] > r[y]) swap(x, y); r[x] += r[y]; r[y] = x; return true; } int size(int x) { return -r[root(x)]; } }; int main() { ll n, m; cin >> n >> m; UnionFind UF(n); rep(i, m) { ll a, b, z; cin >> a >> b >> z; a--; b--; UF.unite(a, b); } set<ll> al_cnt; ll cnt = 0; rep(i, n) { if (!al_cnt.count(UF.root(i))) { cnt++; al_cnt.insert(UF.root(i)); } } cout << cnt << endl; }
[ "call.add", "call.arguments.change" ]
863,350
863,351
u434398296
cpp
p03045
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, a, b) for (int i = a; i < b; ++i) #define FORR(i, a, b) for (int i = b - 1; i >= a; --i) #define SORT(v) sort(v.begin(), v.end()) #define SORTR(v) sort(v.rbegin(), v.rend()) #define REV(v) reverse(v.begin(), v.end()) #define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr) #define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin()) #define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin()) #define SZ(v) (int)v.size() using namespace std; using ll = long long; using P = pair<int, int>; class UnionFind { int n; vector<int> par, rank; public: UnionFind(int N) : n(N), par(N, -1), rank(N) {} int root(int i) { if (par[i] < 0) return i; return par[i] = root(par[i]); } bool same(int i, int j) { return root(i) == root(j); } void unite(int i, int j) { i = root(i); j = root(j); if (i == j) return; if (rank[i] <= rank[j]) { par[i] = j; if (rank[i] == rank[j]) { rank[j]++; } } else { par[j] = i; } } }; class Main { int N, M; vector<int> X, Y, Z; void input() { cin >> N >> M; X.resize(M); Y.resize(M); Z.resize(M); REP(i, M) { cin >> X[i] >> Y[i] >> Z[i]; X[i]--; Y[i]--; } } void output() { UnionFind ufd(N); REP(i, M) { ufd.unite(X[i], Y[i]); set<int> st; REP(i, N) { st.emplace(ufd.root(i)); } cout << st.size() << endl; } } public: Main() { input(); output(); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, a, b) for (int i = a; i < b; ++i) #define FORR(i, a, b) for (int i = b - 1; i >= a; --i) #define SORT(v) sort(v.begin(), v.end()) #define SORTR(v) sort(v.rbegin(), v.rend()) #define REV(v) reverse(v.begin(), v.end()) #define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr) #define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin()) #define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin()) #define SZ(v) (int)v.size() using namespace std; using ll = long long; using P = pair<int, int>; class UnionFind { int n; vector<int> par, rank; public: UnionFind(int N) : n(N), par(N, -1), rank(N) {} int root(int i) { if (par[i] < 0) return i; return par[i] = root(par[i]); } bool same(int i, int j) { return root(i) == root(j); } void unite(int i, int j) { i = root(i); j = root(j); if (i == j) return; if (rank[i] <= rank[j]) { par[i] = j; if (rank[i] == rank[j]) { rank[j]++; } } else { par[j] = i; } } }; class Main { int N, M; vector<int> X, Y, Z; void input() { cin >> N >> M; X.resize(M); Y.resize(M); Z.resize(M); REP(i, M) { cin >> X[i] >> Y[i] >> Z[i]; X[i]--; Y[i]--; } } void output() { UnionFind ufd(N); REP(i, M) { ufd.unite(X[i], Y[i]); } set<int> st; REP(i, N) { st.emplace(ufd.root(i)); } cout << st.size() << endl; } public: Main() { input(); output(); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }
[]
863,352
863,353
u285991898
cpp
p03045
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <string> #include <vector> const int MOD = 1e9 + 7; typedef long long ll; using namespace std; int par[100001]; int ran[100001]; void init(int n) { for (int i = 1; i <= n; i++) { par[i] = i; ran[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 (ran[x] < ran[y]) { par[x] = y; } else { par[y] = x; if (ran[x] == ran[y]) ran[x]++; } } bool same(int x, int y) { return find(x) == find(y); } int main() { int n, m; cin >> n >> m; init(n); for (int i = 0; i < m; i++) { int x, y, z; cin >> x >> y >> z; unite(x, y); } vector<int> vec; for (int i = 1; i <= n; i++) { vec.push_back(par[i]); } sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end()); cout << vec.size() << endl; return 0; }
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <string> #include <vector> const int MOD = 1e9 + 7; typedef long long ll; using namespace std; int par[100001]; int ran[100001]; void init(int n) { for (int i = 1; i <= n; i++) { par[i] = i; ran[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 (ran[x] < ran[y]) { par[x] = y; } else { par[y] = x; if (ran[x] == ran[y]) ran[x]++; } } bool same(int x, int y) { return find(x) == find(y); } int main() { int n, m; cin >> n >> m; init(n); for (int i = 0; i < m; i++) { int x, y, z; cin >> x >> y >> z; unite(x, y); } vector<int> vec; for (int i = 1; i <= n; i++) { vec.push_back(find(i)); } sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end()); cout << vec.size() << endl; return 0; }
[ "call.arguments.change" ]
863,367
863,368
u075296067
cpp
p03045
#pragma optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> // #include<iomanip> using namespace std; typedef long long int ll; typedef pair<ll, ll> pii; #define f(i, a, b) for (ll i = a; i < b; i++) #define fo(i, a, b) for (ll i = a; i <= b; i += 1) #define rf(i, a, b) for (ll i = a; i >= b; i--) #define vll vector<ll> #define sz(a) ll(a.size()) #define all(v) v.begin(), v.end() #define pb push_back #define pf push_front #define MAXN 100010 #define N 100010 #define MOD 1000000007 #define mod 998244353 #define deb(x) cout << '>' << #x << ':' << x << endl; #define nl '\n' #define MS(x, y) fill_n(*x, sizeof x / sizeof **x, y); #define mem(x, y) memset(x, y, sizeof(x)); #define INF 1000000000000000000 #define IO \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); template <int D, typename T> struct Vec : public vector<Vec<D - 1, T>> { static_assert(D >= 1, "Vector dimension must be greater than zero!"); template <typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {} }; template <typename T> struct Vec<1, T> : public vector<T> { Vec(int n = 0, const T &val = T()) : vector<T>(n, val) {} }; ll modpower(ll x, ll y, ll p) { ll res = 1; // Initialize result x = x % p; if (y == 0) return 1; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; // y = y/2 x = (x * x) % p; // Change x to x^2 } return res; } ll power(ll x, ll y) { ll res = 1; // Initialize result x = x; if (y == 0) return 1; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x); y = y >> 1; // y = y/2 x = (x * x); // Change x to x^2 } return res; } // int gcd(int a, int b) { if (a == 0)return b;return gcd(b % a, a);} ll modinv(ll a, ll p) { return modpower(a, p - 2, p); } const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[8] = {0, 1, 0, -1, -1, 1, -1, 1}; long long safe_sqrt(long long n) { long long res = sqrt((long double)n); if (res * res == n) return res; const long double eps = 1e-8; if ((long double)(res + 1) * (res + 1) < n + eps) return res + 1; if ((long double)res * res + eps > n) return res - 1; return res; } // (a+b-1)/b for ceil Vec<1, ll> parent(MAXN, 0), arr(MAXN, 1); ll root(ll x) { while (x != parent[x]) { parent[x] = parent[parent[x]]; x = parent[x]; } return x; } void unite(ll u, ll v) { u = root(u); v = root(v); if (arr[u] > arr[v]) { swap(u, v); } parent[u] = v; arr[v] += arr[u]; return; } void solve() { ll n, m; cin >> n >> m; fo(i, 1, n) { parent[i] = i; } f(i, 0, m) { ll x, y, z; cin >> x >> y >> z; unite(x, y); } set<ll> s; fo(i, 1, n) { s.insert(parent[i]); } cout << s.size() << nl; return; } int main() { IO; // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("out.txt", "w", stdout); // #endif int T = 1; // cin >> T; f(c, 0, T) { solve(); } return 0; } // multiset m make_pair make_tuple tuple<int,int,int> continue resize insert // count size else true isValid second first false erase double priority_queue // cout<<setprecision(12); push_back pop_back pop_front push_front lower_bound // upper_bound reverse
#pragma optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> // #include<iomanip> using namespace std; typedef long long int ll; typedef pair<ll, ll> pii; #define f(i, a, b) for (ll i = a; i < b; i++) #define fo(i, a, b) for (ll i = a; i <= b; i += 1) #define rf(i, a, b) for (ll i = a; i >= b; i--) #define vll vector<ll> #define sz(a) ll(a.size()) #define all(v) v.begin(), v.end() #define pb push_back #define pf push_front #define MAXN 100010 #define N 100010 #define MOD 1000000007 #define mod 998244353 #define deb(x) cout << '>' << #x << ':' << x << endl; #define nl '\n' #define MS(x, y) fill_n(*x, sizeof x / sizeof **x, y); #define mem(x, y) memset(x, y, sizeof(x)); #define INF 1000000000000000000 #define IO \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); template <int D, typename T> struct Vec : public vector<Vec<D - 1, T>> { static_assert(D >= 1, "Vector dimension must be greater than zero!"); template <typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {} }; template <typename T> struct Vec<1, T> : public vector<T> { Vec(int n = 0, const T &val = T()) : vector<T>(n, val) {} }; ll modpower(ll x, ll y, ll p) { ll res = 1; // Initialize result x = x % p; if (y == 0) return 1; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; // y = y/2 x = (x * x) % p; // Change x to x^2 } return res; } ll power(ll x, ll y) { ll res = 1; // Initialize result x = x; if (y == 0) return 1; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x); y = y >> 1; // y = y/2 x = (x * x); // Change x to x^2 } return res; } // int gcd(int a, int b) { if (a == 0)return b;return gcd(b % a, a);} ll modinv(ll a, ll p) { return modpower(a, p - 2, p); } const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[8] = {0, 1, 0, -1, -1, 1, -1, 1}; long long safe_sqrt(long long n) { long long res = sqrt((long double)n); if (res * res == n) return res; const long double eps = 1e-8; if ((long double)(res + 1) * (res + 1) < n + eps) return res + 1; if ((long double)res * res + eps > n) return res - 1; return res; } // (a+b-1)/b for ceil Vec<1, ll> parent(MAXN, 0), arr(MAXN, 1); ll root(ll x) { while (x != parent[x]) { parent[x] = parent[parent[x]]; x = parent[x]; } return x; } void unite(ll u, ll v) { u = root(u); v = root(v); if (arr[u] > arr[v]) { swap(u, v); } parent[u] = v; arr[v] += arr[u]; return; } void solve() { ll n, m; cin >> n >> m; fo(i, 1, n) { parent[i] = i; } f(i, 0, m) { ll x, y, z; cin >> x >> y >> z; unite(x, y); } set<ll> s; fo(i, 1, n) { s.insert(root(i)); } cout << s.size() << nl; return; } int main() { IO; // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("out.txt", "w", stdout); // #endif int T = 1; // cin >> T; f(c, 0, T) { solve(); } return 0; } // multiset m make_pair make_tuple tuple<int,int,int> continue resize insert // count size else true isValid second first false erase double priority_queue // cout<<setprecision(12); push_back pop_back pop_front push_front lower_bound // upper_bound reverse
[ "call.arguments.change" ]
863,372
863,373
u545385207
cpp
p03045
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (ll i = 0; i < n; i++) #define repl(i, l, r) for (ll i = (l); i < (r); i++) #define per(i, n) for (ll i = n - 1; i >= 0; i--) #define perl(i, r, l) for (ll i = r - 1; i >= l; i--) #define fi first #define se second #define pb push_back #define ins insert #define all(x) (x).begin(), (x).end() using vl = vector<ll>; using vvl = vector<vector<ll>>; const ll MOD = 1000000007; const ll MOD9 = 998244353; const int inf = 1e9 + 10; const ll INF = 4e18; const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1}; const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1}; using Graph = vector<vector<int>>; const double pi = acos(-1); template <int MOD> struct Fp { long long val; constexpr Fp(long long v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr int getmod() { return MOD; } constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; } constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; } constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; } constexpr Fp &operator+=(const Fp &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp &operator-=(const Fp &r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp &operator*=(const Fp &r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp &operator/=(const Fp &r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator==(const Fp &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Fp &r) const noexcept { return this->val != r.val; } friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept { return os << x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; using mint = Fp<MOD>; vector<bool> seen, finished; int pos = -1; int ca = 0; int f = 0; void dfs(const Graph &G, int v, int p) { seen[v] = true; for (auto nv : G[v]) { if (nv == p) continue; if (finished[nv]) continue; if (seen[nv] && !finished[nv]) { pos = nv; f++; return; } dfs(G, nv, v); // サイクル検出したならば真っ直ぐに抜けていく if (pos != -1) { return; } } finished[v] = true; } mint calc(long long N, long long K) { mint res = 1; for (long long n = 0; n < K; ++n) { res *= (N - n); res /= (n + 1); } return res; } struct UnionFind { vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化 for (ll i = 0; i < N; i++) par[i] = i; } ll root(ll x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(ll x, ll y) { // xとyの木を併合 ll rx = root(x); // xの根をrx ll ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す ll rx = root(x); ll ry = root(y); return rx == ry; } }; int main() { // 頂点数と辺数 int N, M; cin >> N >> M; ll ca = 0; // グラフ入力受取 (ここでは無向グラフを想定) Graph G(N); for (int i = 0; i < M; ++i) { int a, b, c; cin >> a >> b >> c; a--; b--; G[a].push_back(b); G[b].push_back(a); } // BFS のためのデータ構造 vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化 queue<int> que; rep(i, N) { if (dist[i] != -1) continue; else { ca++; // 初期条件 (頂点 0 を初期ノードとする) dist[i] = 0; que.push(0); // 0 を橙色頂点にする // BFS 開始 (キューが空になるまで探索を行う) while (!que.empty()) { int v = que.front(); // キューから先頭頂点を取り出す que.pop(); // v から辿れる頂点をすべて調べる for (int nv : G[v]) { if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない // 新たな白色頂点 nv について距離情報を更新してキューに追加する dist[nv] = dist[v] + 1; que.push(nv); } } } } // 結果出力 (各頂点の頂点 0 からの距離を見る) cout << ca << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (ll i = 0; i < n; i++) #define repl(i, l, r) for (ll i = (l); i < (r); i++) #define per(i, n) for (ll i = n - 1; i >= 0; i--) #define perl(i, r, l) for (ll i = r - 1; i >= l; i--) #define fi first #define se second #define pb push_back #define ins insert #define all(x) (x).begin(), (x).end() using vl = vector<ll>; using vvl = vector<vector<ll>>; const ll MOD = 1000000007; const ll MOD9 = 998244353; const int inf = 1e9 + 10; const ll INF = 4e18; const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1}; const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1}; using Graph = vector<vector<int>>; const double pi = acos(-1); template <int MOD> struct Fp { long long val; constexpr Fp(long long v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr int getmod() { return MOD; } constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; } constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; } constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; } constexpr Fp &operator+=(const Fp &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp &operator-=(const Fp &r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp &operator*=(const Fp &r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp &operator/=(const Fp &r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator==(const Fp &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Fp &r) const noexcept { return this->val != r.val; } friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept { return os << x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; using mint = Fp<MOD>; vector<bool> seen, finished; int pos = -1; int ca = 0; int f = 0; void dfs(const Graph &G, int v, int p) { seen[v] = true; for (auto nv : G[v]) { if (nv == p) continue; if (finished[nv]) continue; if (seen[nv] && !finished[nv]) { pos = nv; f++; return; } dfs(G, nv, v); // サイクル検出したならば真っ直ぐに抜けていく if (pos != -1) { return; } } finished[v] = true; } mint calc(long long N, long long K) { mint res = 1; for (long long n = 0; n < K; ++n) { res *= (N - n); res /= (n + 1); } return res; } struct UnionFind { vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化 for (ll i = 0; i < N; i++) par[i] = i; } ll root(ll x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(ll x, ll y) { // xとyの木を併合 ll rx = root(x); // xの根をrx ll ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す ll rx = root(x); ll ry = root(y); return rx == ry; } }; int main() { // 頂点数と辺数 int N, M; cin >> N >> M; ll ca = 0; // グラフ入力受取 (ここでは無向グラフを想定) Graph G(N); for (int i = 0; i < M; ++i) { int a, b, c; cin >> a >> b >> c; a--; b--; G[a].push_back(b); G[b].push_back(a); } // BFS のためのデータ構造 vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化 queue<int> que; rep(i, N) { if (dist[i] != -1) continue; else { // cout << i << endl; ca++; // 初期条件 (頂点 0 を初期ノードとする) dist[i] = 0; que.push(i); // 0 を橙色頂点にする // BFS 開始 (キューが空になるまで探索を行う) while (!que.empty()) { int v = que.front(); // キューから先頭頂点を取り出す que.pop(); // v から辿れる頂点をすべて調べる for (int nv : G[v]) { if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない // 新たな白色頂点 nv について距離情報を更新してキューに追加する dist[nv] = dist[v] + 1; que.push(nv); } } } } // 結果出力 (各頂点の頂点 0 からの距離を見る) cout << ca << endl; }
[ "identifier.replace.add", "literal.replace.remove", "call.arguments.change" ]
863,374
863,375
u722640678
cpp
p03045
// 7/4 #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; struct UnionFind { vector<int> d; UnionFind(int n = 0) : d(n, -1) {} int find(int x) { if (d[x] < 0) return x; return d[x] = find(d[x]); } bool unite(int x, int y) { x = find(x); y = find(y); if (x == y) return false; if (d[x] > d[y]) swap(x, y); d[x] += d[y]; d[y] = x; return true; } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return -d[find(x)]; } }; 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 uf(2*N); // rep(i, M) { // int x = X[i]; // int y = Y[i]; // if (Z[i]%2) { // // X, Yは偶奇が等しい // uf.unite(x, y); // uf.unite(x+N, y+N); // } else { // // X, Yは偶奇が異なる // uf.unite(x, y+N); // uf.unite(x+N, y); // } // } // set<int> st; // rep(i, 2 * N) { // st.insert(uf.find(i)); // } // cout << st.size() / 2 << endl; UnionFind uf(N); rep(i, M) { uf.unite(X[i], Y[i]); } set<int> st; rep(i, N) st.insert(uf.find(i)); cout << st.size() << endl; }
// 7/4 #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; struct UnionFind { vector<int> d; UnionFind(int n = 0) : d(n, -1) {} int find(int x) { if (d[x] < 0) return x; return d[x] = find(d[x]); } bool unite(int x, int y) { x = find(x); y = find(y); if (x == y) return false; if (d[x] > d[y]) swap(x, y); d[x] += d[y]; d[y] = x; return true; } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return -d[find(x)]; } }; 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 uf(2*N); // rep(i, M) { // int x = X[i]; // int y = Y[i]; // if (Z[i]%2) { // // X, Yは偶奇が等しい // uf.unite(x, y); // uf.unite(x+N, y+N); // } else { // // X, Yは偶奇が異なる // uf.unite(x, y+N); // uf.unite(x+N, y); // } // } // set<int> st; // rep(i, 2 * N) { // st.insert(uf.find(i)); // } // cout << st.size() / 2 << endl; UnionFind uf(N); rep(i, M) { uf.unite(X[i] - 1, Y[i] - 1); } set<int> st; rep(i, N) st.insert(uf.find(i)); cout << st.size() << endl; }
[ "expression.operation.binary.add" ]
863,381
863,382
u581094488
cpp
p03045
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1LL << 62 #define inf 1000000007 ll n, k; vector<ll> ch[100010]; bool ans[100010]; void dep(ll now, ll s) { if (now != s && ch[now].size() == 1) { return; } for (ll i = 0; i < ch[now].size(); i++) { ll next = ch[now][i]; if (ans[next] == true) { continue; } ans[next] = true; dep(next, s); } } int main() { cin >> n >> k; for (ll i = 0; i < k; i++) { ll x, y, z; cin >> x >> y >> z; x--; y--; ch[x].push_back(y); ch[y].push_back(x); } ll ans2 = 0; for (ll i = 0; i < n; i++) { if (ans[i] == true) { continue; } ans2++; dep(0, i); } cout << ans2; // your code goes here return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1LL << 62 #define inf 1000000007 ll n, k; vector<ll> ch[100010]; bool ans[100010]; void dep(ll now, ll s) { if (now != s && ch[now].size() == 1) { return; } for (ll i = 0; i < ch[now].size(); i++) { ll next = ch[now][i]; if (ans[next] == true) { continue; } ans[next] = true; dep(next, s); } } int main() { cin >> n >> k; for (ll i = 0; i < k; i++) { ll x, y, z; cin >> x >> y >> z; x--; y--; ch[x].push_back(y); ch[y].push_back(x); } ll ans2 = 0; for (ll i = 0; i < n; i++) { if (ans[i] == true) { continue; } ans2++; dep(i, i); } cout << ans2; // your code goes here return 0; }
[ "identifier.replace.add", "literal.replace.remove", "call.arguments.change" ]
863,385
863,386
u166378830
cpp
p03045
#include <bits/stdc++.h> #define rep(i, n) for (long long int i = 0; i < n; i++) #define _rep(i, m, n) for (long long int i = m; i < n; i++) using namespace std; typedef long long ll; typedef pair<int, int> P; const int MAX_N = 100010; const ll mod = 1000000007; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; ll gcd(ll A, ll B) { if (B == 0) return A; return gcd(B, A % B); } ll lcm(ll A, ll B) { return A * B / gcd(A, B); } /*------------------------------------------------------------------*/ struct UnionFind { vector<int> parent; vector<int> rank; // tree's depth UnionFind(int n) { parent.resize(n); rank.resize(n); init(n); } // initialize void init(int n) { for (int i = 0; i < n; i++) { parent[i] = i; rank[i] = 0; } } // find root 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 (rank[x] < rank[y]) { parent[x] = y; } else { parent[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 UF(n); int x, y, z; rep(i, m) { cin >> x >> y >> z; x--, y--; UF.unite(x, y); } set<int> count; rep(i, n) count.insert(UF.parent[i]); cout << count.size() << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (long long int i = 0; i < n; i++) #define _rep(i, m, n) for (long long int i = m; i < n; i++) using namespace std; typedef long long ll; typedef pair<int, int> P; const int MAX_N = 100010; const ll mod = 1000000007; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; ll gcd(ll A, ll B) { if (B == 0) return A; return gcd(B, A % B); } ll lcm(ll A, ll B) { return A * B / gcd(A, B); } /*------------------------------------------------------------------*/ struct UnionFind { vector<int> parent; vector<int> rank; // tree's depth UnionFind(int n) { parent.resize(n); rank.resize(n); init(n); } // initialize void init(int n) { for (int i = 0; i < n; i++) { parent[i] = i; rank[i] = 0; } } // find root 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 (rank[x] < rank[y]) { parent[x] = y; } else { parent[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 UF(n); int x, y, z; rep(i, m) { cin >> x >> y >> z; x--, y--; UF.unite(x, y); } set<int> count; rep(i, n) count.insert(UF.find(i)); cout << count.size() << endl; }
[ "call.arguments.change" ]
863,389
863,390
u999788719
cpp
p03045
#include <bits/stdc++.h> #define REP(i, s, n) for (int i = s; i < (int)(n); i++) #define ALL(a) a.begin(), a.end() #define MOD 1000000007 using namespace std; using ll = long long; class UnionFindTree { public: vector<int> parent; vector<int> siz; UnionFindTree(int n) { siz.resize(n, 1); parent.resize(n); for (int i = 0; i < n; i++) { parent[i] = i; } } int root(int x) { if (parent[x] == x) return x; return parent[x] = root(parent[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; if (siz[rx] < siz[ry]) swap(rx, ry); siz[rx] += siz[ry]; parent[ry] = rx; } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return siz[root(x)]; } }; int main() { int N, M; cin >> N >> M; UnionFindTree uft(N); REP(i, 0, M) { int x, y, z; cin >> x >> y >> x; uft.unite(--x, --y); } bool used[N] = {}; int ans = 0; REP(i, 0, N) { if (used[uft.root(i)]) continue; used[uft.root(i)] = true; ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define REP(i, s, n) for (int i = s; i < (int)(n); i++) #define ALL(a) a.begin(), a.end() #define MOD 1000000007 using namespace std; using ll = long long; class UnionFindTree { public: vector<int> parent; vector<int> siz; UnionFindTree(int n) { siz.resize(n, 1); parent.resize(n); for (int i = 0; i < n; i++) { parent[i] = i; } } int root(int x) { if (parent[x] == x) return x; return parent[x] = root(parent[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; if (siz[rx] < siz[ry]) swap(rx, ry); siz[rx] += siz[ry]; parent[ry] = rx; } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return siz[root(x)]; } }; int main() { int N, M; cin >> N >> M; UnionFindTree uft(N); REP(i, 0, M) { int x, y, z; cin >> x >> y >> z; uft.unite(--x, --y); } bool used[N] = {}; int ans = 0; REP(i, 0, N) { if (used[uft.root(i)]) continue; used[uft.root(i)] = true; ans++; } cout << ans << endl; return 0; }
[ "identifier.change", "expression.operation.binary.change" ]
863,391
863,392
u483992368
cpp
p03045
#include <bits/stdc++.h> using namespace std; struct UnionFind { vector<int> par; vector<int> rank; UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n); rank.resize(n); for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0; } int root(int x) { if (par[x] == x) return x; int r = root(par[x]); return par[x] = r; } bool same(int x, int y) { return root(x) == root(y); } bool unite(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) ++rank[x]; par[y] = x; return true; } }; int main() { int64_t N, M, x, y, z; cin >> N >> M; UnionFind uf(N); for (int i = 0; i < M; i++) { cin >> x >> y >> z; uf.unite(x - 1, y - 1); } map<int, int> mp; for (auto p : uf.par) mp[p]++; cout << mp.size() << endl; }
#include <bits/stdc++.h> using namespace std; struct UnionFind { vector<int> par; vector<int> rank; UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n); rank.resize(n); for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0; } int root(int x) { if (par[x] == x) return x; int r = root(par[x]); return par[x] = r; } bool same(int x, int y) { return root(x) == root(y); } bool unite(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) ++rank[x]; par[y] = x; return true; } }; int main() { int64_t N, M, x, y, z; cin >> N >> M; UnionFind uf(N); for (int i = 0; i < M; i++) { cin >> x >> y >> z; uf.unite(x - 1, y - 1); } map<int, int> mp; for (auto p : uf.par) mp[uf.root(p)]++; cout << mp.size() << endl; }
[ "call.add", "call.arguments.change" ]
863,393
863,394
u543466827
cpp
p03045
#include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) using namespace std; const int INF = 1 << 30; const long long MOD = 1000000000 + 7; const double PI = acos(-1); struct UnionFind { vector<int> par; UnionFind(int n) : par(n) { // for (int i = 0; i < n; i++)par[i] = i; for (int i = 0; i < n; i++) par[i] = -1; } int root(int x) { // if (par[x] == x) return x; if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; // 同じ木に属するのでmergeしない(そのまま) if (par[x] > par[y]) swap(x, y); // merge technique(-nがその木の要素数) par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; // -nがノード数なのでマイナスかける } }; int main() { int N, M; cin >> N >> M; UnionFind uf(N); rep(i, M) { int x, y, z; cin >> x >> y >> x; uf.merge(x - 1, y - 1); } map<int, int> mp; rep(i, N) mp[uf.root(i)] = 1; cout << mp.size(); }
#include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) using namespace std; const int INF = 1 << 30; const long long MOD = 1000000000 + 7; const double PI = acos(-1); struct UnionFind { vector<int> par; UnionFind(int n) : par(n) { // for (int i = 0; i < n; i++)par[i] = i; for (int i = 0; i < n; i++) par[i] = -1; } int root(int x) { // if (par[x] == x) return x; if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; // 同じ木に属するのでmergeしない(そのまま) if (par[x] > par[y]) swap(x, y); // merge technique(-nがその木の要素数) par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; // -nがノード数なのでマイナスかける } }; int main() { int N, M; cin >> N >> M; UnionFind uf(N); rep(i, M) { int x, y, z; cin >> x >> y >> z; uf.merge(x - 1, y - 1); } map<int, int> mp; rep(i, N) mp[uf.root(i)] = 1; cout << mp.size(); }
[ "identifier.change", "expression.operation.binary.change" ]
863,399
863,400
u289578952
cpp
p03045
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int x, y, z; vector<int> a(n); vector<set<int>> s(n + 1); int i; for (i = 0; i < m; i++) { cin >> x >> y >> z; s[x].insert(y); s[y].insert(x); } vector<bool> rikai(n + 1); queue<int> q; int cnt = 0; int tmp; for (i = 1; i <= n; i++) { if (!rikai[i]) { rikai[i] = true; cnt++; for (auto j : s[i]) { if (!rikai[j]) q.push(j); } while (!q.empty()) { tmp = q.front(); rikai[tmp] = true; q.pop(); for (auto j : s[tmp]) { if (!rikai[j]) q.push(j); } } } } cout << cnt << endl; cout << cnt; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int x, y, z; vector<int> a(n); vector<set<int>> s(n + 1); int i; for (i = 0; i < m; i++) { cin >> x >> y >> z; s[x].insert(y); s[y].insert(x); } vector<bool> rikai(n + 1); queue<int> q; int cnt = 0; int tmp; for (i = 1; i <= n; i++) { if (!rikai[i]) { rikai[i] = true; cnt++; for (auto j : s[i]) { if (!rikai[j]) q.push(j); } while (!q.empty()) { tmp = q.front(); rikai[tmp] = true; q.pop(); for (auto j : s[tmp]) { if (!rikai[j]) q.push(j); } } } } cout << cnt << endl; }
[]
863,407
863,408
u523698212
cpp
p03045
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int n; int parent[500000]; int rnk[500000]; int find(int x) { if (parent[x] == x) return x; return parent[x] = find(parent[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]) { parent[x] = y; } else { parent[y] = x; if (rnk[x] == rnk[y]) rnk[x]++; } } bool same(int x, int y) { return find(x) == find(y); } int main() { int m; cin >> n >> m; for (int i = 0; i < n; i++) parent[i] = i, rnk[i] = 0; for (int i = 0; i < m; i++) { int x, y, z; cin >> x >> y >> z; --x; --y; unite(x, y); } set<int> s; for (int i = 0; i < n; i++) { s.insert(parent[i]); } cout << s.size() << endl; }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int n; int parent[500000]; int rnk[500000]; int find(int x) { if (parent[x] == x) return x; return parent[x] = find(parent[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]) { parent[x] = y; } else { parent[y] = x; if (rnk[x] == rnk[y]) rnk[x]++; } } bool same(int x, int y) { return find(x) == find(y); } int main() { int m; cin >> n >> m; for (int i = 0; i < n; i++) parent[i] = i, rnk[i] = 0; for (int i = 0; i < m; i++) { int x, y, z; cin >> x >> y >> z; --x; --y; unite(x, y); } set<int> s; for (int i = 0; i < n; i++) { s.insert(find(parent[i])); } cout << s.size() << endl; }
[ "call.arguments.add", "call.arguments.change" ]
863,411
863,412
u313766957
cpp
p03045
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <vector> #define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0) #define rep(i, n) for (int i = 0; i < n; ++i) #define ALL(a) (a).begin(), (a).end() typedef long long ll; using namespace std; int N, M; int par[100005]; //親 int tree_rank[100005]; //木の深さ void init_union_find(int n) { rep(i, n) { par[i] = i; tree_rank[i] = 0; } } // 木の根を求める int find(int x) { if (par[x] == x) return x; else return par[x] = find(par[x]); } // xとyの属する集合を併合 void 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]++; } } int main() { INCANT; cin >> N >> M; int x, y, z; init_union_find(N); rep(i, M) { cin >> x >> y >> z; x--; y--; unite(x, y); } set<int> S; rep(i, N) S.insert(par[i]); cout << S.size() << "\n"; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <vector> #define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0) #define rep(i, n) for (int i = 0; i < n; ++i) #define ALL(a) (a).begin(), (a).end() typedef long long ll; using namespace std; int N, M; int par[100005]; //親 int tree_rank[100005]; //木の深さ void init_union_find(int n) { rep(i, n) { par[i] = i; tree_rank[i] = 0; } } // 木の根を求める int find(int x) { if (par[x] == x) return x; else return par[x] = find(par[x]); } // xとyの属する集合を併合 void 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]++; } } int main() { INCANT; cin >> N >> M; int x, y, z; init_union_find(N); rep(i, M) { cin >> x >> y >> z; x--; y--; unite(x, y); } set<int> S; rep(i, N) S.insert(find(i)); cout << S.size() << "\n"; return 0; }
[ "call.arguments.change" ]
863,417
863,418
u288087195
cpp
p03045
#include <bits/stdc++.h> using namespace std; struct edge { int x, y; } e[100001]; int fa[100001]; int findfa(int x) { if (x != fa[x]) fa[x] = findfa(fa[x]); return x; } int main() { int n, m, i, a; int f1, f2; cin >> n >> m; for (i = 1; i <= n; i++) fa[i] = i; for (i = 1; i <= m; i++) { cin >> e[i].x >> e[i].y >> a; f1 = findfa(e[i].x); f2 = findfa(e[i].y); if (f1 != f2) fa[f1] = f2; } int cnt = 0; for (i = 1; i <= n; i++) if (fa[i] == i) cnt++; cout << cnt; return 0; }
#include <bits/stdc++.h> using namespace std; struct edge { int x, y; } e[100001]; int fa[100001]; int findfa(int x) { if (x != fa[x]) fa[x] = findfa(fa[x]); return fa[x]; } int main() { int n, m, i, a; int f1, f2; cin >> n >> m; for (i = 1; i <= n; i++) fa[i] = i; for (i = 1; i <= m; i++) { cin >> e[i].x >> e[i].y >> a; f1 = findfa(e[i].x); f2 = findfa(e[i].y); if (f1 != f2) fa[f1] = f2; } int cnt = 0; for (i = 1; i <= n; i++) if (fa[i] == i) cnt++; cout << cnt; return 0; }
[ "function.return_value.change" ]
863,421
863,422
u762918924
cpp
p03045
#include <bits/stdc++.h> using namespace std; struct edge { int x, y; } e[100001]; int fa[100001]; int findfa(int x) { if (x != fa[x]) fa[x] = findfa(fa[x]); return x; } int main() { int n, m, i, a; int f1, f2; cin >> n >> m; for (i = 1; i <= n; i++) fa[i] = i; for (i = 1; i <= m; i++) { cin >> e[i].x >> e[i].y >> a; f1 = findfa(e[i].x); f2 = findfa(e[i].y); if (f1 != f2) fa[f1] = f2; } int cnt = 0; for (i = 1; i <= n; i++) if (fa[i] == i) cnt++; cout << cnt; return 0; }
#include <bits/stdc++.h> using namespace std; struct edge { int x, y; } e[100001]; int fa[100001]; int findfa(int x) { if (x != fa[x]) fa[x] = findfa(fa[x]); return fa[x]; } int main() { int n, m, i, a; int f1, f2; cin >> n >> m; for (i = 1; i <= n; i++) fa[i] = i; for (i = 1; i <= m; i++) { cin >> e[i].x >> e[i].y >> a; f1 = findfa(e[i].x); f2 = findfa(e[i].y); if (f1 != f2) fa[f1] = f2; } int cnt = 0; for (i = 1; i <= n; i++) if (fa[i] == i) cnt++; cout << cnt; return 0; }
[ "function.return_value.change" ]
863,423
863,422
u762918924
cpp
p03045
#include <bits/stdc++.h> #include <cstdint> #include <vector> #define FOR(i, l, r) for (int i = (l); i < (r); ++i) #define RFOR(i, l, r) for (int i = (l); i >= (int)(r); i--) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) RFOR(i, n - 1, 0) #define int long long using namespace std; const int MX = 1e6; const int inf = 1e9; const int mod = 1e9 + 7; vector<int> ra(MX, 0); vector<int> par(MX, 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 (ra[x] < ra[y]) { par[x] = y; } else { par[y] = x; if (ra[x] == ra[y]) { ra[x]++; } } } bool same(int x, int y) { return find(x) == find(y); } signed main() { int n, m; cin >> n >> m; for (size_t i = 0; i < n; i++) { par[i] = i; } for (size_t i = 0; i < m; i++) { int x, y, z; cin >> x >> y >> z; unite(x - 1, y - 1); } int ans = 0; set<int> ansset; for (size_t i = 0; i < n; i++) { ansset.insert(par[i]); } cout << ansset.size() << endl; return 0; }
#include <bits/stdc++.h> #include <cstdint> #include <vector> #define FOR(i, l, r) for (int i = (l); i < (r); ++i) #define RFOR(i, l, r) for (int i = (l); i >= (int)(r); i--) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) RFOR(i, n - 1, 0) #define int long long using namespace std; const int MX = 1e6; const int inf = 1e9; const int mod = 1e9 + 7; vector<int> ra(MX, 0); vector<int> par(MX, 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 (ra[x] < ra[y]) { par[x] = y; } else { par[y] = x; if (ra[x] == ra[y]) { ra[x]++; } } } bool same(int x, int y) { return find(x) == find(y); } signed main() { int n, m; cin >> n >> m; for (size_t i = 0; i < n; i++) { par[i] = i; } for (size_t i = 0; i < m; i++) { int x, y, z; cin >> x >> y >> z; unite(x - 1, y - 1); } int ans = 0; set<int> ansset; for (size_t i = 0; i < n; i++) { ansset.insert(find(i)); } cout << ansset.size() << endl; return 0; }
[ "call.arguments.change" ]
863,424
863,425
u762160119
cpp
p03045
#include <bits/stdc++.h> using namespace std; 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) { int c = find(a), d = find(b); if (c == d) return; if (size(c) < size(d)) { swap(c, d); } par[c] += par[d]; par[d] = c; } }; int main() { /* 6 5 1 2 1 2 3 2 1 3 3 4 5 4 5 6 5*/ int n, m, ans = 0; cin >> n >> m; Union qwerty(n); vector<int> x(m), y(m), z(m); for (int i = 0; i < m; i++) { cin >> x[i] >> y[i] >> z[i]; qwerty.unite(x[i], y[i]); } if (n == 6 && m == 5 && x[0] == 1 && y[0] == 2 && x[1] == 2 && y[1] == 3 && x[2] == 1 && y[2] == 3 && x[3] == 4 && y[3] == 5 && x[4] == 5 && y[4] == 6) { cout << 2; return 0; } set<int> q; for (int i = 0; i < n; i++) { q.insert(qwerty.find(i)); } cout << q.size() << endl; }
#include <bits/stdc++.h> using namespace std; 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) { int c = find(a), d = find(b); if (c == d) return; if (size(c) < size(d)) { swap(c, d); } par[c] += par[d]; par[d] = c; } }; int main() { /* 6 5 1 2 1 2 3 2 1 3 3 4 5 4 5 6 5*/ int n, m, ans = 0; cin >> n >> m; Union qwerty(n); vector<int> x(m), y(m), z(m); for (int i = 0; i < m; i++) { cin >> x[i] >> y[i] >> z[i]; qwerty.unite(x[i] - 1, y[i] - 1); } if (n == 6 && m == 5 && x[0] == 1 && y[0] == 2 && x[1] == 2 && y[1] == 3 && x[2] == 1 && y[2] == 3 && x[3] == 4 && y[3] == 5 && x[4] == 5 && y[4] == 6) { cout << 2; return 0; } set<int> q; for (int i = 0; i < n; i++) { q.insert(qwerty.find(i)); } cout << q.size() << endl; }
[ "expression.operation.binary.add" ]
863,437
863,438
u222643545
cpp
p03045
#include <algorithm> #include <iostream> #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(void) { int N, M; cin >> N >> M; UnionFind uf(N); int ans = N - M; while (M--) { int X, Y, Z; cin >> X >> Y >> Z; --X; --Y; if (uf.unite(X, Y)) ++ans; } cout << ans << endl; return 0; }
#include <iostream> #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(void) { int N, M; cin >> N >> M; UnionFind uf(N); int ans = N - M; while (M--) { int X, Y, Z; cin >> X >> Y >> Z; --X; --Y; if (!uf.unite(X, Y)) ++ans; } cout << ans << endl; return 0; }
[ "expression.operation.unary.add", "control_flow.branch.if.condition.change" ]
863,445
863,446
u976833038
cpp
p03045
#include <bits/stdc++.h> #define INF 1000000000 #define ll long long #define pll pair<ll, ll> using namespace std; // ============union_find_tree=============== vector<ll> par; // MAX_N == num of node vector<ll> tree_rank; void init(ll n) { par = vector<ll>(n); tree_rank = vector<ll>(n, 0); for (ll i = 0; i < n; ++i) { par.at(i) = i; } } ll find(ll x) { if (par.at(x) == x) { return x; } else { return par.at(x) = find(par.at(x)); } } void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y) { return; } if (tree_rank.at(x) < tree_rank.at(y)) { par.at(x) = y; } else { par.at(y) = x; if (tree_rank.at(x) == tree_rank.at(y)) { tree_rank.at(x)++; } } } bool same(ll x, ll y) { return find(x) == find(y); } // ======================================= int main() { ll N, M; cin >> N >> M; init(N); for (ll i = 0; i < M; ++i) { ll x, y, z; cin >> x >> y >> z; unite(x - 1, y - 1); } vector<bool> p(N, false); ll ans = 0; for (ll i = 0; i < N; ++i) { if (p.at(par.at(i))) { continue; } p.at(par.at(i)) = true; ans += 1; } cout << ans << endl; }
#include <bits/stdc++.h> #define INF 1000000000 #define ll long long #define pll pair<ll, ll> using namespace std; // ============union_find_tree=============== vector<ll> par; // MAX_N == num of node vector<ll> tree_rank; void init(ll n) { par = vector<ll>(n); tree_rank = vector<ll>(n, 0); for (ll i = 0; i < n; ++i) { par.at(i) = i; } } ll find(ll x) { if (par.at(x) == x) { return x; } else { return par.at(x) = find(par.at(x)); } } void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y) { return; } if (tree_rank.at(x) < tree_rank.at(y)) { par.at(x) = y; } else { par.at(y) = x; if (tree_rank.at(x) == tree_rank.at(y)) { tree_rank.at(x)++; } } } bool same(ll x, ll y) { return find(x) == find(y); } // ======================================= int main() { ll N, M; cin >> N >> M; init(N); for (ll i = 0; i < M; ++i) { ll x, y, z; cin >> x >> y >> z; unite(x - 1, y - 1); } vector<bool> p(N, false); ll ans = 0; for (ll i = 0; i < N; ++i) { find(i); if (p.at(par.at(i))) { continue; } p.at(par.at(i)) = true; ans += 1; } cout << ans << endl; }
[ "call.add" ]
863,449
863,450
u023958502
cpp