%% Defining adjacency matrix

A=[0 1 0 1 1 0 0 0 1
0 0 1 0 0 0 0  0  0
1 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 0 0
1 0 0 0 0 0 0 0 0
0 0 0 0 1 0 1 0 0
0 0 0 0 0 1 0 1 0
0 0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0 0];

%% Strong-connectivity  - Compute powers of adjacency matrix

Asum=0; % Defining the sum matrix. Check its positivity!
 for i=0:8
Asum=Asum+A^i;
 end
Asum
%% computing shortest path between St. Gallen and Zermatt
Acheck=0;
 for i=1:9
Acheck=A^i;
if Acheck(2,8)~=0
kbar=i;
break
end 
 end

%% Required links between Bern and Chur 

% check variables BC4links and BC5links. 1 implies yes, 0 implies no 
BC4links=0;
BC5links=0;
Acheck1=A^4;
%
%
if Acheck1(6,3)~=0
BC4links=1;
end
%
%
Acheck1=A^5;
if Acheck1(6,3)~=0
BC5links=1;
end

%% Check the (1,7)th element of Asum
NZL=Asum(1,7);