QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#647687#5407. 基础图论练习题tx3440 80ms113560kbC++143.6kb2024-10-17 15:13:382024-10-17 15:13:38

Judging History

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

  • [2024-10-17 15:13:38]
  • 评测
  • 测评结果:0
  • 用时:80ms
  • 内存:113560kb
  • [2024-10-17 15:13:38]
  • 提交

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,cnt0;
bool lk[N][N],ins[N],vis[N][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 Tarjan2(int x)
{
	dfn[x]=low[x]=++tot;
	ins[Sta[++top]=x]=1;
	if(x==B)
	{
		if(!dfn[A])
		{
			Tarjan2(A);
			low[x]=min(low[x],low[A]);
		}
		else if(ins[A])low[x]=min(low[x],dfn[A]);
	}
	for(int y:scp[C])if(lk[x][y]&&(x!=A||y!=B))
	{
		if(!dfn[y])
		{
			Tarjan2(y);
			low[x]=min(low[x],low[y]);
		}
		else if(ins[y])low[x]=min(low[x],dfn[y]);
	}
	if(low[x]!=dfn[x])return;
	++cnt0;
	while(1)
	{
		int u=Sta[top--];
		ins[u]=0;
		if(u==x)break;
	}
}
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++)for(int j=1;j<=n;j++)if(lk[i][j])printf("%d %d\n",i,j);
	for(int i=1;i<=n;i++)if(!dfn[i])Tarjan(i);
	// return;
	for(int i=1;i<=n;i++)dfn[i]=0;
	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,cnt0=0;
			for(int x:scp[i])if(!dfn[x])Tarjan2(x);
			// DFS(A);
			// printf("ans:%d %d %d\n",A,B,cnt-1+cnt0);
			(ans+=(ll)pw[F(A,B)]*(cnt-1+cnt0)%Mod)%=Mod;
			for(int x:scp[i])dfn[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])
		printf("ans:%d %d %d\n",i,j,cnt),
		(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);
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 80ms
memory: 113560kb

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:

ans:1 4 1
ans:1 5 1
ans:1 6 1
ans:1 8 1
ans:1 10 1
ans:1 11 1
ans:1 14 1
ans:1 16 1
ans:1 23 1
ans:1 25 1
ans:1 28 1
ans:1 29 1
ans:1 31 1
ans:1 33 1
ans:1 34 1
ans:1 35 1
ans:1 39 1
ans:1 42 1
ans:1 45 1
ans:1 47 1
ans:1 49 1
ans:1 50 1
ans:1 51 1
ans:1 52 1
ans:1 53 1
ans:1 56 1
ans:1 57 1
ans:1 5...

result:

wrong output format Expected integer, but "ans:1" found

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%