#include using namespace std; using ll = long long; using ld = long double; // -------------------------------------------------------- #define FOR(i,l,r) for (ll i = (l); i < (r); ++i) #define RFOR(i,l,r) for (ll i = (r)-1; (l) <= i; --i) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) RFOR(i,0,n) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) #define MIN(c) *min_element(ALL(c)) #define MAX(c) *max_element(ALL(c)) #define COUNT(c,v) count(ALL(c),(v)) #define SZ(c) ((ll)(c).size()) #define BIT(b,i) (((b)>>(i)) & 1) #define PCNT(b) __builtin_popcountll(b) #define P0(i) (((i) & 1) == 0) #define P1(i) (((i) & 1) == 1) #define LB(c,v) distance((c).begin(), lower_bound(ALL(c), (v))) #define UB(c,v) distance((c).begin(), upper_bound(ALL(c), (v))) #define UQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end()) #define elif else if #ifdef _LOCAL #define debug_bar cerr << "--------------------\n"; #define debug(x) cerr << "l." << __LINE__ << " : " << #x << " = " << (x) << '\n' #define debug_pair(x) cerr << "l." << __LINE__ << " : " << #x << " = (" << x.first << "," << x.second << ")\n"; template void debug_line(const vector& ans, int l, int r, int L = 0) { cerr << "l." << L << " :"; for (int i = l; i < r; i++) { cerr << ' ' << ans[i]; } cerr << '\n'; } #else #define cerr if (false) cerr #define debug_bar #define debug(x) #define debug_pair(x) template void debug_line([[maybe_unused]] const vector& ans, [[maybe_unused]] int l, [[maybe_unused]] int r, [[maybe_unused]] int L = 0) {} #endif template void input(T&... a) { (cin >> ... >> a); } void print() { cout << '\n'; } template void print(const T& a) { cout << a << '\n'; } template void print(const T& a, const Ts&... b) { cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; } template void cout_line(const vector& ans, int l, int r) { for (int i = l; i < r; i++) { if (i != l) { cout << ' '; } cout << ans[i]; } cout << '\n'; } template bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; } template bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; } template T SUM(const vector& A) { return accumulate(ALL(A), T(0)); } template vector cumsum(const vector& A, bool offset = true) { int N = A.size(); vector S(N+1, 0); for (int i = 0; i < N; i++) { S[i+1] = S[i] + A[i]; } if (not offset) { S.erase(S.begin()); } return S; } ll mod(ll x, ll m) { assert(m != 0); return (x % m + m) % m; } ll ceil(ll a, ll b) { if (b < 0) { return ceil(-a, -b); } assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); } ll floor(ll a, ll b) { if (b < 0) { return floor(-a, -b); } assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); } ll powint(ll x, ll n) { assert(n >= 0); if (n == 0) { return 1; }; ll res = powint(x, n>>1); res *= res; if (n & 1) { res *= x; } return res; } pair divmod(ll a, ll b) { assert(b != 0); ll q = floor(a, b); return make_pair(q, a - q * b); } ll bitlen(ll b) { if (b <= 0) { return 0; } return (64LL - __builtin_clzll(b)); } ll digit_len(ll n) { assert(n >= 0); if (n == 0) { return 1; } ll sum = 0; while (n > 0) { sum++; n /= 10; } return sum; } ll digit_sum(ll n) { assert(n >= 0); ll sum = 0; while (n > 0) { sum += n % 10; n /= 10; } return sum; } ll digit_prod(ll n) { assert(n >= 0); if (n == 0) { return 0; } ll prod = 1; while (n > 0) { prod *= n % 10; n /= 10; } return prod; } ll xor_sum(ll x) { assert(0 <= x); switch (x % 4) { case 0: return x; case 1: return 1; case 2: return x ^ 1; case 3: return 0; } assert(false); } string toupper(const string& S) { string T(S); for (int i = 0; i < (int)T.size(); i++) { T[i] = toupper(T[i]); } return T; } string tolower(const string& S) { string T(S); for (int i = 0; i < (int)T.size(); i++) { T[i] = tolower(T[i]); } return T; } int a2i(const char& c) { assert(islower(c)); return (c - 'a'); } int A2i(const char& c) { assert(isupper(c)); return (c - 'A'); } int d2i(const char& d) { assert(isdigit(d)); return (d - '0'); } char i2a(const int& i) { assert(0 <= i && i < 26); return ('a' + i); } char i2A(const int& i) { assert(0 <= i && i < 26); return ('A' + i); } char i2d(const int& i) { assert(0 <= i && i <= 9); return ('0' + i); } using P = pair; using VP = vector

