fork download
  1. program grdeg
  2. integer, allocatable :: adjac(:,:)
  3. character(len=40):: fmt
  4.  
  5. read(*, *) n
  6. allocate(adjac(n,n))
  7. adjac = 0
  8. do
  9. read(*,*, end=1) i,j
  10. adjac(i,j) = adjac(i,j)+1
  11. adjac(j,i) = adjac(j,i)+1
  12. end do
  13. 1 continue
  14. 2 format ("Node ", i0, " has a degree of " , i0)
  15. print 2, (i, sum(adjac(:,i),1),i=1,n)
  16.  
  17. write(fmt, '(a,i0,a)') '(', n, '(I2))'
  18. print fmt, ((adjac(j,i), j=1,n),i=1,n)
  19. end program
Success #stdin #stdout 0s 3976KB
stdin
16
1 2
1 3
2 3
1 4
3 4
1 5
2 5
1 6
2 6
3 6
3 7
5 7
6 7
3 8
4 8
6 8
7 8
2 9
5 9
6 9
2 10
9 10
6 11
7 11
8 11
9 11
10 11
1 12
6 12
7 12
8 12
11 12
6 13
7 13
9 13
10 13
11 13
5 14
8 14
12 14
13 14
1 15
2 15
5 15
9 15
10 15
11 15
12 15
13 15
1 16
2 16
5 16
6 16
11 16
12 16
13 16
14 16
15 16
stdout
Node 1 has a degree of 8
Node 2 has a degree of 8
Node 3 has a degree of 6
Node 4 has a degree of 3
Node 5 has a degree of 7
Node 6 has a degree of 10
Node 7 has a degree of 7
Node 8 has a degree of 7
Node 9 has a degree of 7
Node 10 has a degree of 5
Node 11 has a degree of 9
Node 12 has a degree of 8
Node 13 has a degree of 8
Node 14 has a degree of 5
Node 15 has a degree of 9
Node 16 has a degree of 9
 0 1 1 1 1 1 0 0 0 0 0 1 0 0 1 1
 1 0 1 0 1 1 0 0 1 1 0 0 0 0 1 1
 1 1 0 1 0 1 1 1 0 0 0 0 0 0 0 0
 1 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0
 1 1 0 0 0 0 1 0 1 0 0 0 0 1 1 1
 1 1 1 0 0 0 1 1 1 0 1 1 1 0 0 1
 0 0 1 0 1 1 0 1 0 0 1 1 1 0 0 0
 0 0 1 1 0 1 1 0 0 0 1 1 0 1 0 0
 0 1 0 0 1 1 0 0 0 1 1 0 1 0 1 0
 0 1 0 0 0 0 0 0 1 0 1 0 1 0 1 0
 0 0 0 0 0 1 1 1 1 1 0 1 1 0 1 1
 1 0 0 0 0 1 1 1 0 0 1 0 0 1 1 1
 0 0 0 0 0 1 1 0 1 1 1 0 0 1 1 1
 0 0 0 0 1 0 0 1 0 0 0 1 1 0 0 1
 1 1 0 0 1 0 0 0 1 1 1 1 1 0 0 1
 1 1 0 0 1 1 0 0 0 0 1 1 1 1 1 0