n = int(input())
adjacency_list = []
for i in range(n):
    input_list = list(map(int, input().split()))
    adjacency_list.append(input_list[2:])
checked_set = set()
dfs_stack = []
v =[0 for i in range(n)]
f =[0 for i in range(n)]
time = 1
for i in range(n):
    if i not in checked_set:
        dfs_stack = []
        dfs_stack.append(i)
        while dfs_stack:
            current = dfs_stack.pop()
            if current not in checked_set:
                checked_set.add(current)
                v[current] = time
                dfs_stack.append(current)
                for ad in reversed(adjacency_list[current]):
                    if ad-1 not in checked_set:
                        dfs_stack.append(ad-1)
                time +=1
            elif f[current] == 0:
                f[current] = time
                time +=1
for i in range(n):
    print(f'{i+1} {v[i]} {f[i]}') n = int(input()) n int(input()) int input() input adjacency_list = [] adjacency_list [] for i in range(n):
    input_list = list(map(int, input().split()))
    adjacency_list.append(input_list[2:]) i range(n) range n input_list = list(map(int, input().split())) input_list list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split adjacency_list.append(input_list[2:]) adjacency_list.append adjacency_list append input_list[2:] input_list 2: 2 checked_set = set() checked_set set() set dfs_stack = [] dfs_stack [] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 v =[0 for i in range(n)] v [0 for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 f =[0 for i in range(n)] f [0 for i in range(n)] time = 1 time 1 for i in range(n):
    if i not in checked_set:
        dfs_stack = []
        dfs_stack.append(i)
        while dfs_stack:
            current = dfs_stack.pop()
            if current not in checked_set:
                checked_set.add(current)
                v[current] = time
                dfs_stack.append(current)
                for ad in reversed(adjacency_list[current]):
                    if ad-1 not in checked_set:
                        dfs_stack.append(ad-1)
                time +=1
            elif f[current] == 0:
                f[current] = time
                time +=1 i range(n) range n if i not in checked_set:
        dfs_stack = []
        dfs_stack.append(i)
        while dfs_stack:
            current = dfs_stack.pop()
            if current not in checked_set:
                checked_set.add(current)
                v[current] = time
                dfs_stack.append(current)
                for ad in reversed(adjacency_list[current]):
                    if ad-1 not in checked_set:
                        dfs_stack.append(ad-1)
                time +=1
            elif f[current] == 0:
                f[current] = time
                time +=1 i not in checked_set i checked_set dfs_stack = [] dfs_stack [] dfs_stack.append(i) dfs_stack.append dfs_stack append i while dfs_stack:
            current = dfs_stack.pop()
            if current not in checked_set:
                checked_set.add(current)
                v[current] = time
                dfs_stack.append(current)
                for ad in reversed(adjacency_list[current]):
                    if ad-1 not in checked_set:
                        dfs_stack.append(ad-1)
                time +=1
            elif f[current] == 0:
                f[current] = time
                time +=1 dfs_stack current = dfs_stack.pop() current dfs_stack.pop() dfs_stack.pop dfs_stack pop if current not in checked_set:
                checked_set.add(current)
                v[current] = time
                dfs_stack.append(current)
                for ad in reversed(adjacency_list[current]):
                    if ad-1 not in checked_set:
                        dfs_stack.append(ad-1)
                time +=1
            elif f[current] == 0:
                f[current] = time
                time +=1 current not in checked_set current checked_set checked_set.add(current) checked_set.add checked_set add current v[current] = time v[current] v current time dfs_stack.append(current) dfs_stack.append dfs_stack append current for ad in reversed(adjacency_list[current]):
                    if ad-1 not in checked_set:
                        dfs_stack.append(ad-1)
                 ad reversed(adjacency_list[current]) reversed adjacency_list[current] adjacency_list current if ad-1 not in checked_set:
                        dfs_stack.append(ad-1)
                 ad-1 not in checked_set ad-1 ad 1 checked_set dfs_stack.append(ad-1) dfs_stack.append dfs_stack append ad-1 ad 1 time +=1 time 1 elif f[current] == 0:
                f[current] = time
                time +=1 f[current] == 0 f[current] f current 0 f[current] = time f[current] f current time time +=1 time 1 for i in range(n):
    print(f'{i+1} {v[i]} {f[i]}') i range(n) range n print(f'{i+1} {v[i]} {f[i]}') print f'{i+1} {v[i]} {f[i]}' time = 1 1 time dfs_stack = [] [] dfs_stack time +=1 1 time v =[0 for i in range(n)] [0 for i in range(n)] v current = dfs_stack.pop() dfs_stack.pop() current n = int(input()) int(input()) n input_list = list(map(int, input().split())) list(map(int, input().split())) input_list f =[0 for i in range(n)] [0 for i in range(n)] f dfs_stack = [] [] dfs_stack checked_set = set() set() checked_set time +=1 1 time adjacency_list = [] [] adjacency_list
n = int(input())
adjacency_list = []
for i in range(n):
    input_list = list(map(int, input().split()))
    adjacency_list.append(input_list[2:])
checked_set = set()
dfs_stack = []
v =[0 for i in range(n)]
f =[0 for i in range(n)]
time = 1
for i in range(n):
    if i not in checked_set:
        dfs_stack = []
        dfs_stack.append(i)
        while dfs_stack:
            current = dfs_stack.pop()
            if current not in checked_set:
                checked_set.add(current)
                v[current] = time
                dfs_stack.append(current)
                for ad in reversed(adjacency_list[current]):
                    if ad-1 not in checked_set:
                        dfs_stack.append(ad-1)
                time +=1
            elif f[current] == 0:
                f[current] = time
                time +=1
for i in range(n):
    print(f'{i+1} {v[i]} {f[i]}')
