結果

問題 No.1744 Selfish Spies 1 (à la Princess' Perfectionism)
ユーザー 👑 emthrmemthrm
提出日時 2021-11-14 21:24:01
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 409 ms / 5,000 ms
コード長 3,045 bytes
コンパイル時間 2,873 ms
コンパイル使用メモリ 214,556 KB
実行使用メモリ 18,184 KB
最終ジャッジ日時 2023-08-20 05:56:15
合計ジャッジ時間 7,767 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 6 ms
4,380 KB
testcase_17 AC 19 ms
4,376 KB
testcase_18 AC 29 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 34 ms
6,324 KB
testcase_25 AC 10 ms
4,380 KB
testcase_26 AC 6 ms
4,380 KB
testcase_27 AC 24 ms
4,380 KB
testcase_28 AC 237 ms
18,028 KB
testcase_29 AC 34 ms
4,380 KB
testcase_30 AC 41 ms
4,384 KB
testcase_31 AC 34 ms
4,376 KB
testcase_32 AC 38 ms
4,380 KB
testcase_33 AC 359 ms
18,088 KB
testcase_34 AC 405 ms
17,980 KB
testcase_35 AC 257 ms
18,184 KB
testcase_36 AC 334 ms
17,836 KB
testcase_37 AC 402 ms
17,820 KB
testcase_38 AC 409 ms
18,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0