n = int(input())
ukv = [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(n)]

stack = []
visited = []
time = 0
d = [0] * (n + 1)
f = [0] * (n + 1)
for i in range(1, n + 1):
    if i not in visited:
        stack.append(i)
        visited.append(i)
        time += 1
        d[i] = time

        while stack:
            s = stack[-1]
            k = ukv[s][1]
            if k == 0:
                stack.pop()
                time += 1
                f[s] = time
            else:
                ukv[s][1] -= 1
                v = ukv[s].pop(2)
                if v not in visited:
                    stack.append(v)
                    visited.append(v)
                    time += 1
                    d[v] = time

for i in range(1, n + 1):
    print(i, d[i], f[i]) n = int(input()) n int(input()) int input() input list(map(int, input().split())) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ukv = [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(n)] ukv [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(n)] [[0, 0, 0]] [0, 0, 0] 0 0 0 [list(map(int, input().split())) for _ in range(n)] stack = [] stack [] visited = [] visited [] time = 0 time 0 d = [0] * (n + 1) d [0] * (n + 1) [0] 0 n + 1 n 1 f = [0] * (n + 1) f [0] * (n + 1) [0] 0 n + 1 n 1 for i in range(1, n + 1):
    if i not in visited:
        stack.append(i)
        visited.append(i)
        time += 1
        d[i] = time

        while stack:
            s = stack[-1]
            k = ukv[s][1]
            if k == 0:
                stack.pop()
                time += 1
                f[s] = time
            else:
                ukv[s][1] -= 1
                v = ukv[s].pop(2)
                if v not in visited:
                    stack.append(v)
                    visited.append(v)
                    time += 1
                    d[v] = time i range(1, n + 1) range 1 n + 1 n 1 if i not in visited:
        stack.append(i)
        visited.append(i)
        time += 1
        d[i] = time

        while stack:
            s = stack[-1]
            k = ukv[s][1]
            if k == 0:
                stack.pop()
                time += 1
                f[s] = time
            else:
                ukv[s][1] -= 1
                v = ukv[s].pop(2)
                if v not in visited:
                    stack.append(v)
                    visited.append(v)
                    time += 1
                    d[v] = time i not in visited i visited stack.append(i) stack.append stack append i visited.append(i) visited.append visited append i time += 1 time 1 d[i] = time d[i] d i time while stack:
            s = stack[-1]
            k = ukv[s][1]
            if k == 0:
                stack.pop()
                time += 1
                f[s] = time
            else:
                ukv[s][1] -= 1
                v = ukv[s].pop(2)
                if v not in visited:
                    stack.append(v)
                    visited.append(v)
                    time += 1
                    d[v] = time stack s = stack[-1] s stack[-1] stack -1 k = ukv[s][1] k ukv[s][1] [s] ukv s 1 if k == 0:
                stack.pop()
                time += 1
                f[s] = time
            else:
                ukv[s][1] -= 1
                v = ukv[s].pop(2)
                if v not in visited:
                    stack.append(v)
                    visited.append(v)
                    time += 1
                    d[v] = time k == 0 k 0 stack.pop() stack.pop stack pop time += 1 time 1 f[s] = time f[s] f s time ukv[s][1] -= 1 ukv[s][1] [s] ukv s 1 1 v = ukv[s].pop(2) v ukv[s].pop(2) [s].pop [s] ukv s pop 2 if v not in visited:
                    stack.append(v)
                    visited.append(v)
                    time += 1
                    d[v] = time v not in visited v visited stack.append(v) stack.append stack append v visited.append(v) visited.append visited append v time += 1 time 1 d[v] = time d[v] d v time for i in range(1, n + 1):
    print(i, d[i], f[i]) i range(1, n + 1) range 1 n + 1 n 1 print(i, d[i], f[i]) print i d[i] d i f[i] f i time = 0 0 time d = [0] * (n + 1) [0] * (n + 1) d ukv = [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(n)] [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(n)] ukv time += 1 1 time f = [0] * (n + 1) [0] * (n + 1) f time += 1 1 time v = ukv[s].pop(2) ukv[s].pop(2) v s = stack[-1] stack[-1] s time += 1 1 time stack = [] [] stack k = ukv[s][1] ukv[s][1] k n = int(input()) int(input()) n visited = [] [] visited
n = int(input())
ukv = [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(n)]

stack = []
visited = []
time = 0
d = [0] * (n + 1)
f = [0] * (n + 1)
for i in range(1, n + 1):
    if i not in visited:
        stack.append(i)
        visited.append(i)
        time += 1
        d[i] = time

        while stack:
            s = stack[-1]
            k = ukv[s][1]
            if k == 0:
                stack.pop()
                time += 1
                f[s] = time
            else:
                ukv[s][1] -= 1
                v = ukv[s].pop(2)
                if v not in visited:
                    stack.append(v)
                    visited.append(v)
                    time += 1
                    d[v] = time

for i in range(1, n + 1):
    print(i, d[i], f[i])
