PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#LCA0000082. Sửa cầu (Bridge Repairs)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Sửa cầu (Bridge Repairs)

Bridge Repairs

Source: VNOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Pirate lives on nn islands connected by n−1n-1 bridges forming a tree. On each of mm days he inspects every bridge on the unique route between islands aa and bb. Count bridges that were never inspected. Repeated inspection does not increase the number of inspected bridges.

Input

First line: nn. Next n−1n-1 lines: edges u,vu,v. Then mm, followed by mm pairs a,ba,b.

Output

Print one integer: the number of bridges never inspected.

Subtasks

  • Subtask 1 (20 points): 1≤n≤351\le n\le 35; 1≤m≤351\le m\le 35; 1≤u,v,a,b≤n1\le u,v,a,b\le n; edges form a tree.

  • Subtask 2 (30 points): 1≤n≤12001\le n\le 1200; 1≤m≤12001\le m\le 1200; 1≤u,v,a,b≤n1\le u,v,a,b\le n; edges form a tree.

  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 1≤m≤2000001\le m\le 200000; 1≤u,v,a,b≤n1\le u,v,a,b\le n; edges form a tree.

Examples

Input

6
1 2
2 3
2 4
4 5
4 6
2
3 6
5 6

Output

1

Explanation

The first journey inspects bridges 2−32-3, 2−42-4, 4−64-6; the second inspects 4−54-5, 4−64-6. Only bridge 1−21-2 remains uninspected.