#include <fstream>
#include <vector>
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];//vactorul muchiilor
vector<int> V[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].insert(V[x].end(),y); //V[x].push_back(y);
V[y].insert(V[y].end(),x); //V[y].push_back(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=0; j<V[i].size(); j++) fout<<V[i][j]<<" ";
fout<<endl;
}
}
int main()
{
citire();
afis();
fin.close();
fout.close();
return 0;
}
|