#include #include #include #include using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; int M; cin >> M; vector> adj(N); for(int i=0; i> u >> v; u--; v--; adj[u].push_back(v); } vector adj_at(N, 0); vector visiting(N, 0); // mark edges in eliminated cycles : adj[v][i] = -1 auto dfs = [&](auto& dfs, int v) -> int { visiting[v] = 1; while(adj_at[v] < (int)adj[v].size()){ int w = adj[v][adj_at[v]]; if(visiting[w]){ adj[v][adj_at[v]] = -1; adj_at[v]++; visiting[v] = 0; return w; } int res = dfs(dfs, w); if(res >= 0){ adj[v][adj_at[v]] = -1; if(res != v){ visiting[v] = 0; adj_at[v]++; return res; } } adj_at[v]++; } visiting[v] = 0; return -1; }; for(int s=0; s> ans; for(int v=0; v