stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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");

    }

}

// Faster C++ solution for the same problem (measured speedup: 1.7812965297737093x):
#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<cstring>

#include<vector>

#include<stack>

#include<queue>

using namespace std;

#define maxn 100005

#define NIL -1



int n,m;

vector<int> G[maxn]; //邻接表

int color[maxn]; //编号（可以互相链接的两个节点编号相同）



void dfs(int r,int c) //给节点r分配编号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 dfs_(int r,int c) //给节点r分配编号c（深搜实现）（递归）

{

    color[r]=c;

    for(int i=0;i<G[r].size();i++) //注意这里代码于上面的不同

    {

        int v=G[r][i];

        if(color[v]==NIL)

            {

                color[v]=c;

                dfs_(v,c);

            }

    }

}



void bfs(int r,int c) //给节点r分配编号c（广搜实现）

{

    queue<int> S;

    S.push(r);

    color[r]=c;

    while(!S.empty())

    {

        int u=S.front();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;

    memset(color,NIL,sizeof(color)); //这里要记得初始化

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

        if(color[u]==NIL)

            dfs_(u,id++); //这里选取了广搜的方式给各个节点编号

}



int main()

{

    int s,t,q;

    cin>>n>>m;

    while(m--)

    {

        cin>>s>>t;

        G[s].push_back(t); //从顶点s向t画边

        G[t].push_back(s); //反过来连边

    }

    assigncolor();

    cin>>q;

    while(q--)

    {

        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.9085176898080043x):
#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<cstring>

#include<vector>

#include<stack>

#include<queue>

using namespace std;

#define maxn 100005

#define NIL -1



int n,m;

vector<int> G[maxn]; //邻接表

int color[maxn]; //编号（可以互相链接的两个节点编号相同）



void dfs(int r,int c) //给节点r分配编号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 dfs_(int r,int c) //给节点r分配编号c（深搜实现）（递归）

{

    color[r]=c;

    for(int i=0;i<G[r].size();i++) //注意这里代码于上面的不同

    {

        int v=G[r][i];

        if(color[v]==NIL)

            {

                color[v]=c;

                dfs_(v,c);

            }

    }

}



void bfs(int r,int c) //给节点r分配编号c（广搜实现）

{

    queue<int> S;

    S.push(r);

    color[r]=c;

    while(!S.empty())

    {

        int u=S.front();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;

    memset(color,NIL,sizeof(color)); //这里要记得初始化

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

        if(color[u]==NIL)

            dfs_(u,id++); //这里选取了广搜的方式给各个节点编号

}



int main()

{

    int s,t,q;

    cin>>n>>m;

    while(m--)

    {

        cin>>s>>t;

        G[s].push_back(t); //从顶点s向t画边

        G[t].push_back(s); //反过来连边

    }

    assigncolor();

    cin>>q;

    while(q--)

    {

        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.1135756925746372x):
#include<iostream>

using namespace std;

#include<vector>

#include<stack>

#define MAX 100000

int n,m;

vector<int>G[MAX];

stack<int>mp;

int color[MAX];



void dfs(int r,int c){

	mp.push(r);

	color[r] = c;

	while (!mp.empty()){

		int u = mp.top();

		mp.pop();

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

			int v = G[u][i];

			if (color[v] == -1){

				color[v] = c;

				mp.push(v);

			}

		}

	}

}



void assignColor(){

	int id = 1;

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

		color[i] = -1;

	}

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

		if (color[j] == -1){

			dfs(j,id++);

		}

	}

}



int main()

{

	cin >> n >> m;

	int x,y; 

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

		cin >> x >> y;

		G[x].push_back(y);

		G[y].push_back(x);

	}

	assignColor();

	cin >> m;

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

		cin >> x >> y;

		if (color[x] == color[y]){

			cout << "yes" << endl;

		}

		else{

			cout << "no" << endl;

		}

	}

	return 0;

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

#include<cstring>

#include<vector>

#include<stack>

#include<queue>

using namespace std;

#define maxn 100005

#define NIL -1



int n,m;

vector<int> G[maxn]; //邻接表

int color[maxn]; //编号（可以互相链接的两个节点编号相同）



void dfs(int r,int c) //给节点r分配编号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 dfs_(int r,int c) //给节点r分配编号c（深搜实现）（递归）

{

    color[r]=c;

    for(int i=0;i<G[r].size();i++) //注意这里代码于上面的不同

    {

        int v=G[r][i];

        if(color[v]==NIL)

            {

                color[v]=c;

                dfs_(v,c);

            }

    }

}



void bfs(int r,int c) //给节点r分配编号c（广搜实现）

