#include <fstream>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");
struct muchie
{
int i,j;
};
int A[50][50];//matricea de adiacenta
muchie M[1000];//vectorul muchiilor
int V[50][50];//listele de adiacenta
int n,m;//noduri/muchii
void citire()
{
int x,y,i;
fin>>n>>m;
for(i=1;i<=m;i++)
{
fin>>x>>y;
M[i].i=x; M[i].j=y;
A[x][y]=A[y][x]=1;
V[x][0]++; V[x][V[x][0]]=y;
V[y][0]++; V[y][V[y][0]]=x;
}
}
void afis()
{
int i,j;
fout<<"matricea de adiacenta:\n";
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
fout<<A[i][j]<<" ";
fout<<endl;
}
fout<<"lista muchiilor:\n";
for(i=1;i<=m;i++) fout<<M[i].i<<" "<<M[i].j<<endl;
fout<<"lista vecinilor:\n";
for(i=1;i<=n;i++)
{
fout<<i<<": ";
for(j=1; j<=V[i][0]; j++) fout<<V[i][j]<<" ";
fout<<endl;
}
}
int main()
{
citire();
afis();
fin.close();
fout.close();
return 0;
}
|