解题关键:dfs的简单应用,需要注意类型double与int
#include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<iostream> #include<cmath> #define maxn 100002 using namespace std; typedef long long ll; int n; double z,r; int vis[maxn]; int cnt=0,head[maxn]; struct edge{ int to,nxt; }e[maxn]; void add_edge(int u,int v){ e[cnt].to=v; e[cnt].nxt=head[u]; head[u]=cnt++; } double dfs(int u,double val){ if(vis[u]){ val*=vis[u]; return val; } double res=0; val*=r; for(int i=head[u];i!=-1;i=e[i].nxt){ int v=e[i].to; res+=dfs(v,val); } return res; } int main(){ memset(head, -1, sizeof head); cin>>n>>z>>r; r=1-0.01*r; for(int i=0;i<n;i++){ int tmp,t2; cin>>tmp; if(tmp==0){ cin>>t2; vis[i]=t2; }else{ for(int j=0;j<tmp;j++){ int t; cin>>t; add_edge(i,t); } } } printf("%d ",(int)dfs(0,z)); return 0; }