func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 5005;   vector<int> adj[N];   bool visited[N];   bool reach[N];   pair<int, int> has[N];   int cnt = 0;   void dfs(int s) {     if (!visited[s]) {       visited[s] = 1;       reach[s] = 1;       for (int i = 0; i < adj[s].size(); i++) {         dfs(adj[s][i]);       }     }   }   void dfs2(int s, int a) {     if (!visited[s]) {       visited[s] = 1;       if (reach[s] == 0) has[a].first++;       for (int i = 0; i < adj[s].size(); i++) {         dfs2(adj[s][i], a);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m, s;     cin >> n >> m >> s;     s--;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       adj[a].push_back(b);     }     dfs(s);     for (int i = 0; i < n; i++) {       has[i].second = i;     }     for (int i = 0; i < n; i++) {       if (!reach[i]) {         memset(visited, 0, sizeof(visited));         dfs2(i, i);       }     }     sort(has, has + N);     reverse(has, has + N);     int ans = 0;     cnt = 0;     memset(visited, 0, sizeof(visited));     for (int i = 0; i < n; i++) {       if (!reach[has[i].second]) {         dfs(has[i].second);         memset(visited, 0, sizeof(visited));         ans++;       }     }     cout << ans;     return 0;   }   