Pagini recente » Cod sursa (job #1961624) | Cod sursa (job #1390745) | Cod sursa (job #1749580) | Cod sursa (job #1724948) | Cod sursa (job #1611874)
#include <bits/stdc++.h>
using namespace std;
const int nmax = 100009;
int r , mxr , cr , p , n , m , i , x , y;
stack < int > is;
vector < int > g[nmax] , t[nmax];
int mark[nmax];
void df(int x)
{
for (int i = 0 ; i < g[x].size() ; ++i)
{
int y = g[x][i];
if (mark[y]) continue;
mark[y] = 1;
df(y);
}
is.push(x);
}
void tdf(int x)
{
r++;
for (int i = 0 ; i < t[x].size() ; ++i)
{
int y = t[x][i];
if (mark[y] == 0) continue;
mark[y] = 0;
tdf(y);
}
}
int main()
{
freopen("ctc.in" , "r" , stdin);
freopen("ctc.out" , "w" , stdout);
p = 1;
//scanf("%d" , &p);
scanf("%d" , &n);
scanf("%d" , &m);
for (i = 1 ; i <= m ; ++i)
{
scanf("%d" , &x);
scanf("%d" , &y);
g[x].push_back(y);
t[y].push_back(x);
}
for (i = 1 ; i <= n ; ++i)
{
if (mark[i]) continue;
mark[i] = 1;
df(i);
}
while (is.size())
{
x = is.top();
//cerr << x << '\n';
is.pop();
if (mark[x] == 0) continue;
mark[x] = 0 , r = 0;
tdf(x);
//if (r >= 2)
{
cr++;
mxr = max(mxr , r);
}
}
if (p == 1) printf("%d\n" , cr);
else printf("%d\n" , mxr);
return 0;
}