n = int(input())
mat = [[0] * n for _ in range(n)]
d, f = [0] * n, [0] * n
for _ in range(n):
    adj = list(map(int, input().split()))
    i = adj[0]
    v = adj[2:]
    for j in v:
        mat[i - 1][j - 1] = 1

time, current = 0, 0
stack = []
while 0 in f:
    if not stack:
        for i, v in enumerate(f):
            if v == 0:
                stack.append(i)
                time += 1
                d[i] = time
                break
    time += 1
    current = stack[-1]
    for i in range(len(mat[current])):
        if mat[current][i] and not d[i]:
            current = i
            d[i] = time
            stack.append(i)
            break
    else:
        f[current] = time
        current = stack.pop()

for l in zip(range(1, n + 1), d, f):
    print(*l) 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 mat = [[0] * n for _ in range(n)] mat [[0] * n for _ in range(n)] d, f = [0] * n, [0] * n d [0] * n [0] 0 n f [0] * n [0] 0 n for _ in range(n):
    adj = list(map(int, input().split()))
    i = adj[0]
    v = adj[2:]
    for j in v:
        mat[i - 1][j - 1] = 1 _ range(n) range n adj = list(map(int, input().split())) adj list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split i = adj[0] i adj[0] adj 0 v = adj[2:] v adj[2:] adj 2: 2 for j in v:
        mat[i - 1][j - 1] = 1 j v mat[i - 1][j - 1] = 1 mat[i - 1][j - 1] [i - 1] mat i - 1 i 1 j - 1 j 1 1 time, current = 0, 0 time 0 current 0 stack = [] stack [] while 0 in f:
    if not stack:
        for i, v in enumerate(f):
            if v == 0:
                stack.append(i)
                time += 1
                d[i] = time
                break
    time += 1
    current = stack[-1]
    for i in range(len(mat[current])):
        if mat[current][i] and not d[i]:
            current = i
            d[i] = time
            stack.append(i)
            break
    else:
        f[current] = time
        current = stack.pop() 0 in f 0 f if not stack:
        for i, v in enumerate(f):
            if v == 0:
                stack.append(i)
                time += 1
                d[i] = time
                break
     not stack stack for i, v in enumerate(f):
            if v == 0:
                stack.append(i)
                time += 1
                d[i] = time
                break
     i v enumerate(f) enumerate f if v == 0:
                stack.append(i)
                time += 1
                d[i] = time
                break
     v == 0 v 0 stack.append(i) stack.append stack append i time += 1 time 1 d[i] = time d[i] d i time break time += 1 time 1 current = stack[-1] current stack[-1] stack -1 for i in range(len(mat[current])):
        if mat[current][i] and not d[i]:
            current = i
            d[i] = time
            stack.append(i)
            break
    else:
        f[current] = time
        current = stack.pop() i range(len(mat[current])) range len(mat[current]) len mat[current] mat current if mat[current][i] and not d[i]:
            current = i
            d[i] = time
            stack.append(i)
            break
     mat[current][i] and not d[i] mat[current][i] [current] mat current i not d[i] d[i] d i current = i current i d[i] = time d[i] d i time stack.append(i) stack.append stack append i break f[current] = time f[current] f current time current = stack.pop() current stack.pop() stack.pop stack pop for l in zip(range(1, n + 1), d, f):
    print(*l) l zip(range(1, n + 1), d, f) zip range(1, n + 1) range 1 n + 1 n 1 d f print(*l) print *l l adj = list(map(int, input().split())) list(map(int, input().split())) adj current = 0, 0 0 current time += 1 1 time n = int(input()) int(input()) n current = stack[-1] stack[-1] current stack = [] [] stack i = adj[0] adj[0] i f = [0] * n, [0] * n [0] * n f mat = [[0] * n for _ in range(n)] [[0] * n for _ in range(n)] mat v = adj[2:] adj[2:] v current = i i current time += 1 1 time time, current = 0, 0 0 time d, f = [0] * n, [0] * n [0] * n d current = stack.pop() stack.pop() current
n = int(input())
mat = [[0] * n for _ in range(n)]
d, f = [0] * n, [0] * n
for _ in range(n):
    adj = list(map(int, input().split()))
    i = adj[0]
    v = adj[2:]
    for j in v:
        mat[i - 1][j - 1] = 1

time, current = 0, 0
stack = []
while 0 in f:
    if not stack:
        for i, v in enumerate(f):
            if v == 0:
                stack.append(i)
                time += 1
                d[i] = time
                break
    time += 1
    current = stack[-1]
    for i in range(len(mat[current])):
        if mat[current][i] and not d[i]:
            current = i
            d[i] = time
            stack.append(i)
            break
    else:
        f[current] = time
        current = stack.pop()

for l in zip(range(1, n + 1), d, f):
    print(*l)