Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# GRL_5_E: Tree - Range Query on Tree 2


class RAQ:
    def __init__(self, n, initial=0):
        size = 1
        while size < n:
            size *= 2
        self.size = 2*size - 1
        self.data = [initial] * self.size

    def add(self, i, j, v):
        def _add(r, lo, hi):
            if hi < i or lo > j:
                return
            elif i <= lo and hi <= j:
                self.data[r] += v
            else:
                mid = lo + (hi - lo)//2
                _add(r*2 + 1, lo, mid)
                _add(r*2 + 2, mid+1, hi)

        return _add(0, 0, self.size//2)

    def add_nested(self, ranges, v):
        def _add(r, lo, hi, n):
            while n >= 0:
                i, j = ranges[n]
                if hi < i or lo > j:
                    return
                elif (i <= lo and hi <= j):
                    self.data[r] += v
                    n -= 1
                else:
                    mid = lo + (hi - lo)//2
                    _add(r*2 + 1, lo, mid, n)
                    _add(r*2 + 2, mid+1, hi, n)
                    return

        return _add(0, 0, self.size//2, len(ranges)-1)

    def get(self, i):
        def _get(r, lo, hi, v):
            v += self.data[r]
            if lo == hi:
                return v
            mid = lo + (hi - lo)//2
            if mid >= i:
                return _get(r*2 + 1, lo, mid, v)
            else:
                return _get(r*2 + 2, mid+1, hi, v)

        return _get(0, 0, self.size//2, 0)


class Edge:
    __slots__ = ('v', 'w')

    def __init__(self, v, w):
        self.v = v
        self.w = w

    def either(self):
        return self.v

    def other(self, v):
        if v == self.v:
            return self.w
        else:
            return self.v


class Graph:
    def __init__(self, v):
        self.v = v
        self._edges = [[] for _ in range(v)]

    def add(self, e):
        self._edges[e.v].append(e)
        self._edges[e.w].append(e)

    def adj(self, v):
        return self._edges[v]

    def edges(self):
        for es in self._edges:
            for e in es:
                yield e


class PathSum2:
    """PathSum with range update.
    """
    def __init__(self, graph, root):
        self.root = root
        self.seg = RAQ(graph.v)
        self._dfs(graph, root)

    def _dfs(self, graph, root):
        visited = [False] * graph.v
        pos = [None] * graph.v
        parent = [None] * graph.v
        stack = [root]
        n = 0
        ns = []
        while stack:
            v = stack.pop()
            if not visited[v]:
                visited[v] = True
                ns.append(n)
                n += 1
                stack.append(v)
                for e in graph.adj(v):
                    w = e.other(v)
                    if not visited[w]:
                        parent[w] = v
                        stack.append(w)
            else:
                pos[v] = (ns.pop(), n - 1)

        self._pos = pos
        self._parent = parent

    def add(self, v, val):
        ps = []
        u = v
        while u != self.root:
            ps.append(self._pos[u])
            u = self._parent[u]
        self.seg.add_nested(ps, val)

    def get(self, v):
        return self.seg.get(self._pos[v][0])


def run():
    n = int(input())
    g = Graph(n)

    for i in range(n):
        k, *cs = [int(i) for i in input().split()]
        if k > 0:
            for j in cs:
                g.add(Edge(i, j))

    ps = PathSum2(g, 0)
    q = int(input())
    for _ in range(q):
        com, *args = [int(i) for i in input().split()]
        if com == 0:
            u, val = args
            ps.add(u, val)
        elif com == 1:
            u, = args
            print(ps.get(u))
        else:
            raise ValueError('invalid command')


if __name__ == '__main__':
    run()



Fixed submission:
#!/usr/bin/env python3
# GRL_5_E: Tree - Range Query on Tree 2


# Undirected Graph
class Edge:
    __slots__ = ('v', 'w')

    def __init__(self, v, w):
        self.v = v
        self.w = w

    def either(self):
        return self.v

    def other(self, v):
        if v == self.v:
            return self.w
        else:
            return self.v


class Graph:
    def __init__(self, v):
        self.v = v
        self._edges = [[] for _ in range(v)]

    def add(self, e):
        self._edges[e.v].append(e)
        self._edges[e.w].append(e)

    def adj(self, v):
        return self._edges[v]

    def edges(self):
        for es in self._edges:
            for e in es:
                yield e


class HeavyLightDecomposition:
    class _Path:
        __slots__ = ('nodes', '_index')

        def __init__(self):
            self.nodes = []
            self._index = None

        @property
        def head(self):
            return self.nodes[0]

        @property
        def size(self):
            return len(self.nodes)

        def append(self, v):
            self.nodes.append(v)

        def index(self, v):
            if self._index is None:
                self._index = {v: i for i, v in enumerate(self.nodes)}
            return self._index[v]

        def next(self, v):
            return self.nodes[self.index(v)+1]

    def __init__(self, graph, root):
        self._paths = {}
        self._parent = [root] * graph.v
        self._head = [-1] * graph.v
        self._find_paths(graph, root)

    def _find_paths(self, graph, root):
        def create_path(v):
            path = self._Path()
            u = v
            while u != -1:
                path.append(u)
                self._head[u] = v
                u = heavy[u]
            return path

        size = [1] * graph.v
        maxsize = [0] * graph.v
        heavy = [-1] * graph.v
        visited = [False] * graph.v

        stack = [root]
        while stack:
            v = stack.pop()
            if not visited[v]:
                visited[v] = True
                stack.append(v)
                for e in graph.adj(v):
                    w = e.other(v)
                    if not visited[w]:
                        self._parent[w] = v
                        stack.append(w)
            else:
                if v != root:
                    p = self._parent[v]
                    if size[v] > maxsize[p]:
                        maxsize[p] = size[v]
                        heavy[p] = v
                    size[p] += size[v]
                for e in graph.adj(v):
                    w = e.other(v)
                    if w != self._parent[v] and w != heavy[v]:
                        self._paths[w] = create_path(w)

        self._paths[root] = create_path(root)

    def parent(self, v):
        return self._parent[v]

    def paths(self):
        return self._paths.values()

    def get_path(self, v):
        return self._paths[self._head[v]]


class PathSum2:
    """PathSum with range update.
    """
    def __init__(self, graph, root):
        self.root = root
        self.hld = HeavyLightDecomposition(graph, root)
        self.rq = {p.head: RangeQuery(p.size) for p in self.hld.paths()}

    def add(self, v, val):
        u = v
        while u != self.root:
            path = self.hld.get_path(u)
            head = path.head
            if head != self.root:
                i = path.index(head)
            else:
                i = path.index(path.next(head))
            j = path.index(u)
            self.rq[head].add(i+1, j+1, val)
            u = self.hld.parent(head)

    def get(self, v):
        weight = 0
        u = v
        while u != self.root:
            path = self.hld.get_path(u)
            head = path.head
            i = path.index(head)
            j = path.index(u)
            weight += self.rq[head].sum(i+1, j+1)
            u = self.hld.parent(head)

        return weight


# Binary Indexed Tree
class BinaryIndexedTree:
    def __init__(self, n):
        self.size = n
        self.bit = [0] * (self.size+1)

    def add(self, i, v):
        while i <= self.size:
            self.bit[i] += v
            i += (i & -i)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= (i & -i)
        return s


class RangeQuery:
    def __init__(self, n):
        self.size = n
        self.bit1 = BinaryIndexedTree(n+1)
        self.bit2 = BinaryIndexedTree(n+1)

    def add(self, i, j, v):
        self.bit1.add(i, v * -i)
        self.bit1.add(j+1, v * (j+1))
        self.bit2.add(i, v)
        self.bit2.add(j+1, -v)

    def sum(self, i, j):
        s = self.bit1.sum(j+1) + (j+1)*self.bit2.sum(j+1)
        s -= self.bit1.sum(i) + i*self.bit2.sum(i)
        return s


def run():
    n = int(input())
    g = Graph(n)

    for i in range(n):
        k, *cs = [int(i) for i in input().split()]
        if k > 0:
            for j in cs:
                g.add(Edge(i, j))

    ps = PathSum2(g, 0)
    q = int(input())
    for _ in range(q):
        com, *args = [int(i) for i in input().split()]
        if com == 0:
            u, val = args
            ps.add(u, val)
        elif com == 1:
            u, = args
            print(ps.get(u))
        else:
            raise ValueError('invalid command')


if __name__ == '__main__':
    run()