Buggy python submission (verdict: Runtime Error):
# Acceptance of input

import sys

f_i = sys.stdin

n = int(f_i.readline())

edges = [[None] * n for i in range(n)]

for l_i in f_i:
    s, t, w = map(int, l_i.split())
    edges[s][t] = w
    edges[t][s] = w

# Tree Walk and Output

distance = [0] * n

def tree_walk(u, d, p):
    for v, e in enumerate(edges[u]):
        if e != None and v != p:
            c_d = d + e
            distance[v] = c_d
            tree_walk(v, c_d, u)

tree_walk(0, 0, None)

end_point = distance.index(max(distance))

tree_walk(end_point, 0, None)

print(max(distance))

Fixed submission:
# Acceptance of input

import sys

f_i = sys.stdin

n = int(f_i.readline())

edges = [[] for i in range(n)]

for l_i in f_i:
    s, t, w = map(int, l_i.split())
    edges[s].append((t, w))
    edges[t].append((s, w))

# Tree Walk function

import collections

def tree_walk(start, switch = 0):
    path = collections.deque()
    path.append(start)

    weight = collections.deque()
    weight.append(0)
    
    unvisited = [True] * n
    unvisited[start] = False
    
    rest = n - 1
    end_point = start
    diameter = 0
    
    while True:
        u = path[-1]
        for v, w in edges[u]:
            if unvisited[v]:
                path.append(v)
                unvisited[v] = False
                rest -= 1
                weight.append(w)
                break

        if u == path[-1]:
            distance = sum(weight)
            if diameter < distance:
                diameter = distance
                end_point = u
            if rest == 0:
                break
            path.pop()
            weight.pop()

    if switch:
        print(diameter)
    else:
        return end_point

# Output

tree_walk(tree_walk(0), 1)

Buggy python submission (verdict: Runtime Error):
# Acceptance of input

import sys

f_i = sys.stdin

n = int(f_i.readline())

edges = [[None] * n for i in range(n)]

for l_i in f_i:
    s, t, w = map(int, l_i.split())
    edges[s][t] = w
    edges[t][s] = w

# dfs tree walk 1

import collections

path = collections.deque()
path.append(0)

distance = 0
max_distance = 0

unvisited = [False] + [True] * (n - 1)

while True:
    u = path[-1]
    adj_e = edges[u]
    for v, e in enumerate(adj_e):
        if unvisited[v] and e != None:
            path.append(v)
            distance += e
            unvisited[v] = False
            if max_distance < distance:
                max_distance = distance
                end_point = v
            break
    if u == path[-1]:
        path.pop()
        if path:
            distance -= edges[u][path[-1]]
        else:
            break

# Measurement of diameter(dfs tree walk 2)

path.append(end_point)

distance = 0
diameter = 0

unvisited = [True] * n
unvisited[end_point] = False

while True:
    u = path[-1]
    adj_e = edges[u]
    for v, e in enumerate(adj_e):
        if unvisited[v] and e != None:
            path.append(v)
            distance += e
            unvisited[v] = False
            if diameter < distance:
                diameter = distance
                end_point = v
            break
    if u == path[-1]:
        path.pop()
        if path:
            distance -= edges[u][path[-1]]
        else:
            break

# output

print(diameter)

Fixed submission:
# Acceptance of input

import sys

f_i = sys.stdin

n = int(f_i.readline())

edges = [[] for i in range(n)]

for l_i in f_i:
    s, t, w = map(int, l_i.split())
    edges[s].append((t, w))
    edges[t].append((s, w))

# Tree Walk function

import collections

def tree_walk(start, switch = 0):
    path = collections.deque()
    path.append(start)

    weight = collections.deque()
    weight.append(0)
    
    unvisited = [True] * n
    unvisited[start] = False
    
    rest = n - 1
    end_point = start
    diameter = 0
    
    while True:
        u = path[-1]
        for v, w in edges[u]:
            if unvisited[v]:
                path.append(v)
                unvisited[v] = False
                rest -= 1
                weight.append(w)
                break

        if u == path[-1]:
            distance = sum(weight)
            if diameter < distance:
                diameter = distance
                end_point = u
            if rest == 0:
                break
            path.pop()
            weight.pop()

    if switch:
        print(diameter)
    else:
        return end_point

