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

import sys

UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2


def generate_adj(v_info):
    for v_detail in v_info:
        v_adj_list = v_detail[2:]
        assert len(v_adj_list) == int(v_detail[1])
        for each in v_adj_list:
            init_adj_matrix[int(v_detail[0]) - 1][int(each) - 1] = 1
    return init_adj_matrix


def graph_dfs(v_init):
    global time
    # init the first node of overall graph iterations(times >= 1)
    vertex_visit_stack.append(v_init)
    vertex_status_list[v_init] = VISITED_IN_STACK
    vertex_d_time[v_init] += time
    # init end
    while len(vertex_visit_stack) > 1:
        current_vertex = vertex_visit_stack[-1]
        next_vertex = get_adj_vertices(_vertex=current_vertex)
        # print('start', current_vertex, next_vertex, vertex_status_list, vertex_visit_stack)

        if next_vertex:
            if vertex_status_list[next_vertex] is UNVISITED:
                vertex_status_list[next_vertex] = VISITED_IN_STACK
                time += 1
                vertex_d_time[next_vertex] += time
                vertex_visit_stack.append(next_vertex)
                # print('on', current_vertex, next_vertex, vertex_status_list, vertex_visit_stack)
        else:
            # print('no out degree', current_vertex)
            vertex_visit_stack.pop()
            vertex_status_list[current_vertex] = POPPED_OUT
            time += 1
            vertex_f_time[current_vertex] += time
        # print('end', current_vertex, vertex_status_list, vertex_visit_stack)

    return None


