bfs
import java.util.*;
class pair {
int a;//序号
double b;//当前功力
public pair(int a,double b) {
this.a = a;
this.b = b;
}
}
public class Main {
static int N = 100010;
static int n;
static double z,r;
static double[] shu = new double[N];//放大倍数
static List<Integer>[] mp = new ArrayList[N];//邻接表
static double ans = 0;
public static void bfs() {
Queue<pair> q = new LinkedList<>();
q.offer(new pair(0,z));//把祖师爷加进队列
while (q.size() != 0) {
pair t = q.remove();
int x = t.a;
double y = t.b;
if (mp[x].size() == 0) { //得道者
ans += y * shu[x];
continue;
}
for (int i:mp[x])
q.offer(new pair(i,y * (1 - r / 100)));
}
System.out.println((int)ans);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
z = sc.nextDouble();
r = sc.nextDouble();
for (int i = 0;i < n;i ++) {
mp[i] = new ArrayList<>();//初始化邻接表
int k = sc.nextInt();
if (k == 0) {
shu[i] = sc.nextDouble();
} else {
for (int j = 0;j < k;j ++) {
int id = sc.nextInt();
mp[i].add(id);//邻接表建图
}
}
}
bfs();
}
}
dfs
import java.util.*;
public class Main {
static int N = 100010;
static double[] shu = new double[N];//放大倍数
static int n;
static double z,r;
static ArrayList<Integer>[] mp = new ArrayList[N];
static double ans;
public static void dfs(int a,double b) { //
if (mp[a].size() == 0) {
ans += b * shu[a];
} else {
for (int i:mp[a]) {
dfs(i,b * (1 - r));
}
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
z = sc.nextDouble();
r = sc.nextDouble();
r = r / 100;//处理r
for (int i = 0;i < n;i ++) {
mp[i] = new ArrayList<>();
int k = sc.nextInt();
if (k == 0) {
shu[i] = sc.nextInt();
} else {
for (int j = 0;j < k;j ++) {
int id = sc.nextInt();
mp[i].add(id);//邻接表建图
}
}
}
dfs(0,z);
System.out.println((int)ans);
}
}