; using VVP = vector; using VS = vector; using VVS = vector; using VI = vector; using VVI = vector; using VVVI = vector; using VLL = vector; using VVLL = vector; using VVVLL = vector; using VB = vector; using VVB = vector; using VVVB = vector; using VD = vector; using VVD = vector; using VVVD = vector; using VLD = vector; using VVLD = vector; using VVVLD = vector; const ld EPS = 1e-10; const ld PI = acosl(-1.0); constexpr ll MOD = 1000000007; // constexpr ll MOD = 998244353; constexpr int inf = (1 << 30) - 1; // 1073741824 - 1 constexpr ll INF = (1LL << 62) - 1; // 4611686018427387904 - 1 // -------------------------------------------------------- // #include // using namespace atcoder; // References: // // // Disjoint-set data structure (Union Find) // struct dsu { public: dsu() : N(0) {} explicit dsu(int n) : N(n), parent_or_size(n, -1), n_edge(n, 0) {} // 辺 (a, b) を張ってマージ成否を返す : amortized O(α(N)) bool merge(int a, int b) { assert(0 <= a && a < N); assert(0 <= b && b < N); int x = leader(a), y = leader(b); if (x == y) { n_edge[x]++; return false; } if (-parent_or_size[x] < -parent_or_size[y]) { swap(x, y); } parent_or_size[x] += parent_or_size[y]; parent_or_size[y] = x; n_edge[x] += n_edge[y] + 1; return true; } // 頂点 a, b が連結か判定する : amortized O(α(N)) bool same(int a, int b) { assert(0 <= a && a < N); assert(0 <= b && b < N); return leader(a) == leader(b); } // 頂点 a の属する連結成分のルートを返す : amortized O(α(N)) int leader(int a) { assert(0 <= a && a < N); if (parent_or_size[a] < 0) { return a; } return parent_or_size[a] = leader(parent_or_size[a]); } // 頂点 a が属する連結成分のサイズを返す : amortized O(α(N)) int size(int a) { assert(0 <= a && a < N); return -parent_or_size[leader(a)]; } // a が属する連結成分の辺の数を返す : amortized O(α(N)) int size_e(int a) { assert(0 <= a && a < N); return n_edge[leader(a)]; } // 「一つの連結成分の頂点番号リスト」のリストを返す : O(N) vector> groups() { vector leader_buf(N), group_size(N); for (int i = 0; i < N; i++) { leader_buf[i] = leader(i); group_size[leader_buf[i]]++; } vector> result(N); for (int i = 0; i < N; i++) { result[i].reserve(group_size[i]); } for (int i = 0; i < N; i++) { result[leader_buf[i]].push_back(i); } result.erase( remove_if(result.begin(), result.end(), [&](const vector& v) { return v.empty(); }), result.end()); return result; } private: int N; // [x < 0] -x が連結成分のサイズに対応 // [0 <= x] x が parent に対応 vector parent_or_size; vector n_edge; }; // References: // - LowLink: // // - Two-Edge-Connected Components // // // 二辺連結成分分解 (Two-Edge-Connected Components) // - O(N + M) // - 二辺連結成分で構成されるグラフは木になる struct TwoEdgeConnectedComponents { public: int N_cc = 0; // 二辺連結成分の数 vector>> G; // 元のグラフ: (to, edge_idx) vector> edges; // 元のグラフの辺集合: (u, v) TwoEdgeConnectedComponents(int N, int M) : N(N), M(M) { G.resize(N); ord.resize(N); low.resize(N); comp.resize(N, -1); edges.resize(M); } // 双方向に辺を張る // - amortized O(1) void add_edge(int u, int v, int edge_idx) { assert(0 <= u && u < N); assert(0 <= v && v < N); assert(0 <= edge_idx && edge_idx < M); G[u].emplace_back(v, edge_idx); G[v].emplace_back(u, edge_idx); edges[edge_idx] = {u, v}; } // 構築 // - O(N + M) void build() { // LowLink int k = 0; // 現在の DFS 訪問順序 vector used(N, false); auto dfs1 = [&](auto&& self, int u, int e_i) -> void { used[u] = true; ord[u] = low[u] = k++; for (const auto& [v, e_j] : G[u]) if (e_i != e_j) { if (not used[v]) { self(self, v, e_j); low[u] = min(low[u], low[v]); if (ord[u] < low[v]) { bridge.push_back(e_j); } } else { // 後退辺 low[u] = min(low[u], ord[v]); } } }; // Two-Edge-Connected Components auto dfs2 = [&](auto&& self, int u, int p, int e_i) -> void { used[u] = true; if (p == -1 || ord[p] < low[u]) { comp[u] = N_cc++; comp_edges.resize(N_cc); } else { comp[u] = comp[p]; comp_edges[comp[u]].push_back(e_i); } for (const auto& [v, e_j] : G[u]) if (e_i != e_j) { if (comp[v] == -1) { self(self, v, u, e_j); } else { // 後退辺 if (ord[u] > ord[v]) { comp_edges[comp[v]].push_back(e_j); } } } }; for (int u = 0; u < N; u++) { if (not used[u]) { dfs1(dfs1, u, -1); } } for (int u = 0; u < N; u++) { used[u] = false; } for (int u = 0; u < N; u++) { if (not used[u]) { dfs2(dfs2, u, -1, -1); } } } // 橋となる辺の番号の集合を返す // - O(1) vector get_bridges() const noexcept { return bridge; } // 二辺連結成分の番号リストを返す // - O(1) vector get_comp() const noexcept { return comp; } // 二辺連結成分における辺の番号の集合を返す(橋以外の辺が全て含まれる) // - O(1) vector> get_comp_edges() const noexcept { return comp_edges; } // 二辺連結成分を一つの頂点とみなしたグラフを返す // - O(N + M) // - このグラフは木となる vector>> get_tecc_graph() const noexcept { vector>> G_cc(N_cc); for (const auto& edge_idx : bridge) { const auto& [u, v] = edges[edge_idx]; int u_cc = comp[u]; int v_cc = comp[v]; G_cc[u_cc].emplace_back(v_cc, edge_idx); G_cc[v_cc].emplace_back(u_cc, edge_idx); } return G_cc; } private: int N, M; vector ord; // DFS 訪問順序 // lowlink: // DFS Tree の葉方向の辺を 0 回以上、(その後) 後退辺を 0〜1 回 // 通って到達できる全頂点における ord の最小値 vector low; vector bridge; // 橋となる辺の番号の集合 vector comp; // comp[u] := 頂点 u が属する二辺連結成分の番号 vector> comp_edges; // 二辺連結成分における辺の番号の集合 }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int N, M, Q; cin >> N >> M >> Q; vector> E(M); dsu uf(N); REP(i,M) { int u, v; cin >> u >> v; u--; v--; uf.merge(u, v); E[i] = {u, v}; } auto gs = uf.groups(); int n_g = SZ(gs); VVI memo_ans(n_g); VVI memo_edge(n_g); VI belong(N); REP(ig,n_g) { auto& g = gs[ig]; for (auto u : g) belong[u] = ig; } vector> xy(Q); REP(i,Q) { int u, v; cin >> u >> v; u--; v--; xy[i] = {u, v}; if (uf.same(u, v)) memo_ans[belong[u]].push_back(i); } REP(i,M) { auto [u, v] = E[i]; memo_edge[belong[u]].push_back(i); } VB ans(Q); VI index(N,-1); REP(ig,n_g) { auto& g = gs[ig]; ll n = SZ(g); ll m = SZ(memo_edge[ig]); REP(i,n) index[g[i]] = i; TwoEdgeConnectedComponents tecc(n, m); const auto& edges = tecc.edges; REP(i,m) { const auto& [u, v] = E[memo_edge[ig][i]]; tecc.add_edge(index[u], index[v], i); } tecc.build(); const vector& bridge = tecc.get_bridges(); dsu uf2(n); for (const auto& edge_idx : bridge) { const auto& [u, v] = edges[edge_idx]; uf2.merge(u, v); } for (const auto& i : memo_ans[ig]) { auto [x, y] = xy[i]; if (uf2.same(index[x], index[y])) ans[i] = true; } } REP(i,Q) { string ans2 = (ans[i] ? "Yes" : "No"); print(ans2); } return 0; }