#line 1 "main.cpp" #include #line 2 "library/utility/eoln.cpp" constexpr char eoln = '\n'; #line 2 "library/utility/int_alias.cpp" #line 5 "library/utility/int_alias.cpp" using i8 = std::int8_t; using u8 = std::uint8_t; using i16 = std::int16_t; using i32 = std::int32_t; using i64 = std::int64_t; using u16 = std::uint16_t; using u32 = std::uint32_t; using u64 = std::uint64_t; using usize = std::size_t; using isize = std::ptrdiff_t; #line 2 "library/utility/int_infinity.cpp" #line 5 "library/utility/int_infinity.cpp" template constexpr T infty = std::numeric_limits::max() / Div; constexpr i32 infi32 = infty; constexpr i64 infi64 = infty; constexpr u32 infu32 = infty; constexpr u64 infu64 = infty; constexpr isize infisz = infty; constexpr usize infusz = infty; #line 2 "library/utility/int_literal.cpp" #line 6 "library/utility/int_literal.cpp" constexpr std::int8_t operator""_i8(unsigned long long n) noexcept { return static_cast(n); } constexpr std::int16_t operator""_i16(unsigned long long n) noexcept { return static_cast(n); } constexpr std::int32_t operator""_i32(unsigned long long n) noexcept { return static_cast(n); } constexpr std::int64_t operator""_i64(unsigned long long n) noexcept { return static_cast(n); } constexpr std::int8_t operator""_u8(unsigned long long n) noexcept { return static_cast(n); } constexpr std::uint16_t operator""_u16(unsigned long long n) noexcept { return static_cast(n); } constexpr std::uint32_t operator""_u32(unsigned long long n) noexcept { return static_cast(n); } constexpr std::uint64_t operator""_u64(unsigned long long n) noexcept { return static_cast(n); } constexpr isize operator""_iz(unsigned long long n) noexcept { return static_cast(n); } constexpr usize operator""_uz(unsigned long long n) noexcept { return static_cast(n); } #line 7 "main.cpp" #line 2 "library/utility/rep.cpp" #line 4 "library/utility/rep.cpp" class rep { struct rep_iterator { usize itr; constexpr rep_iterator(const usize pos) noexcept : itr(pos) {} constexpr void operator++() noexcept { ++itr; } constexpr bool operator!=(const usize &other) const noexcept { return itr != other; } constexpr usize operator*() const noexcept { return itr; } }; const rep_iterator first; const usize last; public: constexpr rep(const usize first_, const usize last_) noexcept : first(first_), last(last_) {} constexpr rep_iterator begin() const noexcept { return first; } constexpr usize end() const noexcept { return last; } }; #line 2 "library/utility/revrep.cpp" #line 4 "library/utility/revrep.cpp" class revrep { struct revrep_iterator { usize itr; constexpr revrep_iterator(const usize pos) noexcept : itr(pos) {} constexpr void operator++() noexcept { --itr; } constexpr bool operator!=(const usize &other) const noexcept { return itr != other; } constexpr usize operator*() const noexcept { return itr; } }; const revrep_iterator first; const usize last; public: constexpr revrep(const usize first_, const usize last_) noexcept : first(last_ - 1), last(first_ - 1) {} constexpr revrep_iterator begin() const noexcept { return first; } constexpr usize end() const noexcept { return last; } }; #line 10 "main.cpp" #line 2 "library/utility/scan.cpp" #line 4 "library/utility/scan.cpp" template T scan() { T x; std::cin >> x; return x; } #line 12 "main.cpp" #ifndef CL_DEBUG #define pdebug(...) #endif #line 1 "atcoder/maxflow.hpp" #line 9 "atcoder/maxflow.hpp" #line 1 "atcoder/internal_queue.hpp" #line 5 "atcoder/internal_queue.hpp" namespace atcoder { namespace internal { template struct simple_queue { std::vector payload; int pos = 0; void reserve(int n) { payload.reserve(n); } int size() const { return int(payload.size()) - pos; } bool empty() const { return pos == int(payload.size()); } void push(const T& t) { payload.push_back(t); } T& front() { return payload[pos]; } void clear() { payload.clear(); pos = 0; } void pop() { pos++; } }; } // namespace internal } // namespace atcoder #line 11 "atcoder/maxflow.hpp" namespace atcoder { template struct mf_graph { public: mf_graph() : _n(0) {} explicit mf_graph(int n) : _n(n), g(n) {} int add_edge(int from, int to, Cap cap) { assert(0 <= from && from < _n); assert(0 <= to && to < _n); assert(0 <= cap); int m = int(pos.size()); pos.push_back({from, int(g[from].size())}); int from_id = int(g[from].size()); int to_id = int(g[to].size()); if (from == to) to_id++; g[from].push_back(_edge{to, to_id, cap}); g[to].push_back(_edge{from, from_id, 0}); return m; } struct edge { int from, to; Cap cap, flow; }; edge get_edge(int i) { int m = int(pos.size()); assert(0 <= i && i < m); auto _e = g[pos[i].first][pos[i].second]; auto _re = g[_e.to][_e.rev]; return edge{pos[i].first, _e.to, _e.cap + _re.cap, _re.cap}; } std::vector edges() { int m = int(pos.size()); std::vector result; for (int i = 0; i < m; i++) { result.push_back(get_edge(i)); } return result; } void change_edge(int i, Cap new_cap, Cap new_flow) { int m = int(pos.size()); assert(0 <= i && i < m); assert(0 <= new_flow && new_flow <= new_cap); auto &_e = g[pos[i].first][pos[i].second]; auto &_re = g[_e.to][_e.rev]; _e.cap = new_cap - new_flow; _re.cap = new_flow; } Cap flow(int s, int t) { return flow(s, t, std::numeric_limits::max()); } Cap flow(int s, int t, Cap flow_limit) { assert(0 <= s && s < _n); assert(0 <= t && t < _n); assert(s != t); std::vector level(_n), iter(_n); internal::simple_queue que; auto bfs = [&]() { std::fill(level.begin(), level.end(), -1); level[s] = 0; que.clear(); que.push(s); while (!que.empty()) { int v = que.front(); que.pop(); for (auto e : g[v]) { if (e.cap == 0 || level[e.to] >= 0) continue; level[e.to] = level[v] + 1; if (e.to == t) return; que.push(e.to); } } }; auto dfs = [&](auto self, int v, Cap up) { if (v == s) return up; Cap res = 0; int level_v = level[v]; for (int &i = iter[v]; i < int(g[v].size()); i++) { _edge &e = g[v][i]; if (level_v <= level[e.to] || g[e.to][e.rev].cap == 0) continue; Cap d = self(self, e.to, std::min(up - res, g[e.to][e.rev].cap)); if (d <= 0) continue; g[v][i].cap += d; g[e.to][e.rev].cap -= d; res += d; if (res == up) return res; } level[v] = _n; return res; }; Cap flow = 0; while (flow < flow_limit) { bfs(); if (level[t] == -1) break; std::fill(iter.begin(), iter.end(), 0); Cap f = dfs(dfs, t, flow_limit - flow); if (!f) break; flow += f; } return flow; } std::vector min_cut(int s) { std::vector visited(_n); internal::simple_queue que; que.push(s); while (!que.empty()) { int p = que.front(); que.pop(); visited[p] = true; for (auto e : g[p]) { if (e.cap && !visited[e.to]) { visited[e.to] = true; que.push(e.to); } } } return visited; } private: int _n; struct _edge { int to, rev; Cap cap; }; std::vector> pos; std::vector> g; }; } // namespace atcoder #line 18 "main.cpp" void main_() { // main process const usize N = scan(); const usize M = scan(); atcoder::mf_graph graph(N + M + 2); const usize L = scan(); std::vector S(L), T(L); for (const auto i : rep(0, L)) { S[i] = scan() - 1; T[i] = scan() - 1; graph.add_edge(S[i] + 1, N + T[i] + 1, 1); } for (const auto i : rep(0, N)) graph.add_edge(0, i + 1, 1); for (const auto i : rep(0, M)) graph.add_edge(N + i + 1, N + M + 1, 1); const auto max_flow = graph.flow(0, N + M + 1); auto edges = graph.edges(); std::set needcheck; for (const auto i : rep(0, L)) if (edges[i].flow == 1) needcheck.emplace(i); std::vector is_ok(L, true); for (const auto e : needcheck) is_ok[e] = false; while (not needcheck.empty()) { for (const auto i : rep(0, L + N + M)) graph.change_edge(i, 1, 0); const auto f = *needcheck.begin(); needcheck.erase(f); graph.change_edge(f, 1, 1); const auto max_flow_sub = graph.flow(0, N + M + 1); if (max_flow_sub != max_flow) continue; is_ok[f] = true; edges = graph.edges(); for (const auto i : rep(0, L)) if (edges[i].flow == 0) { if (needcheck.find(i) != needcheck.end()) { is_ok[i] = true; needcheck.erase(i); } } } for (const auto e : is_ok) std::cout << (e ? "Yes" : "No") << eoln; // Dinic 法の実用的な計算量はオーダーから想定されるより小さいらしいが、わからん! } int main(void) { usize T = 1; // std::cin >> T; while (T--) main_(); }