{

    queue<int> S;

    S.push(r);

    color[r]=c;

    while(!S.empty())

    {

        int u=S.front();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;

    memset(color,NIL,sizeof(color)); //这里要记得初始化

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

        if(color[u]==NIL)

            dfs_(u,id++); //这里选取了广搜的方式给各个节点编号

}



int main()

{

    int s,t,q;

    cin>>n>>m;

    while(m--)

    {

        cin>>s>>t;

        G[s].push_back(t); //从顶点s向t画边

        G[t].push_back(s); //反过来连边

    }

    assigncolor();

    cin>>q;

    while(q--)

    {

        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.12097750567831x):
#include<bits/stdc++.h>

using namespace std;

const int MAX = 100000;

const int NIL = -1;

int n;

vector<int> G[MAX];

int color[MAX];

void dfs(int r,int c) {

    if(color[r] == NIL) color[r] = c;

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

        int v = G[r][i];

        if(color[v] == NIL) dfs(v,c);

    }

}

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 s,t,m,q;

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

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

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

        G[s].push_back(t);

        G[t].push_back(s);

    }

    assignColor();

    scanf("%d",&q);

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

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

        if(color[s] == color[t]) printf("yes\n");

        else printf("no\n");

    }

    return 0;

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

#include <vector>

#include <queue>



using namespace std;



struct Node {

    int color = 0;

    vector<int> next;

} node[100000];



int main() {

    int n, m, q, t1, t2;



    cin >> n >> m;

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

        cin >> t1 >> t2;

        node[t1].next.push_back(t2);

        node[t2].next.push_back(t1);

    }



    int color = 1;

    queue<int> que;

    while (1) {

        int start = -1;

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

            if (node[i].color == 0) {

                start = i;

                break;

            }

        }

        if (start == -1) {

            break;

        }

        

        node[start].color = color;

        que.push(start);

        while (!que.empty()) {

            int temp = que.front();

            int size = node[temp].next.size();

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

                if (node[node[temp].next[i]].color == 0) {

                    node[node[temp].next[i]].color = color;

                    que.push(node[temp].next[i]);

                }

            }

            que.pop();

        }

        color++;

    }



    cin >> q;

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

        cin >> t1 >> t2;

        if (node[t1].color == node[t2].color && node[t1].color > 0 && node[t2].color > 0) {

            cout << "yes" << endl;

        }

        else {

            cout << "no" << endl;

        }

    }



    return 0;

}

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



using namespace std;



int user[100000];



void init(int n) {

    fill_n(user, n, -1);

}



int root(int s) {

    if (user[s] < 0)

        return s;

    else

        return user[s] = root(user[s]);

}



void unite(int s, int t) {

    int rs = root(s);

    int rt = root(t);

    if (rs != rt) {

        if (user[rs] < user[rt])

            swap(rs, rt);

        user[rs] += user[rt];

        user[rt] = rs;

    }

}



bool same(int s, int t) {

    return root(s) == root(t);

}



int main() {

    int n, m, q, s, t, c = 1;

    cin >> n >> m;

    init(n);

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

        cin >> s >> t;

        unite(s, t);

    }

    cin >> q;

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

        cin >> s >> t;

        if (same(s, t))

            cout << "yes" << endl;

        else 

            cout << "no" << endl;

    }



    return 0;

}
// Slower C++ solution:


#include<iostream>

#include<queue>



using namespace std;



const int MAX = 100000;



int parent(int table[], int child) {

	queue<int> q;



	while (table[child] != -1) {

		q.push(child);

		child = table[child];

	}

	while (!q.empty()) {

		table[q.front()] = child;

		q.pop();

	}

	return child;

}



int main() {

	int n, m, q;

	int table[MAX];



	cin >> n >> m;



	for (int i = 0; i < n; i++)table[i] = -1;

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

		int s, t;

		cin >> s >> t;

		

		int ps = parent(table, s);

		int pt = parent(table, t);

		if (ps != pt) {

			table[ps] = pt;

		}

	}



	cin >> q;



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

		int s, t;

		cin >> s >> t;



		int ps = parent(table, s);

		int pt = parent(table, t);



		if (ps == pt) {

			cout << "yes" << endl;

		}

		else {

			cout << "no" << endl;

		}

	}

	return 0;

}

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

using namespace std;



const int MAX = 100000;



int parent(int table[], int child) {

	if (table[child] == -1)return child;

	return table[child] = parent(table, table[child]);

}



