結果

問題 No.1745 Selfish Spies 2 (à la Princess' Perfectionism)
ユーザー KowerKoint2010KowerKoint2010
提出日時 2021-11-19 22:19:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 473 ms / 5,000 ms
コード長 8,966 bytes
コンパイル時間 2,796 ms
コンパイル使用メモリ 235,940 KB
実行使用メモリ 60,320 KB
最終ジャッジ日時 2024-06-10 09:26:30
合計ジャッジ時間 10,520 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 3 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 4 ms
6,944 KB
testcase_18 AC 3 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 8 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 5 ms
6,940 KB
testcase_28 AC 39 ms
10,964 KB
testcase_29 AC 4 ms
6,940 KB
testcase_30 AC 5 ms
6,940 KB
testcase_31 AC 5 ms
6,940 KB
testcase_32 AC 5 ms
6,944 KB
testcase_33 AC 36 ms
10,980 KB
testcase_34 AC 35 ms
10,836 KB
testcase_35 AC 38 ms
10,676 KB
testcase_36 AC 39 ms
10,668 KB
testcase_37 AC 38 ms
10,672 KB
testcase_38 AC 34 ms
10,784 KB
testcase_39 AC 21 ms
7,168 KB
testcase_40 AC 30 ms
9,880 KB
testcase_41 AC 29 ms
9,892 KB
testcase_42 AC 68 ms
16,428 KB
testcase_43 AC 99 ms
21,056 KB
testcase_44 AC 139 ms
26,636 KB
testcase_45 AC 350 ms
42,796 KB
testcase_46 AC 356 ms
42,484 KB
testcase_47 AC 460 ms
59,580 KB
testcase_48 AC 473 ms
59,720 KB
testcase_49 AC 149 ms
18,988 KB
testcase_50 AC 133 ms
19,292 KB
testcase_51 AC 41 ms
9,052 KB
testcase_52 AC 44 ms
13,388 KB
testcase_53 AC 49 ms
13,228 KB
testcase_54 AC 142 ms
26,060 KB
testcase_55 AC 143 ms
26,080 KB
testcase_56 AC 277 ms
25,384 KB
testcase_57 AC 456 ms
59,664 KB
testcase_58 AC 445 ms
60,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "Contests/yukicoder_/6654/main.cpp"
/* #define aclmodint */
/* #define aclsegtree */
/* #include <atcoder/all> */
/* using namespace atcoder; */

#include <atcoder/dsu>
#include <atcoder/maxflow>
#include <atcoder/scc>
using namespace atcoder;

#line 1 "library/me/template.cpp"
#include <bits/stdc++.h>
using namespace std;

#define REP(a,b) for(int a = 0;a < (int)(b);++a)
#define FOR(i,a,b) for(ll i = a; i < (ll)(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define END(a) { print(a); return; }
#define DBG(a) { cerr << #a << ": "; dbg(a); }
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using ll = long long;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
using VD = vector<double>;
using VVD = vector<VD>;
using VVVD = vector<VVD>;
using VS = vector<string>;
using VVS = vector<VS>;
using VVVS = vector<VVS>;
using VC = vector<char>;
using VVC = vector<VC>;
using VVVC = vector<VVC>;
using P = pair<int, int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VVVP = vector<VVP>;
using LP = pair<ll, ll>;
using VLP = vector<LP>;
using VVLP = vector<VLP>;
using VVVLP = vector<VVLP>;
constexpr int INF = 1001001001;
constexpr ll LINF = 1001001001001001001ll;
constexpr int DX[] = {1, 0, -1, 0};
constexpr int DY[] = {0, 1, 0, -1};

#ifdef aclmodint

using MI7 = modint1000000007;
using V7 = vector<MI7>;
using VV7 = vector<V7>;
using VVV7 = vector<VV7>;
using MI3 = modint998244353;
using V3 = vector<MI3>;
using VV3 = vector<V3>;
using VVV3 = vector<VV3>;

ostream &operator<<(ostream &os, const modint &x) {
    os << x.val();
    return os;
}

ostream &operator<<(ostream &os, const MI3 &x) {
    os << x.val();
    return os;
}

ostream &operator<<(ostream &os, const MI7 &x) {
    os << x.val();
    return os;
}

istream &operator>>(istream &is, modint &x) {
    int y; is >> y;
    x = y;
    return is;
}

istream &operator>>(istream &is, MI3 &x) {
    int y; is >> y;
    x = y;
    return is;
}

istream &operator>>(istream &is, MI7 &x) {
    int y; is >> y;
    x = y;
    return is;
}

#endif

void print() { cout << '\n'; }
template<class T>
void print(const T &t) { cout << t << '\n'; }
template<class Head, class... Tail>
void print(const Head &head, const Tail &... tail) {
    cout << head << ' ';
    print(tail...);
}

void dbg() { cout << '\n'; }
template<class T>
void dbg(const T &t) { cerr << t << '\n'; }
template<class Head, class... Tail>
void dbg(const Head &head, const Tail &... tail) {
    cerr << head << ' ';
    dbg(tail...);
}

template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
    os << p.first << " " << p.second;
    return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
    is >> p.first >> p.second;
    return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
    for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != (int) v.size() ? " " : "");
    }
    return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
    for(T &in : v) is >> in;
    return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template <typename T>
pair<VI, vector<T>> compress(const vector<T> &a) {
    int n = a.size();
    vector<T> x;
    REP(i, n) x.push_back(a[i]);
    sort(ALL(x)); x.erase(unique(ALL(x)), x.end());
    VI res(n);
    REP(i, n) res[i] = lower_bound(ALL(x), a[i]) - x.begin();
    return make_pair(res, x);
}

#ifdef aclsegtree
template<typename S>
struct value_size { S value; int size; };

