#define LOCAL #include using namespace std; #pragma region Macros typedef long long ll; typedef __int128_t i128; typedef unsigned int uint; typedef unsigned long long ull; #define ALL(x) (x).begin(), (x).end() template istream& operator>>(istream& is, vector& v) { for (T& x : v) is >> x; return is; } template ostream& operator<<(ostream& os, const vector& v) { for (size_t i = 0; i < v.size(); i++) { os << v[i] << (i + 1 == v.size() ? "" : " "); } return os; } template ostream& operator<<(ostream& os, const pair& p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template ostream& operator<<(ostream& os, const map& m) { os << '{'; for (auto itr = m.begin(); itr != m.end();) { os << '(' << itr->first << ',' << itr->second << ')'; if (++itr != m.end()) os << ','; } os << '}'; return os; } template ostream& operator<<(ostream& os, const unordered_map& m) { os << '{'; for (auto itr = m.begin(); itr != m.end();) { os << '(' << itr->first << ',' << itr->second << ')'; if (++itr != m.end()) os << ','; } os << '}'; return os; } template ostream& operator<<(ostream& os, const set& s) { os << '{'; for (auto itr = s.begin(); itr != s.end();) { os << *itr; if (++itr != s.end()) os << ','; } os << '}'; return os; } template ostream& operator<<(ostream& os, const multiset& s) { os << '{'; for (auto itr = s.begin(); itr != s.end();) { os << *itr; if (++itr != s.end()) os << ','; } os << '}'; return os; } template ostream& operator<<(ostream& os, const unordered_set& s) { os << '{'; for (auto itr = s.begin(); itr != s.end();) { os << *itr; if (++itr != s.end()) os << ','; } os << '}'; return os; } template ostream& operator<<(ostream& os, const deque& v) { for (size_t i = 0; i < v.size(); i++) { os << v[i] << (i + 1 == v.size() ? "" : " "); } return os; } template ostream& operator<<(ostream& os, const array& v) { for (size_t i = 0; i < N; i++) { os << v[i] << (i + 1 == N ? "" : " "); } return os; } template void print_tuple(ostream&, const T&) {} template void print_tuple(ostream& os, const T& t) { if (i) os << ','; os << get(t); print_tuple(os, t); } template ostream& operator<<(ostream& os, const tuple& t) { os << '{'; print_tuple<0, tuple, Args...>(os, t); return os << '}'; } void debug_out() { cerr << '\n'; } template void debug_out(Head&& head, Tail&&... tail) { cerr << head; if (sizeof...(Tail) > 0) cerr << ", "; debug_out(move(tail)...); } #ifdef LOCAL #define debug(...) \ cerr << " "; \ cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n'; \ cerr << " "; \ debug_out(__VA_ARGS__) #else #define debug(...) void(0) #endif template T gcd(T x, T y) { return y != 0 ? gcd(y, x % y) : x; } template T lcm(T x, T y) { return x / gcd(x, y) * y; } int topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); } int topbit(long long t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); } int botbit(signed a) { return a == 0 ? 32 : __builtin_ctz(a); } int botbit(long long a) { return a == 0 ? 64 : __builtin_ctzll(a); } int popcount(signed t) { return __builtin_popcount(t); } int popcount(long long t) { return __builtin_popcountll(t); } bool ispow2(int i) { return i && (i & -i) == i; } long long MSK(int n) { return (1LL << n) - 1; } template T ceil(T x, T y) { assert(y >= 1); return (x > 0 ? (x + y - 1) / y : x / y); } template T floor(T x, T y) { assert(y >= 1); return (x > 0 ? x / y : (x - y + 1) / y); } template inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return true; } return false; } template void mkuni(vector& v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); } template int lwb(const vector& v, const T& x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); } #pragma endregion #include #include #include struct HeavyLightDecomposition { std::vector> G; // child of vertex v on heavy edge is G[v].front() if it is not parent of v int n, time; std::vector par, // parent of vertex v sub, // size of subtree whose root is v dep, // distance bitween root and vertex v head, // vertex that is the nearest to root on heavy path of vertex v tree_id, // id of tree vertex v belongs to vertex_id, // id of vertex v (consecutive on heavy paths) vertex_id_inv; // vertex_id_inv[vertex_id[v]] = v HeavyLightDecomposition(int n) : G(n), n(n), time(0), par(n, -1), sub(n), dep(n, 0), head(n), tree_id(n, -1), vertex_id(n, -1), vertex_id_inv(n) {} void add_edge(int u, int v) { assert(0 <= u && u < n); assert(0 <= v && v < n); G[u].emplace_back(v); G[v].emplace_back(u); } void build() { int tree_id_cur = 0; for (int r = 0; r < n; r++) { // assert(0 <= r && r < n); if (vertex_id[r] != -1) continue; dfs_sz(r); head[r] = r; dfs_hld(r, tree_id_cur++); } assert(time == n); for (int v = 0; v < n; v++) vertex_id_inv[vertex_id[v]] = v; } int idx(int v) const { return vertex_id[v]; } int la(int v, int k) { assert(0 <= v && v < n); assert(0 <= k && k <= dep[v]); while (1) { int u = head[v]; if (vertex_id[v] - k >= vertex_id[u]) return vertex_id_inv[vertex_id[v] - k]; k -= vertex_id[v] - vertex_id[u] + 1; v = par[u]; } } int lca(int u, int v) const { assert(0 <= u && u < n); assert(0 <= v && v < n); assert(tree_id[u] == tree_id[v]); for (;; v = par[head[v]]) { if (vertex_id[u] > vertex_id[v]) std::swap(u, v); if (head[u] == head[v]) return u; } } int distance(int u, int v) const { assert(0 <= u && u < n); assert(0 <= v && v < n); assert(tree_id[u] == tree_id[v]); return dep[u] + dep[v] - 2 * dep[lca(u, v)]; } template void query_path(int u, int v, const F& f, bool vertex = false) const { assert(0 <= u && u < n); assert(0 <= v && v < n); assert(tree_id[u] == tree_id[v]); int p = lca(u, v); for (auto& e : ascend(u, p)) f(e.second, e.first + 1); if (vertex) f(vertex_id[p], vertex_id[p] + 1); for (auto& e : descend(p, v)) f(e.first, e.second + 1); } template void query_path_noncommutative(int u, int v, const F& f, bool vertex = false) const { assert(0 <= u && u < n); assert(0 <= v && v < n); assert(tree_id[u] == tree_id[v]); int p = lca(u, v); for (auto& e : ascend(u, p)) f(e.first + 1, e.second); if (vertex) f(vertex_id[p], vertex_id[p] + 1); for (auto& e : descend(p, v)) f(e.first, e.second + 1); } template void query_subtree(int u, const F& f, bool vertex = false) const { assert(0 <= u && u < n); f(vertex_id[u] + !vertex, vertex_id[u] + sub[u]); } private: void dfs_sz(int v) { sub[v] = 1; if (!G[v].empty() && G[v].front() == par[v]) std::swap(G[v].front(), G[v].back()); for (int& u : G[v]) { if (u == par[v]) continue; par[u] = v; dep[u] = dep[v] + 1; dfs_sz(u); sub[v] += sub[u]; if (sub[u] > sub[G[v].front()]) std::swap(u, G[v].front()); } } void dfs_hld(int v, int tree_id_cur) { vertex_id[v] = time++; tree_id[v] = tree_id_cur; for (int& u : G[v]) { if (u == par[v]) continue; head[u] = (u == G[v][0] ? head[v] : u); dfs_hld(u, tree_id_cur); } } std::vector> ascend(int u, int v) const { // [u, v), v is ancestor of u std::vector> res; while (head[u] != head[v]) { res.emplace_back(vertex_id[u], vertex_id[head[u]]); u = par[head[u]]; } if (u != v) res.emplace_back(vertex_id[u], vertex_id[v] + 1); return res; } std::vector> descend(int u, int v) const { // (u, v], u is ancestor of v if (u == v) return {}; if (head[u] == head[v]) return {{vertex_id[u] + 1, vertex_id[v]}}; auto res = descend(u, par[head[v]]); res.emplace_back(vertex_id[head[v]], vertex_id[v]); return res; } }; struct TwoEdgeConnectedComponents { int time, k; vector ord, low, cmp; vector> G, C, T; vector> bridge; TwoEdgeConnectedComponents(int n) : time(0), k(0), ord(n, -1), low(n), cmp(n, -1), G(n) {} void add_edge(int u, int v) { G[u].emplace_back(v); G[v].emplace_back(u); } bool is_bridge(int u, int v) { if (ord[u] > ord[v]) swap(u, v); return ord[u] < low[v]; } void dfs(int v, int p) { ord[v] = low[v] = time++; int bic = 0; for (int u : G[v]) { if (u == p && !bic) { bic = 1; continue; } if (~ord[u]) { low[v] = min(low[v], ord[u]); continue; } dfs(u, v); low[v] = min(low[v], low[u]); if (is_bridge(v, u)) bridge.emplace_back(v, u); } } void fill_component(int v) { C[cmp[v]].emplace_back(v); for (int u : G[v]) { if (~cmp[u] || is_bridge(u, v)) continue; cmp[u] = cmp[v]; fill_component(u); } } void add_component(int v) { if (~cmp[v]) return; cmp[v] = k++; C.emplace_back(); fill_component(v); } int build() { int n = G.size(); for (int v = 0; v < n; ++v) { if (ord[v] < 0) dfs(v, -1); } for (int v = 0; v < n; ++v) add_component(v); T.resize(k); for (auto e : bridge) { int u = cmp[e.first], v = cmp[e.second]; T[u].emplace_back(v); T[v].emplace_back(u); } return k; } int operator[](int i) const { return cmp[i]; } }; #include "atcoder/fenwicktree" const int INF = 1e9; const long long IINF = 1e18; const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; const char dir[4] = {'D', 'R', 'U', 'L'}; const long long MOD = 1000000007; // const long long MOD = 998244353; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M, Q; cin >> N >> M >> Q; TwoEdgeConnectedComponents TECC(N); for (; M--;) { int x, y; cin >> x >> y; TECC.add_edge(--x, --y); } int n = TECC.build(); auto& C = TECC.C; auto& T = TECC.T; HeavyLightDecomposition HLD(n); for (int v = 0; v < n; v++) { for (int& u : T[v]) { if (v < u) { HLD.add_edge(v, u); } } } HLD.build(); atcoder::fenwick_tree FT(n); for (int i = 0; i < n; i++) { if (C[i].size() > 1) { FT.add(HLD.idx(i), 1); } } vector> mp(n); // 各連結成分で隣接点 v に向かう辺を持つ頂点 for (auto e : TECC.bridge) { int u = TECC[e.first], v = TECC[e.second]; mp[u][v] = e.first; mp[v][u] = e.second; } auto query = [&](int x, int y) -> bool { int sum = 0; int a = TECC[x], b = TECC[y]; if (HLD.tree_id[a] != HLD.tree_id[b]) return false; if (a == b) return false; auto q = [&](int l, int r) { sum += FT.sum(l, r); }; HLD.query_path(a, b, q, true); sum -= (C[a].size() > 1); sum -= (C[b].size() > 1); if (sum > 0) return false; int p = HLD.lca(a, b); if (p == b) { swap(a, b); swap(x, y); } if (p == a) { int diff = HLD.dep[b] - HLD.dep[a]; if (mp[a][HLD.la(b, diff - 1)] != x) return false; if (mp[b][HLD.la(b, 1)] != y) return false; } else { if (mp[a][HLD.la(a, 1)] != x) return false; if (mp[b][HLD.la(b, 1)] != y) return false; } return true; }; for (; Q--;) { int x, y; cin >> x >> y; cout << (query(--x, --y) ? "Yes" : "No") << '\n'; } return 0; }