int main() {

	int n, m, q;

	int table[MAX];



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



	for (int i = 0; i < n; i++)table[i] = -1;

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

		int s, t;

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

		

		int ps = parent(table, s);

		int pt = parent(table, t);

		if (ps != pt) {

			table[ps] = pt;

		}

	}



	scanf("%d", &q);



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

		int s, t;

		

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



		int ps = parent(table, s);

		int pt = parent(table, t);



		if (ps == pt) {

			printf("yes\n");

		}

		else {

			printf("no\n");

		}

	}

	return 0;

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

#include<queue>



using namespace std;



const int MAX = 100000;



int parent(int table[], int child) {

	queue<int> q;



	while (table[child] != -1) {

		q.push(child);

		child = table[child];

	}

	while (!q.empty()) {

		table[q.front()] = child;

		q.pop();

	}

	return child;

}



int main() {

	int n, m, q;

	int table[MAX];



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



	for (int i = 0; i < n; i++)table[i] = -1;

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

		int s, t;

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

		

		int ps = parent(table, s);

		int pt = parent(table, t);

		if (ps != pt) {

			table[ps] = pt;

		}

	}



	scanf("%d", &q);



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

		int s, t;

		

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



		int ps = parent(table, s);

		int pt = parent(table, t);



		if (ps == pt) {

			printf("yes\n");

		}

		else {

			printf("no\n");

		}

	}

	return 0;

}

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

using namespace std;



const int MAX = 100000;



int parent(int table[], int child) {

	if (table[child] == -1)return child;

	return table[child] = parent(table, table[child]);

}



int main() {

	int n, m, q;

	int table[MAX];



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



	for (int i = 0; i < n; i++)table[i] = -1;

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

		int s, t;

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

		

		int ps = parent(table, s);

		int pt = parent(table, t);

		if (ps != pt) {

			table[ps] = pt;

		}

	}



	scanf("%d", &q);



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

		int s, t;

		

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



		int ps = parent(table, s);

		int pt = parent(table, t);



		if (ps == pt) {

			printf("yes\n");

		}

		else {

			printf("no\n");

		}

	}

	return 0;

}
// Slower C++ solution:


#include<iostream>

#include<queue>



using namespace std;



const int MAX = 100000;



int parent(int table[], int child) {

	queue<int> q;



	while (table[child] != -1) {

		q.push(child);

		child = table[child];

	}

	while (!q.empty()) {

		table[q.front()] = child;

		q.pop();

	}

	return child;

}



int main() {

	int n, m, q;

	int table[MAX];



	cin >> n >> m;



	for (int i = 0; i < n; i++)table[i] = -1;

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

		int s, t;

		cin >> s >> t;

		

		int ps = parent(table, s);

		int pt = parent(table, t);

		if (ps != pt) {

			table[ps] = pt;

		}

	}



	cin >> q;



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

		int s, t;

		cin >> s >> t;



		int ps = parent(table, s);

		int pt = parent(table, t);



		if (ps == pt) {

			cout << "yes" << endl;

		}

		else {

			cout << "no" << endl;

		}

	}

	return 0;

}

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

using namespace std;



const int MAX = 100001;



int parent(int table[], int child) {

	if (table[child] == 0)return child;

	return table[child] = parent(table, table[child]);

}



int main() {

	int n, m, q;

	int table[MAX] ={0};



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



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

		int s, t;

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

		s++;t++;

		int ps = parent(table, s);

		int pt = parent(table, t);

		if (ps != pt) {

			table[ps] = pt;

		}

	}



	scanf("%d", &q);



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

		int s, t;

		

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

                s++;t++;

		int ps = parent(table, s);

		int pt = parent(table, t);



		if (ps == pt) {

			printf("yes\n");

		}

		else {

			printf("no\n");

		}

	}

	return 0;

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

#include<queue>



using namespace std;



const int MAX = 100000;



int parent(int table[], int child) {

	queue<int> q;



	while (table[child] != -1) {

		q.push(child);

		child = table[child];

	}

	while (!q.empty()) {

		table[q.front()] = child;

		q.pop();

	}

	return child;

}



int main() {

	int n, m, q;

	int table[MAX];



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



	for (int i = 0; i < n; i++)table[i] = -1;

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

		int s, t;

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

		

		int ps = parent(table, s);

		int pt = parent(table, t);

		if (ps != pt) {

			table[ps] = pt;

		}

	}



	scanf("%d", &q);



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

		int s, t;

		

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



		int ps = parent(table, s);

		int pt = parent(table, t);



		if (ps == pt) {

			printf("yes\n");

		}

		else {

			printf("no\n");

		}

	}

	return 0;

}

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

using namespace std;



const int MAX = 100001;



int parent(int table[], int child) {

	if (table[child] == 0)return child;

	return table[child] = parent(table, table[child]);

}



