QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#450585#6874. Leshphonmzmz001WA 364ms3924kbC++142.3kb2024-06-22 15:56:562024-06-22 15:56:56

Judging History

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

  • [2024-06-22 15:56:56]
  • 评测
  • 测评结果:WA
  • 用时:364ms
  • 内存:3924kb
  • [2024-06-22 15:56:56]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll T,n,m,S;
ll G1[55],G2[55],vis,num1[55][55],num2[55][55],ans,n1,n2;
queue<ll> q,q1,q2,q3,Q1,Q2,q4,q5;
struct node{
	ll u,v,op;//0:spare 1:deleted 2:unsed 
}E[2505];
void bfs(ll GG[],ll num[][55],queue<ll> &Q){
	q.push(1ll);
	vis=1ll;
	while(!q.empty()){
		ll u=q.front();
		q.pop();
		ll G=GG[u];
		G^=(G&vis);
		vis|=G;
		for(;G;G^=G&-G){
			ll v=__builtin_ctzll(G)+1ll;
			q.push(v);
			Q.push(num[u][v]);
		}
	}
}
bool check(){
	while(!Q1.empty())Q1.pop();
	bfs(G1,num1,Q1);
	while(!Q2.empty())Q2.pop();
	bfs(G2,num2,Q2);
	return (ll)Q1.size()==n-1&&(ll)Q2.size()==n-1;
}
int main(){
	scanf("%lld",&T);
	while(T--){
		ans=0;
		scanf("%lld%lld",&n,&m);
		for(int i=0;i<=n;i++)
			for(int j=0;j<=n;j++)
				num1[i][j]=num2[i][j]=0;
		for(int i=0;i<=n;i++)G1[i]=G2[i]=0;
		S=(1ll<<n)-1;
		for(ll i=1;i<=m;i++){
			ll u,v;
			scanf("%lld%lld",&u,&v);
			E[i].u=u,E[i].v=v;
			G1[u]|=(1ll<<(v-1));
			G2[v]|=(1ll<<(u-1));
			num1[u][v]=i,num2[v][u]=i;
		}
		bfs(G1,num1,q1);bfs(G2,num2,q1);
		while(!q1.empty()){
			ll i=q1.front(),u=E[i].u,v=E[i].v;
			q1.pop();
			if(E[i].op!=0)continue;
			E[i].op=1;n1++;
			G1[u]^=(1ll<<(v-1));
			G2[v]^=(1ll<<(u-1));
			if(check()){
				bfs(G1,num1,q2);bfs(G2,num2,q2);
				while(!q2.empty()){
					ll j=q2.front(),u=E[j].u,v=E[j].v;
					q4.push(j);q2.pop();
					if(E[j].op!=0)continue;
					E[j].op=2;n2++;
					G1[u]^=(1ll<<(v-1));
					G2[v]^=(1ll<<(u-1));
					if(check()){
						bfs(G1,num1,q3);bfs(G2,num2,q3);
						while(!q3.empty()){
							ll k=q3.front(),u=E[k].u,v=E[k].v;
							q5.push(k);q3.pop();
							if(E[k].op!=0)continue;
							G1[u]^=(1ll<<(v-1));
							G2[v]^=(1ll<<(u-1));
							E[k].op=3;
							if(!check())ans++;
							G1[u]^=(1ll<<(v-1));
							G2[v]^=(1ll<<(u-1));
						}
						while(!q5.empty()){
							ll k=q5.front();
							q5.pop();
							if(E[k].op==3)E[k].op=0;
						}
					}
					
					else ans+=(m-n1-n2);
					
					G1[u]^=(1ll<<(v-1));
					G2[v]^=(1ll<<(u-1));
					
				}
				while(!q4.empty()){
					ll j=q4.front();
					q4.pop();
					if(E[j].op==2)E[j].op=0;
				}
				n2=0;
			}
			
			else ans+=(ll)(m-n1)*(m-n1-1)/2;
			
			G1[u]^=(1ll<<(v-1));
			G2[v]^=(1ll<<(u-1));
		}
		n1=0;
		printf("%lld\n",ans);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 364ms
memory: 3924kb

input:

10
50 145
1 6
1 33
1 38
2 11
2 29
2 36
2 42
3 20
3 35
3 36
4 39
5 39
6 10
6 23
6 27
6 34
6 39
6 45
6 47
7 24
7 37
8 14
8 47
9 3
9 40
10 5
10 12
10 25
11 14
11 18
12 13
12 44
13 38
14 38
15 4
15 29
15 31
15 36
15 44
16 17
16 35
17 18
17 50
18 3
18 19
18 20
18 27
19 31
20 22
20 31
21 8
21 22
21 27
21 ...

output:

159936
48858
722
0
833988
2755
1260078
6657
5531904
22966434

result:

wrong answer 2nd lines differ - expected: '126858', found: '48858'