Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring>
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
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;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));

template<typename T>
struct SCC{
    T &G;
    vector<vector<int>> Ngraph,Rgraph;
    vector<int> comp,order;
    vector<bool> used;
    SCC(T &g):G(g),Ngraph((int)g.size()),Rgraph((int)g.size()),comp((int)g.size(),-1),used((int)g.size()){
        for(int i=0;i<(int)g.size();i++){
            for(int to:g[i]){
                Ngraph[i].push_back(to);
                Rgraph[to].push_back(i);
            }
        }
    }
    int operator[](int idx){
        assert(0<=idx&&idx<comp.size());
        return comp[idx];
    }
    void dfs(int idx){
        if(used[idx]) return;
        used[idx]=true;
        for(auto &to:Ngraph[idx]) dfs(to);
        order.push_back(idx);
    }
    void rdfs(int idx,int cnt){
        if(comp[idx]!=-1) return;
        comp[idx]=cnt;
        for(auto &to:Rgraph[idx]) rdfs(to,cnt);
    }
    void build(vector<vector<int>> &ret){
        for(int i=0;i<(int)Ngraph.size();i++) dfs(i);
        reverse(order.begin(),order.end());
        int group=0;
        for(auto i:order){
            if(comp[i]==-1){
                rdfs(i,group);
                group++;
            }
        }
        ret.resize(group);
        for(int i=0;i<(int)G.size();i++){
            for(auto &to:G[i]){
                int s=comp[i],t=comp[to];
                if(s!=t) ret[s].push_back(t);
            }
        }
    }
};

signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int V,E; cin >> V >> E;
    vector<vector<int>> vec(V),ans;
    rep(i,E){
        int a,b; cin >> a >> b;
        vec[a].pb(b);
    }
    SCC<vector<vector<int>>> scc(vec);
    scc.build(ans);
    vector<vector<int>> res(V);
    vector<int> num(V,0);
    int K=0;
    rep(i,V){
        if(num[scc[i]]==0) K++;
        num[scc[i]]++;
        res[scc[i]].pb(i);

    }
    cout << K << endl;
    rep(i,V){
        if(num[i]==0) break;
        cout << num[i] << " ";
        for(auto u:res[i]) cout << u << " ";
        cout << "\n";
    }
}


Compiler output:
a.cc: In member function 'int SCC<T>::operator[](int)':
a.cc:49:9: error: there are no arguments to 'assert' that depend on a template parameter, so a declaration of 'assert' must be available [-fpermissive]
   49 |         assert(0<=idx&&idx<comp.size());
      |         ^~~~~~
a.cc:49:9: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
a.cc: In instantiation of 'int SCC<T>::operator[](int) [with T = std::vector<std::vector<int> >]':
a.cc:98:21:   required from here
   98 |         if(num[scc[i]]==0) K++;
      |                     ^
a.cc:49:15: error: 'assert' was not declared in this scope
   49 |         assert(0<=idx&&idx<comp.size());
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:15:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
   14 | #include <cctype>
  +++ |+#include <cassert>
   15 | #include <locale>