/**
 * @brief ??±???????????¢?´¢????????????
 * @note  ??¢??£URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B
 * @date  2016/02/15~2017/01/03
 */


//****************************************
// ???????????????????????????????????????????????????
//****************************************

#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <vector>
#include <stack>
#include <iostream>



/**
 * @brief ??°????????¢?????´??????????????¢????????????
 *
 * @note  ??°??????G = (V, E)???????¨????????????¨????????????2?????????.??£??\?????????????????????????????¨?????¨??£??\?????????????????¨?????§??????
 *        ?????????????????£??????????????°????????¨????????°????????????????????¨?????§??????.??°????????????(sparse)??§|E|???|V|^2?????????
 *        ?????£??¨?°?????????¨??????????????£??\??????????????¨????????°?????????????????????????????¨?????§??????.???????????¨???????????????????????????????????????
 *        ??°????????????(dense)??§|E|???|V|^2????????????????????¨?????????2?????????????????????????????????????????????????????????
 *        ??????????????????????????????????????¨??????????????£??\????????¨???????\????????????´????????????
 *
 *        ??°??????G = (V, E)?????£??\???????????¨???(adjacency-list representation)??????V????????????????????????1??????
 *        ??¨??¨??§|V|????????????????????????Adj???????§?????????????.???u ??? V?????????????????£??\?????????Adj[u]??????(u, v) ??? E????????¨??????
 *        ?????????????????????????§?????????????.(??£??????????????£??\??????????????????????????????????????????????????????????????¨?????????.)
 *
 *        G???????????°???????????¨???????????????(u, v)???v?????£??\?????????Adj[u]???????´???¨????????????????????¨??§?????¨?????????????????§???
 *        ??£??\?????????????????????????¨????|E|??§??????. G???????????°???????????¨??????(u, v)????????????????????°???u???v?????£??\????????????????´???§????????¨
 *        ?????????v???u?????£??\????????????????´???????????????£??\?????????????????????????¨????2|E|??§??????.????????°????????¨????????°????????????????????????????????????
 *        ??£??\???????????¨????????(V + E)????¨???¶?????????????????¨???????????????????????§???????????£?????????
 *
 *        ??????????????°??????(weighted graph)??§??????????????¢??°(weight function) w:E->R(R????????°???)????????£????????????????????????
 *        ???????????????????????????. ??????????????°???????????¨?????§?????????????????£??\?????????????????´?????????????°??????§??????
 *        ?????¨?????°???G = (V, E)???????????¢??°w???????????????????????°????????¨????????¨??????(u, v) ??? E?????????w(u, v)???u?????£??\????????????
 *        ??????v??¨??¨??????????´???????????????§??????. ???????????°??????????????¢???????????§????????????????????£??§????????¨???????????§???
 *        ??£??\???????????¨???????????????????????§???????????§??????
 *
 *        ??£??\?????????????????¨?????????????¬????????????????????????????(u, v)?????°??????????±????????????????????±?????????????????????£??\?????????Adj[i]????????????
 *        v?????¢?´¢??????????????????????????????????????¨??§??????.???????¬?????????£??\????????¨????????¨????????¨????????§????????????
 *        ????????????????????????????????????????¨???¶?????????????????????
 *
 *        ??°??????G = (V, E)?????£??\????????¨???(adjacency-matrix representation)??§????????????????????§?????????1, 2,...,|V|(one-based)???
 *        ????????????????????¨????????????. ??°??????G?????£??\????????¨??????|V|x|V|?????????A = (aij)??§?????????
 *        aij = { 1 (i, j) ??? E?????¨??? | 0 ????????\????????¨??? }????????????
 *        ??°???????????£??\???????????°??????????????°?????¢???????????(V^2)????¨???¶??????????????§??????
 *
 *        ??£??\????????????????§?????????¢??????????§°??§??????. ????????°????????§???(u, v)??¨(v, u)?????????????????¨???????????????????????°???????????£??\?????????
 *        ????????¢???????????¨?????????. ????????????A = At??§??????. ????????????????????¨??§????????£??\????????????????§???????????????????????????????????´??????????
 *        ???????????°?????????????´???????????????????????¨???¶???????????????????????????????????¨?????§??????
 *
 *        ??°???????????£??\???????????¨?????¨????§??????£??\????????¨?????§?????????????????°???????????¨?????§??????. ?????¨?????°??? G = (V, E)??????????????¢??°w???
 *        ????????????????????°????????¨????????¨?????????(u, v) ??? E?????????w(u, v)?????£??\?????????u???v???????´???¨????????°??????
 *        ???????????¨???????????¨?????????NIL?????????????????????????´?????????¨?????????????????????0??????????????????????????£???????????????????????´????????????
 *
 *        ??£??\???????????¨???????¨???¶??????????????????????????£??\????????¨??????????????????????????¨?????????????????°??????????°?????????¨?????????
 *        ??£??\?????????????´?????????¨????????????. ??°???????????????????????§???????????´?????????1??????????´??????????1???????????§??¨?????§???????????§???
 *        ??£??\????????¨??????????????????????????????
 *
 * @date  ????????\     : 2016/02/08
 * @date  ????????´??°??\ : 2016/02/20
 */



