#!/usr/bin/env python3

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float('inf')

n_nodes = int(input())
graph = [[] for _ in range(n_nodes)]

for _ in range(n_nodes):
    line = list(map(int, input().split()))
    u, k = line[0], line[1]
    if k > 0:
        for v in line[2:]:
            graph[u - 1].append(v - 1)
# pprint(graph)


def dfs(v):
    global time
    time += 1
    for v_adj in graph[v]:
        if d[v_adj] == -1:
            d[v_adj] = time
            dfs(v_adj)
    f[v] = time
    time += 1


d = [-1] * n_nodes
f = [-1] * n_nodes
time = 1

for v in range(n_nodes):
    if d[v] == -1:
        d[v] = time
        dfs(v)

# pprint(d)
# pprint(f)

for v in range(n_nodes):
    print(f"{v + 1} {d[v]} {f[v]}")
 from pprint import pprint from collections import deque, defaultdict import itertools itertools import math math import sys sys sys.setrecursionlimit(10 ** 6) sys.setrecursionlimit sys setrecursionlimit 10 ** 6 10 6 input = sys.stdin.buffer.readline input sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline INF = float('inf') INF float('inf') float 'inf' n_nodes = int(input()) n_nodes int(input()) int input() input [] for _ in range(n_nodes) for _ in range(n_nodes) _ range(n_nodes) range n_nodes for _ in range(n_nodes) [] graph = [[] for _ in range(n_nodes)] graph [[] for _ in range(n_nodes)] for _ in range(n_nodes):
    line = list(map(int, input().split()))
    u, k = line[0], line[1]
    if k > 0:
        for v in line[2:]:
            graph[u - 1].append(v - 1)
# pprint(graph) _ range(n_nodes) range n_nodes line = list(map(int, input().split())) line list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split u, k = line[0], line[1] u line[0] line 0 k line[1] line 1 if k > 0:
        for v in line[2:]:
            graph[u - 1].append(v - 1)
# pprint(graph) k > 0 k 0 for v in line[2:]:
            graph[u - 1].append(v - 1)
# pprint(graph) v line[2:] line 2: 2 graph[u - 1].append(v - 1) [u - 1].append [u - 1] graph u - 1 u 1 append v - 1 v 1 def dfs(v):
    global time
    time += 1
    for v_adj in graph[v]:
        if d[v_adj] == -1:
            d[v_adj] = time
            dfs(v_adj)
    f[v] = time
    time += 1 dfs global time time += 1 time 1 for v_adj in graph[v]:
        if d[v_adj] == -1:
            d[v_adj] = time
            dfs(v_adj)
     v_adj graph[v] graph v if d[v_adj] == -1:
            d[v_adj] = time
            dfs(v_adj)
     d[v_adj] == -1 d[v_adj] d v_adj -1 d[v_adj] = time d[v_adj] d v_adj time dfs(v_adj) dfs v_adj f[v] = time f[v] f v time time += 1 time 1 v v d = [-1] * n_nodes d [-1] * n_nodes [-1] -1 n_nodes f = [-1] * n_nodes f [-1] * n_nodes [-1] -1 n_nodes time = 1 time 1 for v in range(n_nodes):
    if d[v] == -1:
        d[v] = time
        dfs(v)

# pprint(d)
# pprint(f) v range(n_nodes) range n_nodes if d[v] == -1:
        d[v] = time
        dfs(v)

# pprint(d)
# pprint(f) d[v] == -1 d[v] d v -1 d[v] = time d[v] d v time dfs(v) dfs v for v in range(n_nodes):
    print(f"{v + 1} {d[v]} {f[v]}") v range(n_nodes) range n_nodes print(f"{v + 1} {d[v]} {f[v]}") print f"{v + 1} {d[v]} {f[v]}" time = 1 1 time graph = [[] for _ in range(n_nodes)] [[] for _ in range(n_nodes)] graph def dfs(v):
    global time
    time += 1
    for v_adj in graph[v]:
        if d[v_adj] == -1:
            d[v_adj] = time
            dfs(v_adj)
    f[v] = time
    time += 1 def dfs(v):
    global time
    time += 1
    for v_adj in graph[v]:
        if d[v_adj] == -1:
            d[v_adj] = time
            dfs(v_adj)
    f[v] = time
    time += 1 dfs line = list(map(int, input().split())) list(map(int, input().split())) line k = line[0], line[1] line[1] k d = [-1] * n_nodes [-1] * n_nodes d f = [-1] * n_nodes [-1] * n_nodes f u, k = line[0], line[1] line[0] u input = sys.stdin.buffer.readline sys.stdin.buffer.readline input INF = float('inf') float('inf') INF n_nodes = int(input()) int(input()) n_nodes
#!/usr/bin/env python3

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float('inf')

n_nodes = int(input())
graph = [[] for _ in range(n_nodes)]

for _ in range(n_nodes):
    line = list(map(int, input().split()))
    u, k = line[0], line[1]
    if k > 0:
        for v in line[2:]:
            graph[u - 1].append(v - 1)
# pprint(graph)


def dfs(v):
    global time
    time += 1
    for v_adj in graph[v]:
        if d[v_adj] == -1:
            d[v_adj] = time
            dfs(v_adj)
    f[v] = time
    time += 1


d = [-1] * n_nodes
f = [-1] * n_nodes
time = 1

for v in range(n_nodes):
    if d[v] == -1:
        d[v] = time
        dfs(v)

# pprint(d)
# pprint(f)

for v in range(n_nodes):
    print(f"{v + 1} {d[v]} {f[v]}")

