結果
問題 | No.1744 Selfish Spies 1 (à la Princess' Perfectionism) |
ユーザー |
👑 ![]() |
提出日時 | 2021-11-14 21:24:01 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 495 ms / 5,000 ms |
コード長 | 3,045 bytes |
コンパイル時間 | 2,414 ms |
コンパイル使用メモリ | 210,504 KB |
最終ジャッジ日時 | 2025-01-25 17:59:02 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 39 |
ソースコード
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 1000000007; // constexpr int MOD = 998244353; constexpr int DY[]{1, 0, -1, 0}, DX[]{0, -1, 0, 1}; constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1}, DX8[]{0, -1, -1, -1, 0, 1, 1, 1}; template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; } template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; struct BipartiteMatching { std::vector<int> match; BipartiteMatching(const int n) : n(n), match(n, -1), graph(n), is_used(n, 0), is_alive(n, true) {} void add_edge(const int u, const int v) { graph[u].emplace_back(v); graph[v].emplace_back(u); } int solve() { int res = 0; for (int i = 0; i < n; ++i) { if (is_alive[i] && match[i] == -1) { ++t; res += dfs(i); } } return res; } void fix(const int ver) { is_alive[ver] = false; if (match[ver] != -1) { is_alive[match[ver]] = false; } } int enable(const int ver) { if (is_alive[ver]) return 0; is_alive[ver] = true; ++t; return dfs(ver) ? 1 : 0; } int disable(const int ver) { if (!is_alive[ver]) return 0; is_alive[ver] = false; if (match[ver] == -1) return 0; match[match[ver]] = -1; const int m = match[ver]; match[ver] = -1; ++t; return dfs(m) ? 0 : -1; } void no1744(int u_, int v_) { u = u_; v = v_; } private: const int n; int t = 0; std::vector<std::vector<int>> graph; std::vector<int> is_used, is_alive; int u = -1, v = -1; bool dfs(const int ver) { is_used[ver] = t; for (const int e : graph[ver]) { if (!is_alive[e] || (ver == u && e == v) || (ver == v && e == u)) continue; const int m = match[e]; if (m == -1 || (is_used[m] < t && dfs(m))) { match[ver] = e; match[e] = ver; return true; } } return false; } }; int main() { int n, m, l; cin >> n >> m >> l; vector<int> s(l), t(l); REP(i, l) cin >> s[i] >> t[i], --s[i], --t[i]; map<pair<int, int>, int> st; REP(i, l) st[{s[i], t[i]}] = i; BipartiteMatching bm(n + m); REP(i, l) bm.add_edge(s[i], t[i] + n); bm.solve(); vector<int> ans(l, true); REP(i, l) { if (bm.match[i] != -1) ans[st[{i, bm.match[i] - n}]] = false; } REP(i, l) { if (ans[i]) continue; bm.no1744(s[i], n + t[i]); ans[i] = bm.disable(s[i]) == 0 || bm.enable(s[i]) == 1; bm.no1744(-1, -1); bm.disable(s[i]); bm.enable(s[i]); } REP(i, l) cout << (ans[i] ? "Yes\n" : "No\n"); return 0; }