메뉴 건너뛰기

Programing

BAEKJOON

1967

관리자 2019.12.21 11:43 조회 수 : 6

C++

#include <cstdio>

#include <vector>

#include <algorithm>

using namespace std;

 

struct Edge

{

    int node;

    int dist;

};

 

struct Node

{

    int parent;

    vector<Edge> childs;

};

int MAX=0;

const int MAX_N = 10005;

Node tree[MAX_N];

int N;

int f(int n){

    int max_ = 0,max_2 = 0;

    for(auto e : tree[n].childs)

    {

        int d = f(e.node) + e.dist;

        if(d>max_){

            max_2=max_;

            max_=d;

 

        }else if(d>max_2){

            max_2=d;

        }

    }

    MAX=max(MAX,max_+max_2);

    return max_;

}

 

int main()

{

    scanf("%d",&N);

    for(int i=1;i<N;i++){

        int p, c, d;

        scanf("%d %d %d",&p,&c,&d);

        tree[p].childs.push_back({c,d});

        tree[c].parent=p;

    }

    f(1);

    printf("%d",MAX);

    return 0;

}

번호 제목 글쓴이 날짜 조회 수
공지 안내사항 관리자 2019.12.21 163
45 2468 관리자 2019.12.21 8
44 2458 관리자 2020.04.11 44
43 2457 관리자 2020.04.11 47
42 2454 관리자 2020.04.11 43
41 2450 관리자 2020.04.11 40
40 2339 관리자 2020.04.11 41
39 2307 관리자 2019.12.21 8
38 2250 관리자 2019.12.21 8
37 2233 관리자 2019.12.21 6
36 2170 관리자 2019.12.21 7
35 2132 관리자 2019.12.21 7
34 2096 관리자 2019.12.21 8
33 2042 관리자 2020.04.11 45
32 2003 관리자 2020.04.11 39
31 1991 관리자 2019.12.21 8
» 1967 관리자 2019.12.21 6
29 1966 관리자 2020.04.11 45
28 1946 관리자 2020.04.11 39
27 1874 관리자 2020.04.11 43
26 1839 관리자 2020.04.11 44
25 17611 관리자 2019.12.21 7
24 1753 관리자 2019.12.21 8
23 1742 관리자 2020.04.11 6
22 1720 관리자 2020.04.11 6
21 16210 관리자 2020.04.11 57
20 16201 관리자 2020.04.11 44
19 15971 관리자 2019.12.21 6
18 14865 관리자 2019.12.21 8
17 14503 관리자 2019.12.21 7
16 14502 관리자 2019.12.21 6
위로