QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#620153#2443. Dense Subgraphuntitledtwo#WA 225ms13852kbC++172.3kb2024-10-07 16:49:532024-10-07 16:50:06

Judging History

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

  • [2024-10-07 16:50:06]
  • 评测
  • 测评结果:WA
  • 用时:225ms
  • 内存:13852kb
  • [2024-10-07 16:49:53]
  • 提交

answer

#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
typedef long long ll;
#define int ll
int a[35010];
struct Edge
{
	int to, nxt;
} e[70010];
int head[35010], ecnt = 0;
inline void addedge(int from, int to)
{
	e[ecnt].to = to;
	e[ecnt].nxt = head[from];
	head[from] = ecnt++;
}
int deg[35010], fa[35010], son[35010][4], scnt[35010];
int st[35010][16]; // 0: very safe, 1: half safe, 2: g
inline void dfs(int u)
{
	for(int i = head[u]; i != -1; i = e[i].nxt)
	{
		int v = e[i].to;
		if(v == fa[u])
			continue;
		son[u][scnt[u]++] = v, fa[v] = u;
		dfs(v);
	}
}
int dp[35010][3]; // 0: not chosen, 1: cannot choose fa, 2: can choose fa
inline void dfs2(int u)
{
	int m = scnt[u];
	for(int i = 0; i < m; i++)
		dfs2(son[u][i]);
	dp[u][0] = 1, dp[u][1] = dp[u][2] = 0;
	for(int i = 0; i < m; i++)
	{
		int v = son[u][i];
		dp[u][0] = dp[u][0] * (dp[v][0] + dp[v][1] + dp[v][2]) % mod;
	}
	for(int i = 0; i < (1 << m); i++)
	{
		if(st[u][i] == 2)
			continue;
		int res = 1;
		for(int j = 0; j < m; j++)
		{
			int v = son[u][j];
			if((i >> j) & 1)
				res = res * dp[v][2] % mod;
			else
				res = res * dp[v][0] % mod;
		}
		if(st[u][i])
			dp[u][1] = (dp[u][1] + res) % mod;
		else
			dp[u][2] = (dp[u][2] + res) % mod;
	}
}
signed main()
{
	int T;
	scanf("%lld", &T);
	while(T--)
	{
		int n, x;
		scanf("%lld %lld", &n, &x);
		for(int i = 1; i <= n; i++)
			scanf("%lld", &a[i]), a[i] -= x;
		for(int i = 1; i <= n; i++)
			head[i] = -1, deg[i] = 0, scnt[i] = 0;
		ecnt = 0;
		for(int i = 1; i < n; i++)
		{
			int u, v;
			scanf("%lld %lld", &u, &v);
			addedge(u, v), addedge(v, u);
			deg[u]++, deg[v]++;
		}
		int rt = 1;
		for(int i = 1; i <= n; i++)
			if(deg[i] < deg[rt])
				rt = i;
		fa[rt] = rt;
		dfs(rt);
		for(int i = 1; i <= n; i++)
		{
			int m = scnt[i];
			for(int j = 0; j < (1 << m); j++)
			{
				int sum = a[i];
				for(int k = 0; k < m; k++)
					if((j >> k) & 1)
						sum += a[son[i][k]];
				if(sum > 0 && j)
					st[i][j] = 2;
				else if(i != rt && sum + a[fa[i]] > 0)
					st[i][j] = 1;
				else
					st[i][j] = 0;
			}
		}
		dfs2(rt);
		int ans = (dp[rt][0] + dp[rt][1] + dp[rt][2]) % mod;
		printf("%lld\n", ans);
	}
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 225ms
memory: 13852kb

input:

30
10 11086
10189 24947 2265 9138 27104 12453 15173 3048 30054 2382
8 1
1 4
5 10
10 4
3 5
2 10
9 7
6 10
7 1
15 9664
4127 24649 13571 8586 34629 8644 3157 33133 3713 32646 29412 8108 13583 21362 23735
14 9
7 1
15 12
10 15
2 6
3 11
9 1
1 11
6 12
4 10
13 15
8 15
12 11
5 3
20 29310
21738 9421 8412 4617 ...

output:

320
3312
1048576
703391137
354818952
215379798
65695422
73141265
527067474
561320007
973401160
619388222
570012362
51289536
732832863
830197944
698429452
806352562
438458641
327191535
317610455
83091102
228214282
45024183
816501286
779978391
392083356
634600456
907786859
70010555

result:

wrong answer 4th lines differ - expected: '60461799', found: '703391137'