int fillCycle(int[]A, boolean[]v, int[]dp, int i) {
		int j=i;
		for (j=i;!v[j];j=A[j]){
			if (dp[j]!=0) return dfs(A, dp, i);
			v[j]=true;
		}
		int count=1,k=A[j];
		for (;k!=j;k=A[k]) ++count;
		for (k=A[k];k!=j;k=A[k])dp[k]=count;
		dp[j]=count;
		return dfs(A, dp, i);
	}