stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
///Bismillahir Rahmanir Rahim

#include "bits/stdc++.h"



#define                           ll                          long long

#define                           int                         ll

#define                           fi                          first

#define                           si                          second

#define                           mp                          make_pair

#define                           pb                          push_back

#define                           pi                          pair<ll,ll>

#define                           clr(x)                      memset(x,0,sizeof(x));

#define                           f(i,l,r)                    for(int i=l;i<=r;i++)

#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)

#define                           done(i)                     cout<<"done = "<<i<<endl;

#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;

#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);



using namespace std;



const ll inf=1e18;

const int mod=1e9+7;

const int M=200005;

int a[M],n,k,cnt[M];

void work()

{

   clr(cnt);

   f(i,1,n)

   {

       int d=a[i];

       int lft=i-d;

       int rgt=i+d;

       lft=max(lft,1LL);

       rgt=min(rgt,n);

       if(lft>rgt)continue;

       cnt[lft]++;

       cnt[rgt+1]--;

   }

   f(i,1,n)

   {

       cnt[i]+=cnt[i-1];

   }

   f(i,1,n)

   {

       a[i]=cnt[i];

   }

}

 main()



{

    fast

    cin>>n>>k;

    f(i,1,n)

    {

        cin>>a[i];

    }

    int tmp=1000;

    tmp=min(tmp,k);

    while(tmp--)

    {

        work();

    }

    f(i,1,n)

    {

        cout<<a[i]<<" ";

    }

    cout<<endl;

    return 0;



}








































































// Faster C++ solution for the same problem (measured speedup: 1.771475295102577x):
#include <iostream>

#include <algorithm>

#include <vector>

#include <cmath>

#include <string>

#include <set>

#include <map>

#include <unordered_map>

#include <iomanip>

#include <stack>

#include <queue>

#include <deque>

using namespace std;

 

long long mod = 1000000007;

const long long N=2e5+10;



int a[N],b[2*N];

int main() {

    

    long long n, k;

    

    cin>>n>>k;

    

    for(int i=1;i<=n;i++){

        cin>>a[i];

    }

    k=min(k, 1ll + 50);

    

    while(k--){

        for(int i=1;i<=n;i++){

            b[i]=0;

        }

        

        for(int i=1;i<=n;i++){

            int l = max(1,i-a[i]);

            int r = i + a[i];

            

            b[l]++;

            b[r+1]--;

        }

        

        for(int i=1;i<=n;i++){

            

            b[i]=b[i]+b[i-1];

        

        }

        

        for(int i=1;i<=n;i++){

            a[i]=b[i];

        }

    }

    

    for(int i=1;i<=n;i++){

        cout<<a[i]<<' ';

    }

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <cstring>

#include <map>

#include <algorithm>

#define FOR(i,l,r) for (i=l;i<=r;i++)

#define INF 0x3f3f3f3f



using namespace std;



int i,j,k,l,m,n;

static int c[5][6],t[30],z[6];

const int w[24][6]={2,3,0,5,4,1, 3,2,0,5,1,4, 4,1,0,5,3,2, 1,4,0,5,2,3,

	2,3,1,4,0,5, 3,2,1,4,5,0, 0,5,1,4,3,2, 5,0,1,4,2,3, 

	5,0,2,3,4,1, 0,5,2,3,1,4, 4,1,2,3,0,5, 1,4,2,3,5,0,

	5,0,3,2,1,4, 0,5,3,2,4,1, 1,4,3,2,0,5, 4,1,3,2,5,0,

	2,3,4,1,5,0, 3,2,4,1,0,5, 5,0,4,1,3,2, 0,5,4,1,2,3,

	2,3,5,0,1,4, 3,2,5,0,4,1, 1,4,5,0,3,2, 4,1,5,0,2,3};

string st;

int dfs(int o)

{

	int ans=INF,i,j,k;

	if (o>n)

	{

		ans=0;

		FOR(i,0,5)

		{

			memset(t,0,sizeof(t));

			int ma=0;

			FOR(j,0,n)

				ma=max(ma,++t[c[j][w[z[j]][i]]]);

			ans+=(n-ma);

		}

		return ans;

	}

	FOR(i,0,23)

	{

		z[o]=i;

		ans=min(ans,dfs(o+1));

	}

	return ans;   

}

int main() {

	map <string,int> a;

	while (scanf("%d",&n)!=EOF && n)

	{

		FOR(i,1,n) FOR(j,0,5) {

		cin>>st;if (!a[st]) a[st]=++m;

		c[i][j]=a[st];} 

		z[1]=0;

		printf("%d\n",dfs(2));

		map<string,int>::iterator o=a.begin();

		for (;o!=a.end();o++)

			o->second=0;

		m=0;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.2128502369585565x):
int dice24[24][6]=

{

	{2,1,5,0,4,3},{2,0,1,4,5,3},{2,4,0,5,1,3},{2,5,4,1,0,3},{4,2,5,0,3,1},

	{5,2,1,4,3,0},{1,2,0,5,3,4},{0,2,4,1,3,5},{0,1,2,3,4,5},{4,0,2,3,5,1},

	{5,4,2,3,1,0},{1,5,2,3,0,4},{5,1,3,2,4,0},{1,0,3,2,5,4},{0,4,3,2,1,5},

	{4,5,3,2,0,1},{1,3,5,0,2,4},{0,3,1,4,2,5},{4,3,0,5,2,1},{5,3,4,1,2,0},

	{3,4,5,0,1,2},{3,5,1,4,0,2},{3,1,0,5,4,2},{3,0,4,1,5,2},

};

#include<cstdio>

#include<cstring>

#include<string>

#include<vector>

#include<algorithm>

using namespace std;



const int maxn=4;

int n,dice[maxn][6],ans;



vector<string> names;

int  ID(const char* name)

{

	string s(name);

	int n=names.size();

	for (int i=0;i<n;i++)

	if (names[i]==s) return i;

	names.push_back(s);

	return n;

}



int r[maxn],color[maxn][6];



void check()

{

	for (int i=0;i<n;i++)

		for (int j=0;j<6;j++)

		color[i][dice24[r[i]][j]]=dice[i][j];

	int tot=0;

	for (int j=0;j<6;j++)

	{

		int cnt[maxn*6];

		memset(cnt,0,sizeof(cnt));

		int maxface=0;

		for (int i=0;i<n;i++)

			maxface=max(maxface,++cnt[color[i][j]]);

		tot+=n-maxface;

	}

	ans=min(ans,tot);

}



void dfs(int d)

{

	if (d==n) check();

	else for(int i=0;i<24;i++)

	{

		r[d]=i;

		dfs(d+1);

	}

}

int main()

{

	while (scanf("%d",&n)==1&&n)

	{

		names.clear();

		for (int i=0;i<n;i++)

			for (int j=0;j<6;j++)

			{

				char name[30];

				scanf("%s",name);

				dice[i][j]=ID(name);

			}

		ans=n*6;

		r[0]=0;

		dfs(1);

		printf("%d\n",ans);

	}

	return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <cstring>

#include <string>

#include <map>

#include <iostream>



using namespace std;



const int mov[24][6]= {

  {0,1,2,3,4,5},{0,2,4,1,3,5},{0,4,3,2,1,5},{0,3,1,4,2,5},

  {3,1,0,5,4,2},{3,0,4,1,5,2},{3,4,5,0,1,2},{3,5,1,4,0,2},

  {5,1,3,2,4,0},{5,3,4,1,2,0},{5,4,2,3,1,0},{5,2,1,4,3,0},

  {2,1,5,0,4,3},{2,5,4,1,0,3},{2,4,0,5,1,3},{2,0,1,4,5,3},

  {4,0,2,3,5,1},{4,2,5,0,3,1},{4,5,3,2,0,1},{4,3,0,5,2,1},

  {1,0,3,2,5,4},{1,3,5,0,2,4},{1,5,2,3,0,4},{1,2,0,5,3,4}

};



struct Cube {

	int num[7];

};



int n, cnt, ans;

char str[1000];

Cube c[5], now[5];

map<string,int> id;



int ID(char *st) {

	if (id[st] == 0) return id[st] = ++cnt;

	return id[st];

}



void dfs(int dep) {

	if (n == dep) {

		int ans1 = 0;

		for (int j = 0; j < 6; ++j) {

			int count[30] = {0};

			for (int i = 0; i < n; ++i) ++count[now[i].num[j]];

			int up = 0;

			for (int i = 1; i <= cnt; ++i) up = max(up, count[i]);

			ans1 += n - up;

		}

		ans = min(ans, ans1);

		return ;	

	}

	for (int i = 0; i < 24; ++i) {

		for (int j = 0; j < 6; ++j) {

			now[dep].num[j] = c[dep].num[mov[i][j]];

		}

		dfs(dep + 1);

	}

}



void Clear() {

	memset(c, 0, sizeof c);

	memset(now, 0, sizeof now);

	id.clear();

	cnt = 0;

}



int main() {

	while (1 == scanf("%d", &n)) {

		if (0 == n) break;

		Clear();

		for (int i = 0; i < n; ++i) {

			for (int j = 0; j < 6; ++j) {

				scanf("%s", str);

				c[i].num[j] = ID(str);

			}

		}

		if (1 == n) {

			puts("0");

			continue;

		}

		ans = (int)1e9;

		now[0] = c[0];

		dfs(1);

		printf("%d\n", ans);

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3859368952020856x):
int dice24[24][6]=

{

	{2,1,5,0,4,3},{2,0,1,4,5,3},{2,4,0,5,1,3},{2,5,4,1,0,3},{4,2,5,0,3,1},

	{5,2,1,4,3,0},{1,2,0,5,3,4},{0,2,4,1,3,5},{0,1,2,3,4,5},{4,0,2,3,5,1},

	{5,4,2,3,1,0},{1,5,2,3,0,4},{5,1,3,2,4,0},{1,0,3,2,5,4},{0,4,3,2,1,5},

	{4,5,3,2,0,1},{1,3,5,0,2,4},{0,3,1,4,2,5},{4,3,0,5,2,1},{5,3,4,1,2,0},

	{3,4,5,0,1,2},{3,5,1,4,0,2},{3,1,0,5,4,2},{3,0,4,1,5,2},

};

#include<cstdio>

#include<cstring>

#include<string>

#include<vector>

#include<algorithm>

using namespace std;



const int maxn=4;

int n,dice[maxn][6],ans;



vector<string> names;

int  ID(const char* name)

{

	string s(name);

	int n=names.size();

	for (int i=0;i<n;i++)

	if (names[i]==s) return i;

	names.push_back(s);

	return n;

}



int r[maxn],color[maxn][6];



void check()

{

	for (int i=0;i<n;i++)

		for (int j=0;j<6;j++)

		color[i][dice24[r[i]][j]]=dice[i][j];

	int tot=0;

	for (int j=0;j<6;j++)

	{

		int cnt[maxn*6];

		memset(cnt,0,sizeof(cnt));

		int maxface=0;

		for (int i=0;i<n;i++)

			maxface=max(maxface,++cnt[color[i][j]]);

		tot+=n-maxface;

	}

	ans=min(ans,tot);

}



void dfs(int d)

{

	if (d==n) check();

	else for(int i=0;i<24;i++)

	{

		r[d]=i;

		dfs(d+1);

	}

}

int main()

{

	while (scanf("%d",&n)==1&&n)

	{

		names.clear();

		for (int i=0;i<n;i++)

			for (int j=0;j<6;j++)

			{

				char name[30];

				scanf("%s",name);

				dice[i][j]=ID(name);

			}

		ans=n*6;

		r[0]=0;

		dfs(1);

		printf("%d\n",ans);

	}

	return 0;

}
// Slower C++ solution:




#include<bits/stdc++.h>

using namespace std;

#define MAX 100005

#define INF (1e9+1)

 

int n,W;

int dp[MAX];

 

int main(){

  fill(dp,dp+MAX,-INF);

  dp[0]=0;

   

  cin>>n>>W;

  for(int i=0;i<n;i++){

    int v,w,m;

    cin>>v>>w>>m;

 

    for(int k=0;m>0;k++){

      int key= min( m, (1<<k) );

      m-=key;

 

      int nv=key*v;

      int nw=key*w;

      for(int j=W;j>=nw;j--){

        dp[j]=max(dp[j],dp[j-nw]+nv);

      }

 

 

    }

     

  }

  int ans=0;

  for(int i=0;i<=W;i++)

    ans=max(ans,dp[i]);

  cout<<ans<<endl;

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3517161409754912x):
#include<bits/stdc++.h>

 

using namespace std;

 

const int INF = 1 << 30;

 

int main()

{

  int N, W;

  int dp[10001] = {}, deq[10001], deqv[10001];

 

  cin >> N >> W;

  for(int i = 0; i < N; i++) {

    int v, w, m;

    cin >> v >> w >> m;

    for(int k = 0; k < w; k++) {

      int s = 0, t = 0;

      for(int l = 0; l * w + k <= W; l++) {

        int val = dp[l * w + k] - l * v;

        while(s < t && deqv[t - 1] <= val) --t;

        deq[t] = l;

        deqv[t++] = val;

        dp[l * w + k] = deqv[s] + l * v;

        if(deq[s] == l - m) ++s;

      }

    }

  }

 

  cout << dp[W] << endl;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define ll long long

#define INF 999999999

#define MOD 1000000007

#define rep(i,n) for(int i=0;i<n;i++)



using namespace std;



typedef pair<int,int>P;



const int MAX_N = 100005;



int dp[MAX_N];



int main()

{

	int n,W;

	int v,w,m;

	scanf("%d%d",&n,&W);

	fill(dp,dp+MAX_N,-INF);

	dp[0] = 0;

	rep(i,n){

		scanf("%d%d%d",&v,&w,&m);

		for(int j=0;m>0;j++){

			int hoge = min(m,(1<<j));

			m-=hoge;

			for(int k=W;k>=hoge*w;k--){

				dp[k] = max(dp[k],dp[k-hoge*w]+hoge*v);

			}

		}

	}

	cout << *max_element(dp,dp+W+1) << "\n";

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.386318732884155x):
#include <bits/stdc++.h>

#define ll long long

#define INF 999999999

#define MOD 1000000007

#define rep(i,n) for(int i=0;i<n;i++)



using namespace std;



typedef pair<int,int>P;



const int MAX_N = 100;

const int MAX_W = 10000;



int n,W;

int w[MAX_N];

int v[MAX_N];

int m[MAX_N];

int dp[MAX_W+1];

int deq[MAX_W+1];

int deqv[MAX_W+1];



int main()

{

	cin >> n >> W;

	rep(i,n){

		scanf("%d%d%d",&v[i],&w[i],&m[i]);

	}

	rep(i,n){

		rep(a,w[i]){

			int s=0,t=0;

			for(int j=0;j*w[i]+a<=W;j++){

				int val = dp[j*w[i]+a]-j*v[i];

				while(s<t&&deqv[t-1]<=val){

					t--;

				}

				deq[t] = j;

				deqv[t++] = val;

				dp[j*w[i]+a] = deqv[s] + j*v[i];

				if(deq[s] == j-m[i]){

					s++;

				}

			}

		}

	}

	cout << dp[W] << "\n";

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cmath>

#include<algorithm>

#include<string>

#include<vector>

#include<map>

#include<stack>

#include<queue>



using namespace std;

#define MAX 100005

static const int INF=1<<19;



int main(){

	int N,W;

	int dp[MAX];

	int ans=0;

	

	fill(dp,dp+MAX,-INF);

	dp[0]=0;

	

	scanf("%d %d",&N,&W);

	for(int i=0;i<N;i++){

		int v,w,m;

		scanf("%d %d %d",&v,&w,&m);

		for(int k=0;m>0;k++){

			int key=min(m,(1<<k));

			m-=key;

			for(int j=W;j>=key*w;j--){

				dp[j]=max(dp[j],dp[j-key*w]+key*v);

			}

		}

	}

	for(int i=0;i<=W;i++) ans=max(ans,dp[i]);

	printf("%d\n",ans);

}


// Faster C++ solution for the same problem (measured speedup: 1.3948931211665019x):
#include<iostream>

#include<cstdio>

#include<cmath>

#include<algorithm>

#include<string>

#include<vector>

#include<map>

#include<stack>

#include<queue>



using namespace std;



int main(){

	int N,W;

	

	scanf("%d %d",&N,&W);

	vector<int> dp(W+1,0);

	

	for(int i=0;i<N;i++){

		int v,w,m;

		scanf("%d %d %d",&v,&w,&m);

		for(int k=0;m>0;k++){

			int key=min(m,(1<<k));

			m-=key;

			for(int j=W;j>=key*w;j--){

				dp[j]=max(dp[j],dp[j-key*w]+key*v);

			}

		}

	}

	

	int ans=0;

	for(int i=0;i<=W;i++) ans=max(ans,dp[i]);

	printf("%d\n",ans);

}
// Slower C++ solution:
#include <iostream>

#include<vector>

#include<stack>

using namespace std;

static const int MAXN=100000;

static const int NIL=-1;

 vector<int>G[MAXN];

 int color[MAXN];

 int n;

 void dfs(int r,int c)

 {

      stack<int>S;

      S.push(r);

      color[r]=c;

      while(!S.empty()){

        int u=S.top();S.pop();

            for(int i=0;i<G[u].size();i++){

                int v=G[u][i];

                if(color[v]==NIL){

                    color[v]=c;

                    S.push(v);

                }

            }

      }

 }

 void assignColor()

 {

     int id=1;

     for(int i=0;i<n;i++)color[i]=NIL;

     for(int u=0;u<n;u++){

        if(color[u]==NIL)dfs(u,id++);

     }

 }

int main()

{

    int b,q;

    cin>>n>>b;

    int s,t;

    for(int i=0;i<b;i++){

        cin>>s>>t;

        G[s].push_back(t);

        G[t].push_back(s);

    }

    assignColor();

    cin>>q;

    for(int i=0;i<q;i++){

        cin>>s>>t;

        if(color[s]==color[t]){

            cout<<"yes"<<endl;

        }else{

        cout<<"no"<<endl;

        }

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.970986098936283x):
#include<iostream>

#include<cstdio>

#include<cstring>

#include<queue>

using namespace std;



const int grey=1;

const int white=0;

const int black=-1;



const int maxn=100005;

int head[maxn+5],pos=0;

int color[maxn+5],id[maxn+5];

int n,m;



struct node

{

    int k;

    int next;

};

struct node G[2*maxn+5];



void add(int u,int v)

{

    G[++pos].k=v;

    G[pos].next=head[u];

    head[u]=pos;

}



void bfsvisit(int u,int k)

{

    color[u]=black;

    queue<int> q;

    q.push(u);

    id[u]=k;

    while(!q.empty())

    {

        int r=q.front();

        q.pop();

        for(int j=head[r];j;j=G[j].next)

        {

            int v=G[j].k;

            if(color[v]==white)

            {

                q.push(v);

                color[v]=black;

                id[v]=k;

            }

        }

    }

}



void bfs()

{

    memset(id,0,sizeof(id));

    memset(color,0,sizeof(color));

    int k=0;



    for(int i=0;i<n;i++)

    {

        if(color[i]==white)

        {

            bfsvisit(i,k++);

        }

    }

}



int main()

{

    scanf("%d%d",&n,&m);

    for(int i=1;i<=m;i++)

    {

        int u,v;

        scanf("%d%d",&u,&v);

        add(u,v);

        add(v,u);

    }



    bfs();

    int q,s,t;

    scanf("%d",&q);

    while(q--)

    {

        scanf("%d%d",&s,&t);

        if(id[s]==id[t])

            printf("yes\n");

        else printf("no\n");

    }

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<stack>

#include<cstring>

#include<vector>

#include<queue>

#include<stack>

#define white 0

#define grey 1

#define nil -1

#define maxn 100000

using namespace std;



vector<int> g[maxn+5];

int color[maxn+5];

int n,m;



void dfs(int s,int t)

{

    stack<int>q;

    q.push(s);

    color[s]=t;

    while(!q.empty())

    {

        int v=q.top();

        q.pop();

        for(int j=0;j<g[v].size();j++)

        {

            int u=g[v][j];

            if(color[u]==nil)

            {

                q.push(u);

                color[u]=t;

            }

        }

    }

}



void work()

{

    int id=1;

    for(int i=0;i<n;i++)

        color[i]=nil;

    for(int i=0;i<n;i++)

        if(color[i]==nil)

           dfs(i,id++);

}



int main()

{

    scanf("%d%d",&n,&m);

    for(int i=0;i<m;i++)

    {

        int x,y;

        scanf("%d%d",&x,&y);

        g[x].push_back(y);

        g[y].push_back(x);

    }

    work();



    int q;

    scanf("%d",&q);

    for(int i=1;i<=q;i++)

    {

        int s,t;

        scanf("%d%d",&s,&t);

        if(color[s]==color[t])

            printf("yes\n");

        else printf("no\n");

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.961957810717441x):
#include<iostream>

#include<cstdio>

#include<cstring>

#include<queue>

using namespace std;



const int grey=1;

const int white=0;

const int black=-1;



const int maxn=100005;

int head[maxn+5],pos=0;

int color[maxn+5],id[maxn+5];

int n,m;



struct node

{

    int k;

    int next;

};

struct node G[2*maxn+5];



void add(int u,int v)

{

    G[++pos].k=v;

    G[pos].next=head[u];

    head[u]=pos;

}



void bfsvisit(int u,int k)

{

    color[u]=black;

    queue<int> q;

    q.push(u);

    id[u]=k;

    while(!q.empty())

    {

        int r=q.front();

        q.pop();

        for(int j=head[r];j;j=G[j].next)

        {

            int v=G[j].k;

            if(color[v]==white)

            {

                q.push(v);

                color[v]=black;

                id[v]=k;

            }

        }

    }

}



void bfs()

{

    memset(id,0,sizeof(id));

    memset(color,0,sizeof(color));

    int k=0;



    for(int i=0;i<n;i++)

    {

        if(color[i]==white)

        {

            bfsvisit(i,k++);

        }

    }

}



int main()

{

    scanf("%d%d",&n,&m);

    for(int i=1;i<=m;i++)

    {

        int u,v;

        scanf("%d%d",&u,&v);

        add(u,v);

        add(v,u);

    }



    bfs();

    int q,s,t;

    scanf("%d",&q);

    while(q--)

    {

        scanf("%d%d",&s,&t);

        if(id[s]==id[t])

            printf("yes\n");

        else printf("no\n");

    }

}
// Slower C++ solution:
#include <iostream>

#include<vector>

#include<stack>

using namespace std;

static const int MAXN=100000;

static const int NIL=-1;

 vector<int>G[MAXN];

 int color[MAXN];

 int n;

 void dfs(int r,int c)

 {

      stack<int>S;

      S.push(r);

      color[r]=c;

      while(!S.empty()){

        int u=S.top();S.pop();

            for(int i=0;i<G[u].size();i++){

                int v=G[u][i];

                if(color[v]==NIL){

                    color[v]=c;

                    S.push(v);

                }

            }

      }

 }

 void assignColor()

 {

     int id=1;

     for(int i=0;i<n;i++)color[i]=NIL;

     for(int u=0;u<n;u++){

        if(color[u]==NIL)dfs(u,id++);

     }

 }

int main()

{

    int b,q;

    cin>>n>>b;

    int s,t;

    for(int i=0;i<b;i++){

        cin>>s>>t;

        G[s].push_back(t);

        G[t].push_back(s);

    }

    assignColor();

    cin>>q;

    for(int i=0;i<q;i++){

        cin>>s>>t;

        if(color[s]==color[t]){

            cout<<"yes"<<endl;

        }else{

        cout<<"no"<<endl;

        }

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.510910698267422x):
#pragma GCC optimize("03")

#include <bits/stdc++.h>

#define endl '\n'

#define ll long long 

using namespace std;

int f[200000];

int find(int x){

	if(f[x]==x)

		return x;

	else

		return f[x]=find(f[x]);

}

void merge(int c,int d){

	f[d]=c;

}

int main()

{

    ios::sync_with_stdio(0);cin .tie(NULL);

    ll a,b,num;

   	cin >> a >> b;

   	for(int i=0;i<a;i++)

	f[i]=i;

    for(int i=0;i<b;i++)

    {

    	ll c,d;

    	cin >> c >> d;

    	c=find(c);

    	d=find(d);

   		merge(c,d);

	}

	cin >> num;

	for(int i=0;i<num;i++)

	{

		ll e,g;

		cin >> e >> g;

		if(find(e)==find(g))

			cout << "yes" << endl;

		else

			cout << "no" << endl;

	}

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<stack>

#include<cstring>

#include<vector>

#include<queue>

#include<stack>

#define white 0

#define grey 1

#define nil -1

#define maxn 100000

using namespace std;



vector<int> g[maxn+5];

int color[maxn+5];

int n,m;



void dfs(int s,int t)

{

    stack<int>q;

    q.push(s);

    color[s]=t;

    while(!q.empty())

    {

        int v=q.top();

        q.pop();

        for(int j=0;j<g[v].size();j++)

        {

            int u=g[v][j];

            if(color[u]==nil)

            {

                q.push(u);

                color[u]=t;

            }

        }

    }

}



void work()

{

    int id=1;

    for(int i=0;i<n;i++)

        color[i]=nil;

    for(int i=0;i<n;i++)

        if(color[i]==nil)

           dfs(i,id++);

}



int main()

{

    scanf("%d%d",&n,&m);

    for(int i=0;i<m;i++)

    {

        int x,y;

        scanf("%d%d",&x,&y);

        g[x].push_back(y);

        g[y].push_back(x);

    }

    work();



    int q;

    scanf("%d",&q);

    for(int i=1;i<=q;i++)

    {

        int s,t;

        scanf("%d%d",&s,&t);

        if(color[s]==color[t])

            printf("yes\n");

        else printf("no\n");

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.494828639793402x):
#pragma GCC optimize("03")

#include <bits/stdc++.h>

#define endl '\n'

#define ll long long 

using namespace std;

int f[200000];

int find(int x){

	if(f[x]==x)

		return x;

	else

		return f[x]=find(f[x]);

}

void merge(int c,int d){

	f[d]=c;

}

int main()

{

    ios::sync_with_stdio(0);cin .tie(NULL);

    ll a,b,num;

   	cin >> a >> b;

   	for(int i=0;i<a;i++)

	f[i]=i;

    for(int i=0;i<b;i++)

    {

    	ll c,d;

    	cin >> c >> d;

    	c=find(c);

    	d=find(d);

   		merge(c,d);

	}

	cin >> num;

	for(int i=0;i<num;i++)

	{

		ll e,g;

		cin >> e >> g;

		if(find(e)==find(g))

			cout << "yes" << endl;

		else

			cout << "no" << endl;

	}

}