import javax.swing.*; public class ProblemE { public static void main(String[] args) { int i, j, k; String S = JOptionPane.showInputDialog("Enter string S"); // Create adjacency matrix boolean[][] P; P = new boolean[26][]; for (i = 0; i < 26; ++i) P[i] = new boolean[26]; for (i = 0; i < 26; ++i) { for (j = 0; j < 26; ++j) { P[i][j] = false; } } k = 0; while (k < S.length()) { P[S.charAt(k) - 'a'][S.charAt(k+1) - 'a'] = true; k += 2; } // Apply Warshall's Algorithm for (k = 0; k < 26; k++) { for (i = 0; i < 26; i++) { for (j = 0; j < 26; j++) { if (! P[i][j]) { P[i][j] = P[i][k] && P[k][j]; } } } } // Find all concurrent tasks int numOfConcurrentTasks = 0; for (i = 0; i < 26; ++i) { for (j = i+1; j < 26; ++j) { if (!P[i][j] && !P[j][i]) { numOfConcurrentTasks++; } } } // Report answer JOptionPane.showMessageDialog(null, "Number of concurrent tasks = " + numOfConcurrentTasks); } }