title: C++ input difficulty
body: <p>I am trying to solve the following problem from ACM Timus:
  <a href="http://acm.timus.ru/problem.aspx?space=1&amp;num=1242" rel="nofollow">http://acm.timus.ru/problem.aspx?space=1&amp;num=1242</a> , but I don't how to read the input correctly. I am using two while loops. The first one terminates once a string is written in the input but the second one doesn't work after that. Here's  my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  
  
  struct Pair
  {  
      void AddParent(int a)
      { parents.push_back(a); }
      void AddChild(int a)
      { children.push_back(a);}
      vector&lt;int&gt; parents;
      vector&lt;int&gt; children;
  };
  
  vector&lt;bool&gt; visited;
  vector&lt;Pair&gt; graph;
  
  void DFS1(int n)
  {
      visited[n] = true;
      for(int i = 0 ; i &lt; graph[n].parents.size() ; i++)
      {
          int t = graph[n].parents[i];
          if(!visited[t])
              DFS1(t);
      }
      return;
  }
  
  void DFS2(int n)
  {
      visited[n] = true;
      for(int i = 0 ; i &lt; graph[n].children.size() ; i++)
      {
          int t = graph[n].children[i];
          if(!visited[t])
              DFS2(t);
      }
      return;
  }
  
  
  int main()
  {
      int n;
      cin &gt;&gt; n; 
      graph.resize(n);
      visited.resize(n);
      int a,b,c;
      vector&lt;int&gt; victim;
  
  ////////////////////////////////
      while(cin &gt;&gt; a &amp;&amp; cin &gt;&gt; b)
      {   a--;b--;
          graph[a].AddParent(b);
          graph[b].AddChild(a);
      }
  
      cin.clear();
      cin.ignore();
  
      while(cin &gt;&gt; c)
      {
          victim.push_back(c);
      }
  
  ////////////////////////////////    
  
      for(int i = 0 ; i &lt; victim.size() ; i++)
          if(!visited[victim[i]]){
              DFS1(victim[i]);
              DFS2(victim[i]);
          }
  
  
      bool vis = false;
      for(int i = 0 ;  i &lt; n ; i++)
          if(!visited[i])
          { 
              vis = true;
              cout &lt;&lt; i + 1 &lt;&lt; " ";
          }
          if(!vis)
              cout &lt;&lt; 0;
  
  return 0;
  }
  </code></pre>