QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#647634#5407. 基础图论练习题tx3440 127ms113672kbC++143.0kb2024-10-17 15:03:012024-10-17 15:03:01

Judging History

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

  • [2024-10-17 15:03:01]
  • 评测
  • 测评结果:0
  • 用时:127ms
  • 内存:113672kb
  • [2024-10-17 15:03:01]
  • 提交

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)%=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)%=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)%=Mod;
			else (ans+=(ll)pw[F(i,j)]*cnt%Mod)%=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: 127ms
memory: 113672kb

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:

281603732
13
285212672
371842543
82
0
1983
2
268503039
268435455
719476515
32785
2
719476771
91
2621567
2516
0
719476275
371842543
2097159
41087
34815
3113984
719478307
502774846
719476267
719476259
719476259
64712
268697605
719477283
36863
2154623
719476259
371842543
104
82
167
3672063
268435455
13...

result:

wrong answer 5th numbers differ - expected: '84', found: '82'

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%