QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#605179#8759. 小班课UESTC_NLNSCompile Error//C++145.0kb2024-10-02 15:57:452024-10-02 15:57:45

Judging History

你现在查看的是最新测评结果

  • [2024-10-02 15:57:45]
  • 评测
  • [2024-10-02 15:57:45]
  • 提交

answer

#include <limits>
#include <queue>
#include <vector>
using namespace std;
using i64 = long long;
using ll = long long;
const int maxn = 1503;
const int maxm = 600 * 600 * 2;
const int inf = 0x3f3f3f3f;

struct MCMF {

    struct edge {
        int to, cap, cost, rev;
        // edge() {}
        // edge(int to, int _cap, int _cost, int _rev) : to(to), cap(_cap), cost(_cost), rev(_rev) {}
    };

    int V, H[maxn + 5], dis[maxn + 5], PreV[maxn + 5], PreE[maxn + 5];
    vector<edge> G[maxn + 5];

    void init(int n) {
        V = n;
        for (int i = 0; i <= V; ++i) G[i].clear();
    }

    int add(int from, int to, int cap, int cost) {
        int t = G[from].size();
        G[from].emplace_back(edge{to, cap, cost, (int)G[to].size()});

        G[to].emplace_back(edge{from, 0, -cost, (int)G[from].size() - 1});
        return t;
    }

    int mcmf(int s, int t) {
        int res = 0, flow = 0;
        fill(H, H + 1 + V, 0);
        int f = inf;
        while (f) {
            priority_queue<pair<int, int>> q;
            fill(dis, dis + 1 + V, inf);
            dis[s] = 0;
            q.push(pair<int, int>(0, s));
            while (!q.empty()) {
                pair<int, int> now = q.top();
                q.pop();
                int v = now.second, Size;
                if (dis[v] < -now.first) continue;
                Size = G[v].size();
                for (int i = 0; i < Size; ++i) {
                    edge e = G[v][i];
                    if (e.cap > 0 && dis[e.to] > dis[v] + e.cost + H[v] - H[e.to]) {
                        dis[e.to] = dis[v] + e.cost + H[v] - H[e.to];
                        PreV[e.to] = v;
                        PreE[e.to] = i;
                        q.push(pair<int, int>(-dis[e.to], e.to));
                    }
                }
            }
            if (dis[t] == inf) break;
            for (int i = 0; i <= V; ++i) H[i] += dis[i];
            int d = f;
            for (int v = t; v != s; v = PreV[v]) d = min(d, G[PreV[v]][PreE[v]].cap);
            f -= d;
            flow += d;
            res += d * H[t];
            for (int v = t; v != s; v = PreV[v]) {
                edge& e = G[PreV[v]][PreE[v]];
                e.cap -= d;
                G[v][e.rev].cap += d;
            }
        }
        return flow;
    }
};

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f

using namespace std;
const int N = 1505;
vector<int> g[N];
int c[N];
int b[N];
int n, m;

vector<int> get_ans() {
    vector<int> b1(m + 1);
    for (int i = 1; i <= m; ++i) b1[i] = b[i];
    queue<int> q;
    vector<int> ans;
    vector<int> cur(n + 1, 0);
    vector<vector<int>> w(m + 1);

    ans.reserve(n);

    auto get = [&](int i) {
        return g[i][cur[i]];
    };
    for (int i = 1; i <= m; ++i) {
        if (b1[i] == 0) q.push(i);
    }
    for (int i = 1; i <= n; ++i) {
        if (c[i] == 0) continue;
        int w1 = g[i][cur[i]];
        if (w1 == c[i]) {
            // assert(b1[w1] > 0);
            b1[w1]--;
            if (b1[w1] == 0) q.push(w1);
            ans.push_back(i);
        } else {
            w[w1].push_back(i);
        }
    }

    while (q.size()) {
        int f = q.front();
        q.pop();
        for (const auto u : w[f]) {
            while (b1[get(u)] == 0) {
                cur[u]++;
            }
            int w1 = get(u);
            if (w1 == c[u]) {
                // assert(b1[w1] > 0);
                b1[w1]--;
                if (b1[w1] == 0) q.push(w1);
                ans.push_back(u);
            } else {
                w[w1].push_back(u);
            }
        }
        w[f].clear();
    }

    for (int i = 1; i <= n; ++i) {
        if (c[i] == 0) ans.push_back(i);
    }
    return ans;
}

int s, t;

void INIT() {
    s = n + m + 1, t = n + m + 2;
}

void solve() {
    cin >> n >> m;
    INIT();
    vector<vector<int>> as(n + 1, vector<int>(m + 1));
    MCMF mcfg(t + 2);
    for (int i = 1; i <= n; ++i) g[i].clear();
    for (int i = 1; i <= m; ++i) cin >> b[i], mcfg.add(n + i, t, b[i], 0);
    for (int i = 1; i <= n; ++i) {
        mcfg.add(s, i, 1, 0);
        int k;
        cin >> k;
        g[i].reserve(k);
        int la = 0;
        for (int j = 1, tmp; j <= k; ++j) {
            cin >> tmp;
            g[i].push_back(tmp);
            // mcfg.add(i, n + tmp, 1, j);
            as[i][tmp] = mcfg.add(i, n + tmp, 1, j);
        }
    }

    memset(c, 0, sizeof(c));
    int flow = mcfg.mcmf(s, t);
    for (int i = 1; i <= n; ++i) {
        for (int x : g[i]) {
            if (mcfg.G[i][as[i][x]].cap == 0) c[i] = x;
        }
    }
    cout << flow << '\n';
    vector<int> ans = get_ans();
    for (auto u : ans) {
        cout << u << " ";
    }
    cout << '\n';
    // puts("");
}

int main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);

    int t;
    cin >> t;
    while (t--) solve();
}
/*
1
5 4
1 1 1 1

1 1
3 3 1 2
1 1
2 1 3
4 1 2 3 4
*/

詳細信息

answer.code: In function ‘void solve()’:
answer.code:152:20: error: no matching function for call to ‘MCMF::MCMF(int)’
  152 |     MCMF mcfg(t + 2);
      |                    ^
answer.code:11:8: note: candidate: ‘MCMF::MCMF()’
   11 | struct MCMF {
      |        ^~~~
answer.code:11:8: note:   candidate expects 0 arguments, 1 provided
answer.code:11:8: note: candidate: ‘MCMF::MCMF(const MCMF&)’
answer.code:11:8: note:   no known conversion for argument 1 from ‘int’ to ‘const MCMF&’
answer.code:11:8: note: candidate: ‘MCMF::MCMF(MCMF&&)’
answer.code:11:8: note:   no known conversion for argument 1 from ‘int’ to ‘MCMF&&’