#include // clang-format off std::ostream&operator<<(std::ostream&os,std::int8_t x){return os<<(int)x;} std::ostream&operator<<(std::ostream&os,std::uint8_t x){return os<<(int)x;} std::ostream&operator<<(std::ostream&os,const __int128_t &v){if(!v)os<<"0";__int128_t tmp=v<0?(os<<"-",-v):v;std::string s;while(tmp)s+='0'+(tmp%10),tmp/=10;return std::reverse(s.begin(),s.end()),os<std::ostream &operator<<(std::ostream&os,const std::pair&x){return os<<"("<std::ostream &operator<<(std::ostream&os,const std::vector&vec){os<<'[';for(int _=0,__= vec.size();_<__;++_)os<<(_ ?", ":"")<std::ostream &operator<<(std::ostream&os,const std::set&s){os<<'{';int _=0;for(const auto &x:s)os<<(_++ ? ", " : "")<std::ostream&operator<<(std::ostream &os,const std::array &arr) {os<<'['<void print(std::ostream&os,const Tup &x,std::index_sequence){(void)(int[]){(os<(x)<<", ",0)...};} templatestd::ostream &operator<<(std::ostream&os,const std::tuple &x) {static constexpr std::size_t N = sizeof...(Args);os<<"(";if constexpr(N>=2)print(os,x,std::make_index_sequence());return os<(x)<<")";} const std::string COLOR_RESET="\033[0m",BRIGHT_GREEN="\033[1;32m",BRIGHT_RED="\033[1;31m",BRIGHT_CYAN="\033[1;36m",NORMAL_CROSSED="\033[0;9;37m",ITALIC="\033[3m",BOLD="\033[1m",RED_BACKGROUND="\033[1;41m",NORMAL_FAINT="\033[0;2m"; #define func_LINE_FILE NORMAL_FAINT<<" in "<"< struct ListRange { using Iterator= typename std::vector::const_iterator; Iterator bg, ed; Iterator begin() const { return bg; } Iterator end() const { return ed; } size_t size() const { return std::distance(bg, ed); } const T &operator[](int i) const { return bg[i]; } }; template class CsrArray { std::vector csr; std::vector pos; public: CsrArray()= default; CsrArray(const std::vector &c, const std::vector &p): csr(c), pos(p) {} size_t size() const { return pos.size() - 1; } const ListRange operator[](int i) const { return {csr.begin() + pos[i], csr.begin() + pos[i + 1]}; } }; class StronglyConnectedComponents { std::vector> es; std::vector csr, pos, id; public: StronglyConnectedComponents(int n): csr(n, -2), id(n) {} void add_edge(int src, int dst) { es.push_back({src, dst}); } void build() { const int n= id.size(); std::vector g(es.size()), sep(n + 1), ord(n); for (auto [s, d]: es) ++sep[s]; for (int i= 0; i < n; ++i) sep[i + 1]+= sep[i]; for (auto [s, d]: es) g[--sep[s]]= d; std::vector dat(sep.begin(), sep.begin() + n); int k= n, p; for (int s= 0; s < n; ++s) if (csr[s] == -2) for (csr[p= s]= -1; p >= 0;) { if (dat[p] == sep[p + 1]) ord[--k]= p, p= csr[p]; else if (int q= g[dat[p]++]; csr[q] == -2) csr[q]= p, p= q; } sep.assign(n + 1, 0), pos= {p= 0}; for (auto [s, d]: es) ++sep[d]; for (int i= 0; i < n; ++i) sep[i + 1]+= sep[i]; for (auto [s, d]: es) g[--sep[d]]= s; for (int s: ord) if (dat[s] >= 0) { for (csr[k++]= s, dat[s]= -1; p < k; ++p) for (int v= csr[p], j= sep[v], u; j < sep[v + 1]; ++j) if (dat[u= g[j]] >= 0) dat[u]= -1, csr[k++]= u; pos.push_back(k); } for (int i= pos.size() - 1; i--;) while (k > pos[i]) id[csr[--k]]= i; } int components_num() const { return pos.size() - 1; } const ListRange block(int k) const { return {csr.begin() + pos[k], csr.begin() + pos[k + 1]}; } int belong(int i) const { return id[i]; } const CsrArray dag() const { std::vector> es_; for (auto [s, d]: es) if (s= id[s], d= id[d]; s != d) es_.push_back({s, d}); std::sort(es_.begin(), es_.end()), es_.erase(std::unique(es_.begin(), es_.end()), es_.end()); std::vector g(es_.size()), p(pos.size()); for (auto [s, d]: es_) ++p[s]; std::partial_sum(p.begin(), p.end(), p.begin()); for (auto [s, d]: es_) g[--p[s]]= d; return {g, p}; } }; class BipartiteMatching { std::vector> es; std::vector lmate, rmate; public: BipartiteMatching() {} BipartiteMatching(int L, int R): lmate(L, -1), rmate(R, -1) {} void add_edge(int l, int r) { es.push_back({l, r}); } void erase_edge(int l, int r) { auto it= std::find(es.begin(), es.end(), std::array{l, r}); if (assert(it != es.end()), es.erase(it); lmate[l] == r) lmate[l]= rmate[r]= -1; } template void build() { const int n= lmate.size(); std::vector g(es.size()), pos(n + 1), rt, pre, que(n); if constexpr (lex) std::sort(es.rbegin(), es.rend()); for (auto [l, r]: es) ++pos[l]; for (int i= 0; i < n; ++i) pos[i + 1]+= pos[i]; for (auto [l, r]: es) g[--pos[l]]= r; for (bool upd= true; upd;) { upd= false, rt.assign(n, -1), pre.assign(n, -1); int t= 0; for (int l= n; l--;) if (lmate[l] == -1) que[t++]= rt[l]= pre[l]= l; for (int i= 0; i < t; ++i) if (int l= que[i]; lmate[rt[l]] == -1) for (int j= pos[l], r, nl; j < pos[l + 1]; ++j) { if (nl= rmate[r= g[j]]; nl == -1) { for (upd= true; r != -1; l= pre[l]) rmate[r]= l, std::swap(lmate[l], r); break; } if (pre[nl] == -1) rt[que[t++]= nl]= rt[pre[nl]= l]; } } if constexpr (lex) { rt.assign(n, 1); for (int v= 0, l, r; v < n; ++v) if (int u= lmate[v]; u != -1) { for (pre.assign(n, lmate[v]= rmate[u]= -1), pre[l= v]= -2, que.assign(pos.begin(), pos.begin() + n);;) { if (que[l] == pos[l + 1]) l= pre[l]; else if (r= g[que[l]++], u= rmate[r]; u == -1) { for (; r != -1; l= pre[l]) rmate[r]= l, std::swap(lmate[l], r); break; } else if (rt[u] && pre[u] == -1) pre[u]= l, l= u; } rt[v]= 0; } } } inline size_t left_size() const { return lmate.size(); } inline size_t right_size() const { return rmate.size(); } inline int l_to_r(int l) const { return lmate[l]; } inline int r_to_l(int r) const { return rmate[r]; } std::vector> edges() const { return es; } std::vector> max_matching() const { std::vector> ret; for (int l= 0, n= lmate.size(); l < n; ++l) if (int r= lmate[l]; r != -1) ret.push_back({l, r}); return ret; } }; class DulmageMendelsohn { std::vector lblg, rblg; public: DulmageMendelsohn(const BipartiteMatching &bm) { const auto es= bm.edges(); const int n= bm.left_size(), m= bm.right_size(); std::vector g(es.size()), sep(n + 1), que(n + m); lblg.assign(n, -3), rblg.assign(m, -3); for (int l= n; l--;) if (bm.l_to_r(l) == -1) lblg[l]= -1; for (int r= m; r--;) if (bm.r_to_l(r) == -1) rblg[r]= -2; for (auto [l, r]: es) ++sep[l]; for (int i= 0; i < n; ++i) sep[i + 1]+= sep[i]; for (auto [l, r]: es) g[--sep[l]]= r; for (int l= n, i= 0, t= 0; l--;) if (bm.l_to_r(l) == -1) for (que[t++]= l; i < t; ++i) for (int v= que[i], j= sep[v], u, w; j < sep[v + 1]; ++j) if (rblg[u= g[j]] == -3) if (rblg[u]= -1, w= bm.r_to_l(u); w != -1 && lblg[w] == -3) lblg[que[t++]= w]= -1; sep.assign(m + 1, 0); for (auto [l, r]: es) ++sep[r]; for (int i= 0; i < m; ++i) sep[i + 1]+= sep[i]; for (auto [l, r]: es) g[--sep[r]]= l; for (int r= m, i= 0, t= 0; r--;) if (bm.r_to_l(r) == -1) for (que[t++]= r; i < t; ++i) for (int v= que[i], j= sep[v], u, w; j < sep[v + 1]; ++j) if (lblg[u= g[j]] == -3) if (lblg[u]= -2, w= bm.l_to_r(u); w != -1 && rblg[w] == -3) rblg[que[t++]= w]= -2; int t= 0; for (int l= n; l--;) if (lblg[l] == -3) lblg[l]= t, que[t++]= l; for (int r= m; r--;) if (rblg[r] == -3) rblg[r]= t, que[t++]= r + n; StronglyConnectedComponents scc(t); for (int i= t, r;;) { if (r= que[--i] - n; r < 0) break; scc.add_edge(i, lblg[bm.r_to_l(r)]); for (int j= sep[r]; j < sep[r + 1]; ++j) if (int l= g[j], k= lblg[l]; k >= 0) scc.add_edge(k, i); } scc.build(), t= scc.components_num(); debug(lblg); debug(rblg); for (int l= n, v; l--;) v= lblg[l], lblg[l]= v == -1 ? t + 1 : v == -2 ? 0 : scc.belong(v) + 1; for (int r= m, v; r--;) v= rblg[r], rblg[r]= v == -1 ? t + 1 : v == -2 ? 0 : scc.belong(v) + 1; } int componetns_num() const { return -1; /*todo*/ } int left_belong(int l) const { return lblg[l]; } int right_belong(int r) const { return rblg[r]; } }; using namespace std; namespace yukicoder1745 { signed main() { cin.tie(0); ios::sync_with_stdio(0); int N, M, L; cin >> N >> M >> L; BipartiteMatching bm(N, M); int S[L], T[L]; for (int i= 0; i < L; ++i) { cin >> S[i] >> T[i]; bm.add_edge(--S[i], --T[i]); } bm.build(); DulmageMendelsohn dm(bm); for (int i= 0; i < L; ++i) { cout << (dm.left_belong(S[i]) == dm.right_belong(T[i]) ? "Yes" : "No") << '\n'; } return 0; } } signed main() { cin.tie(0); ios::sync_with_stdio(0); yukicoder1745::main(); return 0; }