Problem:
C: 同値命題
問題
$N$ 個の命題があり, それぞれ $1, 2, \cdots,N$ という名前がついている.
また, 命題に関する情報が $M$ 個与えられる. $i$ 番目の情報は「$a_i$ $b_i$」という形式で与えられ, これは $a_i$ ならば $b_i$ であることを表す.（「ならば」は論理包含であり、推移律が成り立つ）
各命題 $i$ に対して $i$ と同値な命題を全て昇順に出力せよ.
ただし命題 $i$ と命題 $i$ は常に同値である.
命題 $X$ と命題 $Y$ が同値とは,「$X$ ならば $Y$」かつ「$Y$ ならば $X$」のことである.
制約
入力値は全て整数である.
$ 2 \leq N \leq 300$
$ 1 \leq M \leq N(N - 1)$
$ a_i \neq b_i $
$1 \leq a_i, b_i \leq N $
入力形式
入力は以下の形式で与えられる.
$N\ M$
$a_1\ b_1$
$a_2\ b_2$
$\vdots$
$a_M\ b_M$
出力
$i$ 行目には命題 $i$ と同値である命題を昇順に空白区切りですべて出力せよ. また, 各行の末尾に改行を出力せよ.
サンプル
サンプル入力 1
5 2
1 2
2 1
サンプル出力 1
1 2
1 2
3
4
5
サンプル入力 2
3 3
1 2
2 3
3 1
サンプル出力 2
1 2 3
1 2 3
1 2 3
サンプル入力 3
6 7
1 2
1 3
2 6
3 4
4 5
5 3
6 2
サンプル出力 3
1
2 6
3 4 5
3 4 5
3 4 5
2 6

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    int N, M; cin >> N >> M;
    vector<vector<int>> G(N); 
    for (int _ = 0 ; _ < M ; _++) {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
    }

    vector<vector<bool>> T(N, vector(N, false));
    for (int s = 0 ; s < N ; s++) {
        auto dfs = [&](auto dfs, int v) -> void {
            T[s][v] = true;
            for (auto x : G[v]) if (not T[s][x]) {
                dfs(dfs, x);
            }
        };
        dfs(dfs, s);
    }

    for (int i = 0 ; i < N ; i++) {
        vector<int> ans;
        for (int j = 0 ; j < N ; j++) {
            if (T[i][j] and T[j][i]) {
                ans.push_back(j + 1);
            }
        }
        sort(ans.begin(), ans.end());
        for (int j = 0 ; j < (int)ans.size() ; j++) {
            cout << ans[j] << (j + 1 == (int)ans.size() ? '\n' : ' ');
        }
    }
}
accuracy: 1
time_ms: 60
memory_kb: 4192
final_rank: 19

code_snippet: #include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i<(n); i++)

using namespace std;
using ll = long long;
using P = pair<int,int>;
const int mod = 998244353;
const int inf = (1<<30);
const int dy[4] = {-1,0,0,1};
const int dx[4] = {0,-1,1,0};

// internal csr
namespace atcoder {
    namespace internal {
        template <class E> struct csr {
            std::vector<int> start;
            std::vector<E> elist;

            explicit csr(int n, const std::vector<std::pair<int, E>>& edges) : start(n + 1), elist(edges.size()) {
                for(auto e : edges) {
                    start[e.first + 1]++;
                }
                for(int i=1;i<=n;i++) {
                    start[i] += start[i-1];
                }
                auto counter = start;
                for(auto e : edges) {
                    elist[counter[e.first]++] = e.second;
                }
            }
        };
    }
}

// internal scc
namespace atcoder {
    namespace internal {
        struct scc_graph {
            public:
                explicit scc_graph(int n) : _n(n) {}

                int num_vertices() {
                    return _n;
                }

                void add_edge(int from, int to) {
                    edges.push_back({from, {to}});
                }

                std::pair<int, std::vector<int>> scc_ids() {
                    auto g = csr<edge>(_n, edges);
                    int now_ord = 0, group_num = 0;
                    std::vector<int> visited, low(_n), ord(_n, -1), ids(_n);
                    visited.reserve(_n);

                    auto dfs = [&](auto self, int v) -> void {
                        low[v] = ord[v] = now_ord++;
                        visited.push_back(v);
                        for(int i=g.start[v]; i < g.start[v+1];i++) {
                            auto to = g.elist[i].to;
                            if(ord[to] == -1) {
                                self(self, to);
                                low[v] = std::min(low[v], low[to]);
                            } else {
                                low[v] = std::min(low[v], ord[to]);
                            }
                        }

                        if(low[v] == ord[v]) {
                            while(true) {
                                int u = visited.back();
                                visited.pop_back();
                                ord[u] = _n;
                                ids[u] = group_num;
                                if (u==v) break;
                            }
                            group_num++;
                        }
                    };

                    for(int i=0;i<_n;i++) {
                        if (ord[i] == -1) {
                            dfs(dfs, i);
                        }
                    }

                    for(auto &x:ids) {
                        x = group_num - 1- x;
                    }
                    return {group_num, ids};
                }

                std::vector<std::vector<int>> scc() {
                    auto ids = scc_ids();
                    int group_num = ids.first;
                    std::vector<int> counts(group_num);
                    for(auto x : ids.second) counts[x]++;
                    std::vector<std::vector<int>> groups(ids.first);
                    for(int i=0;i<group_num;i++) {
                        groups[i].reserve(counts[i]);
                    }
                    for(int i=0;i<_n;i++) {
                        groups[ids.second[i]].push_back(i);
                    }
                    return groups;
                }

            private:
                int _n;
                struct edge {
                    int to;
                };
                std::vector<std::pair<int, edge>> edges;
        };
    }
}

