#include <bits/stdc++.h>
using namespace std;
using ll=long long;
void solve();
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int t=1;
//cin>>t;
while (t--) solve();
}
const int maxn=4e5+1;
int n,m,k;
vector<vector<int>> g(maxn);
vector<int> t(maxn, -1),l(maxn, -1);
vector<bool> vis(maxn,false);
int timer=0;
stack<int> st;
vector<vector<int>> comps;
vector<int> art(maxn);
vector<int> comp(maxn,-1);
void dfs(int v, int p=-1){
t[v]=l[v]=++timer;
vis[v]=true;
st.push(v);
for (int to : g[v]){
if (p==to) continue;
if (vis[to]){
l[v]=min(l[v], t[to]);
}
else {
dfs(to, v);
l[v]=min(l[v], l[to]);
if (l[to]>=t[v]){
art[v]= (t[v]>1 || t[to]>2);
comps.push_back({v});
comp[v]=comps.size()-1;
while (comps.back().back()!=to){
comps.back().push_back(st.top());
comp[st.top()]=comps.size()-1;
st.pop();
}
}
}
}
}
vector<bool> bctvis(maxn,false);
vector<vector<int>> bctg(maxn);
void bct(int v){
bctvis[v]=true;
if (comps[v].size()==1){
for (int to : g[comps[v][0]]){
if (!bctvis[comp[to]]) bct(comp[to]);
}
}else {
for (int node : comps[v]){
if (art[node]){
bctg[v].push_back(comp[node]);
if (!bctvis[comp[node]]) bct(comp[node]);
}
}
}
}
vector<int> pr(maxn,1);
vector<vector<int>> binary(maxn, vector<int> (20, 0));
vector<int> layer(maxn, -1);
void pref(int v, int p=-1){
pr[v]=pr[max(p,0)]-1+comps[v].size();
layer[v]=layer[max(p,0)]+1;
if (p!=-1){
binary[v][0]=p;
for (int i=1;i<20;i++){
binary[v][i]=binary[binary[v][i-1]][i-1];
}
}
for (int to : bctg[v]){
if (to==p) continue;
pref(to,v);
}
}
int lca(int a,int b){
if (layer[a]<layer[b]) swap(a,b);
if (layer[a]>layer[b]){
for (int i=19;i>=0;i--){
int c=binary[a][i];
if (layer[c]<=layer[b]) continue;
a=c;
}
a=binary[a][0];
}
if (a==b) return a;
for (int i=19;i>=0;i--){
int c=binary[a][i];
int d=binary[b][i];
if (c==d) continue;
a=c;
b=d;
}
return binary[a][0];
}
void solve(){
cin>>n>>m>>k;
for (int i = 0; i < m; i++)
{
int a,b;
cin>>a>>b;
g[a].push_back(b);
g[b].push_back(a);
}
dfs(1);
for (int i=1;i<=n;i++){
if (art[i]){
comps.push_back({i});
comp[i]=comps.size()-1;
}
}
for (int i=0;i<comps.size();i++){
if (comps[i].size()==1) continue;
for (int j : comps[i]){
if (art[j]) bctg[comp[j]].push_back(i);
}
}
bct(0);
pref(0);
for (int i = 0; i < k; i++)
{
int a,b;
cin>>a>>b;
a=comp[a];
b=comp[b];
int c = lca(a,b);
cout<<pr[a]+pr[b]-2*pr[c]+comps[c].size()-2<<"\n";
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 71ms | 75620 KiB | ||||
2 | Wrong answer | 152ms | 80224 KiB | ||||
subtask2 | 0/15 | ||||||
3 | Accepted | 75ms | 75752 KiB | ||||
4 | Wrong answer | 90ms | 75784 KiB | ||||
5 | Wrong answer | 76ms | 76588 KiB | ||||
6 | Accepted | 104ms | 76252 KiB | ||||
7 | Accepted | 130ms | 78072 KiB | ||||
8 | Accepted | 177ms | 80184 KiB | ||||
subtask3 | 0/15 | ||||||
9 | Wrong answer | 75ms | 76024 KiB | ||||
10 | Wrong answer | 82ms | 75900 KiB | ||||
11 | Wrong answer | 78ms | 76648 KiB | ||||
12 | Wrong answer | 82ms | 77152 KiB | ||||
13 | Wrong answer | 159ms | 83220 KiB | ||||
14 | Wrong answer | 264ms | 90764 KiB | ||||
15 | Wrong answer | 270ms | 101404 KiB | ||||
subtask4 | 0/15 | ||||||
16 | Wrong answer | 93ms | 76044 KiB | ||||
17 | Wrong answer | 101ms | 75908 KiB | ||||
18 | Wrong answer | 90ms | 76264 KiB | ||||
19 | Accepted | 136ms | 78052 KiB | ||||
20 | Wrong answer | 160ms | 80392 KiB | ||||
subtask5 | 0/15 | ||||||
21 | Accepted | 75ms | 75676 KiB | ||||
22 | Accepted | 90ms | 75620 KiB | ||||
23 | Wrong answer | 75ms | 75876 KiB | ||||
24 | Wrong answer | 82ms | 75636 KiB | ||||
25 | Wrong answer | 89ms | 75748 KiB | ||||
26 | Wrong answer | 75ms | 75748 KiB | ||||
subtask6 | 0/40 | ||||||
27 | Accepted | 75ms | 75620 KiB | ||||
28 | Wrong answer | 202ms | 80256 KiB | ||||
29 | Accepted | 75ms | 75752 KiB | ||||
30 | Wrong answer | 90ms | 75784 KiB | ||||
31 | Wrong answer | 76ms | 76588 KiB | ||||
32 | Accepted | 104ms | 76252 KiB | ||||
33 | Accepted | 130ms | 78072 KiB | ||||
34 | Accepted | 177ms | 80184 KiB | ||||
35 | Wrong answer | 75ms | 76024 KiB | ||||
36 | Wrong answer | 82ms | 75900 KiB | ||||
37 | Wrong answer | 78ms | 76648 KiB | ||||
38 | Wrong answer | 82ms | 77152 KiB | ||||
39 | Wrong answer | 159ms | 83220 KiB | ||||
40 | Wrong answer | 264ms | 90764 KiB | ||||
41 | Wrong answer | 270ms | 101404 KiB | ||||
42 | Wrong answer | 93ms | 76044 KiB | ||||
43 | Wrong answer | 101ms | 75908 KiB | ||||
44 | Wrong answer | 90ms | 76264 KiB | ||||
45 | Accepted | 136ms | 78052 KiB | ||||
46 | Wrong answer | 160ms | 80392 KiB | ||||
47 | Accepted | 75ms | 75676 KiB | ||||
48 | Accepted | 90ms | 75620 KiB | ||||
49 | Wrong answer | 75ms | 75876 KiB | ||||
50 | Wrong answer | 82ms | 75636 KiB | ||||
51 | Wrong answer | 89ms | 75748 KiB | ||||
52 | Wrong answer | 75ms | 75748 KiB | ||||
53 | Wrong answer | 333ms | 101064 KiB | ||||
54 | Wrong answer | 76ms | 75880 KiB | ||||
55 | Wrong answer | 79ms | 76644 KiB | ||||
56 | Wrong answer | 90ms | 76260 KiB | ||||
57 | Wrong answer | 136ms | 78224 KiB | ||||
58 | Wrong answer | 153ms | 78536 KiB | ||||
59 | Wrong answer | 300ms | 103628 KiB | ||||
60 | Wrong answer | 197ms | 80680 KiB | ||||
61 | Wrong answer | 208ms | 80868 KiB | ||||
62 | Wrong answer | 193ms | 80920 KiB |