//****************************************
// ???????????????????????????????????????????????????
//****************************************

#include <utility>
#include <algorithm>
#include <vector>
#include <cassert>



//****************************************
// ???????????§????????¢?????????????????????
//****************************************

#define GRAPH_BEGIN namespace graph {
#define GRAPH_END   }



//****************************************
// ?§????????????????
//****************************************

GRAPH_BEGIN

using weight_t   = std::int32_t;  /**< ???(u, v)????????????w?????¨?????? */
using index_t    = std::int32_t;  /**< ??????v??????????????¨??????       */
using capacity_t = weight_t;      /**< ???(u, v)??????????????¨??????    */



namespace limits {
    enum {  // namespace graph????????£???scoped??§????????????????????????????????????enum(strongly-typed enum)??§?????????
    inf = std::numeric_limits<weight_t>::max() / 3,  /**< @brief ???????????¨???????????´???????????¨????????????     */
    nil = std::numeric_limits<index_t>::min() / 3,   /**< @brief ?????????????????¨???????????´???????????¨???????????? */
};
}



/**
 * @brief  ????????????????§???????(scoped enum)
 * @detail (u, v) ??? E??§??????u??????????????°??????v?????°????????§??????
 *         ?????????????????????????????£??\????????¨?????????????????????????????§??????
 *         ??°???????????????????????£??\???????????¨???????????????????????????????????¢??????????????¨???????????????????¢?????????????
 */
enum struct vcolor : std::int32_t {
    white,  /**< ??????????????? */
    black,  /**< ??¢???????????? */
    gray,   /**< ??¢???????????? */
};

/**
 * @brief ??°????????¨?????????(??????) 
 */
struct vertex {
    union {
        weight_t d;       /**< ?§????s??????????????¢  */
        weight_t key;     /**< Prim?????¢?????´???????????????????????¨????±?????????????????????¨????????¶?????? */
    };
    index_t pi;           /**< ????????????(?????????) */
    union {
        vcolor color;     /**< ????????????        */
        bool  visited;    /**< ????????????????     */
    };
    // weight_t f;           /**< ??????????????°(DFS?????????????????????????????????????????¨??????????????????)     */
    vertex() : d(0), pi(0), color(vcolor::white)/*, f(0)*/ {}
};

/**
 * @brief ??°????????¨??¨??????(???)
 * @note  G = (V, E)???????????¢??°w???????????????????????°????????¨????????¨???
 *        ???(u, v) ??? E????????????w(u, v)??¨??¨?????????
 */
struct edge {
    index_t  src;   /**< ???????§????u */
    index_t  dst;   /**< ????????????v */
    union {
        weight_t w;     /**< ???(u, v)????????????(?????????) */
        capacity_t c;   /**< ???(u, v)????????? */
    };
    edge() = default;
    edge(index_t src, index_t dst) : src(src), dst(dst), w(1) {}
    edge(index_t src, index_t dst, weight_t w) : src(src), dst(dst), w(w) {}

    bool operator < (const edge& e) const { return w < e.w; }
    bool operator > (const edge& e) const { return w > e.w; }
};



using edges_t    = std::vector<edge>;      /**< ??°??????G=(V, E)????????????E   */
using vertices_t = std::vector<vertex>;    /**< ??°??????G=(V, E)???????????????V */
using array_t    = std::vector<weight_t>;  /**< ??????w?????????  */
using indices_t  = std::vector<index_t>;   /**< ????????????????????? */
using matrix_t   = std::vector<array_t>;   /**< ??°??????G?????£??\????????¨???(???????????¨????????¨???) */
using graph_t    = std::vector<edges_t>;   /**< ??°??????G?????£??\???????????¨???(???????????????????????¨??????) */



//****************************************
// ??¢??°?????????
//****************************************

