QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#597208#9424. Stop the Castle 2ucup-team112#RE 0ms3632kbC++2023.9kb2024-09-28 17:17:112024-09-28 17:17:12

Judging History

This is the latest submission verdict.

  • [2024-09-28 17:17:12]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 3632kb
  • [2024-09-28 17:17:11]
  • Submitted

answer

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #define INTERACTIVE

#include <bits/stdc++.h>
using namespace std;

namespace templates {
// type
using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pil = pair<int, ll>;
using Pli = pair<ll, int>;
using Pll = pair<ll, ll>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using qp = priority_queue<T, vector<T>, greater<T>>;
// clang-format off
#define vec(T, A, ...) vector<T> A(__VA_ARGS__);
#define vvec(T, A, h, ...) vector<vector<T>> A(h, vector<T>(__VA_ARGS__));
#define vvvec(T, A, h1, h2, ...) vector<vector<vector<T>>> A(h1, vector<vector<T>>(h2, vector<T>(__VA_ARGS__)));
// clang-format on

// for loop
#define fori1(a) for (ll _ = 0; _ < (a); _++)
#define fori2(i, a) for (ll i = 0; i < (a); i++)
#define fori3(i, a, b) for (ll i = (a); i < (b); i++)
#define fori4(i, a, b, c) for (ll i = (a); ((c) > 0 || i > (b)) && ((c) < 0 || i < (b)); i += (c))
#define overload4(a, b, c, d, e, ...) e
#define fori(...) overload4(__VA_ARGS__, fori4, fori3, fori2, fori1)(__VA_ARGS__)

// declare and input
// clang-format off
#define INT(...) int __VA_ARGS__; inp(__VA_ARGS__);
#define LL(...) ll __VA_ARGS__; inp(__VA_ARGS__);
#define STRING(...) string __VA_ARGS__; inp(__VA_ARGS__);
#define CHAR(...) char __VA_ARGS__; inp(__VA_ARGS__);
#define DOUBLE(...) double __VA_ARGS__; STRING(str___); __VA_ARGS__ = stod(str___);
#define VEC(T, A, n) vector<T> A(n); inp(A);
#define VVEC(T, A, n, m) vector<vector<T>> A(n, vector<T>(m)); inp(A);
// clang-format on

// const value
const ll MOD1   = 1000000007;
const ll MOD9   = 998244353;
const double PI = acos(-1);

// other macro
#if !defined(RIN__LOCAL) && !defined(INTERACTIVE)
#define endl "\n"
#endif
#define spa ' '
#define len(A) ll(A.size())
#define all(A) begin(A), end(A)

// function
vector<char> stoc(string &S) {
    int n = S.size();
    vector<char> ret(n);
    for (int i = 0; i < n; i++) ret[i] = S[i];
    return ret;
}
string ctos(vector<char> &S) {
    int n      = S.size();
    string ret = "";
    for (int i = 0; i < n; i++) ret += S[i];
    return ret;
}

template <class T>
auto min(const T &a) {
    return *min_element(all(a));
}
template <class T>
auto max(const T &a) {
    return *max_element(all(a));
}
template <class T, class S>
auto clamp(T &a, const S &l, const S &r) {
    return (a > r ? r : a < l ? l : a);
}
template <class T, class S>
inline bool chmax(T &a, const S &b) {
    return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
    return (a > b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chclamp(T &a, const S &l, const S &r) {
    auto b = clamp(a, l, r);
    return (a != b ? a = b, 1 : 0);
}

template <typename T>
T sum(vector<T> &A) {
    T tot = 0;
    for (auto a : A) tot += a;
    return tot;
}

template <typename T>
vector<T> compression(vector<T> X) {
    sort(all(X));
    X.erase(unique(all(X)), X.end());
    return X;
}

// input and output
namespace io {
// __int128_t
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
    std::ostream::sentry s(dest);
    if (s) {
        __uint128_t tmp = value < 0 ? -value : value;
        char buffer[128];
        char *d = std::end(buffer);
        do {
            --d;
            *d = "0123456789"[tmp % 10];
            tmp /= 10;
        } while (tmp != 0);
        if (value < 0) {
            --d;
            *d = '-';
        }
        int len = std::end(buffer) - d;
        if (dest.rdbuf()->sputn(d, len) != len) {
            dest.setstate(std::ios_base::badbit);
        }
    }
    return dest;
}

// vector<T>
template <typename T>
istream &operator>>(istream &is, vector<T> &A) {
    for (auto &a : A) is >> a;
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &A) {
    for (size_t i = 0; i < A.size(); i++) {
        os << A[i];
        if (i != A.size() - 1) os << ' ';
    }
    return os;
}

// vector<vector<T>>
template <typename T>
istream &operator>>(istream &is, vector<vector<T>> &A) {
    for (auto &a : A) is >> a;
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, vector<vector<T>> &A) {
    for (size_t i = 0; i < A.size(); i++) {
        os << A[i];
        if (i != A.size() - 1) os << endl;
    }
    return os;
}

// pair<S, T>
template <typename S, typename T>
istream &operator>>(istream &is, pair<S, T> &A) {
    is >> A.first >> A.second;
    return is;
}
template <typename S, typename T>
ostream &operator<<(ostream &os, pair<S, T> &A) {
    os << A.first << ' ' << A.second;
    return os;
}

// vector<pair<S, T>>
template <typename S, typename T>
istream &operator>>(istream &is, vector<pair<S, T>> &A) {
    for (size_t i = 0; i < A.size(); i++) {
        is >> A[i];
    }
    return is;
}
template <typename S, typename T>
ostream &operator<<(ostream &os, vector<pair<S, T>> &A) {
    for (size_t i = 0; i < A.size(); i++) {
        os << A[i];
        if (i != A.size() - 1) os << endl;
    }
    return os;
}

// tuple
template <typename T, size_t N>
struct TuplePrint {
    static ostream &print(ostream &os, const T &t) {
        TuplePrint<T, N - 1>::print(os, t);
        os << ' ' << get<N - 1>(t);
        return os;
    }
};
template <typename T>
struct TuplePrint<T, 1> {
    static ostream &print(ostream &os, const T &t) {
        os << get<0>(t);
        return os;
    }
};
template <typename... Args>
ostream &operator<<(ostream &os, const tuple<Args...> &t) {
    TuplePrint<decltype(t), sizeof...(Args)>::print(os, t);
    return os;
}

// io functions
void FLUSH() {
    cout << flush;
}

void print() {
    cout << endl;
}
template <class Head, class... Tail>
void print(Head &&head, Tail &&...tail) {
    cout << head;
    if (sizeof...(Tail)) cout << spa;
    print(std::forward<Tail>(tail)...);
}

template <typename T, typename S>
void prisep(vector<T> &A, S sep) {
    int n = A.size();
    for (int i = 0; i < n; i++) {
        cout << A[i];
        if (i != n - 1) cout << sep;
    }
    cout << endl;
}
template <typename T, typename S>
void priend(T A, S end) {
    cout << A << end;
}
template <typename T>
void prispa(T A) {
    priend(A, spa);
}
template <typename T, typename S>
bool printif(bool f, T A, S B) {
    if (f)
        print(A);
    else
        print(B);
    return f;
}

template <class... T>
void inp(T &...a) {
    (cin >> ... >> a);
}

} // namespace io
using namespace io;

// read graph
vector<vector<int>> read_edges(int n, int m, bool direct = false, int indexed = 1) {
    vector<vector<int>> edges(n, vector<int>());
    for (int i = 0; i < m; i++) {
        INT(u, v);
        u -= indexed;
        v -= indexed;
        edges[u].push_back(v);
        if (!direct) edges[v].push_back(u);
    }
    return edges;
}
vector<vector<int>> read_tree(int n, int indexed = 1) {
    return read_edges(n, n - 1, false, indexed);
}

template <typename T = long long>
vector<vector<pair<int, T>>> read_wedges(int n, int m, bool direct = false, int indexed = 1) {
    vector<vector<pair<int, T>>> edges(n, vector<pair<int, T>>());
    for (int i = 0; i < m; i++) {
        INT(u, v);
        T w;
        inp(w);
        u -= indexed;
        v -= indexed;
        edges[u].push_back({v, w});
        if (!direct) edges[v].push_back({u, w});
    }
    return edges;
}
template <typename T = long long>
vector<vector<pair<int, T>>> read_wtree(int n, int indexed = 1) {
    return read_wedges<T>(n, n - 1, false, indexed);
}

// yes / no
namespace yesno {

// yes
inline bool yes(bool f = true) {
    cout << (f ? "yes" : "no") << endl;
    return f;
}
inline bool Yes(bool f = true) {
    cout << (f ? "Yes" : "No") << endl;
    return f;
}
inline bool YES(bool f = true) {
    cout << (f ? "YES" : "NO") << endl;
    return f;
}

// no
inline bool no(bool f = true) {
    cout << (!f ? "yes" : "no") << endl;
    return f;
}
inline bool No(bool f = true) {
    cout << (!f ? "Yes" : "No") << endl;
    return f;
}
inline bool NO(bool f = true) {
    cout << (!f ? "YES" : "NO") << endl;
    return f;
}

// possible
inline bool possible(bool f = true) {
    cout << (f ? "possible" : "impossible") << endl;
    return f;
}
inline bool Possible(bool f = true) {
    cout << (f ? "Possible" : "Impossible") << endl;
    return f;
}
inline bool POSSIBLE(bool f = true) {
    cout << (f ? "POSSIBLE" : "IMPOSSIBLE") << endl;
    return f;
}

// impossible
inline bool impossible(bool f = true) {
    cout << (!f ? "possible" : "impossible") << endl;
    return f;
}
inline bool Impossible(bool f = true) {
    cout << (!f ? "Possible" : "Impossible") << endl;
    return f;
}
inline bool IMPOSSIBLE(bool f = true) {
    cout << (!f ? "POSSIBLE" : "IMPOSSIBLE") << endl;
    return f;
}

// Alice Bob
inline bool Alice(bool f = true) {
    cout << (f ? "Alice" : "Bob") << endl;
    return f;
}
inline bool Bob(bool f = true) {
    cout << (f ? "Bob" : "Alice") << endl;
    return f;
}

// Takahashi Aoki
inline bool Takahashi(bool f = true) {
    cout << (f ? "Takahashi" : "Aoki") << endl;
    return f;
}
inline bool Aoki(bool f = true) {
    cout << (f ? "Aoki" : "Takahashi") << endl;
    return f;
}

} // namespace yesno
using namespace yesno;

} // namespace templates
using namespace templates;

#ifndef ATCODER_MAXFLOW_HPP
#define ATCODER_MAXFLOW_HPP 1

#include <algorithm>
#include <cassert>
#include <limits>
#include <queue>
#include <vector>

#ifndef ATCODER_INTERNAL_QUEUE_HPP
#define ATCODER_INTERNAL_QUEUE_HPP 1

#include <vector>

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

#endif // ATCODER_INTERNAL_QUEUE_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

#endif // ATCODER_MAXFLOW_HPP

void solve() {
    INT(n, m, k);
    VEC(Pll, rook, n);
    VEC(Pll, obst, m);
    vec(ll, X, 0);
    vec(ll, Y, 0);
    for (auto [x, y] : rook) {
        X.push_back(x);
        Y.push_back(y);
    }
    for (auto [x, y] : obst) {
        X.push_back(x);
        Y.push_back(y);
    }
    X = compression(X);
    Y = compression(Y);
    for (auto &[x, y] : rook) {
        x = lower_bound(all(X), x) - X.begin();
        y = lower_bound(all(Y), y) - Y.begin();
    }
    for (auto &[x, y] : obst) {
        x = lower_bound(all(X), x) - X.begin();
        y = lower_bound(all(Y), y) - Y.begin();
    }

    int lx  = len(X);
    int ly  = len(Y);
    ll ans  = 0;
    using T = tuple<ll, ll, ll>;
    vvec(T, X_, lx, 0);
    vvec(T, Y_, ly, 0);
    fori(i, n) {
        auto [x, y] = rook[i];
        X_[x].push_back({y, 0, i});
        Y_[y].push_back({x, 0, i});
    }
    fori(i, m) {
        auto [x, y] = obst[i];
        X_[x].push_back({y, 1, i});
        Y_[y].push_back({x, 1, i});
    }

    int c = 0;
    vec(int, L, m, -1);
    vec(int, R, m, -1);
    fori(i, lx) {
        sort(all(X_[i]));
        int l = -1;
        int r = -1;
        fori(j, len(X_[i])) {
            auto [y, t, _] = X_[i][j];
            if (t == 0) {
                if (l == -1) {
                    l = j;
                } else {
                    r = j;
                    ans++;
                }
            }
        }
        if (l == -1) continue;
        fori(j, l + 1, r + 1) {
            auto [y, t, idx] = X_[i][j];
            if (t == 0) {
                c++;
            } else {
                L[idx] = c;
            }
        }
    }

    int xc = c;

    fori(i, ly) {
        sort(all(Y_[i]));
        int l = -1;
        int r = -1;
        fori(j, len(Y_[i])) {
            auto [x, t, _] = Y_[i][j];
            if (t == 0) {
                if (l == -1) {
                    l = j;
                } else {
                    r = j;
                    ans++;
                }
            }
        }
        if (l == -1) continue;
        fori(j, l + 1, r + 1) {
            auto [x, t, idx] = Y_[i][j];
            if (t == 0) {
                c++;
            } else {
                R[idx] = c;
            }
        }
    }
    atcoder::mf_graph<ll> G(c + 2);
    int s = c;
    int t = c + 1;
    fori(i, m) {
        if (L[i] == -1 or R[i] == -1) continue;
        G.add_edge(L[i], R[i], 1);
    }
    fori(i, xc) {
        G.add_edge(s, i, 1);
    }
    fori(i, xc, c) {
        G.add_edge(i, t, 1);
    }

    auto fl = G.flow(s, t);

    vec(ll, PP, 0);
    for (auto l : L) {
        if (l != -1) PP.push_back(l);
    }
    for (auto r : R) {
        if (r != -1) PP.push_back(r);
    }
    ll ma  = len(compression(PP));
    auto M = m;

    m -= k;
    ll two = min<ll>(fl, m);
    m -= two;

    ll minus = min(ma, 2 * two + m);

    print(ans - minus);
    set<Pll> two_edges;
    vec(bool, used_X, lx, false);
    vec(bool, used_Y, ly, false);
    for (auto &e : G.edges()) {
        if (e.flow == 1 and e.from != s and e.to != t) {
            two_edges.insert({e.from, e.to});
        }
    }

    m = M;
    vec(bool, rem, m, false);
    ll cc = m - k;
    fori(i, m) {
        if (cc > 0 and two_edges.count({L[i], R[i]})) {
            rem[i]       = true;
            used_X[L[i]] = true;
            used_Y[R[i]] = true;
            cc--;
        }
    }
    fori(i, m) {
        if (rem[i] or cc == 0) continue;
        if (L[i] != -1 and not used_X[L[i]]) {
            rem[i]       = true;
            used_X[L[i]] = true;
            cc--;
        }
        if (R[i] != -1 and not used_Y[R[i]]) {
            rem[i]       = true;
            used_Y[R[i]] = true;
            cc--;
        }
    }
    fori(i, m) {
        if (cc > 0 and !rem[i]) {
            rem[i] = true;
            cc--;
        }
    }

    vec(ll, ans_idx, 0);
    fori(i, m) {
        if (!rem[i]) ans_idx.push_back(i + 1);
    }
    print(ans_idx);
}

int main() {
#ifndef INTERACTIVE
    std::cin.tie(0)->sync_with_stdio(0);
#endif
    // std::cout << std::fixed << std::setprecision(12);
    int t;
    t = 1;
    std::cin >> t;
    while (t--) solve();
    return 0;
}

// // #pragma GCC target("avx2")
// // #pragma GCC optimize("O3")
// // #pragma GCC optimize("unroll-loops")
// // #define INTERACTIVE
//
// #include "kyopro-cpp/template.hpp"
//
// #include "atcoder/maxflow.hpp"
//
// void solve() {
//     INT(n, m, k);
//     VEC(Pll, rook, n);
//     VEC(Pll, obst, m);
//     vec(ll, X, 0);
//     vec(ll, Y, 0);
//     for (auto [x, y] : rook) {
//         X.push_back(x);
//         Y.push_back(y);
//     }
//     for (auto [x, y] : obst) {
//         X.push_back(x);
//         Y.push_back(y);
//     }
//     X = compression(X);
//     Y = compression(Y);
//     for (auto &[x, y] : rook) {
//         x = lower_bound(all(X), x) - X.begin();
//         y = lower_bound(all(Y), y) - Y.begin();
//     }
//     for (auto &[x, y] : obst) {
//         x = lower_bound(all(X), x) - X.begin();
//         y = lower_bound(all(Y), y) - Y.begin();
//     }
//
//     int lx  = len(X);
//     int ly  = len(Y);
//     ll ans  = 0;
//     using T = tuple<ll, ll, ll>;
//     vvec(T, X_, lx, 0);
//     vvec(T, Y_, ly, 0);
//     fori(i, n) {
//         auto [x, y] = rook[i];
//         X_[x].push_back({y, 0, i});
//         Y_[y].push_back({x, 0, i});
//     }
//     fori(i, m) {
//         auto [x, y] = obst[i];
//         X_[x].push_back({y, 1, i});
//         Y_[y].push_back({x, 1, i});
//     }
//
//     int c = 0;
//     vec(int, L, m, -1);
//     vec(int, R, m, -1);
//     fori(i, lx) {
//         sort(all(X_[i]));
//         int l = -1;
//         int r = -1;
//         fori(j, len(X_[i])) {
//             auto [y, t, _] = X_[i][j];
//             if (t == 0) {
//                 if (l == -1) {
//                     l = j;
//                 } else {
//                     r = j;
//                     ans++;
//                 }
//             }
//         }
//         if (l == -1) continue;
//         fori(j, l + 1, r + 1) {
//             auto [y, t, idx] = X_[i][j];
//             if (t == 0) {
//                 c++;
//             } else {
//                 L[idx] = c;
//             }
//         }
//     }
//
//     int xc = c;
//
//     fori(i, ly) {
//         sort(all(Y_[i]));
//         int l = -1;
//         int r = -1;
//         fori(j, len(Y_[i])) {
//             auto [x, t, _] = Y_[i][j];
//             if (t == 0) {
//                 if (l == -1) {
//                     l = j;
//                 } else {
//                     r = j;
//                     ans++;
//                 }
//             }
//         }
//         if (l == -1) continue;
//         fori(j, l + 1, r + 1) {
//             auto [x, t, idx] = Y_[i][j];
//             if (t == 0) {
//                 c++;
//             } else {
//                 R[idx] = c;
//             }
//         }
//     }
//     atcoder::mf_graph<ll> G(c + 2);
//     int s = c;
//     int t = c + 1;
//     fori(i, m) {
//         if (L[i] == -1 or R[i] == -1) continue;
//         G.add_edge(L[i], R[i], 1);
//     }
//     fori(i, xc) {
//         G.add_edge(s, i, 1);
//     }
//     fori(i, xc, c) {
//         G.add_edge(i, t, 1);
//     }
//
//     auto fl = G.flow(s, t);
//
//     vec(ll, PP, 0);
//     for (auto l : L) {
//         if (l != -1) PP.push_back(l);
//     }
//     for (auto r : R) {
//         if (r != -1) PP.push_back(r);
//     }
//     ll ma  = len(compression(PP));
//     auto M = m;
//
//     m -= k;
//     ll two = min<ll>(fl, m);
//     m -= two;
//
//     ll minus = min(ma, 2 * two + m);
//
//     print(ans - minus);
//     set<Pll> two_edges;
//     vec(bool, used_X, lx, false);
//     vec(bool, used_Y, ly, false);
//     for (auto &e : G.edges()) {
//         if (e.flow == 1 and e.from != s and e.to != t) {
//             two_edges.insert({e.from, e.to});
//         }
//     }
//
//     m = M;
//     vec(bool, rem, m, false);
//     ll cc = m - k;
//     fori(i, m) {
//         if (cc > 0 and two_edges.count({L[i], R[i]})) {
//             rem[i]       = true;
//             used_X[L[i]] = true;
//             used_Y[R[i]] = true;
//             cc--;
//         }
//     }
//     fori(i, m) {
//         if (rem[i] or cc == 0) continue;
//         if (L[i] != -1 and not used_X[L[i]]) {
//             rem[i]       = true;
//             used_X[L[i]] = true;
//             cc--;
//         }
//         if (R[i] != -1 and not used_Y[R[i]]) {
//             rem[i]       = true;
//             used_Y[R[i]] = true;
//             cc--;
//         }
//     }
//     fori(i, m) {
//         if (cc > 0 and !rem[i]) {
//             rem[i] = true;
//             cc--;
//         }
//     }
//
//     vec(ll, ans_idx, 0);
//     fori(i, m) {
//         if (!rem[i]) ans_idx.push_back(i + 1);
//     }
//     print(ans_idx);
// }
//
// int main() {
// #ifndef INTERACTIVE
//     std::cin.tie(0)->sync_with_stdio(0);
// #endif
//     // std::cout << std::fixed << std::setprecision(12);
//     int t;
//     t = 1;
//     std::cin >> t;
//     while (t--) solve();
//     return 0;
// }

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3632kb

input:

3
8 6 4
1 3
2 1
2 6
4 1
4 7
6 1
6 3
6 6
2 3
3 1
4 3
4 6
5 2
6 4
3 2 1
10 12
10 10
10 11
1 4
1 5
1 3 2
1 1
2 1
2 2
2 3

output:

4
2 3 5 6
2
2
0
2 3

result:

ok ok 3 cases (3 test cases)

Test #2:

score: -100
Runtime Error

input:

1224
11 17 14
7 3
4 2
8 13
3 15
3 4
5 11
10 2
3 3
8 6
7 11
2 3
10 4
1 3
12 1
2 5
11 9
11 6
11 10
8 15
1 5
9 14
4 11
1 6
10 7
7 6
11 4
8 4
1 11
18 3 2
14 8
2 14
13 13
9 12
14 12
5 6
8 1
10 5
8 6
8 9
6 6
7 5
12 11
6 11
13 5
1 10
7 6
14 5
6 15
2 4
11 1
1 6 4
14 14
13 9
9 3
10 12
7 5
8 13
9 14
1 9 8
4 9...

output:

7
3 4 5 6 7 8 9 10 11 12 13 15 16 17
15
2 3
0
3 4 5 6
0
2 3 4 5 6 7 8 9
11
1 3
8
1 2 3
0
1 2 3 4 5 6 7 8 9 10 11 12
1
5 6 7 9 10 11 12
8
17 18 19
1
1 2 3 4 5 6 7 8
7
6 8
10
13 14 15
1
10 11 12 13 14 15 16 17 18 19 20
0
1
1
2 3
0
5 6 7
7
8 12 13 14 15
2
10 11 12 13 14
4
3 4 5 6 7 8
1
18
1
4 5 6 7 8 9...

result: