Perform depth-first and breadth-first searches on a graph.
HardProblem Statement
Perform depth-first and breadth-first searches on a graph.
Sample Input
Graph: 0 -> 1, 2; 1 -> 2; 2 -> 0, 3; 3 -> 3. Start Node: 2
Sample Output
DFS: 2, 0, 1, 3 BFS: 2, 0, 3, 1
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
using System;
using System.Collections.Generic;
class GraphSearch
{
static void Main()
{
// Perform DFS and BFS on the graph
}
}
Input
Graph: 0 -> 1, 2; 1 -> 2; 2 -> 0, 3; 3 -> 3. Start Node: 2
Expected Output
DFS: 2, 0, 1, 3 BFS: 2, 0, 3, 1