Go: package main

import (
	"bufio"
	"container/list"
	"os"
	"strconv"
	"fmt"
)

const (
	MAX = 100000
	NIL = -1
)

var (
	n     int
	G     [MAX][]int
	color [MAX]int
)

func DFS(r int, c int) {
	S := list.New()
	S.PushFront(r)
	color[r] = c
	for S.Len() != 0 {
		u := S.Remove(S.Front()).(int)
		for i := 0; i < len(G[u]); i++ {
			v := G[u][i]
			if color[v] == NIL {
				color[v] = c
				S.PushFront(v)
			}
		}
	}
}

func assignColor() {
	id := 1
	for i := 0; i < n; i++ {
		color[i] = NIL
	}
	for i := 0; i < n; i++ {
		if color[i] == NIL {
			id++
			DFS(i, id)
		}
	}
}

func main() {
	var s, t, m, q int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ = strconv.Atoi(scanner.Text())
	scanner.Scan()
	m, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < m; i++ {
		scanner.Scan()
		s, _ = strconv.Atoi(scanner.Text())
		scanner.Scan()
		t, _ = strconv.Atoi(scanner.Text())
		if i == 0 {
			G[s] = make([]int, 0)
			G[t] = make([]int, 0)
		}
		G[s] = append(G[s], t)
		G[t] = append(G[t], s)
	}

	assignColor()
	scanner.Scan()
	q, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < q; i++ {
		scanner.Scan()
		s, _ = strconv.Atoi(scanner.Text())
		scanner.Scan()
		t, _ = strconv.Atoi(scanner.Text())
		if color[s] == color[t] {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}

C++: /**
 * @brief ?????£???(????§£)??¢?????´?????????????????????
 * @date  2016/03/12
 */


//****************************************
// ???????????????????????????????????????????????????
//****************************************

#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <vector>
#include <iostream>



//****************************************
// ???????????§????????¢?????????????????????
//****************************************

#define GRAPH_BEGIN namespace graph {
#define GRAPH_END   }



//****************************************
// ????????????????§????
//****************************************

GRAPH_BEGIN



//****************************************
// ?§????????????????
//****************************************

using weight_t   = std::int32_t;  /**< ???(u, v)????????????w?????¨?????? */
using index_t    = std::int32_t;  /**< ??????v??????????????¨??????       */
using capacity_t = weight_t;      /**< ???(u, v)??????????????¨??????    */



namespace limits {
    enum {  // namespace graph????????£???scoped??§????????????????????????????????????enum(strongly-typed enum)??§?????????
    inf = std::numeric_limits<weight_t>::max() / 3,  /**< @brief ???????????¨???????????´???????????¨????????????     */
    nil = std::numeric_limits<index_t>::min() / 3,   /**< @brief ?????????????????¨???????????´???????????¨???????????? */
};
}



/**
 * @brief  ????????????????§???????(scoped enum)
 * @detail (u, v) ??? E??§??????u??????????????°??????v?????°????????§??????
 *         ?????????????????????????????£??\????????¨?????????????????????????????§??????
 *         ??°???????????????????????£??\???????????¨???????????????????????????????????¢??????????????¨???????????????????¢?????????????
 */
enum struct vcolor : std::int32_t {
    white,  /**< ??????????????? */
    black,  /**< ??¢???????????? */
    gray,   /**< ??¢???????????? */
};

/**
 * @brief ??°????????¨?????????(??????) 
 */
struct vertex {
    union {
        weight_t d;       /**< ?§????s??????????????¢  */
        weight_t key;     /**< Prim?????¢?????´???????????????????????¨????±?????????????????????¨????????¶?????? */
    };
    index_t pi;           /**< ????????????(?????????) */
    union {
        vcolor color;     /**< ????????????        */
        bool  visited;    /**< ????????????????     */
    };
    // weight_t f;           /**< ??????????????°(DFS?????????????????????????????????????????¨??????????????????)     */
    vertex() : d(0), pi(0), color(vcolor::white)/*, f(0)*/ {}
};

/**
 * @brief ??°????????¨??¨??????(???)
 * @note  G = (V, E)???????????¢??°w???????????????????????°????????¨????????¨???
 *        ???(u, v) ??? E????????????w(u, v)??¨??¨?????????
 */
struct edge {
    index_t  src;   /**< ???????§????u */
    index_t  dst;   /**< ????????????v */
    union {
        weight_t w;     /**< ???(u, v)????????????(?????????) */
        capacity_t c;   /**< ???(u, v)????????? */
    };
    edge() = default;
    edge(index_t src, index_t dst) : src(src), dst(dst), w(1) {}
    edge(index_t src, index_t dst, weight_t w) : src(src), dst(dst), w(w) {}

    bool operator < (const edge& e) const { return w < e.w; }
    bool operator > (const edge& e) const { return w > e.w; }
};



using edges_t    = std::vector<edge>;      /**< ??°??????G=(V, E)????????????E   */
using vertices_t = std::vector<vertex>;    /**< ??°??????G=(V, E)???????????????V */
using array_t    = std::vector<weight_t>;  /**< ??????w?????????  */
using indices_t  = std::vector<index_t>;   /**< ????????????????????? */
using matrix_t   = std::vector<array_t>;   /**< ??°??????G?????£??\????????¨???(???????????¨????????¨???) */
using graph_t    = std::vector<edges_t>;   /**< ??°??????G?????£??\???????????¨???(???????????????????????¨??????) */



//****************************************
// ??¢??°?????????
//****************************************

/**
 * @brief  ??????????????????????????????????????????
 *
 * @note   ?????????????????°??????G = (V, E)??????????????????????????????(topological sort)??????????????????????????¢????????§???
 *         G??????(u, v)?????????????????°??????????????¢????????§u???v?????????????????????????????§??????. (??°?????????????????????????????°????????????????????¢??????????????¨?????????)
 *         ??°??????????????????????????????????????????????????????????????????????????????????????????????°´???????????§???????????????????????§??????
 * @param  const graph& G ?????????????????°??????
 * @return ??¢??????????????????
 */
array_t tsort(const graph_t& G)
{
    std::int32_t n = G.size();
    std::vector<vcolor> color(n, vcolor::white);
    array_t lst(n);

    // ?????????????¨???????
    std::function<bool(index_t)> dfs_visit = [&](index_t u) {
        color[u] = vcolor::gray;    // u?????°???????????????
        for (auto&& e : G[u]) {      // v??¨??£??\???????????????w????????????
            index_t w = e.dst;
            if (color[w] == vcolor::white
             && !dfs_visit(w)) { return false; }  // w?????????????????°??????w????????????
        }
        color[u] = vcolor::black;   // u?????????????????????
        lst.push_back(u);           // ????????????????°?????????\??????
        return true;
    };


    // ?????????v???????????????v.f????¨???????????????????DFS(G)???????????????
    for (index_t v = 0; v < n; v++) {
        if (color[v] == vcolor::white && !dfs_visit(v)) { return {}; };
    }
    reverse(lst.begin(), lst.end());  // ??????????????????????????????????????????????????§reverse?????????
    return lst;     // ???????????????????????????
}




/**
 * @brief  ?????£?????????(????§£)??¢?????´?????????
 *
 * @note   ??°??????????????£????????????????§£??????????????????????????£??????????????§??¢?????´????????????????????????
 *         ?????????????§£?????????????????£????§??????????????????£??????????????????????????????????§£?????????
 *
 * @note   ??°??????G = (V, E)????????£?????????????±?????????¢?????´????????????G?????¢????????¨??????
 *         G?????¢????????°??????G^T = (V, E^T), E^T = { (u, v) : (v, u) ??? E }??§??????
 *         ???????????????E^T???G??????????????????????????????????????§??????. G?????£??\?????????????????????????????¨???
 *         G^T?????(V + E)????????§????????§??????. ????????±????????¨??????G??¨G^T????????£?????????????????£??????????????????
 *         G?????§u??¨v??????????????°???????????§???????????¨??¨???G^T?????§???????????????????????°???????????§???????????¨??¨???????????§??????
 *
 * @note   ??\???????????¢??????(?????????????????(V + E)??????)??¢?????´?????????????????±???????????¢?´¢???2???????????????G?????§???
 *         ?????????G^T?????§?????????????????¨????????£???????????°??????G = (V, E)????????£?????????????±???????
 *
 *         STRONGLY-CONNECTED-COMPONENTS(G)
 *         1 DFS(G)???????????????????????????u????????????????????????u.f????¨??????????
 *         2 G^T????¨??????????
 *         3 DFS(G^T)?????????????????????DFS?????????????????§???(?¬¬1?????§?¨??????????)u.f???????????§???????????¢?´¢??????
 *         4 ?¬¬3?????§??????????????±??????????£?????????¨????????????????????????????????¢??????????????£???????????¨??????????????????
 *
 * @param  const graph_t& G ??°??????G
 * @return components[v] ??????v?????????????????£????????????????????¨?????????????????????
 */
indices_t scc(const graph_t& G)
{
    index_t n = G.size(); vertices_t vs(n);
    indices_t components(n, -1);
    std::vector<vcolor> color(n, vcolor::white);
    graph_t GT(n);

    // ?????°???????????????????¨???????
    std::function<void(index_t, index_t)> dfs_visit = [&](index_t u, index_t k) {
        color[u] = vcolor::gray;
        components[u] = k;
        for (auto&& e : GT[u]) {
            index_t w = e.dst;
            if (color[w] == vcolor::white) {
                dfs_visit(w, k);
            }
        }
        color[u] = vcolor::black;
    };


    // DFS(G)???????????????????????????u????????????????????????u.f????¨??????????
    array_t tlst = tsort(G);

    // G^T????¨??????????
    for (auto&& es : G) {
        for (auto&& e : es) {
            GT[e.dst].emplace_back(e.dst, e.src);
        }
    }

    // DFS(G^T)???????????????
    index_t k = 0;
    for (auto&& u : tlst) { // ????????°??????????????????????????????????????????????????????????????§?¨??????????
        if (color[u] == vcolor::white) {
            dfs_visit(u, k++);
        }
    }

    // ?????¢??????????????£??????????????????
    return components;
}



//****************************************
// ?????????????????????
//****************************************

GRAPH_END



//****************************************
// ??¨?????????????????????
//****************************************

int main()
{
    using namespace std;
    using namespace graph;
    
    graph_t G;
    int s, t, m, n, q;
    cin >> n >> m;
    G.resize(n);
    for (index_t i = 0; i < m; i++) {
        cin >> s >> t;
        G[s].emplace_back(s, t);
        G[t].emplace_back(t, s);
    }

    auto _scc = scc(G);

    cin >> q;

    for (int i = 0; i < q; i++) {
        cin >> s >> t;
        cout << ((_scc[s] == _scc[t]) ? "yes" : "no") << endl;
    }

    return 0;
}