This documentation is automatically generated by online-judge-tools/verification-helper
#define PROBLEM \
"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_D"
#include <bits/stdc++.h>
using namespace std;
#define call_from_test
#include "../../cpp_src/data_structure/DisjointSetUnion.hpp"
#undef call_from_test
using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()
#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define dump(x) true
#endif
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T, class U>
void chmin(T& t, const U& u) {
if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
if (t < u) t = u;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os << "{";
rep(i, v.size()) {
if (i) os << ",";
os << v[i];
}
os << "}";
return os;
}
int main() {
int n, m;
cin >> n >> m;
unionfind uf;
uf.init(n);
rep(i, m) {
int a, b;
cin >> a >> b;
uf.unite(a, b);
}
int q;
cin >> q;
while (q--) {
int a, b;
cin >> a >> b;
puts(uf.same(a, b) ? "yes" : "no");
}
return 0;
}
#line 1 "test/aoj/ALDS1_11_D.test.cpp"
#define PROBLEM \
"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_D"
#include <bits/stdc++.h>
using namespace std;
#define call_from_test
#line 1 "cpp_src/data_structure/DisjointSetUnion.hpp"
class unionfind {
vector<int> par, rank;
public:
void init(int n) {
par.resize(n);
rank.resize(n);
for (int i = 0; i < n; i++) {
par[i] = i;
rank[i] = 0;
}
}
unionfind() {}
unionfind(int n) { init(n); }
int find(int x) {
if (par[x] == x)
return x;
else
return par[x] = find(par[x]);
}
bool unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) return false;
if (rank[x] < rank[y])
par[x] = y;
else {
par[y] = x;
if (rank[x] == rank[y]) ++rank[x];
}
return true;
}
bool same(int x, int y) { return (find(x) == find(y)); }
};
#line 10 "test/aoj/ALDS1_11_D.test.cpp"
#undef call_from_test
using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()
#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define dump(x) true
#endif
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T, class U>
void chmin(T& t, const U& u) {
if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
if (t < u) t = u;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os << "{";
rep(i, v.size()) {
if (i) os << ",";
os << v[i];
}
os << "}";
return os;
}
int main() {
int n, m;
cin >> n >> m;
unionfind uf;
uf.init(n);
rep(i, m) {
int a, b;
cin >> a >> b;
uf.unite(a, b);
}
int q;
cin >> q;
while (q--) {
int a, b;
cin >> a >> b;
puts(uf.same(a, b) ? "yes" : "no");
}
return 0;
}