#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
int n,m,i,j,k,l,p,u[10][10],a,b,maxi=0,s,x,y,ii,t;
int main()
{ifstream f("graf.in");
f>>n>>m;
for(i=1;i<=m;i++)
{f>>a>>b;
u[a][b]=u[b][a]=1;}
for(i=1;i<=n;i++)
{for(j=1;j<=n;j++)
cout<<setw(3)<<u[i][j];
cout<<endl;}
f>>t;
cout<<endl<<"Noduri adiacente cu nodul "<<t<<" : ";
for(i=1;i<=n;i++)
if(u[t][i]==1)
cout<<i<<" ";
for(i=1;i<=n;i++)
{s=0;
for(j=1;j<=n;j++)
if(u[i][j]==1)
s++;
if(s>maxi)
maxi=s;
}
cout<<endl<<endl<<"Nodurile de grad maxim ("<<maxi<<") : ";
for(i=1;i<=n;i++)
{s=0;
for(j=1;j<=n;j++)
if(u[i][j]==1)
s++;
if(s==maxi)
cout<<i<<" ";}
f>>x>>y;
cout<<endl<<endl<<"Lanturi elementare de L=3 care contin nodurile "<<x<<" si "<<y<<endl;
for(ii=1;ii<=n;ii++)
{
for(i=1;i<=n;i++)
if(u[ii][i]==1)
for(j=1;j<=n;j++)
if(u[i][j]==1 && j!=ii)
for(k=1;k<=n;k++)
if(u[j][k]==1 && k!=ii && k!=i &&
(k==y || i==y || j==y || ii==y) &&
(k==x || i==x || j==x || ii==x))
cout<<"("<<ii<<" "<<i<<" "<<j<<" "<<k<<")"<<endl;
}
for(i=1;i<=n;i++)
{u[5][i]=0;
u[i][5]=0;}
cout<<endl<<"Graful partial obtinut prin eliminarea muchiilor incidente cu nodul "<<t<<endl;
for(i=1;i<=n;i++)
{for(j=1;j<=n;j++)
cout<<setw(3)<<u[i][j];
cout<<endl;}
}
Orar semigroup #2
01/30 - Tiest Grafe R2
duminică, 29 ianuarie 2012
by DlMuresan
Categories:
Graf,
test
|
Leave a comment