import collections,sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
n = I()
ukv = [LI() for _ in range(n)]
graph = {i:collections.deque() for i in range(1,n+1)} #1_indexed
for x in ukv:
    u,k,*v = x
    for y in v:
        graph[u].append(y)
seen = [0]*(n+1) #1_indexed
stack = []
time = 0
seentime = [0]*(n+1) #1_indexed
donetime = [0]*(n+1) #1_indexed
def dfs(j):
    global time
    seen[j] = 1
    stack.append(j)
    time += 1
    seentime[j] = time
    while stack:
        s = stack[-1]
        if not graph[s]:
            stack.pop()
            time += 1
            donetime[s] = time
            continue
        g_NO = graph[s].popleft()
        if seen[g_NO]:
            continue
        seen[g_NO] = 1
        stack.append(g_NO)
        time += 1
        seentime[g_NO] = time
for j in range(1,n+1):
    if seen[j]:
        continue
    dfs(j)
for k,a,b in zip(range(1,n+1),seentime[1:],donetime[1:]):
    print(k,a,b) import collections,sys collections sys def I(): return int(sys.stdin.readline().rstrip()) I def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) LI n = I() n I() I LI() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) LI() LI ukv = [LI() for _ in range(n)] ukv [LI() for _ in range(n)] i:collections.deque() for i in range(1,n+1) for i in range(1,n+1) i range(1,n+1) range 1 n+1 n 1 for i in range(1,n+1) i collections.deque() collections.deque collections deque graph = {i:collections.deque() for i in range(1,n+1)} graph {i:collections.deque() for i in range(1,n+1)} for x in ukv:
    u,k,*v = x
    for y in v:
        graph[u].append(y) x ukv u,k,*v = x u x k *v v for y in v:
        graph[u].append(y) y v graph[u].append(y) [u].append [u] graph u append y seen = [0]*(n+1) seen [0]*(n+1) [0] 0 n+1 n 1 stack = [] stack [] time = 0 time 0 seentime = [0]*(n+1) seentime [0]*(n+1) [0] 0 n+1 n 1 donetime = [0]*(n+1) donetime [0]*(n+1) [0] 0 n+1 n 1 def dfs(j):
    global time
    seen[j] = 1
    stack.append(j)
    time += 1
    seentime[j] = time
    while stack:
        s = stack[-1]
        if not graph[s]:
            stack.pop()
            time += 1
            donetime[s] = time
            continue
        g_NO = graph[s].popleft()
        if seen[g_NO]:
            continue
        seen[g_NO] = 1
        stack.append(g_NO)
        time += 1
        seentime[g_NO] = time dfs global time seen[j] = 1 seen[j] seen j 1 stack.append(j) stack.append stack append j time += 1 time 1 seentime[j] = time seentime[j] seentime j time while stack:
        s = stack[-1]
        if not graph[s]:
            stack.pop()
            time += 1
            donetime[s] = time
            continue
        g_NO = graph[s].popleft()
        if seen[g_NO]:
            continue
        seen[g_NO] = 1
        stack.append(g_NO)
        time += 1
        seentime[g_NO] = time stack s = stack[-1] s stack[-1] stack -1 if not graph[s]:
            stack.pop()
            time += 1
            donetime[s] = time
            continue
         not graph[s] graph[s] graph s stack.pop() stack.pop stack pop time += 1 time 1 donetime[s] = time donetime[s] donetime s time continue g_NO = graph[s].popleft() g_NO graph[s].popleft() [s].popleft [s] graph s popleft if seen[g_NO]:
            continue
         seen[g_NO] seen g_NO continue seen[g_NO] = 1 seen[g_NO] seen g_NO 1 stack.append(g_NO) stack.append stack append g_NO time += 1 time 1 seentime[g_NO] = time seentime[g_NO] seentime g_NO time j j for j in range(1,n+1):
    if seen[j]:
        continue
    dfs(j) j range(1,n+1) range 1 n+1 n 1 if seen[j]:
        continue
     seen[j] seen j continue dfs(j) dfs j for k,a,b in zip(range(1,n+1),seentime[1:],donetime[1:]):
    print(k,a,b) k a b zip(range(1,n+1),seentime[1:],donetime[1:]) zip range(1,n+1) range 1 n+1 n 1 seentime[1:] seentime 1: 1 donetime[1:] donetime 1: 1 print(k,a,b) print k a b n = I() I() n k,*v = x x k seentime = [0]*(n+1) [0]*(n+1) seentime def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) LI time = 0 0 time def dfs(j):
    global time
    seen[j] = 1
    stack.append(j)
    time += 1
    seentime[j] = time
    while stack:
        s = stack[-1]
        if not graph[s]:
            stack.pop()
            time += 1
            donetime[s] = time
            continue
        g_NO = graph[s].popleft()
        if seen[g_NO]:
            continue
        seen[g_NO] = 1
        stack.append(g_NO)
        time += 1
        seentime[g_NO] = time def dfs(j):
    global time
    seen[j] = 1
    stack.append(j)
    time += 1
    seentime[j] = time
    while stack:
        s = stack[-1]
        if not graph[s]:
            stack.pop()
            time += 1
            donetime[s] = time
            continue
        g_NO = graph[s].popleft()
        if seen[g_NO]:
            continue
        seen[g_NO] = 1
        stack.append(g_NO)
        time += 1
        seentime[g_NO] = time dfs stack = [] [] stack seen = [0]*(n+1) [0]*(n+1) seen def I(): return int(sys.stdin.readline().rstrip()) def I(): return int(sys.stdin.readline().rstrip()) I ukv = [LI() for _ in range(n)] [LI() for _ in range(n)] ukv donetime = [0]*(n+1) [0]*(n+1) donetime graph = {i:collections.deque() for i in range(1,n+1)} {i:collections.deque() for i in range(1,n+1)} graph u,k,*v = x x u
import collections,sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
n = I()
ukv = [LI() for _ in range(n)]
graph = {i:collections.deque() for i in range(1,n+1)} #1_indexed
for x in ukv:
    u,k,*v = x
    for y in v:
        graph[u].append(y)
seen = [0]*(n+1) #1_indexed
stack = []
time = 0
seentime = [0]*(n+1) #1_indexed
donetime = [0]*(n+1) #1_indexed
def dfs(j):
    global time
    seen[j] = 1
    stack.append(j)
    time += 1
    seentime[j] = time
    while stack:
        s = stack[-1]
        if not graph[s]:
            stack.pop()
            time += 1
            donetime[s] = time
            continue
        g_NO = graph[s].popleft()
        if seen[g_NO]:
            continue
        seen[g_NO] = 1
        stack.append(g_NO)
        time += 1
        seentime[g_NO] = time
for j in range(1,n+1):
    if seen[j]:
        continue
    dfs(j)
for k,a,b in zip(range(1,n+1),seentime[1:],donetime[1:]):
    print(k,a,b)
