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

#FW0000043. Kiểm tra tập đỉnh trắc địa (The Geodetic Set Problem)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Kiểm tra tập đỉnh trắc địa (The Geodetic Set Problem)

The Geodetic Set Problem

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

A set DD is geodetic in an unweighted connected undirected graph when every vertex lies on some shortest path between two vertices of DD. Answer subset queries.

Input

Integer nn, followed by nn adjacency-list lines for vertices 11 through nn (possibly empty), then qq and qq lines each listing a nonempty vertex subset.

Output

Print yes for every geodetic query set and no otherwise.

Subtasks

  • Subtask 1 (40 points): n≤10n\le10; 2≤n≤402\le n\le40, 1≤q≤301\le q\le30; connected simple undirected graph; each subset is nonempty and contains no repeated vertex.
  • Subtask 2 (60 points): 2≤n≤402\le n\le40, 1≤q≤301\le q\le30; connected simple undirected graph; each subset is nonempty and contains no repeated vertex.

Examples

Input

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

Output

yes
no
no

Explanation

The set {1,2,5} covers all vertices through shortest paths between selected endpoints; the other two proposed sets leave at least one vertex uncovered.