from collections import deque

n = int(input())

g = [deque([]) *n for _ in range(n)]

for i in range(n):
    u, k, *V = list(map(int, input().split()))
    V.sort()
    for v in V:
        g[u-1].append(v-1)
        # g[v-1].append(u-1)

time = 0
arrive_time = [-1] * n
finish_time = [-1] * n
def dfs(v):
    global time
    time += 1
    stack = [v]
    arrive_time[v] = time
    while stack:
        v = stack[-1]
        if g[v]:
            w = g[v].popleft()
            if arrive_time[w] < 0:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[v] = time
            stack.pop()

    return [arrive_time, finish_time]

for i in range(n):
    if arrive_time[i] < 0:
        ans = dfs(i)

for j in range(n):
    temp = [j+1, ans[0][j], ans[1][j]]
    print(*temp) from collections import deque n = int(input()) n int(input()) int input() input deque([]) *n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) deque([]) *n deque([]) deque [] n g = [deque([]) *n for _ in range(n)] g [deque([]) *n for _ in range(n)] for i in range(n):
    u, k, *V = list(map(int, input().split()))
    V.sort()
    for v in V:
        g[u-1].append(v-1)
        # g[v-1].append(u-1) i range(n) range n u, k, *V = list(map(int, input().split())) u list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split k *V V V.sort() V.sort V sort for v in V:
        g[u-1].append(v-1)
        # g[v-1].append(u-1) v V g[u-1].append(v-1) [u-1].append [u-1] g u-1 u 1 append v-1 v 1 time = 0 time 0 arrive_time = [-1] * n arrive_time [-1] * n [-1] -1 n finish_time = [-1] * n finish_time [-1] * n [-1] -1 n def dfs(v):
    global time
    time += 1
    stack = [v]
    arrive_time[v] = time
    while stack:
        v = stack[-1]
        if g[v]:
            w = g[v].popleft()
            if arrive_time[w] < 0:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[v] = time
            stack.pop()

    return [arrive_time, finish_time] dfs global time time += 1 time 1 stack = [v] stack [v] v arrive_time[v] = time arrive_time[v] arrive_time v time while stack:
        v = stack[-1]
        if g[v]:
            w = g[v].popleft()
            if arrive_time[w] < 0:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[v] = time
            stack.pop()

     stack v = stack[-1] v stack[-1] stack -1 if g[v]:
            w = g[v].popleft()
            if arrive_time[w] < 0:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[v] = time
            stack.pop()

     g[v] g v w = g[v].popleft() w g[v].popleft() [v].popleft [v] g v popleft if arrive_time[w] < 0:
                time += 1
                arrive_time[w] = time
                stack.append(w)
         arrive_time[w] < 0 arrive_time[w] arrive_time w 0 time += 1 time 1 arrive_time[w] = time arrive_time[w] arrive_time w time stack.append(w) stack.append stack append w time += 1 time 1 finish_time[v] = time finish_time[v] finish_time v time stack.pop() stack.pop stack pop return [arrive_time, finish_time] [arrive_time, finish_time] arrive_time finish_time v v for i in range(n):
    if arrive_time[i] < 0:
        ans = dfs(i) i range(n) range n if arrive_time[i] < 0:
        ans = dfs(i) arrive_time[i] < 0 arrive_time[i] arrive_time i 0 ans = dfs(i) ans dfs(i) dfs i for j in range(n):
    temp = [j+1, ans[0][j], ans[1][j]]
    print(*temp) j range(n) range n temp = [j+1, ans[0][j], ans[1][j]] temp [j+1, ans[0][j], ans[1][j]] j+1 j 1 ans[0][j] [0] ans 0 j ans[1][j] [1] ans 1 j print(*temp) print *temp temp n = int(input()) int(input()) n g = [deque([]) *n for _ in range(n)] [deque([]) *n for _ in range(n)] g u, k, *V = list(map(int, input().split())) list(map(int, input().split())) u k, *V = list(map(int, input().split())) list(map(int, input().split())) k arrive_time = [-1] * n [-1] * n arrive_time ans = dfs(i) dfs(i) ans time = 0 0 time def dfs(v):
    global time
    time += 1
    stack = [v]
    arrive_time[v] = time
    while stack:
        v = stack[-1]
        if g[v]:
            w = g[v].popleft()
            if arrive_time[w] < 0:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[v] = time
            stack.pop()

    return [arrive_time, finish_time] def dfs(v):
    global time
    time += 1
    stack = [v]
    arrive_time[v] = time
    while stack:
        v = stack[-1]
        if g[v]:
            w = g[v].popleft()
            if arrive_time[w] < 0:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[v] = time
            stack.pop()

    return [arrive_time, finish_time] dfs temp = [j+1, ans[0][j], ans[1][j]] [j+1, ans[0][j], ans[1][j]] temp finish_time = [-1] * n [-1] * n finish_time
from collections import deque

n = int(input())

g = [deque([]) *n for _ in range(n)]

for i in range(n):
    u, k, *V = list(map(int, input().split()))
    V.sort()
    for v in V:
        g[u-1].append(v-1)
        # g[v-1].append(u-1)

time = 0
arrive_time = [-1] * n
finish_time = [-1] * n
def dfs(v):
    global time
    time += 1
    stack = [v]
    arrive_time[v] = time
    while stack:
        v = stack[-1]
        if g[v]:
            w = g[v].popleft()
            if arrive_time[w] < 0:
                time += 1
                arrive_time[w] = time
                stack.append(w)
        else:
            time += 1
            finish_time[v] = time
            stack.pop()

    return [arrive_time, finish_time]

for i in range(n):
    if arrive_time[i] < 0:
        ans = dfs(i)

for j in range(n):
    temp = [j+1, ans[0][j], ans[1][j]]
    print(*temp)
