-
Notifications
You must be signed in to change notification settings - Fork 0
/
1106.cpp
71 lines (56 loc) · 1.34 KB
/
1106.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <cstdio>
#include <vector>
#include <cfloat>
const int MAXN = 100000 + 10;
struct Node {
int id;
std::vector<Node *> ch;
double data;
Node() {
ch.clear();
id = 0;
data = 1;
}
void addChild(Node *x) {
ch.push_back(x);
}
} nodes[MAXN];
void dfs(Node *root, double r) {
if (root->ch.empty()) return;
for (auto &x : root->ch) {
x->data = root->data * (1 + r / 100);
dfs(x, r);
}
}
int main() {
int n;
double p, r;
scanf("%d%lf%lf", &n, &p, &r);
for (int i = 0; i < n; i++) nodes[i].id = i;
Node *root = &nodes[0];
for (int i = 0; i < n; i++) {
int num;
scanf("%d", &num);
for (int j = 0; j < num; j++) {
int ch;
scanf("%d", &ch);
nodes[i].addChild(&nodes[ch]);
}
}
root->data = p;
dfs(root, r);
double ans = DBL_MAX;
int cnt = 0;
for (int i = 0; i < n; i++) {
if (nodes[i].ch.empty()) {
// printf("%.2lf ", nodes[i].data);
if (nodes[i].data == ans) cnt++;
else if (nodes[i].data < ans) {
ans = nodes[i].data;
cnt = 1;
}
}
}
printf("%.4lf %d\n", ans, cnt);
return 0;
}