03/26 - Teza, totti!
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
int a[100][100],n,m,c[100],viz[100],x,y;
void citire()
{ifstream f("date");
int xx,yy;
f>>n>>m;
for(int i=1;i<=m;i++)
{f>>xx>>yy;
a[xx][yy]=1;}
f>>x>>y;
}
void DF(int x, int &k)
{int i;
c[k]=x;
k++;
for(i=1;i<=n;i++)
if(a[x][i]!=0 && viz[i]==0)
{viz[i]=1;
DF(i,k);}
}
int main()
{int i,j,k,p=1;
citire();
cout<<"a) Nodurile pentru care gradul exterior este mai mare decat gradul interior"<<endl;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
a[i][n+1]+=a[i][j];
for(j=1;j<=n;j++)
for(i=1;i<=n;i++)
a[n+1][j]+=a[i][j];
/*for(i=1;i<=n+1;i++)
{ for(j=1;j<=n+1;j++)
cout<<setw(3)<<a[i][j];
cout<<endl;}*/
for(i=1;i<=n;i++)
if(a[n+1][i]<a[i][n+1])
cout<<i<<" ";
cout<<endl<<endl;
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(a[i][k] && a[k][j])
a[i][j]=1;
/*for(i=1;i<=n;i++)
{ for(j=1;j<=n;j++)
cout<<setw(3)<<a[i][j];
cout<<endl;}*/
if(a[x][y] && a[y][x])
cout<<"b) "<<x<<" si "<<y<<" fac parte din aceeasi componenta tare conexa";
else cout<<"b) "<<x<<" si "<<y<<" NU fac parte din aceeasi componenta tare conexa";
DF(x,p);
cout<<endl<<endl<<"c) Ultimul nod vizitat in adancime pornind din "<<x<<" este "<<c[p-1];
}
Fisier
5 8
1 3
1 4
1 5
2 1
3 2
2 4
4 5
5 4
4 2
duminică, 25 martie 2012
by DlMuresan
Categories:
Graf,
graf orientat,
teza
|