def get_adj_vertices(_vertex):
    for j in range(vertex_num):
        if adj_matrix[int(_vertex) - 1][j]:
            adj_matrix[int(_vertex) - 1][j] = 0
            return j + 1
    return None


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


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertex_num = int(_input[0])
    vertex_info = list(map(lambda x: x.split(), _input[1:]))
    init_adj_matrix = [[0] * vertex_num for _ in range(vertex_num)]
    # assert len(vertex_info) == vertex_num
    # config length -> (vertex_num + 1)
    vertex_visit_stack = [-1]
    vertex_status_list = [UNVISITED] * vertex_num
    vertex_status_list.insert(0, -1)
    vertex_d_time, vertex_f_time = ([0] * (vertex_num + 1) for _ in range(2))

    adj_matrix = generate_adj(vertex_info)

    time = 1
    dfs_start()

    for k in range(vertex_num):
        print(k + 1, vertex_d_time[k + 1], vertex_f_time[k + 1]) import sys sys UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2 UNVISITED 0 VISITED_IN_STACK 1 POPPED_OUT 2 def generate_adj(v_info):
    for v_detail in v_info:
        v_adj_list = v_detail[2:]
        assert len(v_adj_list) == int(v_detail[1])
        for each in v_adj_list:
            init_adj_matrix[int(v_detail[0]) - 1][int(each) - 1] = 1
    return init_adj_matrix generate_adj for v_detail in v_info:
        v_adj_list = v_detail[2:]
        assert len(v_adj_list) == int(v_detail[1])
        for each in v_adj_list:
            init_adj_matrix[int(v_detail[0]) - 1][int(each) - 1] = 1
     v_detail v_info v_adj_list = v_detail[2:] v_adj_list v_detail[2:] v_detail 2: 2 assert len(v_adj_list) == int(v_detail[1]) len(v_adj_list) == int(v_detail[1]) len(v_adj_list) len v_adj_list int(v_detail[1]) int v_detail[1] v_detail 1 for each in v_adj_list:
            init_adj_matrix[int(v_detail[0]) - 1][int(each) - 1] = 1
     each v_adj_list init_adj_matrix[int(v_detail[0]) - 1][int(each) - 1] = 1 init_adj_matrix[int(v_detail[0]) - 1][int(each) - 1] [int(v_detail[0]) - 1] init_adj_matrix int(v_detail[0]) - 1 int(v_detail[0]) int v_detail[0] v_detail 0 1 int(each) - 1 int(each) int each 1 1 return init_adj_matrix init_adj_matrix v_info v_info def graph_dfs(v_init):
    global time
    # init the first node of overall graph iterations(times >= 1)
    vertex_visit_stack.append(v_init)
    vertex_status_list[v_init] = VISITED_IN_STACK
    vertex_d_time[v_init] += time
    # init end
    while len(vertex_visit_stack) > 1:
        current_vertex = vertex_visit_stack[-1]
        next_vertex = get_adj_vertices(_vertex=current_vertex)
        # print('start', current_vertex, next_vertex, vertex_status_list, vertex_visit_stack)

        if next_vertex:
            if vertex_status_list[next_vertex] is UNVISITED:
                vertex_status_list[next_vertex] = VISITED_IN_STACK
                time += 1
                vertex_d_time[next_vertex] += time
                vertex_visit_stack.append(next_vertex)
                # print('on', current_vertex, next_vertex, vertex_status_list, vertex_visit_stack)
        else:
            # print('no out degree', current_vertex)
            vertex_visit_stack.pop()
            vertex_status_list[current_vertex] = POPPED_OUT
            time += 1
            vertex_f_time[current_vertex] += time
        # print('end', current_vertex, vertex_status_list, vertex_visit_stack)

    return None graph_dfs global time vertex_visit_stack.append(v_init) vertex_visit_stack.append vertex_visit_stack append v_init vertex_status_list[v_init] = VISITED_IN_STACK vertex_status_list[v_init] vertex_status_list v_init VISITED_IN_STACK vertex_d_time[v_init] += time vertex_d_time[v_init] vertex_d_time v_init time while len(vertex_visit_stack) > 1:
        current_vertex = vertex_visit_stack[-1]
        next_vertex = get_adj_vertices(_vertex=current_vertex)
        # print('start', current_vertex, next_vertex, vertex_status_list, vertex_visit_stack)

        if next_vertex:
            if vertex_status_list[next_vertex] is UNVISITED:
                vertex_status_list[next_vertex] = VISITED_IN_STACK
                time += 1
                vertex_d_time[next_vertex] += time
                vertex_visit_stack.append(next_vertex)
                # print('on', current_vertex, next_vertex, vertex_status_list, vertex_visit_stack)
        else:
            # print('no out degree', current_vertex)
            vertex_visit_stack.pop()
            vertex_status_list[current_vertex] = POPPED_OUT
            time += 1
            vertex_f_time[current_vertex] += time
        # print('end', current_vertex, vertex_status_list, vertex_visit_stack)

     len(vertex_visit_stack) > 1 len(vertex_visit_stack) len vertex_visit_stack 1 current_vertex = vertex_visit_stack[-1] current_vertex vertex_visit_stack[-1] vertex_visit_stack -1 next_vertex = get_adj_vertices(_vertex=current_vertex) next_vertex get_adj_vertices(_vertex=current_vertex) get_adj_vertices _vertex=current_vertex _vertex current_vertex if next_vertex:
            if vertex_status_list[next_vertex] is UNVISITED:
                vertex_status_list[next_vertex] = VISITED_IN_STACK
                time += 1
                vertex_d_time[next_vertex] += time
                vertex_visit_stack.append(next_vertex)
                # print('on', current_vertex, next_vertex, vertex_status_list, vertex_visit_stack)
        else:
            # print('no out degree', current_vertex)
            vertex_visit_stack.pop()
            vertex_status_list[current_vertex] = POPPED_OUT
            time += 1
            vertex_f_time[current_vertex] += time
        # print('end', current_vertex, vertex_status_list, vertex_visit_stack)

     next_vertex if vertex_status_list[next_vertex] is UNVISITED:
                vertex_status_list[next_vertex] = VISITED_IN_STACK
                time += 1
                vertex_d_time[next_vertex] += time
                vertex_visit_stack.append(next_vertex)
                # print('on', current_vertex, next_vertex, vertex_status_list, vertex_visit_stack)
         vertex_status_list[next_vertex] is UNVISITED vertex_status_list[next_vertex] vertex_status_list next_vertex UNVISITED vertex_status_list[next_vertex] = VISITED_IN_STACK vertex_status_list[next_vertex] vertex_status_list next_vertex VISITED_IN_STACK time += 1 time 1 vertex_d_time[next_vertex] += time vertex_d_time[next_vertex] vertex_d_time next_vertex time vertex_visit_stack.append(next_vertex) vertex_visit_stack.append vertex_visit_stack append next_vertex vertex_visit_stack.pop() vertex_visit_stack.pop vertex_visit_stack pop vertex_status_list[current_vertex] = POPPED_OUT vertex_status_list[current_vertex] vertex_status_list current_vertex POPPED_OUT time += 1 time 1 vertex_f_time[current_vertex] += time vertex_f_time[current_vertex] vertex_f_time current_vertex time return None None v_init v_init def get_adj_vertices(_vertex):
    for j in range(vertex_num):
        if adj_matrix[int(_vertex) - 1][j]:
            adj_matrix[int(_vertex) - 1][j] = 0
            return j + 1
    return None get_adj_vertices for j in range(vertex_num):
        if adj_matrix[int(_vertex) - 1][j]:
            adj_matrix[int(_vertex) - 1][j] = 0
            return j + 1
     j range(vertex_num) range vertex_num if adj_matrix[int(_vertex) - 1][j]:
            adj_matrix[int(_vertex) - 1][j] = 0
            return j + 1
     adj_matrix[int(_vertex) - 1][j] [int(_vertex) - 1] adj_matrix int(_vertex) - 1 int(_vertex) int _vertex 1 j adj_matrix[int(_vertex) - 1][j] = 0 adj_matrix[int(_vertex) - 1][j] [int(_vertex) - 1] adj_matrix int(_vertex) - 1 int(_vertex) int _vertex 1 j 0 return j + 1 j + 1 j 1 return None None _vertex _vertex def dfs_start():
    global time
    for i in range(vertex_num):
        if vertex_status_list[i + 1] == UNVISITED:
            # print('round', i + 1)
            graph_dfs(v_init=i + 1)
            time += 1 dfs_start global time for i in range(vertex_num):
        if vertex_status_list[i + 1] == UNVISITED:
            # print('round', i + 1)
            graph_dfs(v_init=i + 1)
            time += 1 i range(vertex_num) range vertex_num if vertex_status_list[i + 1] == UNVISITED:
            # print('round', i + 1)
            graph_dfs(v_init=i + 1)
            time += 1 vertex_status_list[i + 1] == UNVISITED vertex_status_list[i + 1] vertex_status_list i + 1 i 1 UNVISITED graph_dfs(v_init=i + 1) graph_dfs v_init=i + 1 v_init i + 1 i 1 time += 1 time 1 if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertex_num = int(_input[0])
    vertex_info = list(map(lambda x: x.split(), _input[1:]))
    init_adj_matrix = [[0] * vertex_num for _ in range(vertex_num)]
    # assert len(vertex_info) == vertex_num
    # config length -> (vertex_num + 1)
    vertex_visit_stack = [-1]
    vertex_status_list = [UNVISITED] * vertex_num
    vertex_status_list.insert(0, -1)
    vertex_d_time, vertex_f_time = ([0] * (vertex_num + 1) for _ in range(2))

    adj_matrix = generate_adj(vertex_info)

    time = 1
    dfs_start()

    for k in range(vertex_num):
        print(k + 1, vertex_d_time[k + 1], vertex_f_time[k + 1]) __name__ == '__main__' __name__ '__main__' _input = sys.stdin.readlines() _input sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines vertex_num = int(_input[0]) vertex_num int(_input[0]) int _input[0] _input 0 vertex_info = list(map(lambda x: x.split(), _input[1:])) vertex_info list(map(lambda x: x.split(), _input[1:])) list map(lambda x: x.split(), _input[1:]) map lambda x: x.split() x.split() x.split x split x _input[1:] _input 1: 1 [0] * vertex_num for _ in range(vertex_num) for _ in range(vertex_num) _ range(vertex_num) range vertex_num for _ in range(vertex_num) [0] * vertex_num [0] 0 vertex_num init_adj_matrix = [[0] * vertex_num for _ in range(vertex_num)] init_adj_matrix [[0] * vertex_num for _ in range(vertex_num)] vertex_visit_stack = [-1] vertex_visit_stack [-1] -1 vertex_status_list = [UNVISITED] * vertex_num vertex_status_list [UNVISITED] * vertex_num [UNVISITED] UNVISITED vertex_num vertex_status_list.insert(0, -1) vertex_status_list.insert vertex_status_list insert 0 -1 [0] * (vertex_num + 1) for _ in range(2) for _ in range(2) _ range(2) range 2 for _ in range(2) [0] * (vertex_num + 1) [0] 0 vertex_num + 1 vertex_num 1 vertex_d_time, vertex_f_time = ([0] * (vertex_num + 1) for _ in range(2)) vertex_d_time ([0] * (vertex_num + 1) for _ in range(2)) vertex_f_time adj_matrix = generate_adj(vertex_info) adj_matrix generate_adj(vertex_info) generate_adj vertex_info time = 1 time 1 dfs_start() dfs_start for k in range(vertex_num):
        print(k + 1, vertex_d_time[k + 1], vertex_f_time[k + 1]) k range(vertex_num) range vertex_num print(k + 1, vertex_d_time[k + 1], vertex_f_time[k + 1]) print k + 1 k 1 vertex_d_time[k + 1] vertex_d_time k + 1 k 1 vertex_f_time[k + 1] vertex_f_time k + 1 k 1 POPPED_OUT = 0, 1, 2 2 POPPED_OUT vertex_f_time = ([0] * (vertex_num + 1) for _ in range(2)) ([0] * (vertex_num + 1) for _ in range(2)) vertex_f_time vertex_visit_stack = [-1] [-1] vertex_visit_stack def get_adj_vertices(_vertex):
    for j in range(vertex_num):
        if adj_matrix[int(_vertex) - 1][j]:
            adj_matrix[int(_vertex) - 1][j] = 0
            return j + 1
    return None def get_adj_vertices(_vertex):
    for j in range(vertex_num):
        if adj_matrix[int(_vertex) - 1][j]:
            adj_matrix[int(_vertex) - 1][j] = 0
            return j + 1
    return None get_adj_vertices init_adj_matrix = [[0] * vertex_num for _ in range(vertex_num)] [[0] * vertex_num for _ in range(vertex_num)] init_adj_matrix vertex_num = int(_input[0]) int(_input[0]) vertex_num vertex_status_list = [UNVISITED] * vertex_num [UNVISITED] * vertex_num vertex_status_list def graph_dfs(v_init):
    global time
    # init the first node of overall graph iterations(times >= 1)
    vertex_visit_stack.append(v_init)
    vertex_status_list[v_init] = VISITED_IN_STACK
    vertex_d_time[v_init] += time
    # init end
    while len(vertex_visit_stack) > 1:
        current_vertex = vertex_visit_stack[-1]
        next_vertex = get_adj_vertices(_vertex=current_vertex)
        # print('start', current_vertex, next_vertex, vertex_status_list, vertex_visit_stack)

        if next_vertex:
            if vertex_status_list[next_vertex] is UNVISITED:
                vertex_status_list[next_vertex] = VISITED_IN_STACK
                time += 1
                vertex_d_time[next_vertex] += time
                vertex_visit_stack.append(next_vertex)
                # print('on', current_vertex, next_vertex, vertex_status_list, vertex_visit_stack)
        else:
            # print('no out degree', current_vertex)
            vertex_visit_stack.pop()
            vertex_status_list[current_vertex] = POPPED_OUT
            time += 1
            vertex_f_time[current_vertex] += time
        # print('end', current_vertex, vertex_status_list, vertex_visit_stack)

    return None def graph_dfs(v_init):
    global time
    # init the first node of overall graph iterations(times >= 1)
    vertex_visit_stack.append(v_init)
    vertex_status_list[v_init] = VISITED_IN_STACK
    vertex_d_time[v_init] += time
    # init end
    while len(vertex_visit_stack) > 1:
        current_vertex = vertex_visit_stack[-1]
        next_vertex = get_adj_vertices(_vertex=current_vertex)
        # print('start', current_vertex, next_vertex, vertex_status_list, vertex_visit_stack)

        if next_vertex:
            if vertex_status_list[next_vertex] is UNVISITED:
                vertex_status_list[next_vertex] = VISITED_IN_STACK
                time += 1
                vertex_d_time[next_vertex] += time
                vertex_visit_stack.append(next_vertex)
                # print('on', current_vertex, next_vertex, vertex_status_list, vertex_visit_stack)
        else:
            # print('no out degree', current_vertex)
            vertex_visit_stack.pop()
            vertex_status_list[current_vertex] = POPPED_OUT
            time += 1
            vertex_f_time[current_vertex] += time
        # print('end', current_vertex, vertex_status_list, vertex_visit_stack)

    return None graph_dfs adj_matrix = generate_adj(vertex_info) generate_adj(vertex_info) adj_matrix vertex_info = list(map(lambda x: x.split(), _input[1:])) list(map(lambda x: x.split(), _input[1:])) vertex_info VISITED_IN_STACK, POPPED_OUT = 0, 1, 2 1 VISITED_IN_STACK time = 1 1 time UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2 0 UNVISITED def dfs_start():
    global time
    for i in range(vertex_num):
        if vertex_status_list[i + 1] == UNVISITED:
            # print('round', i + 1)
            graph_dfs(v_init=i + 1)
            time += 1 def dfs_start():
    global time
    for i in range(vertex_num):
        if vertex_status_list[i + 1] == UNVISITED:
            # print('round', i + 1)
            graph_dfs(v_init=i + 1)
            time += 1 dfs_start vertex_d_time, vertex_f_time = ([0] * (vertex_num + 1) for _ in range(2)) ([0] * (vertex_num + 1) for _ in range(2)) vertex_d_time _input = sys.stdin.readlines() sys.stdin.readlines() _input def generate_adj(v_info):
    for v_detail in v_info:
        v_adj_list = v_detail[2:]
        assert len(v_adj_list) == int(v_detail[1])
        for each in v_adj_list:
            init_adj_matrix[int(v_detail[0]) - 1][int(each) - 1] = 1
    return init_adj_matrix def generate_adj(v_info):
    for v_detail in v_info:
        v_adj_list = v_detail[2:]
        assert len(v_adj_list) == int(v_detail[1])
        for each in v_adj_list:
            init_adj_matrix[int(v_detail[0]) - 1][int(each) - 1] = 1
    return init_adj_matrix generate_adj
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2


