結果
| 問題 |
No.1744 Selfish Spies 1 (à la Princess' Perfectionism)
|
| コンテスト | |
| ユーザー |
kotamanegi
|
| 提出日時 | 2021-11-14 21:38:27 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 295 ms / 5,000 ms |
| コード長 | 8,765 bytes |
| コンパイル時間 | 3,391 ms |
| コンパイル使用メモリ | 163,412 KB |
| 実行使用メモリ | 11,112 KB |
| 最終ジャッジ日時 | 2024-11-30 06:47:41 |
| 合計ジャッジ時間 | 5,930 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 39 |
ソースコード
#line 2 "library/bits/stdc++.h"
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#line 2 "Contests/yukicoder_/6681/main.cpp"
using namespace std;
typedef string::const_iterator State;
#define eps 1e-8L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
#define REP(a, b) for (long long(a) = 0; (a) < (b); ++(a))
#define ALL(x) (x).begin(), (x).end()
#line 1 "library/atcoder/maxflow.hpp"
#line 5 "library/atcoder/maxflow.hpp"
#include <cassert>
#line 9 "library/atcoder/maxflow.hpp"
#line 1 "library/atcoder/internal_queue.hpp"
#line 5 "library/atcoder/internal_queue.hpp"
namespace atcoder {
namespace internal {
template <class T> struct simple_queue {
std::vector<T> 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 "library/atcoder/maxflow.hpp"
namespace atcoder {
template <class Cap> 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<edge> edges() {
int m = int(pos.size());
std::vector<edge> 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<Cap>::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<int> level(_n), iter(_n);
internal::simple_queue<int> 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<bool> min_cut(int s) {
std::vector<bool> visited(_n);
internal::simple_queue<int> 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<std::pair<int, int>> pos;
std::vector<std::vector<_edge>> g;
};
} // namespace atcoder
#line 17 "Contests/yukicoder_/6681/main.cpp"
using namespace atcoder;
#define int long long
void solve()
{
int n, m, l;
cin >> n >> m >> l;
vector<pair<int, int>> edges;
REP(i, l)
{
int a, b;
cin >> a >> b;
a--;
b--;
edges.push_back({a, b});
}
mf_graph<int> main_graph(n + m + 2);
REP(i, l)
{
main_graph.add_edge(edges[i].first, n + edges[i].second, 1);
}
REP(i, n)
{
main_graph.add_edge(n + m, i, 1);
}
REP(i, m)
{
main_graph.add_edge(n + i, n + m + 1, 1);
}
int expected_value = main_graph.flow(n + m, n + m + 1);
vector<bool> ans(l, true);
REP(i, l)
{
if (main_graph.get_edge(i).flow == 0)
{
continue;
}
assert(main_graph.get_edge(i).flow == 1);
assert(main_graph.get_edge(l + edges[i].first).flow == 1);
assert(main_graph.get_edge(l + n + edges[i].second).flow == 1);
main_graph.change_edge(i, 0, 0);
main_graph.change_edge(l + edges[i].first, 1, 0);
main_graph.change_edge(l + n + edges[i].second, 1, 0);
if (main_graph.flow(n + m, n + m + 1) == 1)
{
main_graph.change_edge(i, 1, 0);
}
else
{
main_graph.change_edge(i, 1, 1);
main_graph.change_edge(l + edges[i].first, 1, 1);
main_graph.change_edge(l + n + edges[i].second, 1, 1);
ans[i] = false;
}
}
REP(i, l)
{
if (ans[i] == true)
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
}
}
#undef int
// generated by oj-template v4.7.2
// (https://github.com/online-judge-tools/template-generator)
int main()
{
// Fasterize input/output script
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(100);
// scanf/printf user should delete this fasterize input/output script
int t = 1;
// cin >> t; // comment out if solving multi testcase
for (int testCase = 1; testCase <= t; ++testCase)
{
solve();
}
return 0;
}
kotamanegi