# Output

tree_walk(tree_walk(0), 1)

Buggy python submission (verdict: Time Limit Exceeded):
# Acceptance of input

import sys

f_i = sys.stdin

n = int(f_i.readline())

edges = [[None] * n for i in range(n)]

for l_i in f_i:
    s, t, w = map(int, l_i.split())
    edges[s][t] = w
    edges[t][s] = w

# dfs tree walk 1

import collections

path = collections.deque()
path.append(0)

distance = 0
max_distance = 0

end_point = 0

unvisited = [False] + [True] * (n - 1)

while True:
    u = path[-1]
    adj_e = edges[u]
    for v, e in enumerate(adj_e):
        if unvisited[v] and e != None:
            path.append(v)
            distance += e
            unvisited[v] = False
            if max_distance < distance:
                max_distance = distance
                end_point = v
            break
    if u == path[-1]:
        path.pop()
        if path:
            distance -= edges[u][path[-1]]
        else:
            break

# Measurement of diameter(dfs tree walk 2)

path.append(end_point)

distance = 0
diameter = 0

unvisited = [True] * n
unvisited[end_point] = False

while True:
    u = path[-1]
    adj_e = edges[u]
    for v, e in enumerate(adj_e):
        if unvisited[v] and e != None:
            path.append(v)
            distance += e
            unvisited[v] = False
            if diameter < distance:
                diameter = distance
                end_point = v
            break
    if u == path[-1]:
        path.pop()
        if path:
            distance -= edges[u][path[-1]]
        else:
            break

# output

print(diameter)

Fixed submission:
# Acceptance of input

import sys

f_i = sys.stdin

n = int(f_i.readline())

edges = [[] for i in range(n)]

for l_i in f_i:
    s, t, w = map(int, l_i.split())
    edges[s].append((t, w))
    edges[t].append((s, w))

# Tree Walk function

import collections

def tree_walk(start, switch = 0):
    path = collections.deque()
    path.append(start)

    weight = collections.deque()
    weight.append(0)
    
    unvisited = [True] * n
    unvisited[start] = False
    
    rest = n - 1
    end_point = start
    diameter = 0
    
    while True:
        u = path[-1]
        for v, w in edges[u]:
            if unvisited[v]:
                path.append(v)
                unvisited[v] = False
                rest -= 1
                weight.append(w)
                break

        if u == path[-1]:
            distance = sum(weight)
            if diameter < distance:
                diameter = distance
                end_point = u
            if rest == 0:
                break
            path.pop()
            weight.pop()

    if switch:
        print(diameter)
    else:
        return end_point

# Output

tree_walk(tree_walk(0), 1)

Buggy python submission (verdict: Runtime Error):
# Acceptance of input

import sys

f_i = sys.stdin

n = int(f_i.readline())

edges = [[] for i in range(n)]

for l_i in f_i:
    s, t, w = map(int, l_i.split())
    edges[s].append([t, w])
    edges[t].append([s, w])

# Tree Walk and Output

distance = [0] * n

sys.setrecursionlimit(10000)

def tree_walk(u, d, p):
    for v, w in edges[u]:
        if v != p:
            c_d = d + w
            distance[v] = c_d
            tree_walk(v, c_d, u)

tree_walk(0, 0, None)

end_point = distance.index(max(distance))

tree_walk(end_point, 0, None)

print(max(distance))

Fixed submission:
# Acceptance of input

import sys

f_i = sys.stdin

n = int(f_i.readline())

edges = [[] for i in range(n)]

for l_i in f_i:
    s, t, w = map(int, l_i.split())
    edges[s].append((t, w))
    edges[t].append((s, w))

# Tree Walk function

import collections

