Dart Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nimport \'dart:collection\';\n\nclass Solution {\n\n\nList<List<int>> getAncestors(int n, List<List<int>> edges) {\n  // Create an adjacency list representation of the graph\n  List<List<int>> graph = List.generate(n, (_) => []);\n  List<int> inDegree = List.filled(n, 0);\n\n  for (var edge in edges) {\n    graph[edge[0]].add(edge[1]);\n    inDegree[edge[1]]++;\n  }\n\n  // List to store the ancestors for each node\n  List<List<int>> ancestors = List.generate(n, (_) => []);\n\n  // Perform topological sort\n  Queue<int> queue = Queue<int>();\n  for (int i = 0; i < n; i++) {\n    if (inDegree[i] == 0) {\n      queue.add(i);\n    }\n  }\n\n  while (queue.isNotEmpty) {\n    int node = queue.removeFirst();\n\n    for (var neighbor in graph[node]) {\n      ancestors[neighbor].add(node);\n      ancestors[neighbor].addAll(ancestors[node]);\n      ancestors[neighbor] = ancestors[neighbor].toSet().toList(); // Remove duplicates\n\n      if (--inDegree[neighbor] == 0) {\n        queue.add(neighbor);\n      }\n    }\n  }\n\n  // Sort ancestors for each node\n  for (var list in ancestors) {\n    list.sort();\n  }\n\n  return ancestors;\n}\n\n\n\n}\n```
['Dart']