Problem 1169. Count the Number of Directed Cycles in a Graph

Given an asymmetric adjacency matrix, determine the number of unique directed cycles.
For example, the graph represented by adjacency matrix
A = [
0 1 1 0;
1 1 0 1;
1 0 0 1;
1 1 0 0];
has 7 cycles. They are:
[2 -> 2]
[1 -> 2 -> 1]
[1 -> 3 -> 1]
[2 -> 4 -> 2]
[1 -> 2 -> 4 -> 1]
[1 -> 3 -> 4 -> 1]
[1 -> 3 -> 4 -> 2 -> 1]
The input is an adjacency matrix of 0s and 1s, and the output should be the number of unique (simple) directed cycles in the graph.

Solution Stats

35.14% Correct | 64.86% Incorrect
Last Solution submitted on Nov 05, 2025

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers12

Suggested Problems

More from this Author3

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!