Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- void Citire(int a[100][100],int &m,int &n)
- {
- ifstream fin("graf.in");
- fin>>n;
- fin>>m;
- for(int i=1;i<=m;i++)
- {
- int x,y;
- fin>>x>>y;
- a[x][y]=1;
- a[y][x]=1;
- }
- fin.close();
- }
- void Rezolvare(int a[100][100],int &n)
- {
- int nod[100],k=0;
- for(int i=1; i<=n; i++)
- {
- int s=0;
- for(int j=1; j<=n; j++)
- s+=a[i][j];
- if(s==0 || s==1)
- {
- nod[k]=i;
- k++;
- }
- }
- for(int i=1;i<=n;i++)
- {
- for(int j=1;j<=n;j++)
- for(int p=0;p<k;p++)
- {
- if(i==nod[p])
- a[i][j]=-1;
- }
- }
- }
- void Afisare(int a[100][100],int &n)
- {
- cout<<"Muchii ramase:"<<endl;
- for(int i=1; i<n; i++)
- {
- for(int j=i+1; j<=n; j++)
- if(a[i][j]!=-1 && a[i][j]==1 && a[j][i]==1)
- cout<<i<<" " <<j<<endl;
- }
- }
- int main()
- {
- int n,m, a[100][100]={0};
- Citire(a,m,n);
- Rezolvare(a,n);
- Afisare(a,n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement