CCCPaste

Untitled

#include 
#include 
#include 
using namespace std;
const int maxn = 1e5 + 10;
vector graph[maxn];
int discovarable_time[maxn];
int low_link[maxn];
bool on_stack[maxn];
int current_time = 0;
stack st;
int n;
int cnt = 0;
int res=  0;
void dfs(int node) {
    discovarable_time[node] = current_time;
    low_link[node] = current_time;
    current_time++;
    st.push(node);
    on_stack[node] = true;
    
    for(int i = 0; i < (int) graph[node].size(); i++) {
        int neighbour = graph[node][i];
        if(discovarable_time[neighbour] == -1) {
            dfs(neighbour);
            low_link[node] = min(low_link[node], low_link[neighbour]);
        }
        else if(on_stack[neighbour]) {
            low_link[node] = min(low_link[node], discovarable_time[neighbour]);
        }
    }
    
    if(discovarable_time[node] == low_link[node]) {
        cnt++;
        int tmp_cnt = 0;
        while(!st.empty()) {
            int tmp = st.top();
            st.pop();
            on_stack[tmp] = false;
            tmp_cnt++;
            res = max(res, tmp_cnt);

            if(tmp == node) {
                break;
            }
        }
        
    }
}
void tarjan() {
    for(int i = 0; i < maxn; i++) {
        discovarable_time[i] = -1;
        on_stack[i] = false;
    }
    for(int i = 0; i < n; i++) {
        if(discovarable_time[i] == -1) {
            dfs(i);
        }
    }
}
int main() {
    int  m;
    cin >> n >> m;
    
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
    }
    tarjan();
    cout << cnt << endl << res << endl;
    return 0;
}