def dfs(u, colors, matrix, time, detect_time, finished_time):
    # ????????????????????¨??????????????????
    colors = colors
    detect_time = detect_time
    finished_time = finished_time
    time = time + 1
    stack = list()
    stack.append(u)
    colors[u] = 1
    detect_time[u] = time
    while len(stack):
        for i, val in enumerate(matrix[u]):
            if val == 1 and colors[i] == 0:
                time += 1
                stack.append(i)
                colors[i] = 1
                detect_time[i] = time
                u = i
                break
        else:
            time += 1
            e = stack.pop()
            colors[e] = 2
            finished_time[e] = time
            if len(stack):
                u = stack[-1]
    return time


if __name__ == '__main__':
    N = int(input())
    matrix = [[0] * N for _ in range(N)]
    color = [0] * N
    for i in matrix:
        node_info = [int(i) for i in input().split()]
        node_i = node_info[0] - 1
        if not node_info[1] == 0:
            for i in node_info[2:]:
                matrix[node_i][i - 1] = 1
    colors = [0] * len(matrix)
    detect_time = [0] * len(matrix)
    finished_time = [0] * len(matrix)
    time = 0
    for i, val in enumerate(colors):
        if val == 0:
            time = dfs(i, colors, matrix, time, detect_time, finished_time)

    for i in range(len(matrix)):
        print('{} {} {}'.format(i + 1, detect_time[i], finished_time[i])) def dfs(u, colors, matrix, time, detect_time, finished_time):
    # ????????????????????¨??????????????????
    colors = colors
    detect_time = detect_time
    finished_time = finished_time
    time = time + 1
    stack = list()
    stack.append(u)
    colors[u] = 1
    detect_time[u] = time
    while len(stack):
        for i, val in enumerate(matrix[u]):
            if val == 1 and colors[i] == 0:
                time += 1
                stack.append(i)
                colors[i] = 1
                detect_time[i] = time
                u = i
                break
        else:
            time += 1
            e = stack.pop()
            colors[e] = 2
            finished_time[e] = time
            if len(stack):
                u = stack[-1]
    return time dfs colors = colors colors colors detect_time = detect_time detect_time detect_time finished_time = finished_time finished_time finished_time time = time + 1 time time + 1 time 1 stack = list() stack list() list stack.append(u) stack.append stack append u colors[u] = 1 colors[u] colors u 1 detect_time[u] = time detect_time[u] detect_time u time while len(stack):
        for i, val in enumerate(matrix[u]):
            if val == 1 and colors[i] == 0:
                time += 1
                stack.append(i)
                colors[i] = 1
                detect_time[i] = time
                u = i
                break
        else:
            time += 1
            e = stack.pop()
            colors[e] = 2
            finished_time[e] = time
            if len(stack):
                u = stack[-1]
     len(stack) len stack for i, val in enumerate(matrix[u]):
            if val == 1 and colors[i] == 0:
                time += 1
                stack.append(i)
                colors[i] = 1
                detect_time[i] = time
                u = i
                break
        else:
            time += 1
            e = stack.pop()
            colors[e] = 2
            finished_time[e] = time
            if len(stack):
                u = stack[-1]
     i val enumerate(matrix[u]) enumerate matrix[u] matrix u if val == 1 and colors[i] == 0:
                time += 1
                stack.append(i)
                colors[i] = 1
                detect_time[i] = time
                u = i
                break
         val == 1 and colors[i] == 0 val == 1 val 1 colors[i] == 0 colors[i] colors i 0 time += 1 time 1 stack.append(i) stack.append stack append i colors[i] = 1 colors[i] colors i 1 detect_time[i] = time detect_time[i] detect_time i time u = i u i break time += 1 time 1 e = stack.pop() e stack.pop() stack.pop stack pop colors[e] = 2 colors[e] colors e 2 finished_time[e] = time finished_time[e] finished_time e time if len(stack):
                u = stack[-1]
     len(stack) len stack u = stack[-1] u stack[-1] stack -1 return time time u u colors colors matrix matrix time time detect_time detect_time finished_time finished_time if __name__ == '__main__':
    N = int(input())
    matrix = [[0] * N for _ in range(N)]
    color = [0] * N
    for i in matrix:
        node_info = [int(i) for i in input().split()]
        node_i = node_info[0] - 1
        if not node_info[1] == 0:
            for i in node_info[2:]:
                matrix[node_i][i - 1] = 1
    colors = [0] * len(matrix)
    detect_time = [0] * len(matrix)
    finished_time = [0] * len(matrix)
    time = 0
    for i, val in enumerate(colors):
        if val == 0:
            time = dfs(i, colors, matrix, time, detect_time, finished_time)

    for i in range(len(matrix)):
        print('{} {} {}'.format(i + 1, detect_time[i], finished_time[i])) __name__ == '__main__' __name__ '__main__' N = int(input()) N int(input()) int input() input [0] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [0] * N [0] 0 N matrix = [[0] * N for _ in range(N)] matrix [[0] * N for _ in range(N)] color = [0] * N color [0] * N [0] 0 N for i in matrix:
        node_info = [int(i) for i in input().split()]
        node_i = node_info[0] - 1
        if not node_info[1] == 0:
            for i in node_info[2:]:
                matrix[node_i][i - 1] = 1
     i matrix int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i node_info = [int(i) for i in input().split()] node_info [int(i) for i in input().split()] node_i = node_info[0] - 1 node_i node_info[0] - 1 node_info[0] node_info 0 1 if not node_info[1] == 0:
            for i in node_info[2:]:
                matrix[node_i][i - 1] = 1
     not node_info[1] == 0 node_info[1] == 0 node_info[1] node_info 1 0 for i in node_info[2:]:
                matrix[node_i][i - 1] = 1
     i node_info[2:] node_info 2: 2 matrix[node_i][i - 1] = 1 matrix[node_i][i - 1] [node_i] matrix node_i i - 1 i 1 1 colors = [0] * len(matrix) colors [0] * len(matrix) [0] 0 len(matrix) len matrix detect_time = [0] * len(matrix) detect_time [0] * len(matrix) [0] 0 len(matrix) len matrix finished_time = [0] * len(matrix) finished_time [0] * len(matrix) [0] 0 len(matrix) len matrix time = 0 time 0 for i, val in enumerate(colors):
        if val == 0:
            time = dfs(i, colors, matrix, time, detect_time, finished_time)

     i val enumerate(colors) enumerate colors if val == 0:
            time = dfs(i, colors, matrix, time, detect_time, finished_time)

     val == 0 val 0 time = dfs(i, colors, matrix, time, detect_time, finished_time) time dfs(i, colors, matrix, time, detect_time, finished_time) dfs i colors matrix time detect_time finished_time for i in range(len(matrix)):
        print('{} {} {}'.format(i + 1, detect_time[i], finished_time[i])) i range(len(matrix)) range len(matrix) len matrix print('{} {} {}'.format(i + 1, detect_time[i], finished_time[i])) print '{} {} {}'.format(i + 1, detect_time[i], finished_time[i]) '{} {} {}'.format '{} {} {}' format i + 1 i 1 detect_time[i] detect_time i finished_time[i] finished_time i def dfs(u, colors, matrix, time, detect_time, finished_time):
    # ????????????????????¨??????????????????
    colors = colors
    detect_time = detect_time
    finished_time = finished_time
    time = time + 1
    stack = list()
    stack.append(u)
    colors[u] = 1
    detect_time[u] = time
    while len(stack):
        for i, val in enumerate(matrix[u]):
            if val == 1 and colors[i] == 0:
                time += 1
                stack.append(i)
                colors[i] = 1
                detect_time[i] = time
                u = i
                break
        else:
            time += 1
            e = stack.pop()
            colors[e] = 2
            finished_time[e] = time
            if len(stack):
                u = stack[-1]
    return time def dfs(u, colors, matrix, time, detect_time, finished_time):
    # ????????????????????¨??????????????????
    colors = colors
    detect_time = detect_time
    finished_time = finished_time
    time = time + 1
    stack = list()
    stack.append(u)
    colors[u] = 1
    detect_time[u] = time
    while len(stack):
        for i, val in enumerate(matrix[u]):
            if val == 1 and colors[i] == 0:
                time += 1
                stack.append(i)
                colors[i] = 1
                detect_time[i] = time
                u = i
                break
        else:
            time += 1
            e = stack.pop()
            colors[e] = 2
            finished_time[e] = time
            if len(stack):
                u = stack[-1]
    return time dfs colors = [0] * len(matrix) [0] * len(matrix) colors matrix = [[0] * N for _ in range(N)] [[0] * N for _ in range(N)] matrix finished_time = [0] * len(matrix) [0] * len(matrix) finished_time detect_time = [0] * len(matrix) [0] * len(matrix) detect_time node_i = node_info[0] - 1 node_info[0] - 1 node_i time = dfs(i, colors, matrix, time, detect_time, finished_time) dfs(i, colors, matrix, time, detect_time, finished_time) time N = int(input()) int(input()) N color = [0] * N [0] * N color node_info = [int(i) for i in input().split()] [int(i) for i in input().split()] node_info time = 0 0 time
