QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#647633#5407. 基础图论练习题tx3440 114ms109292kbC++142.9kb2024-10-17 15:01:322024-10-17 15:01:32

Judging History

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

  • [2024-10-17 15:01:32]
  • 评测
  • 测评结果:0
  • 用时:114ms
  • 内存:109292kb
  • [2024-10-17 15:01:32]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define Int __int128
#define ld double
#define fi first
#define se second
#define PII pair<int,int>
#define PLI pair<ll,int>
#define PIL pair<int,ll>
#define PLL pair<ll,ll>
#define PLPII pair<ll,PII>
#define Bit bitset<M>
using namespace std;
const int N=5005,Mod=1e9+7;
int Q,n,dfn[N],low[N],Sta[N],top,scc[N],tot,cnt,ans,pw[N*N],lk2[N][N],deg[N],rk[N],A,B,C;
bool lk[N][N],ins[N],vis[N][N],com[N];
char a[N];
vector<PII>vec;
vector<int>scp[N];
int ID(char x){return x>='0'&&x<='9'?x-'0':x-'A'+10;}
int F(int x,int y){if(x<y)swap(x,y);return (x-1)*(x-2)/2+y-1;}
void Tarjan(int x)
{
	dfn[x]=low[x]=++tot;
	ins[Sta[++top]=x]=1;
	int pos=-1;
	for(int y=1;y<=n;y++)if(lk[x][y])
	{
		if(!dfn[y])
		{
			vec.push_back({x,y});
			vis[x][y]=1;
			Tarjan(y);
			low[x]=min(low[x],low[y]);
		}
		else if(ins[y]&&dfn[y]<low[x])
		{
			low[x]=dfn[y];
			pos=y;
		}
	}
	if(~pos)vec.push_back({x,pos}),vis[x][pos]=1;
	// printf("%d %d %d\n",x,dfn[x],low[x]),fflush(stdout);
	if(low[x]!=dfn[x])return;
	scp[++cnt].clear();
	while(1)
	{
		int u=Sta[top--];
		ins[u]=0;
		scc[u]=cnt;
		scp[cnt].push_back(u);
		if(u==x)break;
	}
}
void DFS(int x)
{
	com[x]=1;
	for(int y:scp[C])if(lk[x][y]&&!com[y]&&(x!=A||y!=B))DFS(y);
}
void Solve()
{
	vec.clear();
	ans=tot=cnt=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)dfn[i]=0;
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)vis[i][j]=lk2[i][j]=0;
	for(int i=2;i<=n;i++)
	{
		scanf("%s",a);
		for(int j=0;j<(i+2)/4;j++)
		{
			for(int k=0;k<4;k++)if(j*4+k+1<i)
			{
				int x=ID(a[j])>>k&1;
				lk[i][j*4+k+1]=x,lk[j*4+k+1][i]=!x;
			}
		}
	}
	// for(int i=1;i<=n;i++,puts(""))for(int j=1;j<=n;j++)printf("%d",lk[i][j]);
	for(int i=1;i<=n;i++)if(!dfn[i])Tarjan(i);
	// return;
	for(int i=1;i<=cnt;i++)
	{
		C=i;
		for(PII p:vec)if(scc[p.fi]==i&&scc[p.se]==i)
		{
			A=p.fi,B=p.se;
			DFS(A);
			// printf("ans:%d %d %d\n",A,B,cnt+!com[B]);
			ans+=(ll)pw[F(A,B)]*(cnt+!com[B])%Mod;
			for(int x:scp[i])com[x]=0;
		}
	}
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)
		if(lk[i][j]&&scc[i]!=scc[j])++lk2[scc[i]][scc[j]],++deg[scc[i]];
	for(int i=1;i<=cnt;i++)if(!deg[i])Sta[++top]=i;
	tot=0;
	while(top)
	{
		int x=Sta[top--];
		rk[x]=++tot;
		for(int i=1;i<=cnt;i++)if(lk2[i][x]&&!(deg[i]-=lk2[i][x]))Sta[++top]=i;
	}
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(lk[i][j])
	{
		int x=scc[i],y=scc[j];
		if(x==y&&!vis[i][j])ans+=(ll)pw[F(i,j)]*cnt%Mod;
		else if(x!=y)
		{
			if(rk[x]>rk[y])swap(x,y);
			if(rk[x]+1<rk[y]||scp[x].size()>1||scp[y].size()>1)ans+=(ll)pw[F(i,j)]*(cnt-rk[y]+rk[x])%Mod;
			else ans+=(ll)pw[F(i,j)]*cnt%Mod;
		}
	}
	printf("%d\n",ans);
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
    #endif

	pw[0]=1;
	for(int i=1;i<N*N;i++)pw[i]=2*pw[i-1]%Mod;
	scanf("%d",&Q);
	while(Q--)Solve();

	fprintf(stderr,"%.15lf\n",(ld)clock()/CLOCKS_PER_SEC);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 114ms
memory: 109292kb

input:

10000
100
1
2
2
8
C0
F0
27
78
AE1
C01
511
D87
EF20
3873
2742
73D0
DC9B0
FB2A3
9C011
9B4E0
95DC00
A7B980
F43531
6A6245
5347BE0
1A6C8A1
88E46D6
64CF3AE
D25F63C1
C894E4C3
1C0AFD73
EC1C3F9A
087CE17C0
22149A380
B28038AF1
B9CA21C7F
D78F5307C1
49045489A2
72C4DE6FD1
7713F40D05
EEE8878EEC1
310E62812B1
DA9D5B...

output:

1660982308
13
285212672
2076875289
82
0
1983
2
268503039
268435455
-1575490767
32785
2
-1575490511
91
2621567
2516
0
-1575491007
2076875289
2097159
41087
34815
3113984
-1575488975
502774846
-1575491015
-1575491023
-1575491023
64712
268697605
-1575489999
36863
2154623
-1575491023
2076875289
104
82
16...

result:

wrong answer 1st numbers differ - expected: '281603732', found: '1660982308'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%