N = int(input())
adj_list = []
for _ in range(N):
    line = list(input().split(" "))
    adj_list.append([int(k) - 1 for k in line[2:]])

d = [-1 for _ in range(N)]
f = [-1 for _ in range(N)]
time = 1

visited = set()

def dfs(p):
    global time
    if p in visited:
        return

    d[p] = time
    time += 1
    visited.add(p)
    for ad in adj_list[p]:
        if ad not in visited:
            dfs(ad)
    f[p] = time
    time += 1

for i in range(N):
    dfs(i)

for i in range(N):
    print(f"{i + 1} {d[i]} {f[i]}") N = int(input()) N int(input()) int input() input adj_list = [] adj_list [] for _ in range(N):
    line = list(input().split(" "))
    adj_list.append([int(k) - 1 for k in line[2:]]) _ range(N) range N line = list(input().split(" ")) line list(input().split(" ")) list input().split(" ") ().split () input split " " int(k) - 1 for k in line[2:] for k in line[2:] k line[2:] line 2: 2 for k in line[2:] int(k) - 1 int(k) int k 1 adj_list.append([int(k) - 1 for k in line[2:]]) adj_list.append adj_list append [int(k) - 1 for k in line[2:]] -1 for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) -1 d = [-1 for _ in range(N)] d [-1 for _ in range(N)] -1 for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) -1 f = [-1 for _ in range(N)] f [-1 for _ in range(N)] time = 1 time 1 visited = set() visited set() set def dfs(p):
    global time
    if p in visited:
        return

    d[p] = time
    time += 1
    visited.add(p)
    for ad in adj_list[p]:
        if ad not in visited:
            dfs(ad)
    f[p] = time
    time += 1 dfs global time if p in visited:
        return

     p in visited p visited return d[p] = time d[p] d p time time += 1 time 1 visited.add(p) visited.add visited add p for ad in adj_list[p]:
        if ad not in visited:
            dfs(ad)
     ad adj_list[p] adj_list p if ad not in visited:
            dfs(ad)
     ad not in visited ad visited dfs(ad) dfs ad f[p] = time f[p] f p time time += 1 time 1 p p for i in range(N):
    dfs(i) i range(N) range N dfs(i) dfs i for i in range(N):
    print(f"{i + 1} {d[i]} {f[i]}") i range(N) range N print(f"{i + 1} {d[i]} {f[i]}") print f"{i + 1} {d[i]} {f[i]}" d = [-1 for _ in range(N)] [-1 for _ in range(N)] d N = int(input()) int(input()) N def dfs(p):
    global time
    if p in visited:
        return

    d[p] = time
    time += 1
    visited.add(p)
    for ad in adj_list[p]:
        if ad not in visited:
            dfs(ad)
    f[p] = time
    time += 1 def dfs(p):
    global time
    if p in visited:
        return

    d[p] = time
    time += 1
    visited.add(p)
    for ad in adj_list[p]:
        if ad not in visited:
            dfs(ad)
    f[p] = time
    time += 1 dfs f = [-1 for _ in range(N)] [-1 for _ in range(N)] f time = 1 1 time line = list(input().split(" ")) list(input().split(" ")) line adj_list = [] [] adj_list visited = set() set() visited
N = int(input())
adj_list = []
for _ in range(N):
    line = list(input().split(" "))
    adj_list.append([int(k) - 1 for k in line[2:]])

d = [-1 for _ in range(N)]
f = [-1 for _ in range(N)]
time = 1

visited = set()

def dfs(p):
    global time
    if p in visited:
        return

    d[p] = time
    time += 1
    visited.add(p)
    for ad in adj_list[p]:
        if ad not in visited:
            dfs(ad)
    f[p] = time
    time += 1

for i in range(N):
    dfs(i)

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