def dfs(u, colors, matrix, time, detect_time, finished_time):
    # ????????????????????¨??????????????????
    colors = colors
    detect_time = detect_time
    finished_time = finished_time
    time = time + 1
    stack = list()
    stack.append(u)
    colors[u] = 1
    detect_time[u] = time
    while len(stack):
        for i, val in enumerate(matrix[u]):
            if val == 1 and colors[i] == 0:
                time += 1
                stack.append(i)
                colors[i] = 1
                detect_time[i] = time
                u = i
                break
        else:
            time += 1
            e = stack.pop()
            colors[e] = 2
            finished_time[e] = time
            if len(stack):
                u = stack[-1]
    return time


if __name__ == '__main__':
    N = int(input())
    matrix = [[0] * N for _ in range(N)]
    color = [0] * N
    for i in matrix:
        node_info = [int(i) for i in input().split()]
        node_i = node_info[0] - 1
        if not node_info[1] == 0:
            for i in node_info[2:]:
                matrix[node_i][i - 1] = 1
    colors = [0] * len(matrix)
    detect_time = [0] * len(matrix)
    finished_time = [0] * len(matrix)
    time = 0
    for i, val in enumerate(colors):
        if val == 0:
            time = dfs(i, colors, matrix, time, detect_time, finished_time)

    for i in range(len(matrix)):
        print('{} {} {}'.format(i + 1, detect_time[i], finished_time[i]))