HDU-6203 Ping Ping Ping LCA multiplier algorithm +dfs sequence + segment tree

Source: Internet
Author: User

Ping Ping Ping HDU-6203


The structure of the computer in Northeastern University is pretty miraculous. There is n servers, some servers connect to the gateway whose IP address is 0 directly. All servers is connected with each other by n netting twines. It is said the this structure are favorable for maintaining physical problem of servers.
But because of an unexpected rainstorm, the computer, is destroyed by a terrible thunderclap!
Our maintainer bittersweet found this many servers were not able to being visited, so he hurried to the computer Up the reason. After several hours, bittersweet realized the some net gape of servers were broken by Thunderclap. However, there were too many servers to find out all the broken net gapes quickly. So he came up with a idea to assess the damaged condition roughly. Bittersweet decided to turn on some servers and ping other servers randomly, then record the unsuccessful pairs of servers .
Now he need a program to analyze the record to confirm what's the minimum number of servers whose net gape was dest Royed by Thunderclap. Can you help him?
Inputthere is at the most test cases.
In each test case, the first line was an integer n (3≤n≤104, denoting the number of servers. The IP address of these servers is 1...N.
Then follows n lines, each line contains a integers u and V (0≤u,v≤n), denoting that the server wh The OSE IP address is U-connected with the server whose IP address was v by netting twine initially.
After those, there are one line contains only a integer p (p≤50000), denoting the number that bittersweet us Es Ping.
Then follows P lines, each line contains the integers u and V, denoting when using the server U to ping server V, it ret urned unsuccessful.
Outputa single integer xx in a line, denoting at least

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.