def tree_walk(start, switch = 0):
    path = collections.deque()
    path.append(start)

    weight = collections.deque()
    weight.append(0)
    
    unvisited = [True] * n
    unvisited[start] = False
    
    rest = n - 1
    end_point = start
    diameter = 0
    
    while True:
        u = path[-1]
        for v, w in edges[u]:
            if unvisited[v]:
                path.append(v)
                unvisited[v] = False
                rest -= 1
                weight.append(w)
                break

        if u == path[-1]:
            distance = sum(weight)
            if diameter < distance:
                diameter = distance
                end_point = u
            if rest == 0:
                break
            path.pop()
            weight.pop()

    if switch:
        print(diameter)
    else:
        return end_point

# Output

tree_walk(tree_walk(0), 1)

Buggy python submission (verdict: Runtime Error):
# Acceptance of input

import sys

f_i = sys.stdin

n = int(f_i.readline())

edges = [[] for i in range(n)]

for l_i in f_i:
    s, t, w = map(int, l_i.split())
    edges[s].append([t, w])
    edges[t].append([s, w])

# Tree Walk and Output

distance = [0] * n

sys.setrecursionlimit(100000)

def tree_walk(u, d, p):
    for v, w in edges[u]:
        if v != p:
            c_d = d + w
            distance[v] = c_d
            tree_walk(v, c_d, u)

tree_walk(0, 0, None)

end_point = distance.index(max(distance))

tree_walk(end_point, 0, None)

print(max(distance))

Fixed submission:
# Acceptance of input

import sys

f_i = sys.stdin

n = int(f_i.readline())

edges = [[] for i in range(n)]

for l_i in f_i:
    s, t, w = map(int, l_i.split())
    edges[s].append((t, w))
    edges[t].append((s, w))

# Tree Walk function

import collections

def tree_walk(start, switch = 0):
    path = collections.deque()
    path.append(start)

    weight = collections.deque()
    weight.append(0)
    
    unvisited = [True] * n
    unvisited[start] = False
    
    rest = n - 1
    end_point = start
    diameter = 0
    
    while True:
        u = path[-1]
        for v, w in edges[u]:
            if unvisited[v]:
                path.append(v)
                unvisited[v] = False
                rest -= 1
                weight.append(w)
                break

        if u == path[-1]:
            distance = sum(weight)
            if diameter < distance:
                diameter = distance
                end_point = u
            if rest == 0:
                break
            path.pop()
            weight.pop()

    if switch:
        print(diameter)
    else:
        return end_point

# Output

tree_walk(tree_walk(0), 1)

Buggy python submission (verdict: Runtime Error):
# Acceptance of input

import sys

f_i = sys.stdin

n = int(f_i.readline())

edges = [[] for i in range(n)]

for l_i in f_i:
    s, t, w = map(int, l_i.split())
    edges[s].append([t, w])
    edges[t].append([s, w])

# Tree Walk and Output

distance = [0] * n

sys.setrecursionlimit(200000)

def tree_walk(u, d, p):
    for v, w in edges[u]:
        if v != p:
            c_d = d + w
            distance[v] = c_d
            tree_walk(v, c_d, u)

tree_walk(0, 0, None)

end_point = distance.index(max(distance))

tree_walk(end_point, 0, None)

print(max(distance))

Fixed submission:
# Acceptance of input

import sys

f_i = sys.stdin

n = int(f_i.readline())

edges = [[] for i in range(n)]

for l_i in f_i:
    s, t, w = map(int, l_i.split())
    edges[s].append((t, w))
    edges[t].append((s, w))

# Tree Walk function

import collections

def tree_walk(start, switch = 0):
    path = collections.deque()
    path.append(start)

    weight = collections.deque()
    weight.append(0)
    
    unvisited = [True] * n
    unvisited[start] = False
    
    rest = n - 1
    end_point = start
    diameter = 0
    
    while True:
        u = path[-1]
        for v, w in edges[u]:
            if unvisited[v]:
                path.append(v)
                unvisited[v] = False
                rest -= 1
                weight.append(w)
                break

        if u == path[-1]:
            distance = sum(weight)
            if diameter < distance:
                diameter = distance
                end_point = u
            if rest == 0:
                break
            path.pop()
            weight.pop()

    if switch:
        print(diameter)
    else:
        return end_point

# Output

tree_walk(tree_walk(0), 1)