---
# System prepended metadata

title: 1557. Minimum Number of Vertices to Reach All Nodes
tags: [graph]

---

---
title: 1557. Minimum Number of Vertices to Reach All Nodes
tags: graph
description: share source code.
---

# 1557. Minimum Number of Vertices to Reach All Nodes

```java=
class Solution {
    public List<Integer> findSmallestSetOfVertices(int n, List<List<Integer>> edges) {
      int [] indgrees = new int [n];
    
      for(List<Integer> edge : edges){
         indgrees[edge.get(1)]++;
      }
      
       List<Integer> list = new ArrayList<>(); 
       for(int i = 0; i < n; i++){
         if(indgrees[i] == 0){
             list.add(i);
         }
      }
        return list;
    }

}
```