def generate_adj(v_info):
    for v_detail in v_info:
        v_adj_list = v_detail[2:]
        assert len(v_adj_list) == int(v_detail[1])
        for each in v_adj_list:
            init_adj_matrix[int(v_detail[0]) - 1][int(each) - 1] = 1
    return init_adj_matrix


def graph_dfs(v_init):
    global time
    # init the first node of overall graph iterations(times >= 1)
    vertex_visit_stack.append(v_init)
    vertex_status_list[v_init] = VISITED_IN_STACK
    vertex_d_time[v_init] += time
    # init end
    while len(vertex_visit_stack) > 1:
        current_vertex = vertex_visit_stack[-1]
        next_vertex = get_adj_vertices(_vertex=current_vertex)
        # print('start', current_vertex, next_vertex, vertex_status_list, vertex_visit_stack)

        if next_vertex:
            if vertex_status_list[next_vertex] is UNVISITED:
                vertex_status_list[next_vertex] = VISITED_IN_STACK
                time += 1
                vertex_d_time[next_vertex] += time
                vertex_visit_stack.append(next_vertex)
                # print('on', current_vertex, next_vertex, vertex_status_list, vertex_visit_stack)
        else:
            # print('no out degree', current_vertex)
            vertex_visit_stack.pop()
            vertex_status_list[current_vertex] = POPPED_OUT
            time += 1
            vertex_f_time[current_vertex] += time
        # print('end', current_vertex, vertex_status_list, vertex_visit_stack)

    return None


def get_adj_vertices(_vertex):
    for j in range(vertex_num):
        if adj_matrix[int(_vertex) - 1][j]:
            adj_matrix[int(_vertex) - 1][j] = 0
            return j + 1
    return None


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


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertex_num = int(_input[0])
    vertex_info = list(map(lambda x: x.split(), _input[1:]))
    init_adj_matrix = [[0] * vertex_num for _ in range(vertex_num)]
    # assert len(vertex_info) == vertex_num
    # config length -> (vertex_num + 1)
    vertex_visit_stack = [-1]
    vertex_status_list = [UNVISITED] * vertex_num
    vertex_status_list.insert(0, -1)
    vertex_d_time, vertex_f_time = ([0] * (vertex_num + 1) for _ in range(2))

    adj_matrix = generate_adj(vertex_info)

    time = 1
    dfs_start()

    for k in range(vertex_num):
        print(k + 1, vertex_d_time[k + 1], vertex_f_time[k + 1])