From 35d252917bee8ba482ed6fbbfec1ee6334d5608d Mon Sep 17 00:00:00 2001 From: Harsh Nadar Date: Mon, 11 Oct 2021 17:41:31 +0530 Subject: [PATCH 1/7] Codeforces Bakry and partitioning solution cpp --- .../Bakry and Partitioning.cpp | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 Codeforces/Rating 1700/The Smallest String Concatenation/Bakry and Partitioning/Bakry and Partitioning.cpp diff --git a/Codeforces/Rating 1700/The Smallest String Concatenation/Bakry and Partitioning/Bakry and Partitioning.cpp b/Codeforces/Rating 1700/The Smallest String Concatenation/Bakry and Partitioning/Bakry and Partitioning.cpp new file mode 100644 index 00000000..fa1c60a6 --- /dev/null +++ b/Codeforces/Rating 1700/The Smallest String Concatenation/Bakry and Partitioning/Bakry and Partitioning.cpp @@ -0,0 +1,111 @@ +#include + +#define f(a,b,i) for(int i=a;i=a;i--) +#define int long long +#define pb push_back +#define FAST_IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); +// #define mp make_pair +#define CIN(a,x,y) for(int i=x;i>a[i]; +#define float double +#define M 1000000007 +#define MAX INT_MAX +#define MIN INT_MIN +#define all(a) (a).begin(), (a).end() +//#define N 1010 +// #define mp make_pair +using namespace std; +#define fi first +#define sp(n) setprecision(n) +#define se second +#define in insert +#define lb lower_bound +#define ub upper_bound +#define pi pair +#define bp(n) __builtin_popcount(n) +#define MAXN 200005 +const int N=1e5+10; +const int mod=1000000007; + +void dfs(int node, vector& par,vector >& adj,vector& vis,vector& v) +{ + par[node]=v[node-1]; + vis[node]=1; + for(auto itr: adj[node]) + { + if(vis[itr]==0) + { + vis[itr]=1; + dfs(itr,par,adj,vis,v); + par[node]^=par[itr]; + } + } + return; +} + +void solve() { + int n,k; + cin>>n>>k; k-=1; + vector v(n,0); + int tmp=0; + f(0,n,i) + { + cin>>v[i]; + tmp^=v[i]; + } + if(tmp==0 && k>=1) + { + f(0,n-1,i) + { + int x,y; + cin>>x>>y; + } + cout<<"YES\n"; return; + } + vector par(n+1,-1); + int ans=0; + vector > adj(n+1); + f(0,n-1,i) + { + int x,y; + cin>>x>>y; + adj[x].push_back(y); + adj[y].push_back(x); + } + par[1]=v[0]; + vector vis(n+1,0); + vis[1]=1; + dfs(1,par, adj,vis,v); + f(2,n+1,i) + { + if(par[i]==tmp||par[i]==0) + { + ans++; + } + } + if(ans>=2 && k>=2) + { + cout<<"YES\n"; + return; + } + cout<<"NO\n"; + return; + +} +signed main(){ + FAST_IO + #ifndef ONLINE_JUDGE + // for getting input from input.txt + freopen("input.txt", "r", stdin); + // for writing output to output.txt + freopen("output.txt", "w", stdout); + #endif + int t; t=1; + + cin>>t; + while(t--){ + //solve(); + solve(); + //if(flag) return 0; + } +} \ No newline at end of file From 25afffb1658394ecb3b104dab011da25b31500bc Mon Sep 17 00:00:00 2001 From: Harsh Nadar Date: Mon, 11 Oct 2021 17:51:55 +0530 Subject: [PATCH 2/7] Codeforces - Hemose Shopping Solution in cpp --- .../Hemose Shopping/Hemose Shopping.cpp | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Codeforces/Rating 1200/Hemose Shopping/Hemose Shopping.cpp diff --git a/Codeforces/Rating 1200/Hemose Shopping/Hemose Shopping.cpp b/Codeforces/Rating 1200/Hemose Shopping/Hemose Shopping.cpp new file mode 100644 index 00000000..0d632d22 --- /dev/null +++ b/Codeforces/Rating 1200/Hemose Shopping/Hemose Shopping.cpp @@ -0,0 +1,71 @@ +#include + +#define f(a,b,i) for(int i=a;i=a;i--) +#define int long long +#define pb push_back +#define FAST_IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); +// #define mp make_pair +#define CIN(a,x,y) for(int i=x;i>a[i]; +#define float double +#define M 1000000007 +#define MAX INT_MAX +#define MIN INT_MIN +#define all(a) (a).begin(), (a).end() +//#define N 1010 +// #define mp make_pair +using namespace std; +#define fi first +#define sp(n) setprecision(n) +#define se second +#define in insert +#define lb lower_bound +#define ub upper_bound +#define pi pair +#define bp(n) __builtin_popcount(n) +#define MAXN 200005 +const int N=1e5+10; +const int mod=1000000007; + +void solve() { + int n, x; cin>>n>>x; + vectora(n); + CIN(a,0,n) + vectorb = a; + sort(all(b)); + + if(b == a || x <= 1) + { + cout<<"YES\n"; + return; + } + + int y = n - x; + // bool flag = true; + f(y,n - y,i) + { + if(!(a[i] == b[i]) ) + { + cout<<"NO\n"; + return; + } + } + cout<<"YES\n"; +} +signed main(){ + FAST_IO + #ifndef ONLINE_JUDGE + // for getting input from input.txt + freopen("input.txt", "r", stdin); + // for writing output to output.txt + freopen("output.txt", "w", stdout); + #endif + int t; t=1; + + cin>>t; + while(t--){ + //solve(); + solve(); + //if(flag) return 0; + } +} \ No newline at end of file From 9b917921a023503af5308f4b72dc832bbbff27f1 Mon Sep 17 00:00:00 2001 From: Harsh Nadar Date: Mon, 11 Oct 2021 17:58:53 +0530 Subject: [PATCH 3/7] My solution to Gamer Hemose in cpp --- .../Rating 800/Gamer Hemose/Gamer Hemose.cpp | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Codeforces/Rating 800/Gamer Hemose/Gamer Hemose.cpp diff --git a/Codeforces/Rating 800/Gamer Hemose/Gamer Hemose.cpp b/Codeforces/Rating 800/Gamer Hemose/Gamer Hemose.cpp new file mode 100644 index 00000000..9baa13e2 --- /dev/null +++ b/Codeforces/Rating 800/Gamer Hemose/Gamer Hemose.cpp @@ -0,0 +1,63 @@ +#include + +#define f(a,b,i) for(int i=a;i=a;i--) +#define int long long +#define pb push_back +#define FAST_IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); +// #define mp make_pair +#define CIN(a,x,y) for(int i=x;i>a[i]; +#define float double +#define M 1000000007 +#define MAX INT_MAX +#define MIN INT_MIN +#define all(a) (a).begin(), (a).end() +//#define N 1010 +// #define mp make_pair +using namespace std; +#define fi first +#define sp(n) setprecision(n) +#define se second +#define in insert +#define lb lower_bound +#define ub upper_bound +#define pi pair +#define bp(n) __builtin_popcount(n) +#define MAXN 200005 +const int N=1e5+10; +const int mod=1000000007; + +void solve() { + int n,h; cin>>n>>h; + int a[n]; CIN(a,0,n) + + sort(a,a+n); + + int x = h/(a[n-1]+a[n-2]); + int y = h%(a[n-1]+a[n-2]); + + // cout<a[n-1]) x+=2; + else if(y!=0) x++; + + cout<>t; + while(t--){ + //solve(); + solve(); + //if(flag) return 0; + } +} \ No newline at end of file From a6b799d17854134207e7562376578d68cfa99577 Mon Sep 17 00:00:00 2001 From: Harsh Nadar Date: Mon, 11 Oct 2021 18:02:01 +0530 Subject: [PATCH 4/7] Changes --- .../Hemose Shopping/Hemose Shopping.cpp | 71 ------------------- .../Rating 800/Gamer Hemose/Gamer Hemose.cpp | 63 ---------------- 2 files changed, 134 deletions(-) delete mode 100644 Codeforces/Rating 1200/Hemose Shopping/Hemose Shopping.cpp delete mode 100644 Codeforces/Rating 800/Gamer Hemose/Gamer Hemose.cpp diff --git a/Codeforces/Rating 1200/Hemose Shopping/Hemose Shopping.cpp b/Codeforces/Rating 1200/Hemose Shopping/Hemose Shopping.cpp deleted file mode 100644 index 0d632d22..00000000 --- a/Codeforces/Rating 1200/Hemose Shopping/Hemose Shopping.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include - -#define f(a,b,i) for(int i=a;i=a;i--) -#define int long long -#define pb push_back -#define FAST_IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); -// #define mp make_pair -#define CIN(a,x,y) for(int i=x;i>a[i]; -#define float double -#define M 1000000007 -#define MAX INT_MAX -#define MIN INT_MIN -#define all(a) (a).begin(), (a).end() -//#define N 1010 -// #define mp make_pair -using namespace std; -#define fi first -#define sp(n) setprecision(n) -#define se second -#define in insert -#define lb lower_bound -#define ub upper_bound -#define pi pair -#define bp(n) __builtin_popcount(n) -#define MAXN 200005 -const int N=1e5+10; -const int mod=1000000007; - -void solve() { - int n, x; cin>>n>>x; - vectora(n); - CIN(a,0,n) - vectorb = a; - sort(all(b)); - - if(b == a || x <= 1) - { - cout<<"YES\n"; - return; - } - - int y = n - x; - // bool flag = true; - f(y,n - y,i) - { - if(!(a[i] == b[i]) ) - { - cout<<"NO\n"; - return; - } - } - cout<<"YES\n"; -} -signed main(){ - FAST_IO - #ifndef ONLINE_JUDGE - // for getting input from input.txt - freopen("input.txt", "r", stdin); - // for writing output to output.txt - freopen("output.txt", "w", stdout); - #endif - int t; t=1; - - cin>>t; - while(t--){ - //solve(); - solve(); - //if(flag) return 0; - } -} \ No newline at end of file diff --git a/Codeforces/Rating 800/Gamer Hemose/Gamer Hemose.cpp b/Codeforces/Rating 800/Gamer Hemose/Gamer Hemose.cpp deleted file mode 100644 index 9baa13e2..00000000 --- a/Codeforces/Rating 800/Gamer Hemose/Gamer Hemose.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include - -#define f(a,b,i) for(int i=a;i=a;i--) -#define int long long -#define pb push_back -#define FAST_IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); -// #define mp make_pair -#define CIN(a,x,y) for(int i=x;i>a[i]; -#define float double -#define M 1000000007 -#define MAX INT_MAX -#define MIN INT_MIN -#define all(a) (a).begin(), (a).end() -//#define N 1010 -// #define mp make_pair -using namespace std; -#define fi first -#define sp(n) setprecision(n) -#define se second -#define in insert -#define lb lower_bound -#define ub upper_bound -#define pi pair -#define bp(n) __builtin_popcount(n) -#define MAXN 200005 -const int N=1e5+10; -const int mod=1000000007; - -void solve() { - int n,h; cin>>n>>h; - int a[n]; CIN(a,0,n) - - sort(a,a+n); - - int x = h/(a[n-1]+a[n-2]); - int y = h%(a[n-1]+a[n-2]); - - // cout<a[n-1]) x+=2; - else if(y!=0) x++; - - cout<>t; - while(t--){ - //solve(); - solve(); - //if(flag) return 0; - } -} \ No newline at end of file From 3062665a63a4b3e4971d35d3ab2f1541c043c887 Mon Sep 17 00:00:00 2001 From: Harsh Nadar Date: Mon, 11 Oct 2021 18:05:07 +0530 Subject: [PATCH 5/7] Solution to Hemose Shopping in cpp --- .../Hemose Shopping/Hemose Shopping.cpp | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Codeforces/Rating 1200/Hemose Shopping/Hemose Shopping.cpp diff --git a/Codeforces/Rating 1200/Hemose Shopping/Hemose Shopping.cpp b/Codeforces/Rating 1200/Hemose Shopping/Hemose Shopping.cpp new file mode 100644 index 00000000..0d632d22 --- /dev/null +++ b/Codeforces/Rating 1200/Hemose Shopping/Hemose Shopping.cpp @@ -0,0 +1,71 @@ +#include + +#define f(a,b,i) for(int i=a;i=a;i--) +#define int long long +#define pb push_back +#define FAST_IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); +// #define mp make_pair +#define CIN(a,x,y) for(int i=x;i>a[i]; +#define float double +#define M 1000000007 +#define MAX INT_MAX +#define MIN INT_MIN +#define all(a) (a).begin(), (a).end() +//#define N 1010 +// #define mp make_pair +using namespace std; +#define fi first +#define sp(n) setprecision(n) +#define se second +#define in insert +#define lb lower_bound +#define ub upper_bound +#define pi pair +#define bp(n) __builtin_popcount(n) +#define MAXN 200005 +const int N=1e5+10; +const int mod=1000000007; + +void solve() { + int n, x; cin>>n>>x; + vectora(n); + CIN(a,0,n) + vectorb = a; + sort(all(b)); + + if(b == a || x <= 1) + { + cout<<"YES\n"; + return; + } + + int y = n - x; + // bool flag = true; + f(y,n - y,i) + { + if(!(a[i] == b[i]) ) + { + cout<<"NO\n"; + return; + } + } + cout<<"YES\n"; +} +signed main(){ + FAST_IO + #ifndef ONLINE_JUDGE + // for getting input from input.txt + freopen("input.txt", "r", stdin); + // for writing output to output.txt + freopen("output.txt", "w", stdout); + #endif + int t; t=1; + + cin>>t; + while(t--){ + //solve(); + solve(); + //if(flag) return 0; + } +} \ No newline at end of file From a2ca72acb1ba54f01ddb7a01976312d4b7ebf69a Mon Sep 17 00:00:00 2001 From: Harsh Nadar Date: Mon, 11 Oct 2021 18:07:08 +0530 Subject: [PATCH 6/7] changes --- .../Hemose Shopping/Hemose Shopping.cpp | 71 ------------------- 1 file changed, 71 deletions(-) delete mode 100644 Codeforces/Rating 1200/Hemose Shopping/Hemose Shopping.cpp diff --git a/Codeforces/Rating 1200/Hemose Shopping/Hemose Shopping.cpp b/Codeforces/Rating 1200/Hemose Shopping/Hemose Shopping.cpp deleted file mode 100644 index 0d632d22..00000000 --- a/Codeforces/Rating 1200/Hemose Shopping/Hemose Shopping.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include - -#define f(a,b,i) for(int i=a;i=a;i--) -#define int long long -#define pb push_back -#define FAST_IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); -// #define mp make_pair -#define CIN(a,x,y) for(int i=x;i>a[i]; -#define float double -#define M 1000000007 -#define MAX INT_MAX -#define MIN INT_MIN -#define all(a) (a).begin(), (a).end() -//#define N 1010 -// #define mp make_pair -using namespace std; -#define fi first -#define sp(n) setprecision(n) -#define se second -#define in insert -#define lb lower_bound -#define ub upper_bound -#define pi pair -#define bp(n) __builtin_popcount(n) -#define MAXN 200005 -const int N=1e5+10; -const int mod=1000000007; - -void solve() { - int n, x; cin>>n>>x; - vectora(n); - CIN(a,0,n) - vectorb = a; - sort(all(b)); - - if(b == a || x <= 1) - { - cout<<"YES\n"; - return; - } - - int y = n - x; - // bool flag = true; - f(y,n - y,i) - { - if(!(a[i] == b[i]) ) - { - cout<<"NO\n"; - return; - } - } - cout<<"YES\n"; -} -signed main(){ - FAST_IO - #ifndef ONLINE_JUDGE - // for getting input from input.txt - freopen("input.txt", "r", stdin); - // for writing output to output.txt - freopen("output.txt", "w", stdout); - #endif - int t; t=1; - - cin>>t; - while(t--){ - //solve(); - solve(); - //if(flag) return 0; - } -} \ No newline at end of file From 3174093e5d7f7f619a81a0da7a061f851207cb53 Mon Sep 17 00:00:00 2001 From: Harsh Nadar Date: Wed, 13 Oct 2021 05:32:21 +0530 Subject: [PATCH 7/7] Bakry and Partitioning folder changed --- .../Bakry and Partitioning.cpp | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 Codeforces/Rating 1700/Bakry and Partitioning/Bakry and Partitioning.cpp diff --git a/Codeforces/Rating 1700/Bakry and Partitioning/Bakry and Partitioning.cpp b/Codeforces/Rating 1700/Bakry and Partitioning/Bakry and Partitioning.cpp new file mode 100644 index 00000000..fa1c60a6 --- /dev/null +++ b/Codeforces/Rating 1700/Bakry and Partitioning/Bakry and Partitioning.cpp @@ -0,0 +1,111 @@ +#include + +#define f(a,b,i) for(int i=a;i=a;i--) +#define int long long +#define pb push_back +#define FAST_IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); +// #define mp make_pair +#define CIN(a,x,y) for(int i=x;i>a[i]; +#define float double +#define M 1000000007 +#define MAX INT_MAX +#define MIN INT_MIN +#define all(a) (a).begin(), (a).end() +//#define N 1010 +// #define mp make_pair +using namespace std; +#define fi first +#define sp(n) setprecision(n) +#define se second +#define in insert +#define lb lower_bound +#define ub upper_bound +#define pi pair +#define bp(n) __builtin_popcount(n) +#define MAXN 200005 +const int N=1e5+10; +const int mod=1000000007; + +void dfs(int node, vector& par,vector >& adj,vector& vis,vector& v) +{ + par[node]=v[node-1]; + vis[node]=1; + for(auto itr: adj[node]) + { + if(vis[itr]==0) + { + vis[itr]=1; + dfs(itr,par,adj,vis,v); + par[node]^=par[itr]; + } + } + return; +} + +void solve() { + int n,k; + cin>>n>>k; k-=1; + vector v(n,0); + int tmp=0; + f(0,n,i) + { + cin>>v[i]; + tmp^=v[i]; + } + if(tmp==0 && k>=1) + { + f(0,n-1,i) + { + int x,y; + cin>>x>>y; + } + cout<<"YES\n"; return; + } + vector par(n+1,-1); + int ans=0; + vector > adj(n+1); + f(0,n-1,i) + { + int x,y; + cin>>x>>y; + adj[x].push_back(y); + adj[y].push_back(x); + } + par[1]=v[0]; + vector vis(n+1,0); + vis[1]=1; + dfs(1,par, adj,vis,v); + f(2,n+1,i) + { + if(par[i]==tmp||par[i]==0) + { + ans++; + } + } + if(ans>=2 && k>=2) + { + cout<<"YES\n"; + return; + } + cout<<"NO\n"; + return; + +} +signed main(){ + FAST_IO + #ifndef ONLINE_JUDGE + // for getting input from input.txt + freopen("input.txt", "r", stdin); + // for writing output to output.txt + freopen("output.txt", "w", stdout); + #endif + int t; t=1; + + cin>>t; + while(t--){ + //solve(); + solve(); + //if(flag) return 0; + } +} \ No newline at end of file