P3252 [JLOI2012] 树
  • 板块灌水区
  • 楼主oier25
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/3/3 13:33
  • 上次更新2024/3/3 15:30:38
查看原帖
P3252 [JLOI2012] 树
719233
oier25楼主2024/3/3 13:33

my蒟蒻代码

#include<bits/stdc++.h>
using namespace std;
long long ans,cnt,n,s,h[400005],nxt[400005],to[400005],w[400005],fa[400005];
long long add(long long u,long long v){
	to[++cnt]=v;
	nxt[cnt]=h[u];
	h[u]=cnt;
}
inline void dfs(long long u,long long ww){
	if(ww>s)return;
	if(ww==s){
		ans++;
		return;
	}
	for(long long e=h[u];e;e=nxt[e]){
		long long v=to[e];
		if(fa[u]!=v)dfs(v,ww+w[v]);
	}
}
int main(){ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
	//freopen("paths.in","r",stdin);
	//freopen("paths.out","w",stdout);
	cin>>n>>s;
	for(long long i=1;i<=n;i++)cin>>w[i];
	for(long long i=1;i<n;i++){
		long long u,v;
		cin>>u>>v;
		add(u,v);
		fa[v]=u;
	}
	for(long long i=1;i<=n;i++)dfs(i,w[i]);
	cout<<ans;
	return 0;
} 
#1 RE
#2 WA
#3 WA
#4 WA
#5 RE
#6 WA
#7 WA
#8 WA
#9 WA
#10 WA

1.in

100 40
42 18 35 1 20 25 29 9 13 15 6 46 32 28 12 42 46 43 28 37 42 5 3 4 43 33 22 17 19 46 48 27 22 39 20 13 18 50 36 45 4 12 23 34 24 15 42 12 4 19 48 45 13 8 38 10 24 42 30 29 17 36 41 43 39 7 41 43 15 49 47 6 41 30 21 1 7 2 44 49 30 24 35 5 7 41 17 27 32 9 45 40 27 24 38 39 19 33 30 42 
1 2
2 3
2 4
2 5
3 6
3 7
4 8
5 9
6 10
7 11
8 12
8 13
8 14
9 15
9 16
9 17
10 18
11 19
11 20
11 21
12 22
12 23
12 24
13 25
13 26
13 27
14 28
14 29
15 30
16 31
17 32
17 33
17 34
18 35
19 36
20 37
21 38
21 39
22 40
23 41
23 42
23 43
24 44
25 45
25 46
25 47
26 48
26 49
26 50
27 51
28 52
28 53
29 54
29 55
29 56
30 57
30 58
31 59
31 60
31 61
32 62
32 63
33 64
34 65
34 66
35 67
35 68
36 69
36 70
37 71
38 72
38 73
38 74
39 75
39 76
40 77
41 78
41 79
42 80
42 81
42 82
43 83
44 84
45 85
45 86
45 87
46 88
46 89
46 90
47 91
47 92
48 93
48 94
48 95
49 96
49 97
49 98
50 99
51 100

1.out

2

但就是错了

2024/3/3 13:33
加载中...