n = int(input())
M = [[0]*n for _ in range(n)]
st = [0]*n
d = [0]*n
f = [0]*n
tt = 0

def dfs(u,t):
    st[u] = 1
    t += 1
    d[u] = t
    for v in range(n):
        if M[u][v] == 0: continue
        if st[v] == 0: t = dfs(v,t)
    st[u] = 2
    t += 1
    f[u] = t
    return t

for _ in range(n):
    i = [int(i) for i in input().split()]
    u = i[0]
    k = i[1]
    V = i[2:]
    for v in V: M[u-1][v-1] = 1

for i in range(n):
    if st[i] == 0: tt = dfs(i,tt)

for i in range(n): print(i+1,d[i],f[i]) 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 M = [[0]*n for _ in range(n)] M [[0]*n for _ in range(n)] st = [0]*n st [0]*n [0] 0 n d = [0]*n d [0]*n [0] 0 n f = [0]*n f [0]*n [0] 0 n tt = 0 tt 0 def dfs(u,t):
    st[u] = 1
    t += 1
    d[u] = t
    for v in range(n):
        if M[u][v] == 0: continue
        if st[v] == 0: t = dfs(v,t)
    st[u] = 2
    t += 1
    f[u] = t
    return t dfs st[u] = 1 st[u] st u 1 t += 1 t 1 d[u] = t d[u] d u t for v in range(n):
        if M[u][v] == 0: continue
        if st[v] == 0: t = dfs(v,t)
     v range(n) range n if M[u][v] == 0: continue
         M[u][v] == 0 M[u][v] [u] M u v 0 if st[v] == 0: t = dfs(v,t)
     st[v] == 0 st[v] st v 0 st[u] = 2 st[u] st u 2 t += 1 t 1 f[u] = t f[u] f u t return t t u u t t for _ in range(n):
    i = [int(i) for i in input().split()]
    u = i[0]
    k = i[1]
    V = i[2:]
    for v in V: M[u-1][v-1] = 1 _ range(n) range n 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 i = [int(i) for i in input().split()] i [int(i) for i in input().split()] u = i[0] u i[0] i 0 k = i[1] k i[1] i 1 V = i[2:] V i[2:] i 2: 2 for v in V: M[u-1][v-1] v V for i in range(n):
    if st[i] == 0: tt = dfs(i,tt) i range(n) range n if st[i] == 0: tt = dfs(i st[i] == 0 st[i] st i 0 for i in range(n): print(i+1,d[i],f[i]) i range(n) range n tt = 0 0 tt def dfs(u,t):
    st[u] = 1
    t += 1
    d[u] = t
    for v in range(n):
        if M[u][v] == 0: continue
        if st[v] == 0: t = dfs(v,t)
    st[u] = 2
    t += 1
    f[u] = t
    return t def dfs(u,t):
    st[u] = 1
    t += 1
    d[u] = t
    for v in range(n):
        if M[u][v] == 0: continue
        if st[v] == 0: t = dfs(v,t)
    st[u] = 2
    t += 1
    f[u] = t
    return t dfs k = i[1] i[1] k M = [[0]*n for _ in range(n)] [[0]*n for _ in range(n)] M f = [0]*n [0]*n f d = [0]*n [0]*n d st = [0]*n [0]*n st u = i[0] i[0] u V = i[2:] i[2:] V i = [int(i) for i in input().split()] [int(i) for i in input().split()] i n = int(input()) int(input()) n
n = int(input())
M = [[0]*n for _ in range(n)]
st = [0]*n
d = [0]*n
f = [0]*n
tt = 0

def dfs(u,t):
    st[u] = 1
    t += 1
    d[u] = t
    for v in range(n):
        if M[u][v] == 0: continue
        if st[v] == 0: t = dfs(v,t)
    st[u] = 2
    t += 1
    f[u] = t
    return t

for _ in range(n):
    i = [int(i) for i in input().split()]
    u = i[0]
    k = i[1]
    V = i[2:]
    for v in V: M[u-1][v-1] = 1

for i in range(n):
    if st[i] == 0: tt = dfs(i,tt)

for i in range(n): print(i+1,d[i],f[i])
