def depth_search(u, t):
    t += 1
    s.append(u)
    d[u] = t
    for v in range(N):
        if adjacency_list[u][v] == 0:
            continue 
        if d[v] == 0 and v not in s:
            t = depth_search(v, t)
    t += 1
    s.pop()
    f[u] = t
    return t

N = int(input())
adjacency_list = [[0 for j in range(N)] for i in range(N)]
for _ in range(N):
    u, k, *v = input().split()
    for i in v:
        adjacency_list[int(u)-1][int(i)-1] = 1

s = []
d = [0 for _ in range(N)]
f = [0 for _ in range(N)]

t = 0
for u in range(N):
    if d[u] == 0:
        t = depth_search(u, t)

for i in range(N):
    print("{} {} {}".format(i+1, d[i], f[i])) def depth_search(u, t):
    t += 1
    s.append(u)
    d[u] = t
    for v in range(N):
        if adjacency_list[u][v] == 0:
            continue 
        if d[v] == 0 and v not in s:
            t = depth_search(v, t)
    t += 1
    s.pop()
    f[u] = t
    return t depth_search t += 1 t 1 s.append(u) s.append s append u d[u] = t d[u] d u t for v in range(N):
        if adjacency_list[u][v] == 0:
            continue 
        if d[v] == 0 and v not in s:
            t = depth_search(v, t)
     v range(N) range N if adjacency_list[u][v] == 0:
            continue 
         adjacency_list[u][v] == 0 adjacency_list[u][v] [u] adjacency_list u v 0 continue if d[v] == 0 and v not in s:
            t = depth_search(v, t)
     d[v] == 0 and v not in s d[v] == 0 d[v] d v 0 v not in s v s t = depth_search(v, t) t depth_search(v, t) depth_search v t t += 1 t 1 s.pop() s.pop s pop f[u] = t f[u] f u t return t t u u t t N = int(input()) N int(input()) int input() input [0 for j in range(N)] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [0 for j in range(N)] adjacency_list = [[0 for j in range(N)] for i in range(N)] adjacency_list [[0 for j in range(N)] for i in range(N)] for _ in range(N):
    u, k, *v = input().split()
    for i in v:
        adjacency_list[int(u)-1][int(i)-1] = 1 _ range(N) range N u, k, *v = input().split() u input().split() ().split () input split k *v v for i in v:
        adjacency_list[int(u)-1][int(i)-1] = 1 i v adjacency_list[int(u)-1][int(i)-1] = 1 adjacency_list[int(u)-1][int(i)-1] [int(u)-1] adjacency_list int(u)-1 int(u) int u 1 int(i)-1 int(i) int i 1 1 s = [] s [] 0 for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) 0 d = [0 for _ in range(N)] d [0 for _ in range(N)] 0 for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) 0 f = [0 for _ in range(N)] f [0 for _ in range(N)] t = 0 t 0 for u in range(N):
    if d[u] == 0:
        t = depth_search(u, t) u range(N) range N if d[u] == 0:
        t = depth_search(u, t) d[u] == 0 d[u] d u 0 t = depth_search(u, t) t depth_search(u, t) depth_search u t for i in range(N):
    print("{} {} {}".format(i+1, d[i], f[i])) i range(N) range N print("{} {} {}".format(i+1, d[i], f[i])) print "{} {} {}".format(i+1, d[i], f[i]) "{} {} {}".format "{} {} {}" format i+1 i 1 d[i] d i f[i] f i t = depth_search(u, t) depth_search(u, t) t u, k, *v = input().split() input().split() u f = [0 for _ in range(N)] [0 for _ in range(N)] f t = 0 0 t N = int(input()) int(input()) N adjacency_list = [[0 for j in range(N)] for i in range(N)] [[0 for j in range(N)] for i in range(N)] adjacency_list d = [0 for _ in range(N)] [0 for _ in range(N)] d s = [] [] s def depth_search(u, t):
    t += 1
    s.append(u)
    d[u] = t
    for v in range(N):
        if adjacency_list[u][v] == 0:
            continue 
        if d[v] == 0 and v not in s:
            t = depth_search(v, t)
    t += 1
    s.pop()
    f[u] = t
    return t def depth_search(u, t):
    t += 1
    s.append(u)
    d[u] = t
    for v in range(N):
        if adjacency_list[u][v] == 0:
            continue 
        if d[v] == 0 and v not in s:
            t = depth_search(v, t)
    t += 1
    s.pop()
    f[u] = t
    return t depth_search k, *v = input().split() input().split() k
def depth_search(u, t):
    t += 1
    s.append(u)
    d[u] = t
    for v in range(N):
        if adjacency_list[u][v] == 0:
            continue 
        if d[v] == 0 and v not in s:
            t = depth_search(v, t)
    t += 1
    s.pop()
    f[u] = t
    return t

N = int(input())
adjacency_list = [[0 for j in range(N)] for i in range(N)]
for _ in range(N):
    u, k, *v = input().split()
    for i in v:
        adjacency_list[int(u)-1][int(i)-1] = 1

s = []
d = [0 for _ in range(N)]
f = [0 for _ in range(N)]

t = 0
for u in range(N):
    if d[u] == 0:
        t = depth_search(u, t)

for i in range(N):
    print("{} {} {}".format(i+1, d[i], f[i]))
