N = int(input())
adj_list = [ [] for _ in range(N+1) ]
for _ in range(N):
  lst = list(map(int,input().split()))
  node = lst[0]
  if lst[1] != 0:
    adj_list[node] = lst[2:]


visited = [False] * (N+1)
arrived = [-1] * (N+1)
left = [-1] * (N+1)

time = 0
def dfs(node):
  global time

  arrived[node] = time
  visited[node] = True

  for nei in adj_list[node]:
    if not visited[nei]:
      time += 1
      dfs(nei)
  else:
    time += 1
    left[node] = time

for i in range(1, N+1):
  if not visited[i]:
    time += 1
    dfs(i)

for i in range(1, N+1):
  print(i, arrived[i], left[i]) N = int(input()) N int(input()) int input() input [] for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [] adj_list = [ [] for _ in range(N+1) ] adj_list [ [] for _ in range(N+1) ] for _ in range(N):
  lst = list(map(int,input().split()))
  node = lst[0]
  if lst[1] != 0:
    adj_list[node] = lst[2:] _ range(N) range N lst = list(map(int,input().split())) lst list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split node = lst[0] node lst[0] lst 0 if lst[1] != 0:
    adj_list[node] = lst[2:] lst[1] != 0 lst[1] lst 1 0 adj_list[node] = lst[2:] adj_list[node] adj_list node lst[2:] lst 2: 2 visited = [False] * (N+1) visited [False] * (N+1) [False] False N+1 N 1 arrived = [-1] * (N+1) arrived [-1] * (N+1) [-1] -1 N+1 N 1 left = [-1] * (N+1) left [-1] * (N+1) [-1] -1 N+1 N 1 time = 0 time 0 def dfs(node):
  global time

  arrived[node] = time
  visited[node] = True

  for nei in adj_list[node]:
    if not visited[nei]:
      time += 1
      dfs(nei)
  else:
    time += 1
    left[node] = time dfs global time arrived[node] = time arrived[node] arrived node time visited[node] = True visited[node] visited node True for nei in adj_list[node]:
    if not visited[nei]:
      time += 1
      dfs(nei)
  else:
    time += 1
    left[node] = time nei adj_list[node] adj_list node if not visited[nei]:
      time += 1
      dfs(nei)
   not visited[nei] visited[nei] visited nei time += 1 time 1 dfs(nei) dfs nei time += 1 time 1 left[node] = time left[node] left node time node node for i in range(1, N+1):
  if not visited[i]:
    time += 1
    dfs(i) i range(1, N+1) range 1 N+1 N 1 if not visited[i]:
    time += 1
    dfs(i) not visited[i] visited[i] visited i time += 1 time 1 dfs(i) dfs i for i in range(1, N+1):
  print(i, arrived[i], left[i]) i range(1, N+1) range 1 N+1 N 1 print(i, arrived[i], left[i]) print i arrived[i] arrived i left[i] left i N = int(input()) int(input()) N time = 0 0 time lst = list(map(int,input().split())) list(map(int,input().split())) lst arrived = [-1] * (N+1) [-1] * (N+1) arrived adj_list = [ [] for _ in range(N+1) ] [ [] for _ in range(N+1) ] adj_list visited = [False] * (N+1) [False] * (N+1) visited node = lst[0] lst[0] node def dfs(node):
  global time

  arrived[node] = time
  visited[node] = True

  for nei in adj_list[node]:
    if not visited[nei]:
      time += 1
      dfs(nei)
  else:
    time += 1
    left[node] = time def dfs(node):
  global time

  arrived[node] = time
  visited[node] = True

  for nei in adj_list[node]:
    if not visited[nei]:
      time += 1
      dfs(nei)
  else:
    time += 1
    left[node] = time dfs time += 1 1 time left = [-1] * (N+1) [-1] * (N+1) left
N = int(input())
adj_list = [ [] for _ in range(N+1) ]
for _ in range(N):
  lst = list(map(int,input().split()))
  node = lst[0]
  if lst[1] != 0:
    adj_list[node] = lst[2:]


visited = [False] * (N+1)
arrived = [-1] * (N+1)
left = [-1] * (N+1)

time = 0
def dfs(node):
  global time

  arrived[node] = time
  visited[node] = True

  for nei in adj_list[node]:
    if not visited[nei]:
      time += 1
      dfs(nei)
  else:
    time += 1
    left[node] = time

for i in range(1, N+1):
  if not visited[i]:
    time += 1
    dfs(i)

for i in range(1, N+1):
  print(i, arrived[i], left[i])
