N = int(input())
inf = 10 ** 6
graph = [[] for i in range(N)]
visited = [0 for i in range(N)]
time = [[inf,inf] for i in range(N)]

for i in range(N):
  a = list(map(int,input().split()))
  a = list(map(lambda x: x - 1,a))
  k,n = a[0],a[1]
  if n >= 0:
    graph[k] = a[2:]

con = 0

def dfs(cur,par):
  #print("v",visited)
  global con
  visited[cur] = 1
  con += 1
  time[cur][0] = min(time[cur][0],con)
  #print("cur1,con1",cur,con)
  if (graph[cur] == [] or graph[cur] == [cur]):
    visited[cur] = 1
    time[cur][0] = min(con,time[cur][0])
    con += 1
    time[cur][1] = min(con,time[cur][1])
    #print("curif,conif",cur,con)
    return 
  else:
    for chi in graph[cur]:
      if visited[chi] == 0:
        dfs(chi,cur)
      if any(visited[i] == 0 for i in graph[cur]):
        continue
      else:
        con += 1
        time[cur][1] = min(con,time[cur][1])
        #print("cur2,con2",cur,con)
        return
dfs(0,-1)

if any([i == 0 for i in visited]):
  f = visited.index(0)
  dfs(f,f - 1)

for i,t in enumerate(time):
  print(i + 1 ,*t) N = int(input()) N int(input()) int input() input inf = 10 ** 6 inf 10 ** 6 10 6 [] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [] graph = [[] for i in range(N)] graph [[] 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 visited = [0 for i in range(N)] visited [0 for i in range(N)] [inf,inf] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [inf,inf] inf inf time = [[inf,inf] for i in range(N)] time [[inf,inf] for i in range(N)] for i in range(N):
  a = list(map(int,input().split()))
  a = list(map(lambda x: x - 1,a))
  k,n = a[0],a[1]
  if n >= 0:
    graph[k] = a[2:] i range(N) range N a = list(map(int,input().split())) a list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split a = list(map(lambda x: x - 1,a)) a list(map(lambda x: x - 1,a)) list map(lambda x: x - 1,a) map lambda x: x - 1 x - 1 x 1 x a k,n = a[0],a[1] k a[0] a 0 n a[1] a 1 if n >= 0:
    graph[k] = a[2:] n >= 0 n 0 graph[k] = a[2:] graph[k] graph k a[2:] a 2: 2 con = 0 con 0 def dfs(cur,par):
  #print("v",visited)
  global con
  visited[cur] = 1
  con += 1
  time[cur][0] = min(time[cur][0],con)
  #print("cur1,con1",cur,con)
  if (graph[cur] == [] or graph[cur] == [cur]):
    visited[cur] = 1
    time[cur][0] = min(con,time[cur][0])
    con += 1
    time[cur][1] = min(con,time[cur][1])
    #print("curif,conif",cur,con)
    return 
  else:
    for chi in graph[cur]:
      if visited[chi] == 0:
        dfs(chi,cur)
      if any(visited[i] == 0 for i in graph[cur]):
        continue
      else:
        con += 1
        time[cur][1] = min(con,time[cur][1])
        #print("cur2,con2",cur,con)
        return dfs global con visited[cur] = 1 visited[cur] visited cur 1 con += 1 con 1 time[cur][0] = min(time[cur][0],con) time[cur][0] [cur] time cur 0 min(time[cur][0],con) min time[cur][0] [cur] time cur 0 con if (graph[cur] == [] or graph[cur] == [cur]):
    visited[cur] = 1
    time[cur][0] = min(con,time[cur][0])
    con += 1
    time[cur][1] = min(con,time[cur][1])
    #print("curif,conif",cur,con)
    return 
  else:
    for chi in graph[cur]:
      if visited[chi] == 0:
        dfs(chi,cur)
      if any(visited[i] == 0 for i in graph[cur]):
        continue
      else:
        con += 1
        time[cur][1] = min(con,time[cur][1])
        #print("cur2,con2",cur,con)
        return graph[cur] == [] or graph[cur] == [cur] graph[cur] == [] graph[cur] graph cur [] graph[cur] == [cur] graph[cur] graph cur [cur] cur visited[cur] = 1 visited[cur] visited cur 1 time[cur][0] = min(con,time[cur][0]) time[cur][0] [cur] time cur 0 min(con,time[cur][0]) min con time[cur][0] [cur] time cur 0 con += 1 con 1 time[cur][1] = min(con,time[cur][1]) time[cur][1] [cur] time cur 1 min(con,time[cur][1]) min con time[cur][1] [cur] time cur 1 return for chi in graph[cur]:
      if visited[chi] == 0:
        dfs(chi,cur)
      if any(visited[i] == 0 for i in graph[cur]):
        continue
      else:
        con += 1
        time[cur][1] = min(con,time[cur][1])
        #print("cur2,con2",cur,con)
        return chi graph[cur] graph cur if visited[chi] == 0:
        dfs(chi,cur)
       visited[chi] == 0 visited[chi] visited chi 0 dfs(chi,cur) dfs chi cur if any(visited[i] == 0 for i in graph[cur]):
        continue
      else:
        con += 1
        time[cur][1] = min(con,time[cur][1])
        #print("cur2,con2",cur,con)
        return any(visited[i] == 0 for i in graph[cur]) any visited[i] == 0 visited[i] visited i 0 continue con += 1 con 1 time[cur][1] = min(con,time[cur][1]) time[cur][1] [cur] time cur 1 min(con,time[cur][1]) min con time[cur][1] [cur] time cur 1 return cur cur par par dfs(0,-1) dfs 0 -1 if any([i == 0 for i in visited]):
  f = visited.index(0)
  dfs(f,f - 1) any([i == 0 for i in visited]) any [i == 0 for i in visited] f = visited.index(0) f visited.index(0) visited.index visited index 0 dfs(f,f - 1) dfs f f - 1 f 1 for i,t in enumerate(time):
  print(i + 1 ,*t) i t enumerate(time) enumerate time print(i + 1 ,*t) print i + 1 i 1 *t t visited = [0 for i in range(N)] [0 for i in range(N)] visited N = int(input()) int(input()) N inf = 10 ** 6 10 ** 6 inf graph = [[] for i in range(N)] [[] for i in range(N)] graph n = a[0],a[1] a[1] n f = visited.index(0) visited.index(0) f con = 0 0 con time = [[inf,inf] for i in range(N)] [[inf,inf] for i in range(N)] time a = list(map(int,input().split())) list(map(int,input().split())) a k,n = a[0],a[1] a[0] k def dfs(cur,par):
  #print("v",visited)
  global con
  visited[cur] = 1
  con += 1
  time[cur][0] = min(time[cur][0],con)
  #print("cur1,con1",cur,con)
  if (graph[cur] == [] or graph[cur] == [cur]):
    visited[cur] = 1
    time[cur][0] = min(con,time[cur][0])
    con += 1
    time[cur][1] = min(con,time[cur][1])
    #print("curif,conif",cur,con)
    return 
  else:
    for chi in graph[cur]:
      if visited[chi] == 0:
        dfs(chi,cur)
      if any(visited[i] == 0 for i in graph[cur]):
        continue
      else:
        con += 1
        time[cur][1] = min(con,time[cur][1])
        #print("cur2,con2",cur,con)
        return def dfs(cur,par):
  #print("v",visited)
  global con
  visited[cur] = 1
  con += 1
  time[cur][0] = min(time[cur][0],con)
  #print("cur1,con1",cur,con)
  if (graph[cur] == [] or graph[cur] == [cur]):
    visited[cur] = 1
    time[cur][0] = min(con,time[cur][0])
    con += 1
    time[cur][1] = min(con,time[cur][1])
    #print("curif,conif",cur,con)
    return 
  else:
    for chi in graph[cur]:
      if visited[chi] == 0:
        dfs(chi,cur)
      if any(visited[i] == 0 for i in graph[cur]):
        continue
      else:
        con += 1
        time[cur][1] = min(con,time[cur][1])
        #print("cur2,con2",cur,con)
        return dfs a = list(map(lambda x: x - 1,a)) list(map(lambda x: x - 1,a)) a
N = int(input())
inf = 10 ** 6
graph = [[] for i in range(N)]
visited = [0 for i in range(N)]
time = [[inf,inf] for i in range(N)]

for i in range(N):
  a = list(map(int,input().split()))
  a = list(map(lambda x: x - 1,a))
  k,n = a[0],a[1]
  if n >= 0:
    graph[k] = a[2:]

con = 0

def dfs(cur,par):
  #print("v",visited)
  global con
  visited[cur] = 1
  con += 1
  time[cur][0] = min(time[cur][0],con)
  #print("cur1,con1",cur,con)
  if (graph[cur] == [] or graph[cur] == [cur]):
    visited[cur] = 1
    time[cur][0] = min(con,time[cur][0])
    con += 1
    time[cur][1] = min(con,time[cur][1])
    #print("curif,conif",cur,con)
    return 
  else:
    for chi in graph[cur]:
      if visited[chi] == 0:
        dfs(chi,cur)
      if any(visited[i] == 0 for i in graph[cur]):
        continue
      else:
        con += 1
        time[cur][1] = min(con,time[cur][1])
        #print("cur2,con2",cur,con)
        return
dfs(0,-1)

if any([i == 0 for i in visited]):
  f = visited.index(0)
  dfs(f,f - 1)

for i,t in enumerate(time):
  print(i + 1 ,*t)