template<typename S>
S min_op(S l, S r) { return min(l, r); };
template<typename S>
S max_op(S l, S r) { return max(l, r); };
template<typename S>
S sum_op(S l, S r) { return l + r; };
template<typename S>
value_size<S> sum_op_size(value_size<S> l, value_size<S> r) {
    return {l.value + r.value, l.size + r.size};
};
template<typename S>
value_size<S> min_op_size(value_size<S> l, value_size<S> r) {
    return {min(l.value, r.value), l.size + r.size};
};
template<typename S>
value_size<S> max_op_size(value_size<S> l, value_size<S> r) {
    return {max(l.value, r.value), l.size + r.size};
};

template<typename S>
S min_e() { return  numeric_limits<S>::max(); };
template<typename S>
S max_e() { return numeric_limits<S>::min(); };
template<typename S>
S sum_e() { return 0; }
template<typename S>
value_size<S> sum_e_size() { return {0, 0}; }
template<typename S>
value_size<S> min_e_size() { return {numeric_limits<S>::max(), 0}; }
template<typename S>
value_size<S> max_e_size() { return {numeric_limits<S>::min(), 0}; }

template<typename S, typename F>
S chmin_mapping(F f, S x) { return min(x, f); }
template<typename S, typename F>
S chmax_mapping(F f, S x) { return max(x, f); }
template<typename S, typename F>
S add_mapping(F f, S x) { return x + f; }
template<typename S, typename F>
value_size<S> add_mapping_size(F f, value_size<S> x) {
    return {x.value + x.size * f, x.size};
}

template<typename F>
F chmin_composition(F f, F g) { return min(f, g); }
template<typename F>
F chmax_composition(F f, F g) { return max(f, g); }
template<typename F>
F add_composition(F f, F g) { return f + g; }

template<typename F>
F chmin_id() { return numeric_limits<F>::max(); }
template<typename F>
F chmax_id() { return numeric_limits<F>::min(); }
template<typename F>
F add_id() { return 0; }

template<typename S>
using RSumQ = segtree<S, sum_op<S>, sum_e<S>>;
template<typename S>
using RMaxQ = segtree<S, max_op<S>, max_e<S>>;
template<typename S>
using RMinQ = segtree<S, min_op<S>, min_e<S>>;

template<typename S, typename F>
using RAddSumQ = lazy_segtree<value_size<S>, sum_op_size<S>, sum_e_size<S>,
    F, add_mapping_size<S, F>, add_composition<F>, add_id<F>>;
template<typename S, typename F>
using RAddMinQ = lazy_segtree<S, min_op<S>, min_e<S>,
    F, add_mapping<S, F>, add_composition<F>, add_id<F>>;
template<typename S, typename F>
using RAddMaxQ = lazy_segtree<S, max_op<S>, max_e<S>,
    F, add_mapping<S, F>, add_composition<F>, add_id<F>>;
template<typename S, typename F>
using RMinMinQ = lazy_segtree<S, min_op<S>, min_e<S>,
    F, chmin_mapping<S, F>, chmin_composition<F>, chmin_id<F>>;
template<typename S, typename F>
using RMaxMaxQ = lazy_segtree<S, max_op<S>, max_e<S>,
    F, chmax_mapping<S, F>, chmax_composition<F>, chmax_id<F>>;
#endif
#line 12 "Contests/yukicoder_/6654/main.cpp"

void solve(){
    int n, m, l; cin >> n >> m >> l;
    mf_graph<int> mf(n + m + 2);
    scc_graph scc(n + m);
    VVI graph(n + m), rgraph(n + m);
    REP(i, l) {
        int s, t; cin >> s >> t; s--; t--;
        mf.add_edge(s, n + t, 1);
        scc.add_edge(s, n + t);
        graph[s].push_back(n + t);
        rgraph[n + t].push_back(s);
    }
    REP(i, n) mf.add_edge(n + m, i, 1);
    REP(i, m) mf.add_edge(n + i, n + m + 1, 1);
    mf.flow(n + m, n + m + 1);
    VI unmatch(n + m, 1);
    REP(i, l) {
        atcoder::mf_graph<int>::edge e = mf.get_edge(i);
        if(e.flow) {
            scc.add_edge(e.to, e.from);
            graph[e.to].push_back(e.from);
            rgraph[e.from].push_back(e.to);
            unmatch[e.from] = unmatch[e.to] = 0;
        }
    }
    VI from_unmatch(n + m);
    dsu uni(n + m);
    function<void(int)> dfs = [&](int i) {
        if(from_unmatch[i]) return;
        from_unmatch[i] = 1;
        for(int to : graph[i]) {
            uni.merge(i, to);
            dfs(to);
        }
    };
    REP(i, n + m) if(unmatch[i]) {
        dfs(i);
    }
    VI to_unmatch(n + m);
    swap(from_unmatch, to_unmatch);
    swap(graph, rgraph);
    REP(i, n + m) {
        if(unmatch[i]) dfs(i);
    }
    swap(from_unmatch, to_unmatch);
    swap(graph, rgraph);
    VVI groups = scc.scc();
    VI group_num(n + m);
    REP(i, groups.size()) {
        REP(j, groups[i].size()) {
            group_num[groups[i][j]] = i;
            if(j) uni.merge(groups[i][j], groups[i][j - 1]);
        }
    }
    VI from_size(n + m), to_size(n + m);
    REP(i, l) {
        mf_graph<int>::edge e = mf.get_edge(i);
        if(e.flow) {
            from_size[from_unmatch[e.from]]++;
            to_size[to_unmatch[e.from]]++;
        }
    }
    REP(i, l) {
        mf_graph<int>::edge e = mf.get_edge(i);
        if(uni.same(e.from, e.to)) print("Yes");
        else print("No");
    }
}

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