#include<stdio.h>
#ifdef _WIN32
	#include<conio.h>
	#include<Windows.h>
#endif

#define domain 5

void readfile(char fn[13],char adjacency[domain+1][domain+1]);

void main()
{
	char adjacencymx[domain+1][domain+1];
	char fn[13]="pp4-1.dat";
	int i,j,degree;
	/*allocate initial value */
	for(i=1;i<=domain;i++)
	{
		for(j=1;j<=domain;j++)
		{
			adjacencymx[i][j] = 0;
		}
	}

	readfile(fn,adjacencymx);
	printf("}\n\n");
	
	printf("%5cdegree of vertex\n\n",' ');

	for(i=1;i<=domain;i++)
	{
		degree = 0;
		for(j=1;j<=domain;j++)
		{
			if(adjacencymx[i][j] == 1)
			{
				degree++;
			}
		}
		printf("%9cv(%3d)=%4d\n",' ',i,degree);
	}
	printf("\n\n%5cadjancency matrix\n\n",' ');

	for(i=1;i<=domain;i++)
	{
		printf("%5c",' ');
		for(j=1;j<=domain;j++)
		{
			if(adjacencymx[i][j] == 1)
			{
				printf("1 ");
			}else
			{
				printf("0 ");
			}
		}
		printf("\n");
	}

	system("PAUSE");
}

void readfile(char fn[13],char adjacency[domain+1][domain+1])
{
	FILE *fp;
	int x,y;

	fp = fopen(fn,"r");
	printf("입력 받은 관계 R 출력입니다.\n");
	printf("R = {");

	while(!feof(fp))
	{
		fscanf(fp,"%d %d",&x,&y);
		adjacency[x][y] = 1;
		printf("(%2d,%2d)",x,y);
	}

	fclose(fp);
}