// scc
namespace atcoder {
    struct scc_graph {
        public:
            scc_graph() : internal(0) {}
            explicit scc_graph(int n) : internal(n) {}

            void add_edge(int from, int to) {
                int n = internal.num_vertices();
                assert(0 <= from && from < n);
                assert(0 <= to && to < n);
                internal.add_edge(from, to);
            }

            std::vector<std::vector<int>> scc() {
                return internal.scc();
            }
        private:
            internal::scc_graph internal;
    };
}

using namespace atcoder;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);

    int n,m;
    cin>>n>>m;

    scc_graph sg(n);

    for(int i=0;i<m;i++) {
        int a,b;
        cin>>a>>b;

        a--,b--;

        sg.add_edge(a, b);
    }

    auto scc = sg.scc();

    rep(i, n) {
        rep(j, scc.size()) {
            bool found = false;
            rep(k, scc[j].size()) {
                if (scc[j][k] == i) {
                    found = true;
                    break;
                }
            }

            if (found) {
                rep(k, scc[j].size()) {
                    if (k) {
                        cout << " ";
                    }
                    cout << scc[j][k] + 1; // to 1-indexed
                }
                cout << "\n";
                break;
            }
        }
    }
}
accuracy: 1
time_ms: 10
memory_kb: 4004
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
using usize = unsigned long long;
using i64 = long long;

template <class T>
void chmin(T& a, T& b) {
  if (a > b) a = b;
}


//rep.cpp
namespace luz {

  struct rep {
    struct itr {
      usize i;
      constexpr itr(const usize i) noexcept: i(i) {}
      void operator++() noexcept {
        ++i;
      }
      constexpr usize operator*() const noexcept {
        return i;
      }
      constexpr bool operator!=(
          const itr x) const noexcept {
        return i != x.i;
      }
    };
    const itr f, l;
    constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)),
      l(l) {}
    constexpr auto begin() const noexcept {
      return f;
    }
    constexpr auto end() const noexcept {
      return l;
    }
  };

}


// edge.cpp
namespace luz {

  template < typename T >
    class Edge {
      public:
        using cost_type = T;

        usize from, to;
        T cost;
        usize id;
        Edge() = default;
        Edge(usize from_, usize to_, T cost_, usize id_)
          :from(from_),
          to(to_),
          cost(cost_),
          id(id_) {}
    };

  template <typename T>
    using Edges = std::vector<Edge<T>>;

}


// graph.cpp
namespace luz {

  template < typename Edge >
    class DynamicGraph {
      using Edges = std::vector<Edge>;

      protected:
      std::vector<Edges>g;
      usize edge_count;

      public:
      using cost_type = typename Edge::cost_type;

      DynamicGraph() = default;
      explicit DynamicGraph(usize n)
        :g(n),
        edge_count(0) {}

      usize size() const {
        return g.size();
      }

      void add_directed_edge(usize from, usize to,
          cost_type cost = 1) {
        assert(from < size());
        assert(to < size());
        g[from].emplace_back(from, to, cost,
            edge_count++);
      }
      void add_undirected_edge(usize u, usize v,
          cost_type cost = 1) {
        assert(u < size());
        assert(v < size());
        assert(u != v);
        g[u].emplace_back(u, v, cost, edge_count);
        g[v].emplace_back(v, u, cost, edge_count++);
      }

      Edges operator[](const usize &v) {
        return g[v];
      }

      const Edges operator[](const usize &v) const {
        return g[v];
      }
    };

}


// scc.cpp
namespace luz::decomposition {

  template < class G >
    class StronglyConnectedComponents {
      using graph = G;
      using cost_type = typename graph::cost_type;

      graph g;
      usize g_size;
      std::vector<usize> low, ord, visited, group_id;
      usize ord_cnt, group_cnt;

      void dfs(usize v) {
        low[v] = ord[v] = ord_cnt++;
        visited.emplace_back(v);
        for (auto &e: g[v]) {
          if (ord[e.to] == g_size) {
            dfs(e.to);
            chmin(low[v], low[e.to]);
          } else {
            chmin(low[v], ord[e.to]);
          }
        }
        if (low[v] == ord[v]) {
          while (true) {
            usize u = visited.back();
            visited.pop_back();
            ord[u] = g_size + 1;
            group_id[u] = group_cnt;
            if (u == v) break;
          }
          group_cnt++;
        }
      }

      public:
      explicit StronglyConnectedComponents(
          const graph& g_)
        :g(g_),
        g_size(g.size()),
        low(g_size),
        ord(g_size, g_size),
        group_id(g_size),
        ord_cnt(0),
        group_cnt(0) {
          visited.reserve(g_size);
          for (usize v: rep(0, g_size)) {
            if (ord[v] == g_size) {
              dfs(v);
            }
          }
          for (auto& id: group_id) {
            id = group_cnt - id - 1;
          }
        }

      std::vector<std::vector<usize>> groups()
        const {
          std::vector<usize> counts(group_cnt);
          for (usize i: rep(0, g_size)) {
            counts[group_id[i]]++;
          }
          std::vector<std::vector<usize>> groups (group_cnt);
          for (usize i: rep(0, group_cnt)) {
            groups[i].reserve(counts[i]);
          }
          for(usize i: rep(0, g_size)) {
            groups[group_id[i]].emplace_back(i);
          }
          return groups;
        }

      std::vector<usize> group_ids() const {
        return group_id;
      }
    };

}