/**
 * @brief  ??±???????????¢?´¢???????????????
 * 
 * @note   ??±???????????¢?´¢??????????????????????????????????????????????????°??????????????°?????????"????????±?????¨??????"??¢?´¢????????¨???????????\?????????
 *         ?????¢?´¢???????????????????????????????????§??????????????????????????????v????????????????????±???????????¢?´¢?????¢?´¢??????. v????????????????????¢?´¢??????????????¨???
 *         v?????????????????¨???????????£?????????????????????????????????(?????????)?????????v?????´?????????????????????(?????¢?´¢???)????????¢?´¢?????????
 *         ?????????????????????????????°??????????????????????????????????????????????????§?¶????. ?????????????????????????????????????????°?????????1????????°???????§??????¨??????
 *         ??¢?´¢?????°?????????. ??¢?????´??????????????????????????????????????????????????§???????????????????????°?????????
 *
 *         ???????????¢?´¢??¨????§?????????????????????????u?????£??\??????????????°???????????????v?????????????????¨?????±???????????¢?´¢???v?????????????±???§v.?????u????¨??????????
 *         ??????????±?????¨??????????. ???????????¨?????°???????????¨??§?????????????????¢?´¢??¨???????????±???????????¢?´¢??§????????°????§????????????¢?´¢?????°??????????????¨??????????????????
 *         ???????????¨?????°??????????????°?????¨???????§??????????????????¨?????????. ????????§?????±???????????¢?´¢??????????????¨?????°??????(predecessor subgraph)???
 *         ???????????¢?´¢??¨?°?????????£??????G?? = (V, E??)??¨????????????. ????????§
 *           E?? = { (v.??, v) : v ??? V ?????? v.?? != NIL }
 *         ??§??????. ??±???????????¢?´¢??????????????¨?????°??????????????°?????±???????????¨(depth-first tree)???????§???????????????±??????????£?(depth-first forest)
 *         ?????¢?????????. E??????±???????????????¨???(tree edge)??¨?????¶
 *
 *         ???????????¢?´¢??¨????§??????±???????????¢?´¢??????????????¢?´¢??¶?????§???????????§????????????. ????????¶?????§????????????????????§???????????¢?´¢????????§?????????????????°(discovered)
 *         ??°?????????????????¢?´¢?????????????????°(finished)????????????????????????????????£??\?????????????????¨??????????????????. ??±???????????¢?´¢??§??????
 *         ????????????1????????±???????????¨?????????????????????????????¨???????¨???????????????§?????????????????¨??????????????±?????¨??????????????????
 *
 *         ??±???????????¢?´¢?????±??????????£?????§????????????¨??¨??????????????????????????°(timestamp)?????????. ?????????v???2?¨???????????????°?????????
 *         ?¬¬1???????????°v.d???v??????????????????????????°?????????????????????????¨??????????. ?¬¬2???????????°v.f???v?????£??\???????????????????????????????????????????????????????¨??????????
 *         ????????????????????°?????°???????§?????????¢????????????????????±?????????????????±???????????¢?´¢??????????????????????§£?????????????????????
 *
 *         ??\????????????????¶????DFS??§????????????u?????????????????????????±???§u.d????¨??????????u??????????????????????????????????±???§u.f????¨??????????
 *         |V|?????????????????????????????????????±???¨??????????±????????????????1?????????????????????????????????????????°???1??????2|V|??????????????´??°??§??????
 *         ???????????????u????????????
 *           u.d < u.f
 *         ???????????????. ??????u?????????u.d??\??????WHITE, ??????u.d??¨??????u.f?????????GRAY, ??????u.f??\??????BLACK??§??????
 *
 * @note   DFS????????????????????(V + E)??§??????
 *
 * @note   ??±???????????¢?´¢???????????±?????§??????1????????\??????????????°??????G = (V, E)????????????????????¢?´¢????????£?????§???????????¨?????????
 *         ????????????????????°???????????¢????????????????????±???????????§??????. ?????¨?????°???????????°????????????????????§????????????????????????????????¶??????
 *         ??±???????????¢?´¢????????£??????????????????????????????????????¨??§??????
 *
 *         G????????±???????????¢?´¢?????????????????±??????????£?G???????¨??????4?¨?????????????????????§??????
 *
 *         1. ??±??????????£?G??????§??????????????????¨???(tree edge)??¨??????. ???(u, v)?????¢?´¢???????????¨??§v????§???????????????????????????°??????(u, v)?????¨?????§??????
 *
 *         2. ????????±???????????¨???????????????u??¨???????\????v????????¶???(u, v)????????????(back edge)??¨??????
 *            ????????°??????????????±???????????????????????¨???????????????????????????????????¨?????????
 *
 *         3. ????????±???????????¨???????????????u??¨????????????v????????¶???(u, v)??§??¨?????§???????????????????????????(forward edge)??¨??????
 *
 *         4. ????¨???\?????????????????????????¨???????(cross edge)??¨??????. ???????????????????\??????§???????????????????????±???????????¨?????????????????¶????????§?????£???????????????
 *            ?????????2????????±???????????¨????????¶????????§?????£????????????
 *
 *
 * @note   DFS??¢?????´??????????????????????????£?????¨??????????????????????????±????????????????????????????????§???????????¨?????????
 *         ???(u, v)??????????????¢?´¢??????????????????v???????????????????????????????????????????????????????????¨????????????????????¨????????¢????????¢??§??????
 *
 *         1. WHITE?????¨?????§???????????¨?????????
 *         2. GRAY??????????????§???????????¨?????????
 *         3. BLACK?????????????????????????¨?????????§???????????¨?????????
 *
 *
 * @param  ??°??????G(????????§???????????§?????????)
 * @return ??±??????????£?
 */
