QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#482496#898. 二分图最大匹配hcngRE 0ms0kbC++142.2kb2024-07-17 19:48:312024-07-17 19:48:31

Judging History

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

  • [2024-07-17 19:48:31]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-07-17 19:48:31]
  • 提交

answer

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


#define INF 0x7fffffff
char *p1, *p2, buf[1000000];
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++)
inline int read() {int x=0;char c=gc();while(!isdigit(c))c=gc();while(isdigit(c))x=x*10+c-'0',c=gc();return x;}
#define pc(c) putchar(c)
void write(int x) {if(x>9)write(x/10);pc('0'+x%10);}

int head[200010], cur[200010], tot = 1;
int dis[200010];
struct Edge {int fr, to, nxt, f, c;} e[400010];
int S, T;

inline void add_edge(int u, int v, int c) {
    e[++tot] = {u, v, head[u], 0, c};
    head[u] = tot;
    e[++tot] = {v, u, head[v], 0, 0};
    head[v] = tot;
}

inline bool bfs() {
    memset(dis, 0, sizeof(dis));
    queue<int> Q; Q.push(S); dis[S] = 1;
    while (!Q.empty()) {
        int u = Q.front(); Q.pop();
        for (int i = head[u]; i; i = e[i].nxt) {
            int v = e[i].to;
            if (e[i].c - e[i].f == 0) continue;
            if (!dis[v]) dis[v] = dis[u] + 1, Q.push(v);
        }
    }
    return dis[T] != 0;
}

int dfs(int u, int f) {
    if (u == T || !f) return f;
    int ret = 0;
    for (int &i = cur[u]; i && ret < f; i = e[i].nxt) {
        int v = e[i].to, d;
        if (dis[u] + 1 == dis[v] && (d = dfs(v, min(e[i].c - e[i].f, f - ret)))) {
            ret += d;
            e[i].f += d;
            e[i ^ 1].f -= d;
        }
    }
    return ret;
}

inline int dinic() {
    int f = 0;
    while (bfs()) {
        memcpy(cur, head, sizeof(cur));
        f += dfs(S, INF);
    }
    return f;
}

int l, r, m;

int main() {
    l = read(), r = read(), m = read();
    for (int i = 1; i <= m; i++) {
        int a = read() + 1, b = read() + 1;
        add_edge(a, l + b, 1);
    }
    S = l + r + 1, T = l + r + 2;
    for (int i = 1; i <= l; i++) {
        add_edge(S, i, 1);
    }
    for (int i = 1; i <= r; i++) {
        add_edge(l + i, T, 1);
    }
    write(dinic()); pc('\n');
    for (int i = 2; i <= tot; i++) {
        if (e[i].fr == S || e[i].to == T) continue;
        if (e[i].f == 1) {
            write(e[i].fr - 1), pc(' ');
            write(e[i].to - 1 - l), pc('\n');
        }
    }
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

100000 100000 200000
78474 45795
32144 46392
92549 13903
73460 34144
96460 92850
56318 77066
77529 84436
76342 51542
77506 99268
76410 89381
1778 61392
43607 96135
84268 74827
14857 35966
32084 94908
19876 174
1481 94390
12423 55019
64368 92587
81295 7902
25432 46032
36293 61128
73555 84836
8418 102...

output:


result: