QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#17097#61. Cut Cut Cut!JohnAlfnov#WA 5ms14012kbC++111.8kb2022-01-03 11:47:462022-05-04 13:19:03

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-04 13:19:03]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:14012kb
  • [2022-01-03 11:47:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int mod=1004535809;
int d=0;
struct Alfnov{
	int a[23];
}e[300005],l[300005],b[23];
Alfnov operator+(Alfnov a,Alfnov b){
	Alfnov c;
	for(int i=1;i<=d;++i)c.a[i]=(a.a[i]+b.a[i])%mod;
	return c;
}
Alfnov operator*(int a,Alfnov b){
	Alfnov c;
	for(int i=1;i<=d;++i)c.a[i]=1ll*a*b.a[i]%mod;
	return c;
}
vector<pair<int,int>>g[100005],g2[100005];
int q[100005],deg[100005],ans[100005];
int qu[300005];
int Inverse(int x){
	int ans=1,y=mod-2;
	while(y){
		if(y&1)ans=1ll*ans*x%mod;
		y>>=1,x=1ll*x*x%mod;
	}
	return ans;
}
int main(){
	srand(time(0));
	srand(rand()+20090908);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;++i){
		int u,v;
		scanf("%d%d",&u,&v);
		g[u].emplace_back(make_pair(v,i));
		g2[v].emplace_back(make_pair(u,i));
		++deg[v];
		if(u==1)++d;
	}
	int head=0,tail=-1;
	q[++tail]=1;
	while(head<=tail){
		int x=q[head++];
		for(auto P:g[x]){
			int cu=P.first;
			--deg[cu];
			if(!deg[cu])q[++tail]=cu;
		}
		if(x==1){
			int m=0;
			for(auto P:g[x]){
				++m;
				int cu=P.second;
				e[cu].a[m]=1;
			}
		}else{
			int m=0,bs=0;
			for(auto P:g2[x]){
				++m;
				int cu=P.second;
				l[m]=e[cu];
			}
			for(int i=1;i<=m;++i){
				int flag=0,wz=-1;
				for(int j=1;j<=d;++j)if(l[i].a[j]){
					wz=j,flag=1;
					break;
				}
				if(!flag)continue;
				b[++bs]=l[i];
				int ny=Inverse(l[i].a[wz]);
				for(int j=i+1;j<=m;++j)if(l[j].a[wz]){
					int c=-1ll*ny*l[j].a[wz]%mod;
					for(int k=1;k<=d;++k){
						l[j].a[k]=(l[j].a[k]+1ll*l[i].a[k]*c)%mod;
					}
				}
			}
			ans[x]=bs;
			for(auto P:g[x]){
				int cu=P.second;
				for(int i=1;i<=bs;++i)
					e[cu]=e[cu]+rand()*b[i];
			}
		}
	}
	for(int i=2;i<=n;++i){
		printf("%d",ans[i]);
		putchar((' ')*(i!=n)+('\n')*(i==n));
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 14012kb

input:

3 3
1 2
1 3
2 3

output:

1 2

result:

ok 2 number(s): "1 2"

Test #2:

score: 0
Accepted
time: 2ms
memory: 12064kb

input:

8 8
1 2
1 3
1 5
2 4
2 5
3 6
4 5
7 8

output:

1 1 1 2 1 0 0

result:

ok 7 numbers

Test #3:

score: -100
Wrong Answer
time: 5ms
memory: 11900kb

input:

20 70
3 18
14 16
8 10
5 7
2 14
10 18
14 15
17 19
18 20
4 6
3 20
16 17
6 7
6 17
6 19
5 19
12 16
18 19
13 19
13 19
8 9
15 17
8 9
1 7
5 18
6 14
2 17
4 20
12 16
9 20
2 7
6 19
12 13
6 7
1 5
19 20
9 14
13 14
16 17
17 20
9 16
1 6
12 15
2 8
1 3
4 19
1 4
9 13
14 15
15 20
17 18
14 19
13 14
2 5
7 14
7 18
10 16...

output:

0 1 1 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0

result:

wrong answer 4th numbers differ - expected: '1', found: '0'