QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#86650#5407. 基础图论练习题2805734199h0 14ms8080kbC++144.1kb2023-03-10 14:42:092023-03-10 14:42:12

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-10 14:42:12]
  • 评测
  • 测评结果:0
  • 用时:14ms
  • 内存:8080kb
  • [2023-03-10 14:42:09]
  • 提交

answer

#include <bits/stdc++.h>
#define N 5005
#define M 13000005
using namespace std;
const int mod=1e9+7;
int power(int x,int y) {
	int ans=1;
	while(y) {
		if(y&1) ans=1ll*ans*x%mod;
		x=1ll*x*x%mod,y>>=1;
	}
	return ans;
}
int T,n,ans,tot,first[N],nxt[M],ver[M],pw2[N],pw[N];
void add(int s,int e) {
	nxt[++tot]=first[s];
	first[s]=tot;
	ver[tot]=e;
}
int dfn[N],totd,low[N],s[N],top,totb,blo[N];
vector<int> b[N];
void tarjan(int now,int fa) {
	dfn[now]=low[now]=++totd;
	s[++top]=now;
	for(int i=first[now];i;i=nxt[i]) {
		int v=ver[i];
		if(v==fa||blo[v]) continue;
		if(dfn[v]) low[now]=min(low[now],dfn[v]);
		else {
			tarjan(v,now);
			low[now]=min(low[now],low[v]);
		}
	}
	if(low[now]>=dfn[now]) {
		blo[now]=++totb;
		b[totb].push_back(now);
		while(top&&s[top]!=now) {
			b[totb].push_back(s[top]);
			blo[s[top--]]=totb;
		}
		if(top) top--;
	}
}
int ind[N],oud[N],deg[N][N],wou[N],win[N];
vector<int> head[N],hb[N],hbin[N];
void build() {
	for(int i=1;i<=n;++i) for(int j=first[i];j;j=nxt[j]) {
		if(blo[i]==blo[ver[j]]) {
			hb[i].push_back(ver[j]);
			hbin[ver[j]].push_back(i);
		} else {
			head[blo[i]].push_back(blo[ver[j]]);
			deg[blo[i]][blo[ver[j]]]++;
			ind[blo[ver[j]]]++;
		}
	}
}
int dep[N],q[N+10],l,r;
void bfs() {
	l=1,r=0;
	for(int i=1;i<=totb;++i) {
		if(!ind[i]) q[++r]=i;
	}
	while(l<=r) {
		int u=q[l++],sz;
		sz=head[u].size();
		for(int i=0,v;i<sz;++i) {
			v=head[u][i];
			ind[v]--;
			if(!ind[v]) {
				dep[v]=dep[u]+1;
				q[++r]=v;
			}
		}
	}
}
bool vis[N];
string str;
void clear() {
	for(;tot;--tot) nxt[tot]=0;
	for(int i=1;i<=totb;++i) for(int j=1;j<=totb;++j) {
		deg[i][j]=0;
	}
	for(int i=1;i<=n;++i) {
		first[i]=0;
		b[i].clear();
		head[i].clear();
		hb[i].clear();
		hbin[i].clear();
		blo[i]=dfn[i]=dep[i]=ind[i]=wou[i]=win[i];
	}
	ans=totb=totd=0;
}
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>T;
	while(T--) {
		clear();
		cin>>n;
		pw[0]=1;
		for(int i=1;i<=n;++i) {
			pw[i]=(pw[i-1]<<1)%mod;
			if(i>1) pw2[i]=power(2,(i-1)*(i-2)>>1);
		}
		for(int i=2,j,k,c,ed;i<=n;++i) {
			cin>>str;
			for(j=0;j<(i-1)/4+1;++j) {
				ed=i-1-(j<<2);
				c=isdigit(str[j])?str[j]-'0':str[j]-'A'+10;
				for(k=0;k<4&&k<ed;++k) {
					((c>>k)&1)?add(i,(j<<2)+k+1):add((j<<2)+k+1,i);
				}
			}
		}
		for(int i=1;i<=n;++i) {
			if(!blo[i]) tarjan(i,0);
		}
		build();
		bfs();
		for(int i=1;i<=n;++i) {
			oud[i]=hb[i].size();
			ind[i]=hbin[i].size();
		}
		for(int i=1;i<=n;++i) {
			if(oud[i]==1) {
				wou[i]=1;
				for(int j=0;j<ind[i];++j) {
					if(oud[hbin[i][j]]==1) wou[i]++;
				}
			}
			if(ind[i]==1) {
				win[i]=1;
				for(int j=0;j<oud[i];++j) {
					if(ind[hb[i][j]]==1) win[i]++;
				}
			}
		}
		for(int i=1,u,v,res;i<=n;++i) {
			u=blo[i];
			for(int j=first[i];j;j=nxt[j]) {
				v=ver[j];
				if(u!=blo[v]) {
					if(dep[u]<dep[blo[v]]-1||deg[u][blo[v]]>1) {
						res=totb-dep[blo[v]]+dep[u];
					} else res=totb;
				} else {
					int sz;
					if(oud[i]==1&&ind[v]==1) {
						res=2,l=1,r=0;
						vis[i]=vis[v]=1;
						q[++r]=i;q[++r]=v;
						while(l<=r) {
							int x=q[l++],y;
							sz=hb[x].size();
							for(int k=0;k<sz;++k) {
								y=hb[x][k];
								ind[y]--;
								if(!ind[y]&&!vis[y]) res++,vis[y]=1,q[++r]=y;
							}
							sz=hbin[x].size();
							for(int k=0;k<sz;++k) {
								y=hbin[x][k];
								oud[y]--;
								if(!oud[y]&&!vis[y]) res++,vis[y]=1,q[++r]=y;
							}
						}
						sz=b[u].size();
						for(int k=0;k<sz;++k) {
							vis[b[u][k]]=0;
							oud[b[u][k]]=hb[b[u][k]].size();
							ind[b[u][k]]=hbin[b[u][k]].size();
						}
						if(res<sz) res+=totb;
						else res+=totb-1;
					} else res=totb+wou[i]+win[v];
	//				cout<<"totb = "<<totb<<" "<<"res = "<<res<<"woui = "<<wou[i]<<"winv = "<<win[v]<<"\n";
				}
	//			printf("j = %d res = %d\n",j,res);
	//			printf("i = %d v = %d woui = %d winv = %d res = %d\n",i,v,wou[i],win[v],res);
				ans=(ans+1ll*pw2[max(i,v)]*pw[min(i,v)-1]%mod*res)%mod;
			}
		}
		cout<<ans<<"\n";
	}
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 14ms
memory: 8080kb

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
351927998
190
0
4117
2
559951638
291876631
695707686
98581
1
695707430
151
2723015
2272
0
11858600
624944013
8547959
79647
86754
-845653
260863712
330195747
705191283
164189553
168320495
62367
530477861
8175131
64299
3779205
100074863
28524048
118
94
207
583900
354328364
25
49...

result:

wrong answer 4th numbers differ - expected: '371842543', found: '351927998'

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%