fork(1) download
  1.  
  2. program grdeg
  3.  
  4. integer, allocatable :: A(:,:), B(:,:), ecc(:)
  5. logical :: directed
  6.  
  7. read(*, *) directed, n
  8. print*, directed, n
  9. allocate(A(n,n), B(n,n), ecc(n))
  10.  
  11. call rdmat(A, n, directed )
  12. !call prmat (A, n, 2)
  13. call connect(A, n, B)
  14.  
  15. ecc = maxval(B, 1)
  16. irad = minval(ecc, ecc > 0)
  17. if (directed) then
  18. print*, 'directed graph'
  19. else
  20. print*, 'undirected graph'
  21. end if
  22.  
  23. 1 format(A14, (T15, 4(I4:, ',')))
  24. print 1, 'radius: ',irad
  25. print 1, 'diameter: ', maxval(ecc)
  26. print 1, 'center points: ', pack( (/ (i, i = 1,n) /), ecc == irad)
  27.  
  28. ! call prmat(B, n, 2)
  29.  
  30. contains
  31.  
  32. subroutine prmat(A, n, d)
  33. character fmt*40
  34. integer, intent(in) :: n, d, A(n,n)
  35. write(fmt, '(A,I0,A,I0,A)') '(', n, '(I', d, ':,X))'
  36. write(*, fmt) ((A(j,i), j=1,n) ,i=1,n)
  37. end subroutine
  38.  
  39. subroutine rdmat(A, n, directed)
  40. integer, intent(out) :: A(n,n)
  41. logical directed
  42. A = 0
  43. do
  44. read(*,*, end=1) i,j
  45. A(i,j) = A(i,j)+1
  46. if (.not. directed) A(j,i) = A(j,i)+1
  47. end do
  48. 1 continue
  49. end subroutine
  50.  
  51. subroutine connect(A, n, B)
  52. integer, intent(in) :: A(n,n)
  53. integer, intent(out):: B(n,n)
  54. integer:: C(n,n)
  55.  
  56. B = 0
  57. C = A
  58.  
  59. do i=1,n
  60. where (B == 0 .and. C > 0) B = i
  61. C = MATMUL(A,C)
  62. end do
  63.  
  64. do i=1,n
  65. B(i,i) = 0
  66. end do
  67.  
  68. end subroutine
  69.  
  70. end program
  71.  
  72.  
Success #stdin #stdout 0s 3928KB
stdin
T 36
10 2
28 2
2 10
2 4
2 29
2 15
23 24
23 29
15 29
15 14
15 34
7 4
7 24
14 2
14 7
14 29
14 11
14 9
14 15
34 15
34 14
34 29
34 24
34 11
34 33
34 20
29 23
29 7
29 2
29 18
29 27
29 4
29 13
29 24
29 11
29 20
29 9
29 34
29 14
29 15
18 27
18 13
18 11
18 29
27 18
27 4
27 24
4 2
4 27
4 13
4 35
4 24
4 20
4 29
13 18
13 16
13 30
13 20
13 29
13 4
13 2
24 4
24 30
24 5
24 19
24 21
24 20
24 11
24 29
24 7
11 18
11 24
11 30
11 33
11 20
11 34
11 14
20 29
20 11
20 4
20 24
20 13
20 33
20 21
20 26
20 22
20 34
22 34
22 11
22 20
9 29
9 20
21 9
21 20
21 19
21 6
33 24
33 35
33 20
33 34
33 14
33 11
35 33
35 4
35 30
35 16
35 19
35 12
35 26
30 13
30 19
30 35
30 11
30 24
16 36
16 19
16 35
16 13
36 16
31 16
31 19
5 19
19 30
19 16
19 5
19 35
19 33
19 24
12 33
12 35
12 3
12 26
26 21
26 35
6 21
6 19
1 6
8 3
8 6
3 8
3 6
3 12
3 35
33 29
29 33
14 33
29 21
stdout
 T          36
 directed graph
radius:          3
diameter:        6
center points:  20,  24,  33,  35