QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#290142 | #6546. Greedy Bipartite Matching | Crysfly# | RE | 1714ms | 35080kb | C++14 | 3.2kb | 2023-12-24 14:15:09 | 2023-12-24 14:15:10 |
Judging History
answer
// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define ull unsigned long long
//#define int long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 200005
#define inf 0x3f3f3f3f
int n,m,res[maxn];
bool del1[maxn],del[maxn];
int s,t;
namespace F{
int n,s,t,maxflow;
int dep[maxn],cur[maxn];
int tot=1,head[maxn];
bool no[maxn];
struct edge{
int to,nxt,w,pre;
}e[maxn*8];
void adde(int u,int v,int w){
e[++tot]=(edge){v,head[u],w,0};
e[head[u]].pre=tot;
head[u]=tot;
}
void add(int u,int v,int w){
adde(u,v,w);
adde(v,u,0);
}
void del(int u,int i){
if(no[i]) return;
no[i]=1;
e[i].w=e[i^1].w=0;
// return;
if(i==head[u]) head[u]=e[i].nxt;
else {
int j=e[i].pre;
e[j].nxt=e[i].nxt;
if(e[i].nxt) e[e[i].nxt].pre=j;
}
}
int q[maxn],hd,tl;
bool bfs(int s,int t,int ret=1)
{
For(i,0,n)cur[i]=head[i],dep[i]=inf;
dep[s]=0,q[hd=tl=1]=s;
while(hd<=tl)
{
int u=q[hd++];
for(int i=head[u];i;i=e[i].nxt)
{
int v=e[i].to;
if(dep[v]==inf&&e[i].w){
dep[v]=dep[u]+1;
if(v==t && ret)return 1;
q[++tl]=v;
}
}
}return dep[t]<inf;
}
int dfs(int u,int t,int minn)
{
if(!minn||u==t)return minn;
int res=0;
for(int i=cur[u];i;i=e[i].nxt)
{
int v=e[i].to;
cur[u]=i;
if(dep[v]!=dep[u]+1)continue;
int flow=dfs(v,t,min(minn,e[i].w));
if(!flow)continue;
res+=flow,minn-=flow;
e[i].w-=flow,e[i^1].w+=flow;
if(!minn)break;
}
if(!res) dep[u]=0;
return res;
}
inline int dinic(int s,int t)
{
int maxflow=0,flow=0;
while(bfs(s,t))while(flow=dfs(s,t,inf))maxflow+=flow;
return maxflow;
}
inline void init(int N,int S,int T){
n=N,s=S,t=T,tot=1,maxflow=0;
For(i,0,n)head[i]=0;
}
}
using F::add;
int qwq;
int solve(int O)
{
int res=F::dinic(s,t);
F::bfs(s,t,0);
For(i,n+1,n+n)
if(F::dep[i]<inf) del[i]=del1[i]=1;
For(i,1,n){
if(F::dep[i]<inf) ;
else if(!del1[i]){
del[i]=del1[i]=1;
for(int j=F::head[i];j;j=F::e[j].nxt)
if(F::e[j].to>n && F::e[j].to<=n+n && del1[F::e[j].to]) {
int v=F::e[j].to;
F::del(i,j);
F::del(v,j^1);
}
}
}
// For(i,1,n+m) if(del1[i]) del[i]=0;
For(i,1,n+n) del1[i]|=del[i],del[i]=0;
return res;
}
signed main()
{
n=read(),m=read();
s=0,t=n*2+1;
F::init(t,s,t);
For(i,1,n)F::add(s,i,1),F::add(i+n,t,1);
For(i,1,m){
int c=read();
while(c--){
int u=read(),v=read();
if(!del1[u] && !del1[v+n]) F::add(u,n+v,1);
}
qwq=res[i-1];
res[i]=res[i-1]+solve(i);
}
For(i,1,m)cout<<res[i]<<" ";
return 0;
}
/*
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3464kb
input:
3 4 2 1 1 1 2 2 1 1 2 2 2 1 3 3 2 1 3 3
output:
1 2 2 3
result:
ok 4 number(s): "1 2 2 3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3436kb
input:
0 0
output:
result:
ok 0 number(s): ""
Test #3:
score: 0
Accepted
time: 0ms
memory: 3424kb
input:
2 2 0 2 1 2 1 2
output:
0 1
result:
ok 2 number(s): "0 1"
Test #4:
score: 0
Accepted
time: 1676ms
memory: 23480kb
input:
100000 1 200000 78475 45796 32145 46393 92550 13904 73461 34145 96461 92851 56319 77067 77530 84437 76343 51543 77507 99269 76411 89382 1779 61393 43608 96136 84269 74828 14858 35967 32085 94909 19877 175 1482 94391 12424 55020 64369 92588 81296 7903 25433 46033 36294 61129 73556 84837 8419 10215 12...
output:
100000
result:
ok 1 number(s): "100000"
Test #5:
score: 0
Accepted
time: 1691ms
memory: 20960kb
input:
100000 1 200000 56816 52517 2577 76202 40378 1758 50464 66497 15834 50880 9829 16331 80693 9963 51096 17591 15871 35192 91302 65510 90775 57493 11891 8967 44787 41896 3387 35479 93471 47453 84804 93636 90746 34877 18202 38718 7473 34258 36581 19533 13249 27525 6442 69870 8822 61871 94537 67714 41396...
output:
100000
result:
ok 1 number(s): "100000"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3476kb
input:
4 1 7 2 2 3 3 1 1 4 2 2 3 3 1 4 3
output:
3
result:
ok 1 number(s): "3"
Test #7:
score: 0
Accepted
time: 36ms
memory: 35080kb
input:
100000 1 199999 25371 25371 85965 85964 416 416 16797 16797 12438 12438 45410 45409 63006 63005 22156 22156 87829 87828 84014 84014 37308 37308 72325 72325 83704 83704 55391 55390 6781 6780 78091 78091 9376 9376 82193 82193 74695 74695 49842 49842 15799 15799 69856 69855 82949 82948 97390 97389 205 ...
output:
100000
result:
ok 1 number(s): "100000"
Test #8:
score: 0
Accepted
time: 34ms
memory: 35076kb
input:
100000 1 199999 59470 59470 76774 76773 89517 89517 87041 87041 90185 90185 83076 83076 61455 61455 33616 33616 85795 85794 92073 92072 49726 49726 63843 63842 99248 99248 24122 24122 29553 29552 73534 73534 75846 75846 27030 27029 84419 84419 26637 26637 10101 10100 75014 75013 67342 67342 75647 75...
output:
100000
result:
ok 1 number(s): "100000"
Test #9:
score: 0
Accepted
time: 1714ms
memory: 23080kb
input:
100000 1 199999 22285 45796 32145 44931 58735 13904 57137 34145 7549 92851 56319 11875 77530 85279 27040 51543 77507 94258 69266 89382 67074 61393 86160 96136 83228 74828 14858 19501 32085 73640 86885 175 27269 94391 20021 55020 45358 92588 17834 7903 55802 46033 36294 46558 73556 13747 8419 88394 1...
output:
100000
result:
ok 1 number(s): "100000"
Test #10:
score: 0
Accepted
time: 1672ms
memory: 27548kb
input:
100000 1 199999 4851 52517 2577 29251 69017 1758 85855 66497 48301 50880 83742 16331 98932 9963 38731 17591 15871 13961 91302 97596 81693 57493 11891 59333 5077 41896 23575 35479 93471 65246 61977 93636 96141 34877 18202 35367 64058 34258 25589 19533 13249 91004 6442 83449 99192 61871 94537 16903 73...
output:
100000
result:
ok 1 number(s): "100000"
Test #11:
score: -100
Runtime Error
input:
100000 1 199997 4415 9894 97824 23182 2551 30097 24322 27913 64552 31862 23073 68076 28494 14953 11400 33367 14514 13085 40869 51446 63170 88054 76550 23848 22657 57759 9479 56985 96440 59224 69954 84962 55443 22220 96520 87619 31746 72821 8800 6061 36912 77572 8970 95816 32991 68335 29931 84159 333...