#B3765. Reachable Webpages in a LAN
Reachable Webpages in a LAN
Reachable Webpages in a LAN
In a local area network (LAN), there are \(N\) webpages, numbered from \(1\) to \(N\). Each webpage \(i\) contains \(T_i\) hyperlinks that point to webpages \(A_{i,1}, A_{i,2}, \dots, A_{i,T_i}\). Starting from webpage \(1\), determine how many distinct webpages can be reached by clicking at most two hyperlinks. Note that if no hyperlink is clicked, webpage 1 is still considered reachable.
inputFormat
The first line contains an integer \(N\) representing the number of webpages. Each of the following \(N\) lines describes a webpage. The \(i\)-th line starts with an integer \(T_i\) indicating the number of hyperlinks on webpage \(i\), followed by \(T_i\) integers \(A_{i,1}, A_{i,2}, \dots, A_{i,T_i}\) representing the webpages to which these hyperlinks point.
outputFormat
Output a single integer representing the total number of distinct webpages that can be reached from webpage 1 by clicking at most two hyperlinks.
sample
3
1 2
1 3
0
3
</p>