int main() {
  int n, m;
  cin >> n >> m;
  using G = luz::DynamicGraph<luz::Edge<int>>;
  G g(n + 1);

  for (int i = 0; i < m; i++) {
    i64 a, b;
    cin >> a >> b;
    g.add_directed_edge(a, b);
  }

  luz::decomposition::StronglyConnectedComponents<G> scc(g);
  auto groups = scc.groups();
  auto ids = scc.group_ids();

  for (int i = 1; i <= n; i++) {
    sort(groups[ids[i]].begin(), groups[ids[i]].end());
    for (int k = 0; k < groups[ids[i]].size(); k++) {
      if (k > 0) cout << ' ';
      cout << groups[ids[i]][k];
    }
    cout << endl;
  }
}
accuracy: 1
time_ms: 20
memory_kb: 13364
final_rank: 20

code_snippet: #ifdef LOCAL
    #define _GLIBCXX_DEBUG
    #define __clock__
#else
    #pragma GCC optimize("Ofast")
#endif
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;
using PII = pair<ll, ll>;

// #define INT128 // 必要なら有効化してください
#ifdef INT128
  using LL = __int128;
#endif

// tourist set
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(char c){
  string s = {c};
  return s;
}

// LL
#ifdef INT128
// input
istream& operator>>(istream& is, LL& v)
{
    string s;
    is >> s;
    v = 0;
    for (int i = 0; i < (int)s.size(); i++) {
        if (isdigit(s[i])) { v = v * 10 + s[i] - '0'; }
    }
    if (s[0] == '-') { v *= -1; }
    return is;
}
std::ostream &operator<<(std::ostream &dest, LL value) {
  std::ostream::sentry s(dest);
  if (s) {
    LL tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}
string to_string(LL v){
  stringstream ss;
  ss << v;
  return ss.str();
}
#endif // LL

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << '\n'; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<'\n'
#define p2(s, t) cout << (s) << " " << (t) << '\n'
#define SZ(x) ((int)(x).size())
#define SORT(A) sort(ALL(A))
#define RSORT(A) sort(ALL(A), greater<ll>())
#define MP make_pair
#define p_yes() p("Yes")
#define p_no() p("No")
#define p_possible() p("Possible")
#define p_impossible() p("Impossible")
void yes(){p_yes(); exit(0);}
void no(){p_no(); exit(0);}
void possible(){p_possible(); exit(0);}
void impossible(){p_impossible(); exit(0);}

ll SUM(VI& V){
  return accumulate(ALL(V), 0LL);
}

ll MIN(VI& V){return *min_element(ALL(V));}
ll MAX(VI& V){return *max_element(ALL(V));}

void print_vector(VI& V, ll offset=0){
  ll n = V.size();
  rep(i, n){
    if(i) cout << ' ';
    cout << V[i]+offset;
  }
  cout << endl;
}

ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

// long double
using ld = long double;
// #define EPS (1e-14)
constexpr ld EPS = 1e-14;
// #define equals(a,b) (fabs((a)-(b)) < EPS)
constexpr bool equals(ld a, ld b){return fabs((a)-(b)) < EPS;}

// 小さい順に取り出すpriority queue
using inverse_priority_queue = priority_queue<ll, vector<ll>, greater<ll> >;

int popcount(ll t){
    return __builtin_popcountll(t);
}

const ll mod = 1e9 + 7;
// const ll mod = 998244353;
const ll inf = 4e18; // LLONG_MAX = 9223372036854775807 (atcoder, codeforces)
const double PI = acos(-1);

// [a/b] (繰り上げ)
ll ceil_div(ll a, ll b){
  return (a+b-1)/b;
}

ll ll_pow(ll a, ll n){
    ll ans = 1;
    FOR(i, 0, n){
        ans *= a;
    }
    return ans;
}
// modなし

// snuke's mint
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
// const int mod = 1000000007;
struct mint {
  ll x; // using ll = long long;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// ※双方向
// N : 頂点数
// M : 辺数
// return vector<vector<ll>>
VV load_graph(ll N, ll M){
  VV G(N);
  rep(i,M){
    ll a,b;cin>>a>>b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  return G;
}
VV load_tree(ll N){
  return load_graph(N, N-1);
}

VI loadV(ll N){
  VI A(N);
  rep(i,N)cin>>A[i];
  return A;
}

//#include <atcoder/dsu>
//using namespace atcoder; // 忘れがち

// 必要メモリ O(N^2)
// 計算量 O(N^3)
struct WarshallFloyd{
  VV d;
  ll N;
  bool pre_calculated = false;
  WarshallFloyd(ll n){
    if(n>=2000){
      cerr << "[warning]maybe data size is too big";
    }
    N = n;
    d.resize(N, VI(N, inf));
    rep(i, N) d[i][i] = 0;
  }
  // 単方向
  void register_edge(ll a, ll b, ll c){
    d[a][b] = c;
  }
  // 双方向
  void register_edge2(ll a, ll b, ll c){
    register_edge(a,b,c);
    register_edge(b,a,c);
  }
  void calc(){
    rep(i, N){ // 経由点
      rep(j, N){ // 始点
         rep(k, N){ // 終点
          d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
        }
      }
    }
    pre_calculated = true;
  }
  ll distance(ll a, ll b){
    // 計算忘れ対応
    if(!pre_calculated){
      debug("auto calc");
      calc();
    }
    return d[a][b];
  }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    ll N,M;
    cin>>N>>M;

    WarshallFloyd wa(N);

    rep(i,M){
      ll a,b;cin>>a>>b;
      a--;b--;
      wa.register_edge(a,b,1);
    }
    wa.calc();

    rep(i,N){
      VI Ans;
      rep(j,N){
        if(wa.distance(i,j)!=inf && wa.distance(j,i)!=inf)Ans.push_back(j);
      }
      print_vector(Ans,1);
    }

    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3836
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i,x,n) for (int i = x; i < n; i++)
#define all(a) a.begin(), a.end()
#define reall(a) a.rbegin(), a.rend()
#define DOUBLE fixed << setprecision(15)
#define pb emplace_back
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> P;
typedef vector<P> vP;

void debugs() { cout << endl; }
template<class T, class ...Args>
void debugs(const T& x, const Args &... args){
    cout << x << " ";
    debugs(args...);
}
template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>& p){
    ost << "{ " << p.first << ", " << p.second << " }";
    return ost;
}
template<class T>
ostream& operator<<(ostream& ost, const vector<T>& p){
    ost << "{ ";
    for(int i=0;i<p.size();i++){
        if(i)
            ost << ", ";
        ost << p[i];
    }
    ost << " }";
    return ost;
}
template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>& p){
    ost << "{ ";
    for(auto &&ma: p){
        ost << ma.first << ", " << ma.second << " }";
    }
    ost << " }";
    return ost;
}
vvll g;


int main() {
    ll n, m;
    while (cin >> n >> m){
        g.clear();
        g.resize(n, vll(n, 1e9));
        rep(i, n) g[i][i] = 0;
        rep(i, m) {
            ll a,b;
            cin >> a >> b;
            a--, b--;
            g[a][b] = 1;
        }
        rep(k, n) rep(i, n) rep(j, n) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
        rep(i, n) {
            bool f = false;
            rep(j, n) {
                if(g[j][i]!=1e9&&g[i][j]!=1e9){
                    if(f)
                        cout << ' ';
                    else f = true;
                    cout << j+1;
                }
            }
            cout << endl;
        }
    }
}
accuracy: 1
time_ms: 40
memory_kb: 4096
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;

int main() {

  int n, m;
  cin>>n>>m;

  vector<bool> L(n, false);
  vector<vector<bool>> G(n, L);
  for (int i = 0; i < n; i++) {
    G[i][i] = true;
  }

  for (int i = 0; i < m; i++) {
    int a, b;
    cin>>a>>b;
    a--;
    b--;
    G[a][b] = true;
  }

  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        G[i][j] = G[i][j] || (G[i][k] && G[k][j]);
      }
    }
  }

  bool first;
  for (int i = 0; i < n; i++) {
    first = true;
    for (int j = 0; j < n; j++) {
      if ((G[i][j] && G[j][i]) == true && first) {
        cout<<j+1;
        first = false;
      }
      else if ((G[i][j] && G[j][i]) == true) cout<<" "<<j+1;
    }
    cout<<endl;
  }

  return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3188
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void prarr(vector<vector<T>>& a){
rep(i, a.size()){
rep(j, a[i].size()){
cout << a[i][j]; printf(" ");}
printf("\n");} printf("\n");}

