#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
6
1 2 2 3
2 2 3 4
3 1 5
4 1 6
5 1 6
6 0

output:
1 1 12
2 2 11
3 3 8
4 9 10
5 4 7
6 5 6
"""
import sys

UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2


def generate_adj_matrix(v_info):
    for v_detail in v_info:
        v_index, adj_num, *adj_list = map(int, v_detail)
        # assert len(adj_list) == adj_num
        init_adj_table[v_index].extend(sorted(adj_list, reverse=True))
    return init_adj_table


def graph_dfs(v_init):
    global time

    # init the first node of overall graph iterations(times >= 1)
    stack.append(v_init)
    color[v_init] = VISITED_IN_STACK
    d_time[v_init] += time
    # init end

    while stack:
        current = stack[-1]
        v_table = adj_table[current]
        # if adj is None, current's adj(s) have been all visited
        adj = v_table.pop() if v_table else None

        if adj:
            if color[adj] is UNVISITED:
                color[adj] = VISITED_IN_STACK
                time += 1
                d_time[adj] += time
                stack.append(adj)
        else:
            stack.pop()
            color[current] = POPPED_OUT
            time += 1
            f_time[current] += time

    return None


def dfs_start():
    global time
    for i in range(vertices_num):
        if color[i + 1] == UNVISITED:
            # print('round: ', i + 1)
            graph_dfs(i + 1)
            time += 1


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices_num = int(_input[0])
    vertices_info = map(lambda x: x.split(), _input[1:])
    init_adj_table = tuple([] for _ in range(vertices_num + 1))
    # assert len(vertex_info) == vertex_num

    # config length = (vertex_num + 1)
    stack = []
    color = [UNVISITED] * (vertices_num + 1)
    d_time, f_time = ([0] * (vertices_num + 1) for _ in range(2))

    adj_table = generate_adj_matrix(vertices_info)
    # timing start from 1
    time = 1
    dfs_start()

    for index, v in enumerate(zip(d_time[1:], f_time[1:]), 1):
        print(index, *v) """
input:
6
1 2 2 3
2 2 3 4
3 1 5
4 1 6
5 1 6
6 0

