from __future__ import print_function
from sys import stdin

def printf(str, *args):
	print(str % args, end='')

domain = 5

def readfile(fn, adjacency):
	adjacencymx = [[0 for j in range(len(adjacency[0]))] for i in range(len(adjacency))]
	fp = open(fn, 'r')
	printf("입력 받은 관계 R 출력입니다.\n")
	print("R = {")

	lines = fp.readlines()
	for line in lines:
		values = line.strip('\n').split()
		x = int(values[0])
		y = int(values[1])

		adjacencymx[x][y] = 1
		printf("(%2d, %2d)" %(x,y))
	fp.close()
	return adjacencymx

# allocate initial value
adjacencymx = [[0 for j in range(domain+1)] for i in range(domain+1)]
fn = "pp4-1.dat"

adjacencymx = readfile(fn,adjacencymx)
printf("}\n\n")

printf("%5cdegree of vertex\n\n"%' ')

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

for i in range(1, domain + 1):
	printf("%5c"%' ')
	for j in range(1, domain + 1):
		if adjacencymx[i][j] == 1:
			printf("1 ")
		else:
			printf("0 ")
	printf("\n")

stdin.readline()