Tap here to switch tabs
Problem
Submissions

Problem: Reachable Nodes With Restrictions

Try to solve the Reachable Nodes With Restrictions problem.

Statement

There is an undirected tree with n nodes labeled from 00 to n −1- 1 and n −1- 1 edges.

You are given an integer n and a 22D integer array edges of length n −1- 1, where edges[i] =[ai,bi]= [a_i, b_i] indicates an edge between nodes aia_i and bib_i in the tree. You are also given an integer array restricted representing restricted nodes.

Return the maximum number of nodes you can reach from node 00 without visiting any node in restricted.

Note: Node 00 is guaranteed not to be a restricted node.

Constraints:

  • 2≤2 \leq n ≤105\leq 10^5

  • edges.length ==== n −1- 1

  • edges[i].length ==2== 2

  • 0≤ai,bi<0 \leq a_i, b_i < n

  • ai≠bia_i \neq b_i

  • edges represents a valid tree.

  • 1≤1 \leq restricted.length << n

  • 1≤1 \leq restricted[i] << n

  • All the values of restricted are unique.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Reachable Nodes With Restrictions

Try to solve the Reachable Nodes With Restrictions problem.

Statement

There is an undirected tree with n nodes labeled from 00 to n −1- 1 and n −1- 1 edges.

You are given an integer n and a 22D integer array edges of length n −1- 1, where edges[i] =[ai,bi]= [a_i, b_i] indicates an edge between nodes aia_i and bib_i in the tree. You are also given an integer array restricted representing restricted nodes.

Return the maximum number of nodes you can reach from node 00 without visiting any node in restricted.

Note: Node 00 is guaranteed not to be a restricted node.

Constraints:

  • 2≤2 \leq n ≤105\leq 10^5

  • edges.length ==== n −1- 1

  • edges[i].length ==2== 2

  • 0≤ai,bi<0 \leq a_i, b_i < n

  • ai≠bia_i \neq b_i

  • edges represents a valid tree.

  • 1≤1 \leq restricted.length << n

  • 1≤1 \leq restricted[i] << n

  • All the values of restricted are unique.