#C9650. Web Crawl Simulation
Web Crawl Simulation
Web Crawl Simulation
You are given a directed graph representing a collection of web pages, where each page is associated with a keyword count. The graph has ( n ) pages and ( m ) directed edges (hyperlinks). Starting from a designated page ( s ), perform a Breadth-First Search (BFS) to simulate a web crawling process. As you visit pages, accumulate the keyword counts found on them. The task is to output two numbers: the total number of distinct pages visited and the sum of keyword counts on those pages.
Formally, if the pages are numbered from 1 to ( n ) and the keyword counts are given by ( k = [k_1, k_2, \ldots, k_n] ), then starting from page ( s ), determine the pair ((P, K)) where (P) is the number of pages reached and (K) is the sum of the keyword counts from these pages.
inputFormat
The input is read from standard input and formatted as follows:
- The first line contains two integers ( n ) and ( m ) representing the number of pages and the number of directed edges, respectively.
- The following ( m ) lines each contain two integers ( u ) and ( v ), indicating a directed edge from page ( u ) to page ( v ).
- The next line contains a single integer ( s ), the starting page for the crawl.
- The last line contains ( n ) space-separated integers, where the ( i^{th} ) integer is the keyword count on page ( i ).
outputFormat
Output two space-separated integers to standard output: the number of distinct pages visited by the crawler and the total sum of the keyword counts from those pages.## sample
4 4
1 2
1 3
2 4
3 4
1
1 2 3 4
4 10