output:
1 1 12
2 2 11
3 3 8
4 9 10
5 4 7
6 5 6
""" import sys sys UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2 UNVISITED 0 VISITED_IN_STACK 1 POPPED_OUT 2 def generate_adj_matrix(v_info):
    for v_detail in v_info:
        v_index, adj_num, *adj_list = map(int, v_detail)
        # assert len(adj_list) == adj_num
        init_adj_table[v_index].extend(sorted(adj_list, reverse=True))
    return init_adj_table generate_adj_matrix for v_detail in v_info:
        v_index, adj_num, *adj_list = map(int, v_detail)
        # assert len(adj_list) == adj_num
        init_adj_table[v_index].extend(sorted(adj_list, reverse=True))
     v_detail v_info v_index, adj_num, *adj_list = map(int, v_detail) v_index map(int, v_detail) map int v_detail adj_num *adj_list adj_list init_adj_table[v_index].extend(sorted(adj_list, reverse=True)) [v_index].extend [v_index] init_adj_table v_index extend sorted(adj_list, reverse=True) sorted adj_list reverse=True reverse True return init_adj_table init_adj_table v_info v_info def graph_dfs(v_init):
    global time

    # init the first node of overall graph iterations(times >= 1)
    stack.append(v_init)
    color[v_init] = VISITED_IN_STACK
    d_time[v_init] += time
    # init end

    while stack:
        current = stack[-1]
        v_table = adj_table[current]
        # if adj is None, current's adj(s) have been all visited
        adj = v_table.pop() if v_table else None

        if adj:
            if color[adj] is UNVISITED:
                color[adj] = VISITED_IN_STACK
                time += 1
                d_time[adj] += time
                stack.append(adj)
        else:
            stack.pop()
            color[current] = POPPED_OUT
            time += 1
            f_time[current] += time

    return None graph_dfs global time stack.append(v_init) stack.append stack append v_init color[v_init] = VISITED_IN_STACK color[v_init] color v_init VISITED_IN_STACK d_time[v_init] += time d_time[v_init] d_time v_init time while stack:
        current = stack[-1]
        v_table = adj_table[current]
        # if adj is None, current's adj(s) have been all visited
        adj = v_table.pop() if v_table else None

        if adj:
            if color[adj] is UNVISITED:
                color[adj] = VISITED_IN_STACK
                time += 1
                d_time[adj] += time
                stack.append(adj)
        else:
            stack.pop()
            color[current] = POPPED_OUT
            time += 1
            f_time[current] += time

     stack current = stack[-1] current stack[-1] stack -1 v_table = adj_table[current] v_table adj_table[current] adj_table current adj = v_table.pop() if v_table else None adj v_table.pop() if v_table else None v_table v_table.pop() v_table.pop v_table pop None if adj:
            if color[adj] is UNVISITED:
                color[adj] = VISITED_IN_STACK
                time += 1
                d_time[adj] += time
                stack.append(adj)
        else:
            stack.pop()
            color[current] = POPPED_OUT
            time += 1
            f_time[current] += time

     adj if color[adj] is UNVISITED:
                color[adj] = VISITED_IN_STACK
                time += 1
                d_time[adj] += time
                stack.append(adj)
         color[adj] is UNVISITED color[adj] color adj UNVISITED color[adj] = VISITED_IN_STACK color[adj] color adj VISITED_IN_STACK time += 1 time 1 d_time[adj] += time d_time[adj] d_time adj time stack.append(adj) stack.append stack append adj stack.pop() stack.pop stack pop color[current] = POPPED_OUT color[current] color current POPPED_OUT time += 1 time 1 f_time[current] += time f_time[current] f_time current time return None None v_init v_init def dfs_start():
    global time
    for i in range(vertices_num):
        if color[i + 1] == UNVISITED:
            # print('round: ', i + 1)
            graph_dfs(i + 1)
            time += 1 dfs_start global time for i in range(vertices_num):
        if color[i + 1] == UNVISITED:
            # print('round: ', i + 1)
            graph_dfs(i + 1)
            time += 1 i range(vertices_num) range vertices_num if color[i + 1] == UNVISITED:
            # print('round: ', i + 1)
            graph_dfs(i + 1)
            time += 1 color[i + 1] == UNVISITED color[i + 1] color i + 1 i 1 UNVISITED graph_dfs(i + 1) graph_dfs i + 1 i 1 time += 1 time 1 if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices_num = int(_input[0])
    vertices_info = map(lambda x: x.split(), _input[1:])
    init_adj_table = tuple([] for _ in range(vertices_num + 1))
    # assert len(vertex_info) == vertex_num

    # config length = (vertex_num + 1)
    stack = []
    color = [UNVISITED] * (vertices_num + 1)
    d_time, f_time = ([0] * (vertices_num + 1) for _ in range(2))

    adj_table = generate_adj_matrix(vertices_info)
    # timing start from 1
    time = 1
    dfs_start()

    for index, v in enumerate(zip(d_time[1:], f_time[1:]), 1):
        print(index, *v) __name__ == '__main__' __name__ '__main__' _input = sys.stdin.readlines() _input sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines vertices_num = int(_input[0]) vertices_num int(_input[0]) int _input[0] _input 0 vertices_info = map(lambda x: x.split(), _input[1:]) vertices_info map(lambda x: x.split(), _input[1:]) map lambda x: x.split() x.split() x.split x split x _input[1:] _input 1: 1 init_adj_table = tuple([] for _ in range(vertices_num + 1)) init_adj_table tuple([] for _ in range(vertices_num + 1)) tuple [] stack = [] stack [] color = [UNVISITED] * (vertices_num + 1) color [UNVISITED] * (vertices_num + 1) [UNVISITED] UNVISITED vertices_num + 1 vertices_num 1 [0] * (vertices_num + 1) for _ in range(2) for _ in range(2) _ range(2) range 2 for _ in range(2) [0] * (vertices_num + 1) [0] 0 vertices_num + 1 vertices_num 1 d_time, f_time = ([0] * (vertices_num + 1) for _ in range(2)) d_time ([0] * (vertices_num + 1) for _ in range(2)) f_time adj_table = generate_adj_matrix(vertices_info) adj_table generate_adj_matrix(vertices_info) generate_adj_matrix vertices_info time = 1 time 1 dfs_start() dfs_start for index, v in enumerate(zip(d_time[1:], f_time[1:]), 1):
        print(index, *v) index v enumerate(zip(d_time[1:], f_time[1:]), 1) enumerate zip(d_time[1:], f_time[1:]) zip d_time[1:] d_time 1: 1 f_time[1:] f_time 1: 1 1 print(index, *v) print index *v v vertices_info = map(lambda x: x.split(), _input[1:]) map(lambda x: x.split(), _input[1:]) vertices_info d_time, f_time = ([0] * (vertices_num + 1) for _ in range(2)) ([0] * (vertices_num + 1) for _ in range(2)) d_time color = [UNVISITED] * (vertices_num + 1) [UNVISITED] * (vertices_num + 1) color def dfs_start():
    global time
    for i in range(vertices_num):
        if color[i + 1] == UNVISITED:
            # print('round: ', i + 1)
            graph_dfs(i + 1)
            time += 1 def dfs_start():
    global time
    for i in range(vertices_num):
        if color[i + 1] == UNVISITED:
            # print('round: ', i + 1)
            graph_dfs(i + 1)
            time += 1 dfs_start POPPED_OUT = 0, 1, 2 2 POPPED_OUT vertices_num = int(_input[0]) int(_input[0]) vertices_num _input = sys.stdin.readlines() sys.stdin.readlines() _input def generate_adj_matrix(v_info):
    for v_detail in v_info:
        v_index, adj_num, *adj_list = map(int, v_detail)
        # assert len(adj_list) == adj_num
        init_adj_table[v_index].extend(sorted(adj_list, reverse=True))
    return init_adj_table def generate_adj_matrix(v_info):
    for v_detail in v_info:
        v_index, adj_num, *adj_list = map(int, v_detail)
        # assert len(adj_list) == adj_num
        init_adj_table[v_index].extend(sorted(adj_list, reverse=True))
    return init_adj_table generate_adj_matrix stack = [] [] stack init_adj_table = tuple([] for _ in range(vertices_num + 1)) tuple([] for _ in range(vertices_num + 1)) init_adj_table adj_table = generate_adj_matrix(vertices_info) generate_adj_matrix(vertices_info) adj_table def graph_dfs(v_init):
    global time

    # init the first node of overall graph iterations(times >= 1)
    stack.append(v_init)
    color[v_init] = VISITED_IN_STACK
    d_time[v_init] += time
    # init end

    while stack:
        current = stack[-1]
        v_table = adj_table[current]
        # if adj is None, current's adj(s) have been all visited
        adj = v_table.pop() if v_table else None

        if adj:
            if color[adj] is UNVISITED:
                color[adj] = VISITED_IN_STACK
                time += 1
                d_time[adj] += time
                stack.append(adj)
        else:
            stack.pop()
            color[current] = POPPED_OUT
            time += 1
            f_time[current] += time

    return None def graph_dfs(v_init):
    global time

    # init the first node of overall graph iterations(times >= 1)
    stack.append(v_init)
    color[v_init] = VISITED_IN_STACK
    d_time[v_init] += time
    # init end

    while stack:
        current = stack[-1]
        v_table = adj_table[current]
        # if adj is None, current's adj(s) have been all visited
        adj = v_table.pop() if v_table else None

        if adj:
            if color[adj] is UNVISITED:
                color[adj] = VISITED_IN_STACK
                time += 1
                d_time[adj] += time
                stack.append(adj)
        else:
            stack.pop()
            color[current] = POPPED_OUT
            time += 1
            f_time[current] += time

    return None graph_dfs VISITED_IN_STACK, POPPED_OUT = 0, 1, 2 1 VISITED_IN_STACK UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2 0 UNVISITED time = 1 1 time f_time = ([0] * (vertices_num + 1) for _ in range(2)) ([0] * (vertices_num + 1) for _ in range(2)) f_time
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
6
1 2 2 3
2 2 3 4
3 1 5
4 1 6
5 1 6
6 0

output:
1 1 12
2 2 11
3 3 8
4 9 10
5 4 7
6 5 6
"""
import sys

UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2


def generate_adj_matrix(v_info):
    for v_detail in v_info:
        v_index, adj_num, *adj_list = map(int, v_detail)
        # assert len(adj_list) == adj_num
        init_adj_table[v_index].extend(sorted(adj_list, reverse=True))
    return init_adj_table


def graph_dfs(v_init):
    global time

    # init the first node of overall graph iterations(times >= 1)
    stack.append(v_init)
    color[v_init] = VISITED_IN_STACK
    d_time[v_init] += time
    # init end

    while stack:
        current = stack[-1]
        v_table = adj_table[current]
        # if adj is None, current's adj(s) have been all visited
        adj = v_table.pop() if v_table else None

        if adj:
            if color[adj] is UNVISITED:
                color[adj] = VISITED_IN_STACK
                time += 1
                d_time[adj] += time
                stack.append(adj)
        else:
            stack.pop()
            color[current] = POPPED_OUT
            time += 1
            f_time[current] += time

    return None


def dfs_start():
    global time
    for i in range(vertices_num):
        if color[i + 1] == UNVISITED:
            # print('round: ', i + 1)
            graph_dfs(i + 1)
            time += 1


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices_num = int(_input[0])
    vertices_info = map(lambda x: x.split(), _input[1:])
    init_adj_table = tuple([] for _ in range(vertices_num + 1))
    # assert len(vertex_info) == vertex_num

    # config length = (vertex_num + 1)
    stack = []
    color = [UNVISITED] * (vertices_num + 1)
    d_time, f_time = ([0] * (vertices_num + 1) for _ in range(2))

    adj_table = generate_adj_matrix(vertices_info)
    # timing start from 1
    time = 1
    dfs_start()

    for index, v in enumerate(zip(d_time[1:], f_time[1:]), 1):
        print(index, *v)