title: Fast method to check for inter-connected vertices in a edge list of a graph
body: <p>/For eg: i have two lists 
  List 0: [1,2,3 ]  (ie, edges: 0-1, 0-2,0-3)</p>
  
  <p>I want to check if the vertices in the list are interconnected ie, if there is an edge 1-2 , 1-3 etc
  My method works but it takes a lot of time because of multiple loops.
  My code takes 33 sec for an input of 10^5 vertices, i want to reduce it to 2 sec.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    public static void ADACHERY() throws IOException {
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
          PrintWriter out = new PrintWriter(System.out);
          StringTokenizer st = new StringTokenizer(br.readLine());
          int node = Integer.parseInt(st.nextToken());//total no of vertices
          int c = Integer.parseInt(st.nextToken());//total no of edges
          ArrayList&lt;Integer&gt;[] adj = new ArrayList[node];
          for (int i = 0; i &lt; node; ++i) {
              adj[i] = new ArrayList&lt;Integer&gt;();
          }
          int result=0;
          int neg = 0;
          while (c != 0) {
              st = new StringTokenizer(br.readLine());
              int a = Integer.parseInt(st.nextToken());
              int b = Integer.parseInt(st.nextToken());
              //adding edges
              adj[a].add(b);
              adj[b].add(a);
  
               new line of code
              if(!Collections.disjoint(adj[a], adj[b])) neg+=3;
  
              --c;
          }
  
          for(int i = 0; i&lt;node; i++) {
  
              int s = adj[i].size();
  
           if(s&gt;1) {
              result+= s==2?1: s*(s-1)/2;
                  int count = 0;
  
             }
  
                  }
            result-=neg;
            out.println(result);
                  out.close();
  }
  </code></pre>