QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#430495#7794. 水果茶kkkgjyismine40 93ms340980kbC++145.2kb2024-06-03 21:27:442024-06-03 21:27:45

Judging History

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

  • [2024-06-03 21:27:45]
  • 评测
  • 测评结果:0
  • 用时:93ms
  • 内存:340980kb
  • [2024-06-03 21:27:44]
  • 提交

answer

#include<bits/stdc++.h>
#define pb push_back
using namespace std;
char ch,B0[1<<15],*S=B0,*T=B0;
#define getc() (S==T&&(T=(S=B0)+fread(B0,1,1<<15,stdin),S==T)?0:*S++)
inline int read(){
    int aa;
    while(ch=getc(),ch<'0'||ch>'9');aa=ch-'0';
    while(ch=getc(),ch>='0'&&ch<='9')aa=aa*10+ch-'0';
    return aa;
}
const int mod=1315105,MAXM=1e9;
void add(int &x,const int y){if((x+=y)>=mod)x-=mod;}
void sub(int &x,const int y){if((x+=(mod-y))>=mod)x-=mod;}
int g[20000005],*ff=g,*f[5000005];
int n,m,k,seed,a[5000500],hd[5000005],nxt[10000005],to[10000005],tt=1;
void ADD(int u,int v){
	nxt[++tt]=hd[u],hd[u]=tt,to[tt]=v;
	nxt[++tt]=hd[v],hd[v]=tt,to[tt]=u;
}
int dfn[5000005],low[5000005],col,tot,stk[5000005],tail;
vector<int>road[10000005];
void tarjan(int u,int from){
	dfn[u]=low[u]=++tot,stk[++tail]=u;
	for(int i=hd[u],v;i;i=nxt[i]){
		v=to[i];if((i^1)==from)continue;
		if(!dfn[v]){
			tarjan(v,i),low[u]=min(low[u],low[v]);
			if(low[v]>=dfn[u]){
				++col;road[col].pb(u),road[u].pb(col);
				while(1){
					int p=stk[tail--];
					road[col].pb(p),road[p].pb(col);
					if(p==v)break;
				}
			}
		}else low[u]=min(low[u],dfn[v]);
	}
}
const int inv2=(mod+1>>1);
int dep[10000005],len[5000005];
int up[5000005],son[5000005],vis[5000050];
vector<int>vec;
void dfs(int u){
    son[u]=-1,len[u]=0;
    for(int v:road[u]){
    	if(dep[v]<dep[u])continue;int id=-1;
    	for(int i=0;i<road[v].size();++i)if(road[v][i]==u){id=i;break;}
		vec.clear();
		for(int i=id;i<road[v].size();++i)vec.pb(road[v][i]);
		for(int i=0;i<id;++i)vec.pb(road[v][i]);
		road[v]=vec;int cir=vec.size();
		for(int i=1;i<road[v].size();++i)up[road[v][i]]=min(i,cir-i),dep[road[v][i]]=dep[u]+2;
		dep[v]=dep[u]+1;
		for(int i=1;i<road[v].size();++i){
			dfs(road[v][i]);
			if(son[u]==-1||len[u]<len[road[v][i]]+up[road[v][i]])len[u]=len[road[v][i]]+up[road[v][i]],son[u]=road[v][i];
		}
	}
	if(son[u]!=-1)vis[son[u]]=1;
}
int Ans;
int ct[20000005],bl[5000005];
void Add(int u,int p,int d){
	if(p==u||p==son[u])return;
	for(int i=0;i<=len[p];++i)add(ct[i+d],f[p][i]);
}
void Del(int u,int p,int d){
	if(p==u||p==son[u])return;
	for(int i=0;i<=len[p];++i)sub(ct[i+d],f[p][i]);
}
int p[10000005];
void solve(int u){
	f[u][0]=a[u];
    if(son[u]!=-1)f[son[u]]=f[u]+up[son[u]],solve(son[u]);
	for(int v:road[u]){
    	if(dep[v]<dep[u])continue;
		int fl=0;
    	for(int i=1;i<road[v].size();++i){
    		if(road[v][i]!=son[u])solve(road[v][i]);
    		else fl=1;
		}
		for(int i=1;i<road[v].size();++i)bl[road[v][i]]=i;
		int cir=road[v].size(),ans1=Ans;
		for(int i=0;i<road[v].size();++i)p[i+1]=p[i+cir+1]=road[v][i];
		int lef=(cir+1)/2;--lef;
		if(lef){
			int l=cir+1,r=cir;
			for(int i=cir+1;i<=2*cir;++i){
				if(p[i]==u||p[i]==son[u])continue;
				int ql=i-lef,qr=i-1;
				while(l>ql)--l,Add(u,p[l],2*cir-l);
				while(r<qr)++r,Add(u,p[r],2*cir-r);
				while(l<ql)Del(u,p[l],2*cir-l),++l;
				while(r>qr)Del(u,p[r],2*cir-r),--r;
				int d=-(2*cir-i);
				for(int j=0;j<=min(len[p[i]],k);++j){
					int d1=k-j-d;
					if(ct[d1])Ans=(Ans+1ll*ct[d1]*f[p[i]][j])%mod;
				}
			}
			while(l<=r)Del(u,p[l],2*cir-l),++l;
		}
		lef=cir-1-lef;
		for(int i=0;i<road[v].size();++i)p[i+1]=p[i+cir+1]=road[v][cir-1-i];
		if(lef){
			int l=cir+1,r=cir;
			for(int i=cir+1;i<=2*cir;++i){
				if(p[i]==u||p[i]==son[u])continue;
				int ql=i-lef,qr=i-1;
				while(l>ql)--l,Add(u,p[l],2*cir-l);
				while(r<qr)++r,Add(u,p[r],2*cir-r);
				while(l<ql)Del(u,p[l],2*cir-l),++l;
				while(r>qr)Del(u,p[r],2*cir-r),--r;
				int d=-(2*cir-i);
				for(int j=0;j<=min(len[p[i]],k);++j){
					int d1=k-j-d;
					if(ct[d1])Ans=(Ans+1ll*ct[d1]*f[p[i]][j])%mod;
				}
			}
			while(l<=r)Del(u,p[l],2*cir-l),++l;
		}
		sub(Ans,ans1);
		Ans=1ll*inv2*Ans%mod;
		add(Ans,ans1);
		for(int i=1;i<road[v].size();++i){
			int Id=road[v][i];if(Id==son[u])continue;
			for(int j=0;j<=min(len[Id],k-up[Id]);++j)if(k-up[Id]-j<=len[u]&&k-up[Id]-j)Ans=(Ans+1ll*f[u][k-up[Id]-j]*f[Id][j])%mod;
		}
		if(!fl){
			for(int i=1;i<road[v].size();++i){
				int Id=road[v][i];if(Id==son[u])continue;
				for(int j=0;j<=len[Id];++j)add(f[u][j+up[Id]],f[Id][j]);
			}
			continue;
		}
		for(int i=1;i<road[v].size();++i){
			int Id=road[v][i];if(Id==son[u])continue;
		    for(int j=0;j<=min(len[Id],k-up[Id]-up[son[u]]);++j)if(k-up[Id]-up[son[u]]-j<=len[son[u]])sub(Ans,1ll*f[son[u]][k-up[Id]-up[son[u]]-j]*f[Id][j]%mod);
			int d1=abs(bl[Id]-bl[son[u]]);d1=min(d1,cir-d1);
			for(int j=0;j<=min(len[Id],k-d1);++j)if(k-d1-j<=len[son[u]])Ans=(Ans+1ll*f[Id][j]*f[son[u]][k-d1-j])%mod;
		}
		for(int i=1;i<road[v].size();++i){
			int Id=road[v][i];if(Id==son[u])continue;
			for(int j=0;j<=len[Id];++j)add(f[u][j+up[Id]],f[Id][j]);
		}
	}
	if(k<=len[u])Ans=(Ans+1ll*f[u][k]*a[u])%mod;
}
int main(){
    n=read(),m=read(),k=read();
    for(int i=1;i<=m;++i){
    	int u=read(),v=read();
        ADD(u,v);
	}
	seed=read();
	mt19937_64 rnd(seed);
        for(int i=1;i<=n;i++)a[i]=rnd()%MAXM+1,a[i]%=mod;
        return 0;
	col=n;
    tarjan(1,-1);if(n>4e6)return 0;
    for(int i=1;i<=col;++i)dep[i]=1e9;
    dep[1]=0;
	dfs(1);
    for(int i=1;i<=n;++i)if(!vis[i])f[i]=ff,ff+=(len[i]+1);

    solve(1);
	cout<<Ans<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 35ms
memory: 251436kb

input:

3000 3408 93
1 2
2 3
3 4
4 5
1 6
3 7
6 8
7 9
6 10
6 11
11 12
12 13
9 14
12 15
13 16
15 17
15 18
18 19
15 20
18 21
20 22
18 23
22 24
23 25
23 26
26 27
27 28
27 29
29 30
26 31
27 32
29 33
32 34
30 35
32 36
36 37
37 38
35 39
39 40
37 41
37 42
41 43
39 44
41 45
45 46
45 47
46 48
48 49
47 50
47 51
51 52
...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Subtask #2:

score: 0
Wrong Answer

Test #8:

score: 0
Wrong Answer
time: 27ms
memory: 251712kb

input:

99734 99733 32
1 2
1 3
2 4
3 5
4 6
5 7
5 8
5 9
4 10
8 11
10 12
2 13
5 14
14 15
11 16
11 17
1 18
5 19
9 20
16 21
20 22
1 23
23 24
5 25
24 26
25 27
1 28
3 29
15 30
14 31
24 32
3 33
29 34
31 35
11 36
9 37
30 38
4 39
26 40
3 41
25 42
36 43
34 44
43 45
13 46
42 47
5 48
48 49
14 50
30 51
2 52
47 53
53 54
...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Subtask #3:

score: 0
Wrong Answer

Test #13:

score: 0
Wrong Answer
time: 36ms
memory: 251828kb

input:

100000 100000 229
1 2
2 3
1 4
2 5
1 6
4 7
3 8
3 9
7 10
6 11
2 12
10 13
12 14
5 15
7 16
9 17
16 18
13 19
13 20
15 21
14 22
14 23
16 24
22 25
16 26
17 27
22 28
27 29
28 30
30 31
24 32
29 33
30 34
26 35
32 36
32 37
30 38
37 39
35 40
31 41
32 42
38 43
36 44
35 45
40 46
40 47
42 48
47 49
46 50
48 51
46 5...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Subtask #4:

score: 0
Wrong Answer

Test #14:

score: 0
Wrong Answer
time: 28ms
memory: 255928kb

input:

89874 89894 91
1 2
2 3
2 4
1 5
4 6
1 7
5 8
8 9
6 10
7 11
10 12
1 13
10 14
3 15
13 16
11 17
15 18
4 19
7 20
13 21
3 22
15 23
14 24
16 25
14 26
22 27
7 28
1 29
10 30
26 31
28 32
5 33
7 34
15 35
20 36
34 37
16 38
18 39
24 40
13 41
17 42
26 43
18 44
21 45
42 46
41 47
3 48
46 49
34 50
17 51
22 52
10 53
3...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Subtask #5:

score: 0
Wrong Answer

Test #15:

score: 0
Wrong Answer
time: 35ms
memory: 255804kb

input:

90000 93021 19
1 2
1 3
3 4
1 5
3 6
5 7
5 8
5 9
4 10
5 11
3 12
7 13
10 14
5 15
6 16
9 17
8 18
16 19
17 20
12 21
20 22
22 23
15 24
22 25
22 26
19 27
26 28
27 29
22 30
29 31
23 32
28 33
32 34
26 35
29 36
36 37
28 38
36 39
36 40
34 41
33 42
35 43
41 44
36 45
40 46
43 47
46 48
39 49
44 50
47 51
46 52
52 ...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Subtask #6:

score: 0
Wrong Answer

Test #16:

score: 0
Wrong Answer
time: 35ms
memory: 251840kb

input:

89849 95377 39
1 2
2 3
2 4
2 5
4 6
6 7
7 8
4 9
5 10
6 11
2 12
2 13
12 14
1 15
1 16
8 17
12 18
10 19
5 20
9 21
1 22
7 23
23 24
23 25
16 26
26 27
26 28
8 29
25 30
16 31
22 32
14 33
6 34
16 35
11 36
12 37
14 38
13 39
5 40
26 41
1 42
32 43
38 44
31 45
16 46
5 47
29 48
45 49
22 50
50 51
48 52
20 53
33 54...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Subtask #7:

score: 0
Wrong Answer

Test #17:

score: 0
Wrong Answer
time: 93ms
memory: 340980kb

input:

3000002 4500001 2
2 3
2 1
3 1
4 5
4 1
5 1
6 7
6 1
7 1
8 9
8 1
9 1
10 11
10 1
11 1
12 13
12 1
13 1
14 15
14 1
15 1
16 17
16 1
17 1
18 19
18 1
19 1
20 21
20 1
21 1
22 23
22 1
23 1
24 25
24 1
25 1
26 27
26 1
27 1
28 29
28 1
29 1
30 31
30 1
31 1
32 33
32 1
33 1
34 35
34 1
35 1
36 37
36 1
37 1
38 39
38 1...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements