Pagini recente » Cod sursa (job #1481799) | Cod sursa (job #1995532) | Cod sursa (job #271676) | Cod sursa (job #632671) | Cod sursa (job #2635846)
#include <bits/stdc++.h>
using namespace std;
ifstream r("ctc.in");
ofstream w("ctc.out");
int d[100001],n, o, nr, m;
bool v[100001];
vector<int>a[100001],a2[100001],c[100001];
void f(int x)
{
if(v[x]==0)
{
v[x]=1;
for(auto it:a[x]){
f(it);
}
nr++;
d[nr]=x;
}
}
void g(int x)
{
if(v[x]==0)
{
v[x]=0;
for(auto it: a2[x]){
g(it);
}
c[o].push_back(x);
}
}
int main()
{
r>>n>>m;
int x,y,i;
while(r>>x>>y){
a[x].push_back(y);
a2[y].push_back(x);
}
for(i=1; i<=n; i++){
f(i);
}
for(i=n; i>=1; i--){
if(v[d[i]])
{
o++;
g(d[i]);
}
}
w<<o<<"\n";
for(i=1; i<=o; i++)
{
for(auto it: c[i]){
w<<it<<" ";
}
w<<"\n";
}
return 0;
}