struct SCCInternalGraph {
    start: Vec<usize>,
    elist: Vec<usize>,
}

impl SCCInternalGraph {
    fn build(size: usize, edge: &[(usize, usize)]) -> Self {
        let mut start = vec![0; size + 1];
        edge.iter().for_each(|&(s, _)| start[s + 1] += 1);
        for i in 1..=size {
            start[i] += start[i - 1];
        }
        let mut index = start.clone();
        let mut elist = vec![0; edge.len()];
        for &(s, t) in edge.iter() {
            let po = &mut index[s];
            elist[*po] = t;
            *po += 1;
        }
        SCCInternalGraph { start, elist }
    }
    fn neighbor(&self, v: usize) -> &[usize] {
        assert!(v + 1 < self.start.len());
        &self.elist[self.start[v]..self.start[v + 1]]
    }
}

struct SCC {
    size: usize,
    edge: Vec<(usize, usize)>,
}

impl SCC {
    fn new(size: usize) -> Self {
        SCC { size, edge: vec![] }
    }
    fn add_edge(&mut self, a: usize, b: usize) {
        assert!(a < self.size);
        assert!(b < self.size);
        self.edge.push((a, b));
    }
    fn build(&self) -> Vec<usize> {
        let graph = SCCInternalGraph::build(self.size, &self.edge);
        let size = self.size;
        let mut ord = vec![size; size];
        let mut assigned = vec![false; size];
        let mut stack_s = vec![];
        let mut stack_p = vec![];
        let mut call = vec![];
        let mut now_ord = 0;
        let mut res = vec![0; size];
        let mut id = 0;
        enum Operation {
            Call(usize),
            Iter(usize, usize),
            Eval(usize),
        }
        for i in 0..size {
            if ord[i] != size {
                continue;
            }
            call.push(Operation::Call(i));
            while let Some(op) = call.pop() {
                match op {
                    Operation::Call(v) => {
                        ord[v] = now_ord;
                        now_ord += 1;
                        stack_s.push(v);
                        stack_p.push(v);
                        call.push(Operation::Eval(v));
                        call.push(Operation::Iter(v, 0));
                    },
                    Operation::Iter(v, k) => {
                        let g = graph.neighbor(v);
                        for i in k..g.len() {
                            let u = g[i];
                            if ord[u] == size {
                                call.push(Operation::Iter(v, i + 1));
                                call.push(Operation::Call(u));
                                break;
                            } else if !assigned[u] {
                                while ord[*stack_p.last().unwrap()] > ord[u] {
                                    stack_p.pop();
                                }
                            }
                        }
                    },
                    Operation::Eval(v) => {
                        if *stack_p.last().unwrap() == v {
                            while let Some(u) = stack_s.pop() {
                                res[u] = id;
                                assigned[u] = true;
                                if u == v {
                                    break;
                                }
                            }
                            stack_p.pop();
                            id += 1;
                        }
                    },
                }
            }
        }
        res.iter_mut().for_each(|v| *v = id - 1 - *v);
        res
    }
}

use proconio::*;
 
#[fastout]
fn run() {
    input! {
        n: usize,
        m: usize,
        e: [(usize, usize); m],
    }
    let mut scc = SCC::new(n);
    for (a, b) in e {
        scc.add_edge(a, b);
    }
    let id = scc.build();
    let k = *id.iter().max().unwrap() + 1;
    let mut a = vec![vec![]; k];
    for (i, id) in id.iter().enumerate() {
        a[*id].push(i);
    }
    println!("{}", k);
    for a in a.iter() {
        print!("{}", a.len());
        for a in a {
            print!(" {}", *a);
        }
        println!();
    }
}
 
fn main() {
    run();
}


Measured memory_bytes: 50576