본문 바로가기

Algorithm

(C++) - 백준(BOJ) 17073번 : 나무 위의 빗물

반응형

물이 멈추는 구간은 leaf일 때 뿐이므로 입력 시 leaf만 세준다. 그 후 소수점 10자리 출력

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
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int u, v, n;
double cnt,w;
int a[500001];
 
//1번노드에 들어가 있는 물의 양
int main() {
    cin >> n >> w;
    for(int i = 1 ; i<=n-1; i++)
    {
        cin >> u >> v;
        a[u]++;
        a[v]++;
    }
    for (int i = 2; i <= n; i++)
    {
        if (a[i] == 1)
        {
            cnt++;
        }
        //cout << a[i] << ' ';
    }
    printf("%.10f", w / cnt);
    
}
cs