1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include <bits/stdc++.h> using namespace std; const int mxN=1e4; int n, m, ans, cnt; vector<int> adj[mxN]; bool vis[mxN]; void dfs(int u){ cnt++; vis[u] = 1; //cout << u << ' '; for(int v : adj[u]){ if(!vis[v]){ dfs(v); } } } int main() { cin >> n >> m; for(int i = 0, a, b; i < m; i++){ cin >> a >> b; a--, b--; adj[a].emplace_back(b); } for(int i = 0; i < n; i++){ if(!vis[i]){ cnt = 0; memset(vis, false, sizeof(vis)); dfs(i); ans = max(cnt, ans); } } cout << ans; return 0; } |
Friday, July 31, 2020
SPOJ : LastShot Solution
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment