visited[nindex]=2; for(int i=0; i<graphMatrix[nindex].length; i++) { if(graphMatrix[nindex][i]==DIRECTED) if(visited[i]==0) { removeCycles2(i, visited); visited[i]=1; } else if(visited[i]==2) { if(nindex==i) { graphMatrix[nindex][i]=0; } else if(graphMatrix[i][nindex]==DIRECTED) {  graphMatrix[i][nindex]=DOUBLE; graphMatrix[nindex][i]=-DOUBLE; } else {  graphMatrix[i][nindex]=REVERSED; graphMatrix[nindex][i]=-REVERSED; } } }
visited[nindex]=2; for(int i=0; i<graphMatrix[nindex].length; i++) { if(graphMatrix[nindex][i]==DIRECTED) if(visited[i]==0) { removeCycles2(i, visited); visited[i]=1; } else if(visited[i]==2) { if(nindex==i) { graphMatrix[nindex][i]=0; } else if(graphMatrix[i][nindex]==DIRECTED) {  graphMatrix[i][nindex]=DOUBLE; graphMatrix[nindex][i]=-DOUBLE; } else {  graphMatrix[i][nindex]=REVERSED; graphMatrix[nindex][i]=-REVERSED; } }
    private void removeCycles2(int nindex, int visited[]) {	visited[nindex]=2;	for(int i=0; i<graphMatrix[nindex].length; i++) {	    if(graphMatrix[nindex][i]==DIRECTED)		if(visited[i]==0) {		    removeCycles2(i, visited);		    visited[i]=1;		}		else if(visited[i]==2) {		    if(nindex==i) {			graphMatrix[nindex][i]=0;		    }		    else if(graphMatrix[i][nindex]==DIRECTED) { 			//System.out.println("\nFound double "+nindex+','+i); 			graphMatrix[i][nindex]=DOUBLE; 			graphMatrix[nindex][i]=-DOUBLE;		    }		    else { 			//System.out.println("\nReversing "+nindex+','+i); 			graphMatrix[i][nindex]=REVERSED; 			graphMatrix[nindex][i]=-REVERSED; 		    }		}	}    }