QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#479612 | #898. 二分图最大匹配 | Justin# | WA | 1077ms | 19712kb | C++14 | 1.3kb | 2024-07-15 19:21:54 | 2024-07-15 19:21:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5, M = 4e5 + 5;
struct Edge {
int t, n, w;
} e[M << 1];
int tot = 1, n, s, t, h[N], cur[N], dis[N], que[N];
inline void add(int u, int v, int w) { e[++tot] = (Edge){v, h[u], w}, h[u] = tot; }
inline void eadd(int u, int v, int w) { add(u, v, w), add(v, u, 0); }
int bfs() {
memset(dis, 0x3f, sizeof(dis)), dis[que[1] = t] = 0;
for (int i = 1, sz = 1; i <= sz; ++i)
for (int j = h[que[i]]; j; j = e[j].n)
if (e[j ^ 1].w && dis[e[j].t] > n)
dis[que[++sz] = e[j].t] = dis[que[i]] + 1;
if (dis[s] > n) return 0;
memcpy(cur, h, sizeof(h));
return 1;
}
int dfs(int u, int lim) {
if (u == t) return lim;
int sum = 0;
for (int &i = cur[u]; i; i = e[i].n)
if (e[i].w && dis[u] - 1 == dis[e[i].t]) {
int ret = dfs(e[i].t, min(lim, e[i].w));
e[i].w -= ret, e[i ^ 1].w += ret, sum += ret;
if (!(lim -= ret)) return sum;
}
return sum;
}
int main() {
int n1, n2, m, ans = 0;
scanf("%d%d%d", &n1, &n2, &m), n = n1 + n2 + 2, s = n - 1, t = n;
for (int i = 1, u, v; i <= m; ++i) scanf("%d%d", &u, &v), ++u, ++v, v += n1, eadd(u, v, 1);
for (int i = 1; i <= n1; ++i) eadd(s, i, 1);
for (int i = 1; i <= n2; ++i) eadd(i + n1, t, 1);
while (bfs()) ans += dfs(s, n);
printf("%d\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1077ms
memory: 19712kb
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:
100000
result:
wrong output format Unexpected end of file - int32 expected