title: How to find the universal sink of a directed graph with an adjacency-matrix representation
body: <p>I'm working on an excercise (self-study):
  &quot;Show how to determine whether a directed graph G contains a universal link - a vertex with in-degree (V-1) (V is the number of vertices) and out-degree 0 in time O(V), given an adjacency matrix for G.
  I have written the code here:</p>
  <pre><code>    int UniversalSink(const int *a, int N)
  {
      int i,j,i1,j1,q;
      i=0;
  
  
      i=0;
      q=YES;
      j=-1;
      do
      {
      j++;
      if (j==N)
          break;
  
      while ( (*(a+i*MAX+j)) ==0 )
      {
          j++;
          if (j==N)
          {
  
          break;
          }
      }
      if (j==N)
          break;
      q= YES;
  
      for (; i&lt;j; i++)
          if ( (*(a+i*MAX+j)) ==0 )
          {
             i=j,j=i-1;
             q= NO;
             break;
          }
      if (q==NO)
          continue;
      q=YES;
  
      /*
      for (i=0; i&lt;=j; i++ )
          if (a[j][i] ==1 )
          {
          i=j;
          q=NO;
          ok=NO;
          trai = NO;
          break;
  
          }
      if (q==NO)
          continue;
      */
      q=YES;
  
      for (i1= j+1; i1&lt;N; i1++)
          if ((*(a + i1*MAX +j)) ==0 )
          {
          i=i1, j=i-1;
          q=NO;
          break;
  
          }
      if (q==NO)
          continue;
      }
      while (j&lt;N);
  
      {
      i1=i;
      for (j1=0; j1&lt;N;j1++)
          if ( (*(a + i1*MAX +j1 ))  ==1 )
          return -1;
      j1=i;
      for (i1=0; i1&lt;N;i1++)
      {
          if (i1==j1)
          continue;
          if ( (*(a + i1*MAX +j1))==0)
          return -1;
      }
      return i;
  
      }
    
  </code></pre>
  <p>It takes a N-N matrix and returns the position of the universal sink (0 to N-1 if it exists and -1 if it doesn't)
  However I don't really know if it is O(V) or not, and in fact I'm not sure if it will always compute the desired result at all</p>
  <p>(Feel free to comment on any other aspect of my code e.g. using too many breaks)</p>