| 156 | } |
| 157 | |
| 158 | public static void main(String[] args) throws Exception { |
| 159 | FastReader in = new FastReader(System.in); |
| 160 | PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); |
| 161 | n = in.nextInt(); |
| 162 | m = in.nextInt(); |
| 163 | for (int i = 1, u, v; i <= m; i++) { |
| 164 | u = in.nextInt(); |
| 165 | v = in.nextInt(); |
| 166 | addEdge(u, v); |
| 167 | } |
| 168 | for (int i = 1; i <= n; i++) { |
| 169 | if (dfn[i] == 0) { |
| 170 | // tarjan1(i); |
| 171 | tarjan2(i); |
| 172 | } |
| 173 | } |
| 174 | out.println(sccCnt); |
| 175 | for (int i = 1; i <= sccCnt; i++) { |
| 176 | Arrays.sort(sccArr, sccl[i], sccr[i] + 1); |
| 177 | } |
| 178 | for (int i = 1; i <= n; i++) { |
| 179 | int scc = belong[i]; |
| 180 | if (!sccPrint[scc]) { |
| 181 | sccPrint[scc] = true; |
| 182 | for (int j = sccl[scc]; j <= sccr[scc]; j++) { |
| 183 | out.print(sccArr[j] + " "); |
| 184 | } |
| 185 | out.println(); |
| 186 | } |
| 187 | } |
| 188 | out.flush(); |
| 189 | out.close(); |
| 190 | } |
| 191 | |
| 192 | // 读写工具类 |
| 193 | static class FastReader { |