PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#LCA0000041. Tổ tiên chung nhanh với truy vấn sinh tự động (Fast Lowest Common Ancestor)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tổ tiên chung nhanh với truy vấn sinh tự động (Fast Lowest Common Ancestor)
Fast Lowest Common Ancestor
Source: VNOJ
Version: Phuoc Hung OJ Extended
Problem Statement
An undirected tree with vertices is rooted at vertex . Answer LCA queries, where the query vertices are generated from six parameters to reduce input size.
Initially . For , and . Write . Output only , where denotes bitwise XOR.
Do not output individual query answers; can be as large as .
Input
- First line: .
- Next lines: undirected edges .
- Last line: six values $u_{start},v_{start},u_{jump},v_{jump},u_{add},v_{add}$.
Output
Print one integer: the XOR of all query LCA results.
Subtasks
General constraints (all subtasks): ; ; ; .
- Subtask 1 (20 points): ; ; jump and add parameters do not exceed .
- Subtask 2 (30 points): ; ; jump and add parameters do not exceed .
- Subtask 3 (50 points): ; ; jump and add parameters do not exceed .
Examples
Input
3 2
1 2
1 3
3 3 1 1 1 1
Output
1
Explanation
The first query is with LCA . The second is with LCA . Their XOR is .