Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. vector<vector<int> > a;
  4. int n, m, cnt(0), res;
  5. bool visit[1001];
  6. vector<int> b;
  7. deque<int> s;
  8. void DFS(int u)
  9. {
  10.     visit[u]=true;
  11.     s.push_back(u);
  12.     for(int i=0;i<a[u].size();i++)
  13.     {
  14.         int v=a[u][i];
  15.         if(!visit[v])
  16.         {
  17.             DFS(v);
  18.             low[u]=min(low[u],low[v]);
  19.         }
  20.         else{
  21.             low[u]=min(low[u],id[v]);
  22.             if(find(s.begin(),s.end(),v) != s.end())
  23.             {
  24.                 vector<int> c;
  25.                 while(true)
  26.                 {
  27.                     int x = s.back();
  28.                     c.push_back(x);
  29.                     if(x == v) break;
  30.                     s.pop_back();
  31.                 }
  32.                 if(c.size() > b.size()) b = c;
  33.  
  34.             }
  35.         }
  36.     }
  37. }
  38.  
  39. void enter(){
  40.     ios_base::sync_with_stdio(0);
  41.     cin.tie(0);
  42.  
  43.     freopen("GIANGHO.INP","r",stdin);
  44.     freopen("GIANGHO.OUT","w",stdout);
  45.  
  46.     cin>>n;
  47.  
  48.     a.resize(n+1);
  49.  
  50.     int x,y;
  51.     while(cin>>x>>y)
  52.         a[x].push_back(y);
  53. }
  54.  
  55. int main()
  56. {
  57.     enter();
  58.  
  59.     for(int i=1;i<=n;i++)
  60.         if(!visit[i])
  61.             DFS(i);
  62.     cout<<b.size()<<endl;
  63.     for(x : b) cout<<x<<" ";
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement