QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#692198#7898. I Just Want... One More...HomuraAkemi#WA 9ms12288kbC++142.6kb2024-10-31 14:03:032024-10-31 14:03:04

Judging History

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

  • [2024-10-31 14:03:04]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:12288kb
  • [2024-10-31 14:03:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define LL long long
struct edges{
	LL to,flow,nt;
}a[2000005],b[2000005];
LL n,i,j,k,m,ans=0,cnt=1,s,t,x,y,z,sum1,sum2,num1,num2,cnt1=0,t1;
LL nxt[200005],depth[200005],gap[200005],nxt1[200005];
bool flag[200005],vis[200005];
const LL inf=0x7fffffff;
void add(LL x,LL y,LL z){
	a[++cnt].to=y;a[cnt].flow=z;a[cnt].nt=nxt[x];nxt[x]=cnt;
	a[++cnt].to=x;a[cnt].flow=0;a[cnt].nt=nxt[y];nxt[y]=cnt;
}
void add1(LL x,LL y){
	b[++cnt1].to=y;b[cnt1].nt=nxt1[x];nxt1[x]=cnt1;
}
void bfs(){
	for(LL i=1;i<=t;i++)
	  depth[i]=inf;
	queue<LL> q;
	q.push(t);
	depth[t]=0;
	while(!q.empty()){
		LL tmp=q.front();q.pop();
		for(LL i=nxt[tmp];i;i=a[i].nt){
			if(depth[a[i].to]==inf){
				depth[a[i].to]=depth[tmp]+1;
				gap[depth[a[i].to]]++;
				q.push(a[i].to);
			}
		}
	}
}
LL dfs(LL x,LL flow){
	if(x==t){
		ans+=flow;
		//printf("%lld\n",flow);
		return flow;
	}
	LL sum=0;
	for(LL i=nxt[x];i;i=a[i].nt){
		if(depth[a[i].to]+1==depth[x] && a[i].flow!=0){
			LL tmp=dfs(a[i].to,min(a[i].flow,flow-sum));
			if(tmp>0){
				a[i].flow-=tmp;
				a[i^1].flow+=tmp;
				sum+=tmp;
			}
			if(sum==flow) return flow;
		}
	}
	gap[depth[x]]--;
	if(gap[depth[x]]==0) depth[s]=t;
	gap[++depth[x]]++;
	return sum;
}
void isap(){
	while(depth[s]<=t) dfs(s,0x7fffffffffffffff);
}
void dfs1(LL father,LL x){
	vis[x]=true;
	if(x<=n){
		sum1++;
		if(flag[x]==true) num1++;
	}
	else{
		sum2++;
		if(flag[x]==true) num2++; 
	}
	for(LL i=nxt1[x];i;i=b[i].nt)
	  if(vis[b[i].to]==false) dfs1(x,b[i].to);
}
int main(){
	scanf("%lld",&t1);
	while(t1--){
		for(i=0;i<=cnt;i++)
		  a[i].to=a[i].nt=a[i].flow=0;
		for(i=0;i<=cnt1;i++)
		  b[i].to=b[i].nt=0;
		cnt=1,cnt1=0;
		for(i=0;i<=2*n+2;i++)
		  nxt[i]=0,vis[i]=false,flag[i]=false,gap[i]=0,nxt1[i]=0;
		scanf("%lld%lld",&n,&m);
		s=2*n+1,t=2*n+2;
		for(i=1;i<=n;i++)
		  add(s,i,1),add(i+n,t,1);
		for(i=1;i<=m;i++){
			scanf("%lld%lld",&x,&y);
			add(x,n+y,1);add1(x,n+y),add1(n+y,x);
		}
		bfs();
		isap();
		for(i=1;i<=n;i++){
			if(a[4*(i-1)+2].flow==0) flag[i]=true;
			if(a[4*(i-1)+4].flow==0) flag[i+n]=true;
			//printf("%lld %lld\n",a[4*(i-1)+2].flow,a[4*(i-1)+4].flow);
		}
		//for(i=1;i<=2*n;i++)
		//  printf("%lld ",flag[i]);
		//printf("\n");
		LL ans1=0,ans2=0,ans=0;
		for(i=1;i<=2*n;i++)
		  if(vis[i]==false){
		  	sum1=sum2=num1=num2=0;
		  	dfs1(0,i);
		  	if(sum1>num1) ans1+=sum1;
		  	if(sum2>num2) ans2+=sum2;
		  	if(sum1>num1 && sum2>num2) ans+=sum1*sum2;
		  	//printf("%lld %lld %lld %lld %lld\n",i,sum1,sum2,num1,num2);
		  }
		printf("%lld\n",ans1*ans2-ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 11988kb

input:

3
4 3
1 2
3 2
4 3
3 3
1 3
2 2
3 1
3 2
1 2
1 2

output:

6
0
4

result:

ok 3 number(s): "6 0 4"

Test #2:

score: -100
Wrong Answer
time: 9ms
memory: 12288kb

input:

10000
5 4
2 2
3 1
5 3
1 1
1 1
1 1
1 1
1 1
2 2
2 2
1 2
1 1
1 1
1 1
1 1
1 1
1 1
2 3
2 1
1 2
1 1
5 5
1 4
2 2
3 1
1 3
1 2
2 4
2 2
2 1
1 2
1 1
5 1
5 3
3 1
2 2
1 1
1 1
3 2
3 1
2 1
5 2
1 2
2 3
5 3
1 5
4 2
1 2
4 1
1 1
2 3
1 1
2 2
2 1
4 1
1 4
3 1
1 1
1 1
1 1
2 1
2 2
3 3
1 3
2 3
2 2
3 3
1 3
3 3
1 2
3 3
2 2
1 ...

output:

6
0
0
2
0
0
0
0
8
0
16
4
0
6
9
9
9
0
9
4
0
1
1
1
0
4
16
15
3
2
16
0
2
2
20
1
0
0
0
0
16
4
4
16
4
9
0
9
0
2
3
0
9
4
9
16
20
0
0
1
12
0
1
2
0
0
1
0
0
2
2
4
0
12
1
0
0
2
1
2
2
3
0
4
1
6
0
0
0
0
9
16
2
0
1
2
0
12
2
4
0
12
1
1
9
4
6
9
9
12
3
16
15
16
9
4
9
0
1
16
9
9
1
9
16
9
12
4
9
2
0
4
0
6
0
3
0
0
0
0...

result:

wrong answer 9th numbers differ - expected: '6', found: '8'