Under construction

Still being built. Things may change

Apollonian Network

Time limit3sMemory limit512 MB

Summary
Given a weighted Apollonian network with n vertices, find the largest total edge weight of any simple path in the graph.
Level

Hard9 of 10

Topics
Graph, Dynamic programming, Recursion
Solved
No attempts yet

Problem

An Apollonian network is an undirected graph. It starts from a triangle, and then repeatedly takes a triangle in the middle and splits it into three smaller triangles.

In a weighted Apollonian network, find the simple path with the largest total weight, and print that total weight.

Input

The first line contains the number of vertices nn (3≤n≤2503 \le n \le 250).

The next 3(n−2)3(n-2) lines each contain three integers aia_i, bib_i, cic_i. Each line means that an edge with weight cic_i connects vertices aia_i and bib_i. (1≤ai,bi≤n1 \le a_i, b_i \le n, 0≤ci≤1060 \le c_i \le 10^6)

The given graph is an Apollonian network.

Output

Print the largest total weight of a simple path.

Examples2

  1. Example 1

    Input
    3
    1 2 1
    2 3 1
    3 1 2
    
    Expected output
    3
    
  2. Example 2

    Input
    10
    1 2 4
    2 3 4
    3 1 3
    6 1 3
    6 2 3
    6 3 4
    4 6 4
    4 3 4
    4 2 3
    5 1 3
    5 6 3
    5 2 4
    10 1 4
    10 3 3
    10 6 3
    7 1 4
    7 10 4
    7 6 3
    8 1 3
    8 3 4
    8 10 4
    9 3 4
    9 8 3
    9 10 3
    
    Expected output
    35