from typing import List


def dfs(adj_matrix: List[List[int]], vartex: int) -> int:
    global step
    global discover_times
    global finish_times
    if 0 != discover_times[vartex]:
        return 0
    discover_times[vartex] = step

    for col_idx in range(len(adj_matrix)):
        if (0 != adj_matrix[vartex][col_idx]) and (0 == discover_times[col_idx]):
            step += 1
            dfs(adj_matrix, col_idx)

    step += 1
    finish_times[vartex] = step

    return 1


if __name__ == "__main__":
    num_vertices = int(input())
    adj_matrix = [[0] * num_vertices for i in range(num_vertices)]

    for _ in range(num_vertices):
        vertex, _, *adjs = map(lambda x: int(x), input().split())
        for adj in adjs:
            adj_matrix[vertex - 1][adj - 1] = 1

    step = 1
    discover_times = [0] * num_vertices
    finish_times = [0] * num_vertices

    for vartex in range(num_vertices):
        if 1 == dfs(adj_matrix, vartex):
            step += 1

    for vertex, (d, f) in enumerate(zip(discover_times, finish_times)):
        print(f"{vertex + 1} {d} {f}")
 from typing import List def dfs(adj_matrix: List[List[int]], vartex: int) -> int:
    global step
    global discover_times
    global finish_times
    if 0 != discover_times[vartex]:
        return 0
    discover_times[vartex] = step

    for col_idx in range(len(adj_matrix)):
        if (0 != adj_matrix[vartex][col_idx]) and (0 == discover_times[col_idx]):
            step += 1
            dfs(adj_matrix, col_idx)

    step += 1
    finish_times[vartex] = step

    return 1 dfs global step global discover_times global finish_times if 0 != discover_times[vartex]:
        return 0
     0 != discover_times[vartex] 0 discover_times[vartex] discover_times vartex return 0 0 discover_times[vartex] = step discover_times[vartex] discover_times vartex step for col_idx in range(len(adj_matrix)):
        if (0 != adj_matrix[vartex][col_idx]) and (0 == discover_times[col_idx]):
            step += 1
            dfs(adj_matrix, col_idx)

     col_idx range(len(adj_matrix)) range len(adj_matrix) len adj_matrix if (0 != adj_matrix[vartex][col_idx]) and (0 == discover_times[col_idx]):
            step += 1
            dfs(adj_matrix, col_idx)

     (0 != adj_matrix[vartex][col_idx]) and (0 == discover_times[col_idx]) 0 != adj_matrix[vartex][col_idx] 0 adj_matrix[vartex][col_idx] [vartex] adj_matrix vartex col_idx 0 == discover_times[col_idx] 0 discover_times[col_idx] discover_times col_idx step += 1 step 1 dfs(adj_matrix, col_idx) dfs adj_matrix col_idx step += 1 step 1 finish_times[vartex] = step finish_times[vartex] finish_times vartex step return 1 1 adj_matrix: List[List[int]] adj_matrix vartex: int vartex if __name__ == "__main__":
    num_vertices = int(input())
    adj_matrix = [[0] * num_vertices for i in range(num_vertices)]

    for _ in range(num_vertices):
        vertex, _, *adjs = map(lambda x: int(x), input().split())
        for adj in adjs:
            adj_matrix[vertex - 1][adj - 1] = 1

    step = 1
    discover_times = [0] * num_vertices
    finish_times = [0] * num_vertices

    for vartex in range(num_vertices):
        if 1 == dfs(adj_matrix, vartex):
            step += 1

    for vertex, (d, f) in enumerate(zip(discover_times, finish_times)):
        print(f"{vertex + 1} {d} {f}") __name__ == "__main__" __name__ "__main__" num_vertices = int(input()) num_vertices int(input()) int input() input [0] * num_vertices for i in range(num_vertices) for i in range(num_vertices) i range(num_vertices) range num_vertices for i in range(num_vertices) [0] * num_vertices [0] 0 num_vertices adj_matrix = [[0] * num_vertices for i in range(num_vertices)] adj_matrix [[0] * num_vertices for i in range(num_vertices)] for _ in range(num_vertices):
        vertex, _, *adjs = map(lambda x: int(x), input().split())
        for adj in adjs:
            adj_matrix[vertex - 1][adj - 1] = 1

     _ range(num_vertices) range num_vertices vertex, _, *adjs = map(lambda x: int(x), input().split()) vertex map(lambda x: int(x), input().split()) map lambda x: int(x) int(x) int x x input().split() ().split () input split _ *adjs adjs for adj in adjs:
            adj_matrix[vertex - 1][adj - 1] = 1

     adj adjs adj_matrix[vertex - 1][adj - 1] = 1 adj_matrix[vertex - 1][adj - 1] [vertex - 1] adj_matrix vertex - 1 vertex 1 adj - 1 adj 1 1 step = 1 step 1 discover_times = [0] * num_vertices discover_times [0] * num_vertices [0] 0 num_vertices finish_times = [0] * num_vertices finish_times [0] * num_vertices [0] 0 num_vertices for vartex in range(num_vertices):
        if 1 == dfs(adj_matrix, vartex):
            step += 1

     vartex range(num_vertices) range num_vertices if 1 == dfs(adj_matrix, vartex):
            step += 1

     1 == dfs(adj_matrix, vartex) 1 dfs(adj_matrix, vartex) dfs adj_matrix vartex step += 1 step 1 for vertex, (d, f) in enumerate(zip(discover_times, finish_times)):
        print(f"{vertex + 1} {d} {f}") vertex (d, f) d f enumerate(zip(discover_times, finish_times)) enumerate zip(discover_times, finish_times) zip discover_times finish_times print(f"{vertex + 1} {d} {f}") print f"{vertex + 1} {d} {f}" adj_matrix = [[0] * num_vertices for i in range(num_vertices)] [[0] * num_vertices for i in range(num_vertices)] adj_matrix vertex, _, *adjs = map(lambda x: int(x), input().split()) map(lambda x: int(x), input().split()) vertex _, *adjs = map(lambda x: int(x), input().split()) map(lambda x: int(x), input().split()) _ discover_times = [0] * num_vertices [0] * num_vertices discover_times step += 1 1 step step = 1 1 step def dfs(adj_matrix: List[List[int]], vartex: int) -> int:
    global step
    global discover_times
    global finish_times
    if 0 != discover_times[vartex]:
        return 0
    discover_times[vartex] = step

    for col_idx in range(len(adj_matrix)):
        if (0 != adj_matrix[vartex][col_idx]) and (0 == discover_times[col_idx]):
            step += 1
            dfs(adj_matrix, col_idx)

    step += 1
    finish_times[vartex] = step

    return 1 def dfs(adj_matrix: List[List[int]], vartex: int) -> int:
    global step
    global discover_times
    global finish_times
    if 0 != discover_times[vartex]:
        return 0
    discover_times[vartex] = step

    for col_idx in range(len(adj_matrix)):
        if (0 != adj_matrix[vartex][col_idx]) and (0 == discover_times[col_idx]):
            step += 1
            dfs(adj_matrix, col_idx)

    step += 1
    finish_times[vartex] = step

    return 1 dfs num_vertices = int(input()) int(input()) num_vertices finish_times = [0] * num_vertices [0] * num_vertices finish_times
from typing import List


def dfs(adj_matrix: List[List[int]], vartex: int) -> int:
    global step
    global discover_times
    global finish_times
    if 0 != discover_times[vartex]:
        return 0
    discover_times[vartex] = step

    for col_idx in range(len(adj_matrix)):
        if (0 != adj_matrix[vartex][col_idx]) and (0 == discover_times[col_idx]):
            step += 1
            dfs(adj_matrix, col_idx)

    step += 1
    finish_times[vartex] = step

    return 1


if __name__ == "__main__":
    num_vertices = int(input())
    adj_matrix = [[0] * num_vertices for i in range(num_vertices)]

    for _ in range(num_vertices):
        vertex, _, *adjs = map(lambda x: int(x), input().split())
        for adj in adjs:
            adj_matrix[vertex - 1][adj - 1] = 1

    step = 1
    discover_times = [0] * num_vertices
    finish_times = [0] * num_vertices

    for vartex in range(num_vertices):
        if 1 == dfs(adj_matrix, vartex):
            step += 1

    for vertex, (d, f) in enumerate(zip(discover_times, finish_times)):
        print(f"{vertex + 1} {d} {f}")

