#coding:utf-8

from copy import deepcopy



n = int(eval(input()))

c = ["white" for i in range(n)]

d = [0 for i in range(n)]

f = [0 for i in range(n)]

S = []

class DFS:

    def __init__(self, key, color="white",nex=None):

        self.color = color

        self.nex = nex

        self.key = key



objList = [DFS(i+1) for i in range(n)]

for i in range(n):

    data = list(map(int,input().split()))

    times = data[1]

    obj = objList[i]

    for j in range(times):

        index = data[2+j] - 1

        nextobj = DFS(index+1)

        obj.nex = nextobj

        obj = obj.nex





time = 1

def check(first,time):

    obj = objList[first]

    c[first] = "gray"

    d[first] = time

    f[first] = time

    S.append(first+1)

    

    while S != []:

        index = S[-1] - 1

        u = objList[index]

        v = u.nex

    

        if v != None:

            objList[index] = v

            if c[v.key - 1] == "white":

                index = v.key - 1

                v = objList[index]

                c[v.key-1] = "gray"

                time += 1

                d[index] = time

                S.append(v.key)



           

                

        else:

            S.pop()

            c[u.key-1] = "black"

            time += 1

            f[index] = time

    return time





for i in range(n):

    if f[i] == 0:

        time = check(i,time) + 1

        



k = 1

for i,j in zip(d,f):

    print((k,i,j))

    k += 1

#coding: utf-8



n = int(eval(input()))

color = ["white" for i in range(n)]

d = [[] for i in range(n)]

global t

t = 0

M = [[False for i in range(n)] for j in range(n)]

for i in range(n):

    data = list(map(int,input().split()))

    u = data[0]

    k = data[1]

    if i == 0:

        start = u

    for v in data[2:2+k]:

        M[u-1][v-1] = True





def search(u,t):

    t += 1

    color[u-1] = "gray"

    d[u-1].append(t)

    for v in range(1,n+1):

        if M[u-1][v-1] and color[v-1] == "white":

            t = search(v,t)

    color[u-1] = "black"

    t += 1

    d[u-1].append(t)

    return t



t = search(start, t)

for i in range(1,n+1):

    if color[i-1] == "white":

        t = search(i, t)



for i in range(n):

    print((i+1, d[i][0], d[i][1]))



# coding:utf-8
from copy import deepcopy

n = int(eval(input()))
c = ["white" for i in range(n)]
d = [0 for i in range(n)]
f = [0 for i in range(n)]
S = []


class DFS:
    def __init__(self, key, color="white", nex=None):
        self.color = color
        self.nex = nex
        self.key = key


objList = [DFS(i + 1) for i in range(n)]
for i in range(n):
    data = list(map(int, input().split()))
    times = data[1]
    obj = objList[i]
    for j in range(times):
        index = data[2 + j] - 1
        nextobj = DFS(index + 1)
        obj.nex = nextobj
        obj = obj.nex
time = 1


def check(first, time):
    obj = objList[first]
    c[first] = "gray"
    d[first] = time
    f[first] = time
    S.append(first + 1)
    while S != []:
        index = S[-1] - 1
        u = objList[index]
        v = u.nex
        if v != None:
            objList[index] = v
            if c[v.key - 1] == "white":
                index = v.key - 1
                v = objList[index]
                c[v.key - 1] = "gray"
                time += 1
                d[index] = time
                S.append(v.key)
        else:
            S.pop()
            c[u.key - 1] = "black"
            time += 1
            f[index] = time
    return time


for i in range(n):
    if f[i] == 0:
        time = check(i, time) + 1
k = 1
for i, j in zip(d, f):
    print((k, i, j))
    k += 1

# coding: utf-8
n = int(eval(input()))
color = ["white" for i in range(n)]
d = [[] for i in range(n)]
global t
t = 0
M = [[False for i in range(n)] for j in range(n)]
for i in range(n):
    data = list(map(int, input().split()))
    u = data[0]
    k = data[1]
    if i == 0:
        start = u
    for v in data[2 : 2 + k]:
        M[u - 1][v - 1] = True


def search(u, t):
    t += 1
    color[u - 1] = "gray"
    d[u - 1].append(t)
    for v in range(1, n + 1):
        if M[u - 1][v - 1] and color[v - 1] == "white":
            t = search(v, t)
    color[u - 1] = "black"
    t += 1
    d[u - 1].append(t)
    return t


t = search(start, t)
for i in range(1, n + 1):
    if color[i - 1] == "white":
        t = search(i, t)
for i in range(n):
    print((i + 1, d[i][0], d[i][1]))

-# coding:utf-8 -from copy import deepcopy - +# coding: utf-8 -c = ["white" for i in range(n)] -d = [0 for i in range(n)] -f = [0 for i in range(n)] -S = [] +color = ["white" for i in range(n)] +d = [[] for i in range(n)] +global t +t = 0 +M = [[False for i in range(n)] for j in range(n)] +for i in range(n): +    data = list(map(int, input().split())) +    u = data[0] +    k = data[1] +    if i == 0: +        start = u +    for v in data[2 : 2 + k]: +        M[u - 1][v - 1] = True -class DFS: -    def __init__(self, key, color="white", nex=None): -        self.color = color -        self.nex = nex -        self.key = key +def search(u, t): +    t += 1 +    color[u - 1] = "gray" +    d[u - 1].append(t) +    for v in range(1, n + 1): +        if M[u - 1][v - 1] and color[v - 1] == "white": +            t = search(v, t) +    color[u - 1] = "black" +    t += 1 +    d[u - 1].append(t) +    return t -objList = [DFS(i + 1) for i in range(n)] +t = search(start, t) +for i in range(1, n + 1): +    if color[i - 1] == "white": +        t = search(i, t) -    data = list(map(int, input().split())) -    times = data[1] -    obj = objList[i] -    for j in range(times): -        index = data[2 + j] - 1 -        nextobj = DFS(index + 1) -        obj.nex = nextobj -        obj = obj.nex -time = 1 - - -def check(first, time): -    obj = objList[first] -    c[first] = "gray" -    d[first] = time -    f[first] = time -    S.append(first + 1) -    while S != []: -        index = S[-1] - 1 -        u = objList[index] -        v = u.nex -        if v != None: -            objList[index] = v -            if c[v.key - 1] == "white": -                index = v.key - 1 -                v = objList[index] -                c[v.key - 1] = "gray" -                time += 1 -                d[index] = time -                S.append(v.key) -        else: -            S.pop() -            c[u.key - 1] = "black" -            time += 1 -            f[index] = time -    return time - - -for i in range(n): -    if f[i] == 0: -        time = check(i, time) + 1 -k = 1 -for i, j in zip(d, f): -    print((k, i, j)) -    k += 1 +    print((i + 1, d[i][0], d[i][1]))