n = int(input())
G = [[] for i in range(n+1)] #G(i): 頂点iと隣接する頂点のlist
for i in range(n):
    a = [int(i) for i in input().split()]
    G[a[0]] = a[2:]
    G[a[0]].sort()

d = [0] * (n+1)
f = [0] * (n+1)

seen = [0] * (n+1) #頂点iが訪問済みの場合 seen[i] = 1
t = 0

def dfs(s):
    global t
    seen[s] = 1
    d[s] = t
    for i in G[s]:
        if seen[i] == 0:
            t += 1
            dfs(i)
    t += 1
    f[s] = t

for i in range(1, n+1):
    if not seen[i]:
        t += 1
        dfs(i)

for i in range(1, n+1):
    print(i, d[i], f[i]) n = int(input()) n int(input()) int input() input [] for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) [] G = [[] for i in range(n+1)] G [[] for i in range(n+1)] for i in range(n):
    a = [int(i) for i in input().split()]
    G[a[0]] = a[2:]
    G[a[0]].sort() i 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 a = [int(i) for i in input().split()] a [int(i) for i in input().split()] G[a[0]] = a[2:] G[a[0]] G a[0] a 0 a[2:] a 2: 2 G[a[0]].sort() [a[0]].sort [a[0]] G a[0] a 0 sort d = [0] * (n+1) d [0] * (n+1) [0] 0 n+1 n 1 f = [0] * (n+1) f [0] * (n+1) [0] 0 n+1 n 1 seen = [0] * (n+1) seen [0] * (n+1) [0] 0 n+1 n 1 t = 0 t 0 def dfs(s):
    global t
    seen[s] = 1
    d[s] = t
    for i in G[s]:
        if seen[i] == 0:
            t += 1
            dfs(i)
    t += 1
    f[s] = t dfs global t seen[s] = 1 seen[s] seen s 1 d[s] = t d[s] d s t for i in G[s]:
        if seen[i] == 0:
            t += 1
            dfs(i)
     i G[s] G s if seen[i] == 0:
            t += 1
            dfs(i)
     seen[i] == 0 seen[i] seen i 0 t += 1 t 1 dfs(i) dfs i t += 1 t 1 f[s] = t f[s] f s t s s for i in range(1, n+1):
    if not seen[i]:
        t += 1
        dfs(i) i range(1, n+1) range 1 n+1 n 1 if not seen[i]:
        t += 1
        dfs(i) not seen[i] seen[i] seen i t += 1 t 1 dfs(i) dfs i for i in range(1, n+1):
    print(i, d[i], f[i]) i range(1, n+1) range 1 n+1 n 1 print(i, d[i], f[i]) print i d[i] d i f[i] f i def dfs(s):
    global t
    seen[s] = 1
    d[s] = t
    for i in G[s]:
        if seen[i] == 0:
            t += 1
            dfs(i)
    t += 1
    f[s] = t def dfs(s):
    global t
    seen[s] = 1
    d[s] = t
    for i in G[s]:
        if seen[i] == 0:
            t += 1
            dfs(i)
    t += 1
    f[s] = t dfs n = int(input()) int(input()) n t += 1 1 t t = 0 0 t a = [int(i) for i in input().split()] [int(i) for i in input().split()] a f = [0] * (n+1) [0] * (n+1) f d = [0] * (n+1) [0] * (n+1) d seen = [0] * (n+1) [0] * (n+1) seen G = [[] for i in range(n+1)] [[] for i in range(n+1)] G
n = int(input())
G = [[] for i in range(n+1)] #G(i): 頂点iと隣接する頂点のlist
for i in range(n):
    a = [int(i) for i in input().split()]
    G[a[0]] = a[2:]
    G[a[0]].sort()

d = [0] * (n+1)
f = [0] * (n+1)

seen = [0] * (n+1) #頂点iが訪問済みの場合 seen[i] = 1
t = 0

def dfs(s):
    global t
    seen[s] = 1
    d[s] = t
    for i in G[s]:
        if seen[i] == 0:
            t += 1
            dfs(i)
    t += 1
    f[s] = t

for i in range(1, n+1):
    if not seen[i]:
        t += 1
        dfs(i)

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