std::pair<vertices_t, array_t> dfs(const graph_t& G)
{
    index_t n = G.size();
    vertices_t vs(n);
    array_t  f(n);
    weight_t time;

    // ?????°???????????????u????¨??????????
    std::function <void(index_t)> recursive_visit = [&] (index_t u) {  // ????????????????????????...
        time = time + 1;             // time???1?????????
        vs[u].d = time;              // time?????????????????????u.d??¨???????¨??????????
        vs[u].color = vcolor::gray;  // u?????°???????????????
        // ?????????v ??? Adj[u]????????????????????§?????±???????????¢?´¢??????(u, v)?????¢?´¢??????(explore)??¨??????
        for (auto&& e : G[u]) {                  // u??¨??£??\???????????????v????????????
            index_t v = e.dst;
            if (vs[v].color == vcolor::white) {  // v?????????????????°??????v????¨??????????
                vs[v].pi = u;
                recursive_visit(v);
            }
        }
        // u????????????????????????????????¢?´¢?????????????????¨???
        vs[u].color = vcolor::black;  // u?????????????????????
        time = time + 1;              // time????????????
        f[u] = time;                  // ???????????????u.f????¨??????????
    };


    // ?????????????????¨???????????????u????¨??????????
    auto iterative_visit = [&](index_t u) -> void {
        std::stack<index_t> S; S.push(u);
        time = time + 1;             // time???1?????????
        vs[u].d = time;              // time?????????????????????u.d??¨???????¨??????????
        vs[u].color = vcolor::gray;  // u?????°???????????????
        // ?????????v ??? Adj[u]????????????????????§?????±???????????¢?´¢??????(u, v)?????¢?´¢??????(explore)??¨??????
        while (!S.empty()) {
            u = S.top();             // ????????????????????????????´??????????
            std::size_t i = 0, m = G[u].size();  // ??£??\??????????????°???
            while (i < m && vs[G[u][i].dst].color != vcolor::white) { i++; }
            if (i != m) {  // u?????£??\?????????????????§??????????????????????????????????????¨????????´??????
                index_t v = G[u][i].dst;
                S.push(v);                    // v?????????????????????????????\??????
                time = time + 1;              // time???1????????? 
                vs[v].d = time;               // time?????????????????????u.d??¨???????¨??????????
                vs[v].color = vcolor::gray ;  // v?????°???????????????
            }
            else { // u?????£??\??????????????¨????????????????????´??????
                S.pop();                      // ???????????????????????????????´???????????????????
                time = time + 1;              // time????????????
                f[u] = time;                  // ???????????????u.f????¨??????????
                vs[u].color = vcolor::black;  // u?????????????????????
            }
        }
    };
    

    for (auto&& u : vs) {
        u.color = vcolor::white;                // ????????????????????????????????????
        u.pi    = limits::nil;                  // ???±???§???NIL??????????????????
    }
    time = 0;                                   // ?????????????????????????????????
    for (auto u = 0; u < n; ++u) {              // V?????????????????????????????????
        if (vs[u].color == vcolor::white) {     // ??????????????????????????¨???
            iterative_visit(u);                 // visit???????????????????¨??????????
            // visit?????????????????????????????????u?????±??????????£??????°????????¨???????????????
        }
    }
    // DFS??????????????????????????????u??????????????????(discovery time)u.d??¨????????????(finishing time)u.f??????????????????????????????

    return std::make_pair(vs, f);
}



//****************************************
// ?????????????????????
//****************************************

GRAPH_END



//****************************************
// ??¨?????????????????????
//****************************************

int main()
{
    graph::graph_t G;
    int u, k, v, n;
    std::cin >> n;
    G.resize(n);
    for (int i = 0; i < n; i++) {
        std::cin >> u >> k;
        u--;
        G[i].resize(k);
        for (int j = 0; j < k; j++) {
            std::cin >> v;
            v--;
            G[i][j].src = i;
            G[i][j].dst = v;
        }
    }

    auto dfsforest = dfs(G);
    for (int i = 0; i < n; i++) {
        std::cout << i + 1 << " "
                  << dfsforest.first[i].d << " " << dfsforest.second[i] << std::endl;
    }

    return 0;
}

Measured memory_bytes: 3136