Codeforces Beta Round 88
E
Tree or not Tree
Codeforces
2900
原题
← D→
翻译中…

You are given an undirected connected graph $*G*$ consisting of $*n*$ vertexes and $*n*$ edges. $*G*$ contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off.

翻译中…

You are also given $*m*$ queries represented as $(*v*, *u*)$ — change the state of all edges on the shortest path from vertex $*v*$ to vertex $*u*$ in graph $*G*$. If there are several such paths, the lexicographically minimal one is chosen. More formally, let us consider all shortest paths from vertex $*v*$ to vertex $*u*$ as the sequences of vertexes $*v*, *v*_{1}, *v*_{2}, ..., *u*$. Among such sequences we choose the lexicographically minimal one.

翻译中…

After each query you should tell how many connected components has the graph whose vertexes coincide with the vertexes of graph $*G*$ and edges coincide with the switched on edges of graph $*G*$.

翻译中…

Input

翻译中…

The first line contains two integers $*n*$ and $*m*$ ($3 ≤ *n* ≤ 10^{5}$, $1 ≤ *m* ≤ 10^{5}$). Then $*n*$ lines describe the graph edges as $*a*$ $*b*$ ($1 ≤ *a*, *b* ≤ *n*$). Next $*m*$ lines contain the queries as $*v*$ $*u*$ ($1 ≤ *v*, *u* ≤ *n*$).

翻译中…

It is guaranteed that the graph is connected, does not have any self-loops or multiple edges.

翻译中…

Output

翻译中…

Print $*m*$ lines, each containing one integer — the query results.

翻译中…

Note

翻译中…

Let's consider the first sample. We'll highlight the switched on edges blue on the image.

翻译中…
  • The graph before applying any operations. No graph edges are switched on, that's why there initially are 5 connected components. image
  • The graph after query $*v* = 5, *u* = 4$. We can see that the graph has three components if we only consider the switched on edges. image
  • The graph after query $*v* = 1, *u* = 5$. We can see that the graph has three components if we only consider the switched on edges. image
翻译中…

Lexicographical comparison of two sequences of equal length of $*k*$ numbers should be done as follows. Sequence $*x*$ is lexicographically less than sequence $*y*$ if exists such $*i*$ ($1 ≤ *i* ≤ *k*$), so that $*x*_{*i*} < *y*_{*i*}$, and for any $*j*$ ($1 ≤ *j* < *i*$) $*x*_{*j*} = *y*_{*j*}$.

翻译中…

样例

Input #1
5 2
2 1
4 3
2 4
2 5
4 1
5 4
1 5
Output #1
3
3
InputCopy OutputCopy
Input #2
6 2
4 6
4 3
1 2
6 5
1 5
1 4
2 5
2 6
Output #2
4
3
InputCopy OutputCopy
题目信息
题号
117E
时间限制
5 s
内存限制
256 MB
标签
数据结构
分治
图论
模拟
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。