Buggy python submission (verdict: Time Limit Exceeded):
import sys
import heapq
sys.setrecursionlimit(10**6)
INF = 10**9

n = int(input())
edge = [[] for _ in range(n)]

def get_max_dist(frm, n, dist):
    val = 0
    index = -1
    for item in edge[n]:
        if item == frm:
            if len(edge[n]) == 1:
                return dist, n
            continue
        tmp, tindex = get_max_dist(n, item, dist+1)
        if val < tmp:
            val = tmp
            index = tindex
    return val, index

for i in range(n-1):
    a, b = [int(item) for item in input().split()]
    a -= 1; b -= 1
    edge[a].append(b)
    edge[b].append(a)

val, left = get_max_dist(-1, 0, 0)
diam, right = get_max_dist(-1, left, 0)

if diam % 3 == 1:
    print("Second")
else:
    print("First")

Fixed submission:
import heapq
INF = 10**9

n = int(input())
edge = [[] for _ in range(n)]

class Dijkstra:
    def __init__(self, adj):
        self.adj = adj
        self.num = len(adj)
        self.dist = [INF] * self.num
        self.prev = [INF] * self.num
        self.q = []

    def reset(self):
        self.dist = [INF] * self.num
        self.prev = [INF] * self.num
        self.q = []

    def calc(self, start):
        self.dist[start] = 0
        heapq.heappush(self.q, (0, start))
        while len(self.q) != 0:
            prov_cost, src = heapq.heappop(self.q)
            if self.dist[src] < prov_cost:
                continue
            for dest in self.adj[src]:
                cost = 1
                if self.dist[dest] > self.dist[src] + cost:
                    self.dist[dest] = self.dist[src] + cost
                    heapq.heappush(self.q, (self.dist[dest], dest))
                    self.prev[dest] = src
        return self.dist 

for i in range(n-1):
    a, b = [int(item) for item in input().split()]
    a -= 1; b -= 1
    edge[a].append(b)
    edge[b].append(a)

dij = Dijkstra(edge)
dist = dij.calc(0)
left = dist.index(max(dist))
dij.reset()
dist = dij.calc(left)
diam = max(dist)
if diam % 3 == 1:
    print("Second")
else:
    print("First")

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import heapq
sys.setrecursionlimit(10**6)
INF = 10**9

n = int(input())
edge = [[] for _ in range(n)]

def get_max_dist(frm, n, dist):
    val = 0
    index = -1
    for item in edge[n]:
        if item == frm:
            if len(edge[n]) == 1:
                return dist, n
            continue
        tmp, tindex = get_max_dist(n, item, dist+1)
        if val < tmp:
            val = tmp
            index = tindex
    return val, index

for i in range(n-1):
    a, b = [int(item) for item in input().split()]
    a -= 1; b -= 1
    edge[a].append(b)
    edge[b].append(a)

val, left = get_max_dist(-1, 0, 0)
diam, right = get_max_dist(-1, left, 0)

if diam % 3 == 1:
    print("Second")
else:
    print("First")

Fixed submission:
import heapq
INF = 10**9

n = int(input())
edge = [[] for _ in range(n)]

class Dijkstra:
    def __init__(self, adj):
        self.adj = adj
        self.num = len(adj)
        self.dist = [INF] * self.num
        self.prev = [INF] * self.num
        self.q = []

    def reset(self):
        self.dist = [INF] * self.num
        self.prev = [INF] * self.num
        self.q = []

    def calc(self, start):
        self.dist[start] = 0
        heapq.heappush(self.q, (0, start))
        while len(self.q) != 0:
            prov_cost, src = heapq.heappop(self.q)
            if self.dist[src] < prov_cost:
                continue
            for dest in self.adj[src]:
                cost = 1
                if self.dist[dest] > self.dist[src] + cost:
                    self.dist[dest] = self.dist[src] + cost
                    heapq.heappush(self.q, (self.dist[dest], dest))
                    self.prev[dest] = src
        return self.dist 

for i in range(n-1):
    a, b = [int(item) for item in input().split()]
    a -= 1; b -= 1
    edge[a].append(b)
    edge[b].append(a)

dij = Dijkstra(edge)
dist = dij.calc(0)
left = dist.index(max(dist))
dij.reset()
dist = dij.calc(left)
diam = max(dist)
if diam % 3 == 1:
    print("Second")
else:
    print("First")

Buggy python submission (verdict: Runtime Error):
import heapq
INF = 10**9

n = int(input())
edge = [[] for _ in range(n)]

def get_max_dist(frm, n, dist):
    val = 0
    index = -1
    for item in edge[n]:
        if item == frm:
            if len(edge[n]) == 1:
                return dist, n
            continue
        tmp, tindex = get_max_dist(n, item, dist+1)
        if val < tmp:
            val = tmp
            index = tindex
    return val, index

for i in range(n-1):
    a, b = [int(item) for item in input().split()]
    a -= 1; b -= 1
    edge[a].append(b)
    edge[b].append(a)

val, left = get_max_dist(-1, 0, 0)
diam, right = get_max_dist(-1, left, 0)

if diam % 3 == 1:
    print("Second")
else:
    print("First")

Fixed submission:
import heapq
INF = 10**9

n = int(input())
edge = [[] for _ in range(n)]

class Dijkstra:
    def __init__(self, adj):
        self.adj = adj
        self.num = len(adj)
        self.dist = [INF] * self.num
        self.prev = [INF] * self.num
        self.q = []

    def reset(self):
        self.dist = [INF] * self.num
        self.prev = [INF] * self.num
        self.q = []

    def calc(self, start):
        self.dist[start] = 0
        heapq.heappush(self.q, (0, start))
        while len(self.q) != 0:
            prov_cost, src = heapq.heappop(self.q)
            if self.dist[src] < prov_cost:
                continue
            for dest in self.adj[src]:
                cost = 1
                if self.dist[dest] > self.dist[src] + cost:
                    self.dist[dest] = self.dist[src] + cost
                    heapq.heappush(self.q, (self.dist[dest], dest))
                    self.prev[dest] = src
        return self.dist 

for i in range(n-1):
    a, b = [int(item) for item in input().split()]
    a -= 1; b -= 1
    edge[a].append(b)
    edge[b].append(a)

dij = Dijkstra(edge)
dist = dij.calc(0)
left = dist.index(max(dist))
dij.reset()
dist = dij.calc(left)
diam = max(dist)
if diam % 3 == 1:
    print("Second")
else:
    print("First")