int n, m;
set<int> s[305];
arr<bool> G;

void makeG(int a, int b){
    if(G[a][b]) return;

    G[a][b] = true;
    rep(i, n){
        if(!G[i][a]) continue;
        rep(j, n){
            if(!G[b][j]) continue;
            G[i][j] = true;
        }
    }
}

int main()
{
    cin >> n >> m;
    G.resize(n, vector<bool>(n, false));
    // memset(G, 0, sizeof(G));
    rep(i, n) {
        G[i][i] = true;
        // s[i].insert(i);
    }
    rep(i, m){
        int a, b; cin >> a >> b;
        makeG(--a,--b);
    }

    // prarr(G);
    vector<int> ans[n];
    rep(i, n){
        rep(j, n){
            if(G[i][j] && G[j][i]) ans[i].push_back(j+1); 
        }
    }

    rep(i, n){
        prvec(ans[i]);
    }
    return 0;}
accuracy: 1
time_ms: 40
memory_kb: 3680
final_rank: 14

code_snippet: /*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
using P = pair<int64, int64>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
#define bn '\n'
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;

struct StronglyConnectedComponents{
    vector<int> topological_idx; //属する強連結成分のトポロジカル順序
    vector<bool> visited;
    vector<vector<int>> edge, edge_rev;
    vector<int> post_order;
    int N;
    int scc_size = 0; //強連結成分の数


    //O(N+M)
    StronglyConnectedComponents(vector<vector<int>>& edge):edge(edge){
        N = edge.size();
        edge_rev.resize(N);
        for(int v=0;v<N;v++){
            for(auto to:edge[v]){
                edge_rev[to].emplace_back(v);
            }
        }
        visited.assign(N,false);
        topological_idx.resize(N);
        for(int i=0;i<N;i++){
            if(not visited[i]) dfs(i);
        }
        visited.assign(N,false);
        reverse(post_order.begin(), post_order.end());
        for(auto v:post_order){
            if(not visited[v]) dfs_rev(v,scc_size++);
        }
    }

    void dfs(int v){
        visited[v] = true;
        for(auto to:edge[v]){
            if(not visited[to]) dfs(to);
        }
        post_order.emplace_back(v);
    }

    void dfs_rev(int v, int idx){
        visited[v] = true;
        topological_idx[v] = idx;
        for(auto to:edge_rev[v]){
            if(not visited[to]) dfs_rev(to, idx);
        }
    }

    //vが属している強連結成分のトポロジカル順序
    int get_topological_idx(int v){
        return topological_idx[v];
    }

    //強連結成分の数
    int get_scc_size(){
        return scc_size;
    }

    vector<vector<int>> build_graph(){
        vector<vector<int>> new_edge(N);
        for(int i=0;i<N;i++){
            int topo = topological_idx[i];
            for(auto to:edge[i]){
                new_edge[topo].emplace_back(topological_idx[to]);
            }
        }
        for(int i=0;i<scc_size;i++){
            sort(new_edge[i].begin(), new_edge[i].end());
            new_edge[i].erase(unique(new_edge[i].begin(), new_edge[i].end()), new_edge[i].end());
        }
        return new_edge;
    }

};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N , M;
    cin >> N >> M;

    vector<vector<int>> edge(N);
    REP(i,M){
        int a,b;
        cin >> a >> b;
        edge[--a].emplace_back(--b);
    }

    StronglyConnectedComponents SCC(edge);
    vector<vector<int>> components(SCC.get_scc_size());
    REP(i,N){
        components[SCC.get_topological_idx(i)].emplace_back(i);;
    }
    vector<vector<int>> ans(N);
    REP(i,N){
        for(auto a:components[SCC.get_topological_idx(i)]){
            ans[i].emplace_back(a+1);
        }
        cout << ans[i];
    }
}
accuracy: 1
time_ms: 10
memory_kb: 5260
final_rank: 4

code_snippet: #include<iostream>
#include<vector>
using namespace std;
vector<vector<int> > g,rg;
vector<int> vs,used,cmp;

void dfs(int v){
    used[v] = 1;
    for(int i = 0; i < g[v].size(); i++){
        if(!used[g[v][i]])dfs(g[v][i]);
    }
    vs.push_back(v);
}

void rdfs(int v, int k){
    used[v] = 1;
    cmp[v] = k;
    for(int i = 0; i < rg[v].size(); i++){
        if(!used[rg[v][i]])rdfs(rg[v][i],k);
    }
}

int main(){
    int n,m;
    cin >> n >> m;
    g = rg = vector<vector<int> >(n);
    used = cmp = vector<int>(n,0);
    for(int i = 0; i < m; i++){
        int a,b;
        cin >> a >> b;
        a--,b--;
        g[a].push_back(b);
        rg[b].push_back(a);
    }
    for(int v = 0; v < n; v++){
        if(!used[v])dfs(v);
    }
    used = vector<int>(n,0);
    int k = 0;
    for(int i = vs.size()-1; i >= 0; i--){
        if(!used[vs[i]])rdfs(vs[i],k++);
    }
    for(int i = 0; i < n; i++){
        int num = cmp[i];
        vector<int> ans;
        for(int j = 0; j < n; j++){
            if(cmp[j] == num)ans.push_back(j);
        }
        for(int j = 0; j < ans.size(); j++){
            if(j)cout << " ";
            cout << ans[j]+1;
        }
        cout << endl;
    }
}
accuracy: 1
time_ms: 30
memory_kb: 4160
final_rank: 10

code_snippet: #include <bits/stdc++.h>
#define PREP(i, s, x) for(ll (i) = (s); (i) < (x); (i) ++)
#define REP(i, x) PREP(i, 0, x)
#define MREP(i, s, x) for(ll (i) = (s); (i) >= (x); (i) --)
#define MOD7 (1000000007LL)
#define MOD9 998244353LL
#define INF (1LL<<60)
typedef long long ll;
using namespace std;
using P = pair<ll, ll>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using graph = vector<vector<ll>>;

graph g, rev_g;
vector<bool> seen;
vector<ll> numbering;
vector<ll> scc; // 頂点番号がgroupのグループに属するか返す
vector<vector<ll>> group; // グループごとに属する頂点番号を格納

void dfs(ll v){
    seen[v] = true;
    for(auto next_v : g[v]){
        if(seen[next_v]) continue;
        dfs(next_v);
    }
    numbering.push_back(v);
    return;
}

void rev_dfs(ll v, ll num){
    seen[v] = true;
    group[num].push_back(v);
    scc[v] = num;
    for(auto next_v : rev_g[v]){
        if(seen[next_v]) continue;
        rev_dfs(next_v, num);
    }
}

int main(){
    ll n, m;
    cin >> n >> m;
    g.resize(n);
    rev_g.resize(n);
    REP(i, m){
        ll a, b;
        cin >> a >> b;
        a --, b --;
        g[a].push_back(b);
        rev_g[b].push_back(a);
    }

    seen.resize(n);
    REP(i, n){
        // 未探索
        seen[i] = false;
    }

    REP(v, n){
        if(seen[v] == false) dfs(v);
    }

    reverse(numbering.begin(), numbering.end());

    REP(i, n){
        seen[i] = false;
    }

    scc.resize(n);

    ll num = 0;
    for(auto v : numbering){
        if(seen[v] == false){
            group.push_back(vector<ll>());
            rev_dfs(v, num);
            num ++;
        }
    }

    REP(i, num){
        sort(group[i].begin(), group[i].end());
    }

    REP(v, n){
        ll i = scc[v];
        for(auto ite = group[i].begin(); ite < group[i].end(); ite ++){
            cout << (*ite) + 1;
            if(ite != group[i].end() - 1) cout << " ";
        }
        cout << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 5672
final_rank: 8

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;

struct SCC{
	vector<vector<int> > gg,rg;
	vector<int> comp,order;
	vector<bool> used;
	vector<vector<int> > ng,vs;
	int n,nn;
	SCC(){}
	SCC(int v):gg(v),rg(v),comp(v,-1),used(v,0),n(v){}
	void add_edge(int x,int y){
		gg[x].push_back(y);
		rg[y].push_back(x);
	}
	int operator[](int k){
		return comp[k];
	}
	void dfs(int v){
		used[v]=1;
		for(int i:gg[v]){
			if(!used[i])dfs(i);
		}
		order.push_back(v);
	}
	void rdfs(int v,int k){
		used[v]=1;
		comp[v]=k;
		for(int i:rg[v]){
			if(!used[i])rdfs(i,k);
		}
	}
	int build(){
		for(int i=0;i<n;i++){
			if(!used[i])dfs(i);
		}
		for(int i=0;i<n;i++){
			used[i]=0;
		}
		int k=0;
		for(int i=order.size()-1;i>=0;i--){
			if(!used[order[i]])rdfs(order[i],k++);
		}
		nn=k;
		// それぞれの強連結成分に含まれる頂点の番号
		vs.resize(k,vector<int>());
		for(int i=0;i<n;i++){
			vs[comp[i]].push_back(i);
		}
		// 強連結成分をまとめた後のグラフ
		ng.resize(k,vector<int>());
		for(int i=0;i<n;i++){
			for(int j:gg[i]){
				if(comp[i]!=comp[j]){
					ng[comp[i]].push_back(comp[j]);
				}
			}
		}
		for(int i=0;i<nn;i++){
			sort(ng[i].begin(),ng[i].end());
			ng[i].erase(unique(ng[i].begin(),ng[i].end()),ng[i].end());
		}
		return k;
	}
	int size(){
		return nn;
	}
	vector<vector<int> > graph(){
		return ng;
	}
	vector<int> vertices(int v){
		return vs[v];
	}
};

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m; cin >> n >> m;
	SCC scc(n);
	for(int i=0;i<m;i++){
		int x,y; cin >> x >> y;
		x--; y--;
		scc.add_edge(x,y);
	}
	scc.build();
	for(int i=0;i<n;i++){
		vector<int> v;
		for(int j=0;j<n;j++){
			if(scc[i]==scc[j])v.push_back(j);
		}
		cout << v[0]+1;
		for(int k=1;k<v.size();k++){
			cout << " " << v[k]+1;
		}
		cout << endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 4212
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct SCC{
  vector<vector<int> > G,R,T,C;
  vector<int> vs,used,blg;
  SCC(){}
  SCC(int n):G(n),R(n),used(n),blg(n){}

  void add_edge(int u,int v){
    G[u].emplace_back(v);
    R[v].emplace_back(u);
  }

  void dfs(int v){
    used[v]=1;
    for(int u:G[v])
      if(!used[u]) dfs(u);
    vs.emplace_back(v);
  }

  void rdfs(int v,int k){
    used[v]=1;
    blg[v]=k;
    C[k].emplace_back(v);
    for(int u:R[v])
      if(!used[u]) rdfs(u,k);
  }

  int build(){
    int n=G.size();
    for(int v=0;v<n;v++)
      if(!used[v]) dfs(v);

    fill(used.begin(),used.end(),0);
    int k=0;
    for(int i=n-1;i>=0;i--){
      if(!used[vs[i]]){
        T.emplace_back();
        C.emplace_back();
        rdfs(vs[i],k++);
      }
    }
    for(int v=0;v<n;v++)
      for(int u:G[v])
        if(blg[v]!=blg[u])
          T[blg[v]].push_back(blg[u]);

    for(int i=0;i<k;i++){
      sort(T[i].begin(),T[i].end());
      T[i].erase(unique(T[i].begin(),T[i].end()),T[i].end());
    }
    return k;
  }
  int operator[](int k) const{return blg[k];};
};

struct TwoSat{
  int n;
  SCC scc;
  TwoSat(int n):n(n),scc(n*2){}
  int negate(int v){return (n+v)%(n*2);}
  void add_if(int u,int v){
    // u -> v <=> !v -> !u
    scc.add_edge(u,v);
    scc.add_edge(negate(v),negate(u));
  }
  void add_or(int u,int v){
    // u or v <=> !u -> v
    add_if(negate(u),v);
  }
  void add_nand(int u,int v){
    // u nand v <=> u -> !v
    add_if(u,negate(v));
  }
  void set_true(int v){
    //  v <=> !v ->  v
    scc.add_edge(negate(v),v);
  }
  void set_false(int v){
    // !v <=>  v -> !v
    scc.add_edge(v,negate(v));
  }
  vector<int> build(){
    scc.build();
    vector<int> res(n);
    for(int i=0;i<n;i++){
      if(scc[i]==scc[n+i]) return {};
      res[i]=scc[i]>scc[n+i];
    }
    return res;
  }
};

//INSERT ABOVE HERE
signed main(){
  int n,m;
  cin>>n>>m;

  TwoSat G(n);
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G.add_if(a,b);
  }
  G.build();

  for(int i=0;i<n;i++){
    int flg=0;
    for(int j=0;j<n;j++){
      if(G.scc.blg[i]!=G.scc.blg[j]) continue;
      if(flg) cout<<" ";
      flg=1;
      cout<<j+1;
    }
    cout<<endl;
  }

  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 5588
final_rank: 12

code_snippet: /*  -*- coding: utf-8 -*-
 *
 * 3102.cc: iff
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 300;

/* typedef */

