title: Efficiently Implement Degree of separation for connected paths in java
body: <p>Question:
  If Boston is the City for which the connecting interstates degree needs to be figured, 0 is the degree of separation for Boston. If new York can connect directly to Boston the degree of separation is 1, If new York connects to Boston through a different city road , the degree of separation is 2 and so on</p>
  <p>E.g Input :</p>
  <pre class="lang-none prettyprint-override"><code>Boston,I-94;I-90
  NewYork,I-80;I-94
  Seattle,I-80;I-5
  </code></pre>
  <p>E.g Output:</p>
  <pre class="lang-none prettyprint-override"><code>0, Boston
  1, NewYork
  2, Seattle
  </code></pre>
  <p>**This question already has been asked but the question is closed and the answer is not quite right and efficient also there is no implementation **
  <a href="https://stackoverflow.com/questions/39935241/c-sharp-degree-of-separation-for-connected-paths">C# Degree of separation for connected paths</a></p>
  <p>I know I have to create an adjacency list and solve it using BFS but I am looking for an efficient Implementation (I shouldn't use the LINQ library or any other library like that)</p>