QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#341608 | #898. 二分图最大匹配 | WRuperD# | WA | 3891ms | 88148kb | C++14 | 2.3kb | 2024-02-29 20:04:31 | 2024-02-29 20:04:35 |
Judging History
answer
// Problem: 18. 二分图最大匹配
// URL: https://qoj.ac/contest/1536/problem/898
// Writer: WRuperD
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const int mininf = 1e9 + 7;
#define int long long
#define pb emplace_back
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
inline void write(int x){if(x<0){x=~(x-1);putchar('-');}if(x>9)write(x/10);putchar(x%10+'0');}
#define put() putchar(' ')
#define endl puts("")
const int MAX = 2e6 + 10;
int n, m, s, t;
struct node{
int v, w, cp;
}; vector <node> g[MAX];
int dis[MAX];
bool bfs(){
for(int i = 1; i <= n; i++) dis[i] = mininf;
dis[s] = 0;
queue <int> q;
q.push(s);
while(!q.empty()){
int u = q.front();
q.pop();
for(auto V : g[u]){
if(V.w > 0 and dis[V.v] > dis[u] + 1){
dis[V.v] = dis[u] + 1;
q.push(V.v);
}
}
}
if(dis[t] == mininf) return 0;
return 1;
}
int cur[MAX];
int aug(int u, int now){
if(u == t) return now;
int ans = 0;
for(int &i = cur[u]; i < g[u].size(); i++){
int v = g[u][i].v, w = g[u][i].w, cp = g[u][i].cp;
if(dis[v] != dis[u] + 1) continue;
int ret = aug(v, min(w, now));
g[u][i].w -= ret, g[v][cp].w += ret;
now -= ret, ans += ret;
if(now <= 0) break;
}
return ans;
}
void add_edge(int u, int v, int w){
g[u].pb(node{v, w, g[v].size()});
g[v].pb(node{u, 0, g[u].size() - 1});
}
void solve(){
n = read(), m = read();
int e = read();
for(int i = 1; i <= e; i++){
int u = read() + 1, v = read() + 1;
add_edge(u + 1, n + v + 1, 1);
}
for(int i = 1; i <= n; i++){
add_edge(1, i + 1, 1);
}
for(int i = 1; i <= m; i++){
add_edge(n + i + 1, n + m + 2, 1);
}
int n2 = n;
n = n + m + 2;
s = 1, t = n;
int ans = 0;
while(bfs()){
for(int i = 1; i <= n; i++) cur[i] = 0;
ans += aug(1, inf);
}
write(ans), endl;
// write(n), endl;
for(int u = 1; u <= n2; u++){
for(auto V : g[u]){
if(!V.w and V.v - n2 - 1 - 1 >= 0){
write(u - 1 - 1), put(), write(V.v - n2 - 1 - 1), endl;
}
}
}
}
signed main(){
int t = 1;
while(t--) solve();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 3891ms
memory: 88148kb
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 0 54731 1 26066 2 89637 3 1717 4 68505 5 28330 6 55261 7 34703 8 42170 9 23249 10 90437 11 69580 12 72086 13 47593 14 29944 15 87183 16 763 17 2814 18 46044 19 75228 20 11487 21 72701 22 60611 23 36775 24 66081 25 45592 26 3321 27 88211 28 71467 29 47516 30 55528 31 83162 32 46298 33 26459 34...
result:
wrong output format Unexpected end of file - int32 expected