/* global variables */

bool ms[MAX_N][MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < n; i++) ms[i][i] = true;

  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    ms[a][b] = true;
  }

  for (int k = 0; k < n; k++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
	ms[i][j] = ms[i][j] || (ms[i][k] && ms[k][j]);

  for (int i = 0; i < n; i++) {
    for (int j = 0, cont = 0; j < n; j++)
      if (ms[i][j] && ms[j][i]) {
	if (cont) putchar(' ');
	printf("%d", j + 1);
	cont = 1;
      }
    putchar('\n');
  }  

  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3320
final_rank: 6

code_snippet: //
// Created by yamunaku on 2019/10/06.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

mti e,ne;
vi vis,c;

void dfs(int x, int &t){
    vis[x]=true;
    for(auto nx:e[x]){
        if(vis[nx]==false){
            dfs(nx, t);
        }
    }
    c[t++]=x;
}

int dfs2(int x, vi &v){
    vis[x]=true;
    v.push_back(x);
    for(auto nx:ne[x]){
        if(vis[nx]==false){
            dfs2(nx, v);
        }
    }
}

int main(){
    int n,m;
    cin >> n >> m;
    e=mti(n);
    ne=mti(n);
    vis=vi(n,false);
    c=vi(n);
    int u,v;
    rep(i,m){
        cin >> u >> v;
        u--,v--;
        e[u].push_back(v);
        ne[v].push_back(u);
    }
    int t=0;
    rep(i,n){
        if(!vis[i]){
            dfs(i, t);
        }
    }
    vis=vi(n,false);
    mti st;
    per(i,n){
        if(!vis[c[i]]){
            st.push_back(vi());
            dfs2(c[i], st[st.size()-1]);
        }
    }
    mti ans(n);
    rep(i,st.size()){
        rep(j,st[i].size()){
            rep(k,st[i].size()){
                ans[st[i][j]].push_back(st[i][k]);
            }
        }
    }
    rep(i,n){
        sort(all(ans[i]));
        cout << ans[i][0]+1;
        repl(j,1,ans[i].size()){
            cout << " " << ans[i][j]+1;
        }
        cout << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 4748
final_rank: 11

code_snippet: #include<stdio.h>
int main() {
	int n, m, i, j, k, data[301][301] = {}, a, b,flag;
	scanf("%d%d", &n, &m);
	for (i = 1; i <= m; ++i) {
		scanf("%d%d", &a, &b);
		data[a][b] = 1;
	}
	for (i = 1; i <= n; ++i) {
		for (j = 1; j <= n; ++j) {
			for (k = 1; k <= n; ++k) {
				if (data[j][i] && data[i][k]) data[j][k] = 1;
			}
		}
	}
	for (i = 1; i <= n; ++i) {
		flag = 0;
		for (j = 1; j <= n; ++j) {
			if (i == j) {
				if (flag) printf(" ");
				printf("%d",i); flag = 1;
			}
			if (i != j && data[i][j] && data[j][i]) {
				if (flag) printf(" ");
				printf("%d", j); flag = 1;
			}
		}
		printf("\n");
	}
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3096
final_rank: 3

code_snippet: #include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int n, m; cin >> n >> m;
	vector<vector<int> > G(n, vector<int>(n, 1));
	for (int i = 0; i < n; ++i) G[i][i] = 0;
	while (m--) {
		int a, b; cin >> a >> b;
		G[a - 1][b - 1] = 0;
	}
	for (int k = 0; k < n; ++k)
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)
				G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
	for (int i = 0; i < n; ++i) {
		bool flag = false;
		for (int j = 0; j < n; ++j) {
			if (G[i][j] + G[j][i] == 0) {
				if (flag) cout << " ";
				cout << j + 1, flag = true;
			}
		}
		cout << endl;
	}

	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3264
final_rank: 17

code_snippet: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

class WF{
	public:
	ll N;
	ll makeFlg;
	vector<vector<ll> >cost;
	WF(ll _N, ll INF = 1145141919){
		N = _N + 1;
		cost = vector<vector<ll> >(N, vector<ll>(N, INF));
		makeFlg = 0;
	}
	void add(ll a, ll b, ll c){
		cost[a][b] = min(cost[a][b], c);
		makeFlg = 0;
	}
	void make(){
		if(makeFlg)return;
		makeFlg = 1;
		for(ll i = 0; i < N; i++){
			for(ll j = 0; j < N; j++){
				for(ll k = 0; k < N; k++){
					cost[j][k] = min(cost[j][k], cost[j][i] + cost[i][k]);
				}
			}
		}
	}
	ll get(ll a, ll b){
		if(makeFlg == 0)make();
		return cost[a][b];
	}
};

int main(){

    ll N, M;
    cin >> N >> M;
    WF wf(N);
    rep(i, M){
        ll a, b;
        cin >> a >> b;
        wf.add(a, b, 0);
    }
    rep1(i, N){
        vector<ll>ans;
        rep1(j, N){
            if(i == j)ans.push_back(j);
            else if(wf.get(i, j) == 0 && wf.get(j, i) == 0)ans.push_back(j);
        }
        rep(j, ans.size()){
            cout << ans[j];
            if(j + 1 == ans.size())cout << endl;
            else cout << " ";
        }
    }

    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3652
final_rank: 13

code_snippet: // #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1001001001;
const ll LONGINF = 1001001001001001LL;
const ll MOD = 1000000007LL;

// 移動元と行先と辺のコストを記録する構造体
template <typename T = int>
struct Edge {
    int from, to;
    T cost;
    Edge(int s, T d = 1) : to(s), cost(d) {}
    Edge(int f, int s, T d) : from(f), to(s), cost(d) {}

    bool operator<(const Edge &e) const {
        return cost < e.cost;
    }
    bool operator>(const Edge &e) const {
        return cost > e.cost;
    }
};

template <typename T = int>
using Graph = vector< vector< Edge<T> > >;

// 強連結成分分解
// Verified: AOJ GRL_3_C (Strongly Connected Components)
// Verified: ARC030 C (有向グラフ) ← 強連結を潰したグラフの構築の検証

// これは 2 回の DFS によって実現できる。
// はじめに普通の DFS をするが、その時に帰りがけ順に頂点番号の配列を作る。
// 次に、元のグラフの逆辺のみで構成されたグラフに対して、
// 帰りがけ順が遅かったものから順に DFS を行う。
// 帰りかけが遅かった頂点ほど、 DAG の先頭の強連結成分に属しているため、
// 辺を逆向きにすると、先頭の強連結成分から外に出られなくなることを利用している。

template <typename T = int>
struct GraphSCC {
public:
    const int n;
    vector<bool> isthrough;
    vector<int> vs, cmp;
    vector< vector<int> > G, rG, H; // グラフ、逆辺グラフ、縮約後のグラフ

    GraphSCC(vector< vector< Edge<T> > > &g) :
        n(g.size()), isthrough(n, false), cmp(n, 0), G(n), rG(n) {
        for(int i=0; i<n; i++) {
            for(size_t j=0; j<g[i].size(); j++) {
                G[i].push_back(g[i][j].to);
                rG[ g[i][j].to ].push_back(i);
            }
        }
    }

    void SCC_dfsone(int cur) {
        isthrough[cur] = true;
        for(size_t i=0; i<G[cur].size(); i++) {
            if(!isthrough[G[cur][i]]) {
                SCC_dfsone(G[cur][i]);
            }
        }
        vs.push_back(cur);
    }

    void SCC_dfstwo(vector<int> &vec, int cur, int k) {
        cmp[cur] = k;
        isthrough[cur] = true;
        vec.push_back(cur);
        for(size_t i=0; i<rG[cur].size(); i++) {
            if(!isthrough[rG[cur][i]]) {
                SCC_dfstwo(vec, rG[cur][i], k);
            }
        }
    }

    // 縮約後のグループ、グループ数
    pair<vector<int>, int> scc() {
        // 1回めのDFS
        for(int i=0; i<n; i++)
            if(!isthrough[i]) SCC_dfsone(i);

        fill(isthrough.begin(), isthrough.end(), false);
        reverse(vs.begin(), vs.end());
        int k = 0; vector< vector<int> > S;

        // 2回めのDFS
        for(size_t i=0; i<vs.size(); i++) {
            if(!isthrough[vs[i]]) {
                S.push_back(vector<int>());
                SCC_dfstwo(S.back(), vs[i], k++);
            }
        }

        H.resize(k);
        fill(isthrough.begin(), isthrough.end(), false);
        for(size_t i=0; i<k; i++) {
            for(size_t j=0; j<S[i].size(); j++) {
                int v = S[i][j];
                for(size_t x=0; x<G[v].size(); x++) {
                    int u = G[v][x];
                    if(isthrough[cmp[u]] || cmp[v] == cmp[u]) continue;
                    isthrough[cmp[u]] = true;
                    H[cmp[v]].push_back(cmp[u]);
                }
            }
            for(size_t j=0; j<H[i].size(); j++) isthrough[ H[i][j] ] = false;
        }
        return make_pair(cmp, k);
    }
};


int main() {
    int N, M; cin >> N >> M;

    Graph<int> G(N);
    for(int i=0; i<M; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].emplace_back(b);
    }

    GraphSCC<> gs(G);
    auto res = gs.scc();

    int K = res.second;
    vector< vector<int> > ans(K);
    for(int i=0; i<N; i++) {
        int group = res.first[i];
        ans[group].emplace_back(i+1);
    }

    for(int i=0; i<N; i++) {
        int group = res.first[i];
        for(size_t j=0; j<ans[group].size(); j++) {
            cout << ans[group][j] << " \n"[j + 1 == ans[group].size()];
        }
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 5932
final_rank: 15

code_snippet: #include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
class SCC {
public:
	int V, cnt;
	vector<vector<int> > G, rG, graph;
	vector<int> vs, cmp;
	vector<bool> used;
	SCC(int node_size) : V(node_size), G(V), rG(V), cmp(V), used(V, false) {}
	void add_edge(int from, int to) {
		G[from].push_back(to);
		rG[to].push_back(from);
	}
	void dfs(int u) {
		used[u] = true;
		for (int v : G[u]) {
			if (!used[v]) {
				dfs(v);
			}
		}
		vs.push_back(u);
	}
	void dfs(int u, const int k) {
		used[u] = true;
		cmp[u] = k;
		for (int v : rG[u]) {
			if (!used[v]) {
				dfs(v, k);
			}
		}
	}
	int solve() { //強連結成分の数を返す
		for (int i = 0; i < V; i++) {
			if (!used[i]) {
				dfs(i);
			}
		}
		fill(used.begin(), used.end(), false);
		cnt = 0;
		for (int i = V - 1; i >= 0; i--) {
			if (!used[vs[i]]) {
				dfs(vs[i], cnt++);
			}
		}
		return cnt;
	}
	void make_graph() {
		graph.resize(cnt);
		for (int i = 0; i < V; i++) {
			for (int v : G[i]) {
				if (cmp[i] != cmp[v]) {
					graph[cmp[i]].push_back(cmp[v]);
				}
			}
		}
	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	SCC scc(N);
	int a, b;
	for (int i = 0; i < M; i++) {
		cin >> a >> b; a--; b--;
		scc.add_edge(a, b);
	}
	scc.solve();
	for (int i = 0; i < N; i++) {
		bool f = true;
		for (int j = 0; j < N; j++) {
			if (scc.cmp[i] == scc.cmp[j]) {
				if (f)f = false;
				else cout << " ";
				cout << j + 1;
			}
		}
		cout << endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 5428
final_rank: 7

code_snippet: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 305

int N,M;
bool can_go[SIZE][SIZE];

int main(){

	scanf("%d %d",&N,&M);

	for(int i = 0; i < N; i++){
		for(int k = 0; k < N; k++){

			can_go[i][k] = (i == k);
		}
	}

	int from,to;

	for(int loop = 0; loop < M; loop++){

		scanf("%d %d",&from,&to);
		from--;
		to--;

		can_go[from][to] = true;
	}

	for(int mid = 0; mid < N; mid++){
		for(int start = 0; start < N; start++){
			if(!can_go[start][mid])continue;
			for(int goal = 0; goal < N; goal++){
				if(!can_go[mid][goal])continue;

				can_go[start][goal] = true;
			}
		}
	}

	for(int i = 0; i < N; i++){
		bool is_First = true;
		for(int k = 0; k < N; k++){
			if(can_go[i][k] && can_go[k][i]){
				if(is_First){

					printf("%d",k+1);
					is_First = false;
				}else{

					printf(" %d",k+1);
				}
			}
		}
		printf("\n");
	}

	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3312
final_rank: 5