Count on the path
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 92 Accepted Submission(s): 10 Problem Description
bobo has a tree, whose vertices are conveniently labeled by 1,2,…,n. Let f(a,b) be the minimum of vertices not on the path between vertices a and b. There are q queries (u i,v i) for the value of f(u i,v i). Help bobo answer them.
Input
The input consists of several tests. For each tests: The first line contains 2 integers n,q (4≤n≤10 6,1≤q≤10 6). Each of the following (n - 1) lines contain 2 integers a i,b i denoting an edge between vertices a i and b i (1≤a i,b i≤n). Each of the following q lines contains 2 integer u′ i,v′ i (1≤u i,v i≤n). The queries are encrypted in the following manner. u 1=u′ 1,v 1=v′ 1. For i≥2, u i=u′ i⊕f(u i - 1,v i - 1),v i=v′ i⊕f(u i-1,v i-1). Note ⊕ denotes bitwise exclusive-or. It is guaranteed that f(a,b) is defined for all a,b. The task contains huge inputs. `scanf` in g++ is considered too slow to get accepted. You may (1) submit the solution in c++; or (2) use hand-written input utilities.
Output
For each tests: For each queries, a single number denotes the value.
Sample Input
4 1 1 2 1 3 1 4 2 3 5 2 1 2 1 3 2 4 2 5 1 2 7 6
Sample Output
4 3 1
Author
Xiaoxu Guo (ftiasch)
给定一棵树,求不经过路径的最小标号。
把1作为根,然后增加不经过1,那么答案直接为1,否则就是预处理,
数据规模非常大,所以仅仅能用bfs,而且须要加读写外挂,具体过程代码具体解释。
代码:
/* ***********************************************Author :rabbitCreated Time :2014/8/6 10:44:17File Name :5.cpp************************************************ */#pragma comment(linker, "/STACK:102400000,102400000")#include#include #include #include #include #include #include #include #include #include #include #include #include #include