QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#480776 | #898. 二分图最大匹配 | zyz07# | WA | 1714ms | 53680kb | C++17 | 2.0kb | 2024-07-16 18:47:53 | 2024-07-16 18:47:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define For(Ti,Ta,Tb) for(auto Ti=(Ta);Ti<=(Tb);++Ti)
#define Dec(Ti,Ta,Tb) for(auto Ti=(Ta);Ti>=(Tb);--Ti)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define range(Tx) begin(Tx),end(Tx)
using ll=long long;
struct MaxFlow{
const int n;
struct Edge{
int v;
ll w;
};
vector<Edge> e;
vector<vector<int>> g;
MaxFlow(int n):n(n),g(n){}
void add_edge(int u,int v,ll w){
g[u].push_back(e.size());
e.push_back({v,w});
g[v].push_back(e.size());
e.push_back({u,0});
}
vector<int> dis,now;
bool bfs(int s,int t){
dis.assign(n,int(1e9));
queue<int> q;
dis[s]=0;
q.push(s);
while(q.size()){
int u=q.front();
q.pop();
for(int i:g[u]){
if(e[i].w&&dis[e[i].v]==int(1e9)){
dis[e[i].v]=dis[u]+1;
q.push(e[i].v);
if(e[i].v==t){
return 1;
}
}
}
}
return 0;
}
ll dinic(int u,int t,ll flow){
if(u==t){
return flow;
}
ll rest=flow;
for(int i=now[u];i<int(g[u].size())&&rest;++i){
now[u]=i;
int j=g[u][i];
auto [v,w]=e[j];
if(w&&dis[v]==dis[u]+1){
ll k=dinic(v,t,min(rest,w));
if(!k){
dis[v]=-1;
}else{
e[j].w-=k;
e[j^1].w+=k;
rest-=k;
}
}
}
return flow-rest;
}
ll flow(int s,int t){
ll ans=0;
while(bfs(s,t)){
now.assign(n,0);
ans+=dinic(s,t,numeric_limits<ll>::max());
}
return ans;
}
auto edges() const{
vector<tuple<int,int,ll>> res;
for(int i=0;i<int(e.size());i+=2){
res.emplace_back(e[i^1].v,e[i].v,e[i].w);
}
return res;
}
};
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
int n1,n2,m;
cin>>n1>>n2>>m;
MaxFlow f(n1+n2+2);
int s=f.n-2,t=f.n-1;
For(i,0,n1-1){
f.add_edge(s,i,1);
}
For(i,n1,n1+n2-1){
f.add_edge(i,t,1);
}
For(i,1,m){
int u,v;
cin>>u>>v;
f.add_edge(u,v+n1,1);
}
cout<<f.flow(s,t)<<'\n';
auto edges=f.edges();
for(auto [u,v,w]:edges){
if(max(u,v)<n1+n2&&!w){
cout<<u<<' '<<v-n2<<'\n';
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1714ms
memory: 50252kb
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 78474 45795 92549 13903 73460 34144 96460 92850 76342 51542 76410 89381 1778 61392 43607 96135 84268 74827 19876 174 1481 94390 12423 55019 64368 92587 81295 7902 25432 46032 7004 23282 29100 60189 70797 28664 49166 48275 56159 7961 23562 76094 4507 80396 70329 91264 41532 61133 3580 43660 44...
result:
ok OK
Test #2:
score: 0
Accepted
time: 1703ms
memory: 47468kb
input:
100000 100000 200000 56815 52516 2576 76201 40377 1757 50463 66496 15833 50879 9828 16330 80692 9962 51095 17590 15870 35191 91301 65509 90774 57492 11890 8966 44786 41895 3386 35478 93470 47452 84803 93635 90745 34876 18201 38717 7472 34257 36580 19532 13248 27524 6441 69869 8821 61870 94536 67713 ...
output:
100000 56815 52516 40377 1757 50463 66496 15833 50879 9828 16330 80692 9962 51095 17590 90774 57492 44786 41895 3386 35478 84803 93635 90745 34876 7472 34257 36580 19532 8821 61870 41395 2585 99666 33504 90496 2775 8128 71333 85506 34046 65629 62628 15022 71577 7538 82555 64524 72576 33208 93167 531...
result:
ok OK
Test #3:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
4 4 7 1 1 2 2 0 0 3 1 1 2 2 0 3 2
output:
3 1 1 2 2 0 0
result:
ok OK
Test #4:
score: 0
Accepted
time: 77ms
memory: 45004kb
input:
100000 100000 199999 25370 25370 85964 85963 415 415 16796 16796 12437 12437 45409 45408 63005 63004 22155 22155 87828 87827 84013 84013 37307 37307 72324 72324 83703 83703 55390 55389 6780 6779 78090 78090 9375 9375 82192 82192 74694 74694 49841 49841 15798 15798 69855 69854 82948 82947 97389 97388...
output:
100000 25370 25370 415 415 16796 16796 12437 12437 22155 22155 84013 84013 37307 37307 72324 72324 83703 83703 78090 78090 9375 9375 82192 82192 74694 74694 49841 49841 15798 15798 36770 36770 27645 27645 50147 50147 73191 73191 47835 47835 80563 80563 22103 22103 12751 12751 24922 24922 15168 15168...
result:
ok OK
Test #5:
score: 0
Accepted
time: 67ms
memory: 45796kb
input:
100000 100000 199999 59469 59469 76773 76772 89516 89516 87040 87040 90184 90184 83075 83075 61454 61454 33615 33615 85794 85793 92072 92071 49725 49725 63842 63841 99247 99247 24121 24121 29552 29551 73533 73533 75845 75845 27029 27028 84418 84418 26636 26636 10100 10099 75013 75012 67341 67341 756...
output:
100000 59469 59469 89516 89516 87040 87040 90184 90184 83075 83075 61454 61454 33615 33615 49725 49725 99247 99247 24121 24121 73533 73533 75845 75845 84418 84418 26636 26636 67341 67341 32504 32504 5752 5752 41749 41749 33184 33184 70841 70841 98815 98815 3265 3265 57647 57647 24293 24293 89920 899...
result:
ok OK
Test #6:
score: 0
Accepted
time: 1618ms
memory: 48892kb
input:
100000 100000 199999 22284 45795 32144 44930 58734 13903 57136 34144 7548 92850 56318 11874 77529 85278 27039 51542 77506 94257 69265 89381 67073 61392 86159 96135 83227 74827 14857 19500 32084 73639 86884 174 27268 94390 20020 55019 45357 92587 17833 7902 55801 46032 36293 46557 73555 13746 8418 88...
output:
100000 22284 45795 58734 13903 57136 34144 7548 92850 27039 51542 69265 89381 67073 61392 86159 96135 83227 74827 86884 174 27268 94390 20020 55019 45357 92587 17833 7902 55801 46032 73310 23282 89482 60189 60485 28664 2721 48275 89892 7961 24437 76094 58192 80396 28938 91264 6101 61133 70994 43660 ...
result:
ok OK
Test #7:
score: 0
Accepted
time: 1670ms
memory: 53680kb
input:
100000 100000 199999 4850 52516 2576 29250 69016 1757 85854 66496 48300 50879 83741 16330 98931 9962 38730 17590 15870 13960 91301 97595 81692 57492 11890 59332 5076 41895 23574 35478 93470 65245 61976 93635 96140 34876 18201 35366 64057 34257 25588 19532 13248 91003 6441 83448 99191 61870 94536 169...
output:
100000 4850 52516 69016 1757 85854 66496 48300 50879 83741 16330 98931 9962 38730 17590 81692 57492 5076 41895 23574 35478 61976 93635 96140 34876 64057 34257 25588 19532 99191 61870 73134 2585 60977 33504 67485 2775 79816 71333 35920 34046 16162 62628 89591 71577 91372 82555 96933 72576 92891 93167...
result:
ok OK
Test #8:
score: -100
Wrong Answer
time: 95ms
memory: 38780kb
input:
61217 61379 199943 14003 13749 24504 24347 30371 30219 27661 27461 33247 33397 38346 38157 17300 16944 50476 50643 56488 56551 46690 46949 21355 21288 3899 3659 24330 24165 8806 8305 40957 40994 15089 14813 20397 20389 30864 30800 33635 33755 20900 20808 55447 55499 4335 4040 36726 36551 16496 16095...
output:
37154 24504 24185 38346 37995 17300 16782 50476 50481 46690 46787 3899 3497 40957 40832 30864 30638 33635 33593 55447 55337 4335 3878 6706 6086 747 546 56154 56086 40713 40512 53348 53288 33018 32966 47854 47960 42852 42712 47465 47584 20473 20278 34589 34539 46524 46617 45548 45480 17364 16839 6914...
result:
wrong answer Matching is incorrect (24504, 24185)