File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed
Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` cpp
2+ #include < bits/stdc++.h>
3+ using namespace std ;
4+
5+ int D, L;
6+ vector<vector<int >> v (5001), r(5001);
7+
8+ bitset<5001> vis;
9+ int cnt = 0, ans = 0;
10+ stack<int > st;
11+
12+ void dfs1(int n) {
13+ for(int i: v [ n] ) if(!vis[ i] ) {
14+ vis[ i] = 1;
15+ dfs1(i);
16+ }
17+ st.push(n);
18+ }
19+
20+ void dfs2(int n) {
21+ cnt++;
22+ for(int i: r [ n] ) if(!vis[ i] ) {
23+ vis[ i] = 1;
24+ dfs2(i);
25+ }
26+ }
27+
28+ int main(){
29+ cin.tie(0)->sync_with_stdio(0);
30+
31+ for(cin>>D>>L;L--;) {
32+ int a,b;
33+ cin>>a>>b;
34+ v[a].push_back(b);
35+ r[b].push_back(a);
36+ }
37+
38+ for(int i=1;i<=D;i++) if(!vis[i]) {
39+ vis[i] = 1;
40+ dfs1(i);
41+ }
42+ vis.reset();
43+ while(!st.empty()) {
44+ int n = st.top(); st.pop();
45+ if(vis[n]) continue;
46+ cnt = 0;
47+ vis[n] = 1;
48+ dfs2(n);
49+ ans = max(ans, cnt);
50+ }
51+
52+ cout<<ans;
53+
54+ }
55+ ```
You can’t perform that action at this time.
0 commit comments