This repository contains a C++ program that detects cycles in directed graphs using Depth-First Search (DFS). The program takes an input file representing a directed graph and outputs whether the graph contains a cycle or not.
- C++ compiler supporting C++11 standard
- ArgumentManager.h (included)
To build the program, compile the main.cpp
file along with ArgumentManager.h
.
g++ -std=c++11 main.cpp -o cycle_detection
The program takes two command-line arguments:
input
: Path to the input file containing the directed graph representation.output
: Path to the output file where the result will be written.
Example usage:
./cycle_detection input=input.txt output=output.txt
The input file format should follow these specifications:
- The first line contains an integer
n
, representing the number of vertices in the graph. - Subsequent lines represent directed edges in the graph. Each line contains two integers
x
andy
, indicating an edge from vertexx
to vertexy
.
Example input file (input.txt
):
4
0 1
1 2
2 0
2 3
The output file contains a single line indicating whether the input graph contains a cycle or not. It outputs "True" if a cycle exists, and "False" otherwise.
Example output file (output.txt
):
True
This project is licensed under the MIT License - see the LICENSE file for details.
- The implementation utilizes Depth-First Search (DFS) algorithm.
- ArgumentManager.h is used for parsing command-line arguments.