Visible Profiles

Company: Meesho

Difficulty: medium

Problem Statement

Visible Profiles A popular social media platform provides a feature to connect people online. Connections are represented as an **undirected graph**: a user can see the profile of every user they are connected to, directly or through a chain of other users. A user can always see their own profile. There are `connection_nodes` users, numbered `1` through `connection_nodes`, and `connection_edges` connections. The `i`-th connection joins the users `connection_from[i]` and `connection_to[i]`. The `queries` array contains user numbers. For each `queries[i]`, report the number of users whose profiles are visible to user `queries[i]`. Input format Line 1: the integer `connection_nodes`. Line 2: the integer `connection_edges`. Line 3: `connection_edges` space-separated integers, the array `connection_from`. Line 4: `connection_edges` space-separated integers, the array `connection_to`. Line 5: the integer `q`, the number of queries. Line 6: `q` space-separated integers, the array `queries`. O