Airline

아직 제출이 없습니다시간 제한15초메모리 제한512 MB

문제

An airline company offers regular flights involving nn different airports. Each flight links two airports directly (i.e. without stopping at any other airport) and allows travel in both directions. The flights are arranged such that for any choice of starting airport ss and destination airport tt, there exists exactly one sequence of flights between the two airports without visiting any airport more than once. The number of flights in this sequence is called the distance between ss and tt.

Were the airline to add another flight, say between airports xx and yy, it is possible that for some pairs (s,t)(s, t), another, shorter sequence of flights from ss to tt would form. The more pairs affected, the more promising the new connection between xx and yy is considered to be. The airline is asking you to help them evaluate several possible additions (x,y)(x, y) with respect to this criterion.

입력

The first line contains two integers, nn, the number of airports, and qq, the number of possible additions (x,y)(x, y) that are to be evaluated.

The next n1n-1 lines describe the original flights before any additions. The ii-th of these lines contains two integers u_iu\_i and v_iv\_i, indicating that there is a direct flight connection between airports u_iu\_i and v_iv\_i.

The remaining qq lines describe the possible additional flights that are being considered. The ii-th of these lines contains two integers x_ix\_i and y_iy\_i, indicating that in the ii-th scenario the original n1n-1 flights would be supplemented by a new direct flight connection between airports x_ix\_i and y_iy\_i .

출력

Output qq lines; in the ii-th line, output the number of pairs (s,t)(s, t) such that 1s<tn1 ≤ s < t ≤ n and the distance between airports ss and tt would decrease if the original network of n1n - 1 flights were supplemented by a direct flight connection between the airports x_ix\_i and y_iy\_i .

제한

  • 2n1062 ≤ n ≤ 10^6
  • 1q1051 ≤ q ≤ 10^5
  • 1u_in1 ≤ u\_i ≤ n; 1v_in1 ≤ v\_i ≤ n; u_iv_iu\_i \ne v\_i
  • 1x_in1 ≤ x\_i ≤ n; 1y_in1 ≤ y\_i ≤ n; x_iy_ix\_i \ne y\_i
  • _i=1qd_i107\sum\_{i=1}^{q}{d\_i} ≤ 10^7, where d_id\_i is the distance between x_ix\_i and y_iy\_i in the original flight network.