1class Solution {2int count = 0;3ArrayList<ArrayList<Integer>> adj = new ArrayList<>();45public int reachableNodes(int n, int[][] edges, int[] restricted) {6boolean[] vis = new boolean[n];7for (int i : restricted) {8vis[i] = true;9}10for (int i = 0; i < n; i++) {11adj.add(new ArrayList<>());12}13for (int[] ii : edges) {14adj.get(ii[0]).add(ii[1]);15adj.get(ii[1]).add(ii[0]);16}17dfs(0, vis);18return count;19}2021private void dfs(int node, boolean[] vis) {22vis[node] = true;23count++;24for (int it : adj.get(node)) {25if (vis[it] == false) {26dfs(it, vis);27}28}29}30}