Se da un graf neorientat cu n varfuri si m muchii. Afisati grupurile de muchii incidente.
Exemplu
n=5 , m=4
muchiile:
[1,2]
[1,3]
[1,4]
[3,4]
grupurile de muchii incidente sunt
[1,2] [1,3] [1,4]
[1,3] [3,4]
[1,4] [3,4]
#include <fstream>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");
int n,m,a[100][100];
void citire()
{
fin>>n>>m;
for(int i=0;i<=m;i++)
{
int x,y;
fin>>x>>y;
a[x][y]=a[y][x]=1;
}
}
int grad(int v)
{
int g=0;
for(int i=1;i<=n;i++)
g=g+a[v][i];
return g;
}
int main()
{
citire();
for(int i=1;i<=n;i++)
if(grad(i)>=2)
{
for(int j=1;j<=n;j++)
if(a[i][j]==1) fout<<"["<<i<<","<<j<<"] ";
fout<<endl;
}
fin.close();
fout.close();
return 0;
}