using System.Collections.Generic;
public bool ValidPath(int n, int[][] edges, int source, int destination) {
var graph = new Dictionary<int, List<int>>();
foreach (var edge in edges) {
int a = edge[0], b = edge[1];
if (!graph.ContainsKey(a)) {
graph[a] = new List<int>();
if (!graph.ContainsKey(b)) {
graph[b] = new List<int>();
return Dfs(graph, seen, source, destination);
private bool Dfs(Dictionary<int, List<int>> graph, bool[] seen, int currNode, int destination) {
if (currNode == destination) {
foreach (int nextNode in graph[currNode]) {
if (Dfs(graph, seen, nextNode, destination)) {