int main() {

	int n, m, q;

	int table[MAX] ={0};



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



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

		int s, t;

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

		s++;t++;

		int ps = parent(table, s);

		int pt = parent(table, t);

		if (ps != pt) {

			table[ps] = pt;

		}

	}



	scanf("%d", &q);



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

		int s, t;

		

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

                s++;t++;

		int ps = parent(table, s);

		int pt = parent(table, t);



		if (ps == pt) {

			printf("yes\n");

		}

		else {

			printf("no\n");

		}

	}

	return 0;

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

#include <string>

#include <stdio.h>

#include <vector>

#include <stack>

#include <queue>

#define N 100000

using namespace std;





int C[N];

queue<int> k;

vector<int> v[N];

void color(int);

bool search(int,int);



int main(){

	int n,m,a,b,q;

	cin >> n >>m;

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

		cin >> a >> b;

		v[a].push_back(b);

		v[b].push_back(a);

	}

	cin >> q;

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

		C[i]=-1; //?????????

	}

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

		if(C[i]==-1)color(i); //i????§??????¨????????±???

	}

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

		cin>>a>>b;

		if(search(a,b)) cout<<"yes"<<endl;

		else cout<<"no"<<endl;

	}

	return 0;

}



bool search(int a,int b){

	if(C[a]==C[b]) return true;

	else return false;

}



void color(int a){

	static int c=0;

	c++;

	C[a]=c;

	k.push(a);

	while(!k.empty()){

		int m = k.front();

		k.pop();

		for(int i=0;i<v[m].size();i++){

			int Z= v[m].at(i);

			if(C[Z]==-1){

				C[Z]=c;

				k.push(Z);

			}

		}

	}

}

// Faster C++ solution for the same problem (measured speedup: 3.5092095712237916x):
/*

	 AOJ DSL_1

	 ??????????´??????????

	 2??????????´????????????????????±??????????????????¶=2??????????´??????????????????§??????

	 ?????????????????¨???father[]?????´??\?????§???????????§????????????find??¢??°??§??¢?´¢??????????????????

	 ??????????????????????????¨?????¨??????????????????

	 */

#include<iostream>

#include <string>

#define maxn 100100

using namespace std;

int n,q,m;

int father[maxn];



void init(){

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

}



int find(int x){ // x?????????????????¢??°

	if(father[x]==x)return x; // ?????????????????????????????´??????x???????????????

	return father[x]=find(father[x]); // ??????????????§????????°??????????????????????????????(????????§?????????)

}



void unite(int x,int y){

	father[find(x)]=find(y); // x????????¨y????????????????????????

}



string same(int x,int y){

	if(find(x)==find(y))return "yes"; // ????????????????????????

	else return "no";

}



int main(void){

	cin>>n>>m;

	init();

	while(m--){

		int x,y;

		cin>>x>>y;

		unite(x,y);

	}

	cin>>q;

	while(q--){

		int x,y;

		cin>>x>>y;

		cout<<same(x,y)<<endl;

	}

	return 0;

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

#include <vector>

#define N_MAX 100000

using namespace std;



vector<int> sns[N_MAX];

int* group;

int g = 0;



void dfs(int s) {

  if (group[s] != 0) return;

  group[s] = g;

  

  int len = sns[s].size();

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

    dfs(sns[s][i]);

  }

}



int main() {

  int n,m,q,s,t;

  cin >> n >> m;



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

    cin >> s >> t;



    sns[s].push_back(t);

    sns[t].push_back(s);

  }



  // dfs

  group = new int[n];

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

    if (group[i] == 0) {

      g++;

      dfs(i);

    }

  }



  cin >> q;

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

    cin >> s >> t;

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

      cout << "yes" << endl;

    } else {

      cout << "no" << endl;

    }

  }

  return 0;

}

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

#include <vector>

#define eol '\n'

using namespace std;



vector< vector<int> > list;

vector<int> group;



void bfs(int v, int g) {

  if (group[v] != 0) {

    return;

  }

  group[v] = g;

  for (int i = 0; i < list[v].size(); i++) {

    bfs(list[v][i], g);

  }

}



int main() {

  ios_base::sync_with_stdio(false);

  cin.tie(0);



  int n,m,s,t,q;

  cin >> n >> m;



  list = vector< vector<int> >(n, vector<int>());

  group = vector<int>(n,0);

  

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

    cin >> s >> t;

    list[s].push_back(t);

    list[t].push_back(s);

  }



  int g = 1;

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

    if (group[i] == 0) {

      bfs(i, g);

      g++;

    }

  }



  cin >> q;

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

    cin >> s >> t;

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

      cout << "yes" << eol;

    } else {

      cout << "no" << eol;

    }

  }

  return 0;

}