title: What is wrong in my code for finding if a graph is Bipartite or not?
body: <p>I am doing a simple BFS and marks the neighbouring elements for the vertices which comes under the current traversing vertice and if it's again found in the next vertices of the current traversing vertice then it's not a bipartite.<br/></p>
  <pre><code>#include &lt;bits/stdc++.h&gt;
  
  using namespace std;
  
  vector&lt;long&gt; g[100000];
  
  void neighbour(long it, vector&lt;bool&gt;&amp; nei)
  {
      for (auto itr : g[it])
          nei[itr] = true;
  }
  
  bool BFSbipartile(vector&lt;bool&gt;&amp; vis, long v, long ver)
  {
      queue&lt;long&gt; q;
  
      bool flag = true;
      q.push(v);
      vis[v] = true;
      while (!q.empty()) {
          long t = q.front();
          q.pop();
          vector&lt;bool&gt; nei(ver + 1, false);
          for (auto it : g[t]) {
              if (!vis[it]) {
                  neighbour(it, nei);
                  if (nei[it] == true) {
                      flag = false;
                      break;
                  }
                  vis[it] = true;
                  q.push(it);
              }
              if (!flag)
                  return false;
          }
      }
      return true;
  }
  
  int main()
  {
      long v, e, e1, e2;
      cin &gt;&gt; v &gt;&gt; e;
      for (long i = 0; i &lt; e; i++) {
          cin &gt;&gt; e1 &gt;&gt; e2;
          g[e1].push_back(e2);
          g[e2].push_back(e1);
      }
      vector&lt;bool&gt; vis(v + 1, false);
      bool tru = true;
      for (int i = 1; i &lt;= v; i++) {
          if (!vis[i])
              tru = BFSbipartile(vis, i, v);
          if (!tru) {
              cout &lt;&lt; 0 &lt;&lt; endl;
              break;
          }
      }
      if (tru)
          cout &lt;&lt; 1 &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>