F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

mustedge mustedge mustedge

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1165    Accepted Submission(s): 268


Problem Description
Give an connected undirected graph with $n$ nodes and $m$ edges, ($n,m\leq 10^5$) which has no selfloops or multiple edges $initially$.
Now we have $q$ operations ($q\leq 10^5$):
  
$\cdot 1\ u\ v$: add an undirected edge from $u$ to $v$; $(u \neq v\&\& 1 \leq u,v \leq n)$
$\cdot 2\ u\ v$: count the number of $mustedges$ from $u$ to $v$; $(1 \leq u,v \leq n)$.

$mustedge$: we define set $E_i$ as a path from $u$ to $v$ which contain edges in this path, and $| \cap_1^kE_i |$ is the number of $mustedges$. $| x |$ means size of set $x$, and $E_1, E_2\dots E_k$ means all the paths.
It's guaranteed that $\sum{n},\sum{m},\sum{q}\leq 10^6$
Please note that maybe there are more than one edges between two nodes after we add edges. They are not the same, which means they can be in a set at the same time. Read the sample data for more information.
 

Input
Input starts with an integer $T$, denoting the number of test cases.
For each case:
First line are two number $n$ and $m$;
Then next $m$ lines, each contains two integers $u$ and $v$, which indicates an undirected edge from $u$ to $v$;
Next line contains a number $q$, the number of operations;
Then next $q$ lines, contains three integers $x$, $u$ and $v$ where $x$ is the operation type, which describes an operation.

 

Output
For each test case, output "Case #x:" where $x$ is the test case number starting from 1.
In each test case, print a single number one line when query the number of $mustedges$.
 

Sample Input
2 4 3 1 2 2 3 3 4 5 2 1 4 1 2 3 2 1 4 2 2 3 2 2 4 8 9 1 2 2 3 1 3 3 4 4 5 4 6 5 7 5 8 7 8 5 2 7 8 2 1 6 2 4 7 1 6 8 2 5 6
 

Sample Output
Case #1: 3 2 0 1 Case #2: 0 2 1 0
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-21 22:35:19, Gzip enabled