SHARE
TWEET

Untitled

a guest Feb 27th, 2020 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream f("bazine.in");
  6. ofstream g("componenteconexe.in");
  7.  
  8. int v[105],n,a[105][105],vec[105],nr1;
  9. void dfs(int nod)
  10. {
  11.     v[nod]=1;
  12.     vec[nr1]=nod;
  13.     nr1++;
  14.     for(int k=1;k<=n;k++)
  15.         if(a[nod][k]==1 && v[k]==0)
  16.         dfs(k);
  17. }
  18. int main()
  19. {
  20.     int m,x,y,nr=0;
  21.     f>>n;
  22.         while(f>>x>>y)
  23.         a[x][y]=a[y][x]=1;
  24.     for(int i=1;i<=n;i++)
  25.     {
  26.         if(v[i]==0)
  27.         {
  28.             dfs(i);
  29.             nr++;
  30.         }
  31.     }
  32.     cout<<nr<<endl;
  33.     for(int i=1;i<=n;i++)
  34.         v[i]=0;
  35.       for(int i=1;i<=n;i++)
  36.     {
  37.         nr1=1;
  38.         if(v[i]==0)
  39.         {
  40.             dfs(i);
  41.             sort(vec+1,vec+nr1+1);
  42.         for(int j=1;j<nr1;j++)
  43.             cout<<vec[j]<<" ";
  44.         cout<<endl;
  45.         }
  46.  
  47.     }
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top