QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#321984#7607. The Doubling Game 2huazai676WA 5ms24952kbC++141.4kb2024-02-06 00:18:212024-02-06 00:18:22

Judging History

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

  • [2024-02-06 00:18:22]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:24952kb
  • [2024-02-06 00:18:21]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#define int long long

using namespace std;

typedef long long ll;

const int N=3e5+10,mod=1e9+7;

int n,ans[N];
vector<int> T[N],f[N],g[N];

void add(int &x,ll y)
{
	x+=y%mod;
	if(x>=mod) x-=mod;
}

void dfs(int u,int fa)
{
	for(int v:T[u]) if(v!=fa) dfs(v,u);
	vector<int> f1(2),g1(2);
	f1[0]=1;
	int sz=0;
	sort(T[u].begin(),T[u].end(),[](int x,int y){return f[x].size()<f[y].size();});
	for(int v:T[u])
	{
		if(v==fa) continue;
		vector<int> f2(1<<(f[v].size()+1)),g2(1<<(f[v].size()+1));
		for(int i=0;i<(1<<sz);i++)
		{
			add(f2[i],1LL*f1[i]*ans[v]),add(g2[i],1LL*g1[i]*ans[v]);
			for(int j=0;j<f[v].size();j++)
			{
				if((i>>j)&1) continue;
				add(f2[i|(1<<j)],1LL*f1[i]*f[v][j]);
				if((1<<j)>i) add(g2[i|(1<<j)],1LL*f1[i]*g[v][j]);
				else add(g2[i|(1<<j)],1LL*g1[i]*f[v][j]);
			}
		}
		swap(f1,f2),swap(g1,g2);
		sz=f[v].size();
		vector<int>().swap(f2),vector<int>().swap(g2);
	}
	f[u].resize(sz+1),g[u].resize(sz+1);
	for(int i=0;i<=sz;i++)
	{
		int s=(1<<i)-1;
		add(ans[u],f1[s]+g1[s]);
		add(f[u][i],f1[s]),add(g[u][i],f1[i]);
		for(int j=0;j<i-1;j++) add(g[u][j],f1[s^(1<<j)]+g1[s^(1<<j)]);
	}
}

signed main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int u,v;
		cin>>u>>v;
		T[u].push_back(v),T[v].push_back(u);
	}
	dfs(1,0);
	cout<<ans[1];
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 24688kb

input:

5
1 2
1 3
1 4
4 5

output:

21

result:

ok single line: '21'

Test #2:

score: 0
Accepted
time: 5ms
memory: 24848kb

input:

1

output:

1

result:

ok single line: '1'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 24952kb

input:

128
11 32
116 81
65 4
117 47
5 81
104 30
61 8
82 59
95 20
92 29
29 127
97 39
123 33
59 128
115 33
83 67
74 16
77 33
64 73
124 123
8 127
61 51
101 122
35 90
119 116
112 27
81 93
109 123
54 1
119 100
116 16
65 47
67 27
22 105
76 87
36 39
27 96
72 31
91 123
21 105
118 12
110 48
121 72
14 115
24 16
106 ...

output:

95726735

result:

wrong answer 1st lines differ - expected: '508800953', found: '95726735'