#include <bits/stdc++.h>
using namespace std;
const int c=3e5+5;
const int ce=1e6+6;
int n,m,q,tt,K;
vector<int> adj[c];
bool volt[ce], vis[c];
int vag[c], t[c], l[c], cnt[c], dep[c];
int mp[c];
vector<vector<int>> comp;
vector<pair<int,int>> s;
vector<int> tree[c];
void dfs(int v, int p){
t[v]=l[v]=++tt;
int vag1=0;
for(int x:adj[v]){
if(x==p) continue;
if(!t[x]){
vag1++;
s.push_back(make_pair(v,x));
dfs(x,v);
l[v]=min(l[v],l[x]);
if(l[x]>=t[v] && p){
if(!vag[v]) vag[v]=++K;
comp.push_back(vector<int>());
while(!s.empty()){
int a=s.back().first,b=s.back().second;
comp.back().push_back(a);
comp.back().push_back(b);
s.pop_back();
if(a==v) break;
}
}
if(!p){
comp.push_back(vector<int>());
while(!s.empty()){
comp.back().push_back(s.back().first);
comp.back().push_back(s.back().second);
s.pop_back();
}
}
}
else l[v]=min(l[v],t[x]);
}
if(vag1>1 && !p) vag[1]=++K;
}
void build(){
for(int i=1;i<=n;i++){
if(vag[i]) {mp[i]=vag[i]+comp.size(); cnt[mp[i]]=-1;}
}
for(int i=0;i<comp.size();i++){
vector<int> cut;
sort(comp[i].begin(),comp[i].end());
comp[i].resize(unique(comp[i].begin(),comp[i].end())-comp[i].begin());
cnt[i+1]=comp[i].size();
for(int x:comp[i])
{
if(!vag[x]) mp[x]=i+1;
else {
cut.push_back(x);
tree[i+1].push_back(mp[x]);
tree[mp[x]].push_back(i+1);
}
}
}
}
int up[c][19];
int sum[c][19];
void dfs2(int v, int p){
up[v][0]=p;
sum[v][0]=cnt[v];
for(int i=1;i<19;i++){
int x = up[v][i-1];
up[v][i]=up[x][i-1];
sum[v][i]=sum[v][i-1]+sum[x][i-1];
}
for(int x:tree[v]){
if(x != p){
dep[x]=dep[v]+1;
dfs2(x,v);
}
}
}
int query(int a, int b){
int res=(vag[a]>0) + (vag[b]>0);
a=mp[a], b=mp[b];
if(dep[a]>dep[b]) swap(a,b);
int k=dep[b]-dep[a];
for(int i=18;i>=0;i--){
if((k>>i)&1){
res+=sum[b][i];
b=up[b][i];
}
}
if(a==b){
res+=sum[a][0];
return res;
}
for(int i=18;i>=0;i--){
if(up[a][i] != up[b][i]){
res+=sum[a][i]+sum[b][i];
a=up[a][i], b=up[b][i];
}
}
res+=sum[up[a][0]][0];
return res;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m>>q;
for(int i=1;i<=m;i++){
int a,b; cin>>a>>b;
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(1,0);
build();
dfs2(1,0);
while(q--){
int a,b; cin>>a>>b;
cout << query(a,b)-2 << '\n';
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 13ms | 30280 KiB | ||||
2 | Wrong answer | 103ms | 44936 KiB | ||||
subtask2 | 15/15 | ||||||
3 | Accepted | 14ms | 30816 KiB | ||||
4 | Accepted | 14ms | 31144 KiB | ||||
5 | Accepted | 21ms | 35784 KiB | ||||
6 | Accepted | 21ms | 33224 KiB | ||||
7 | Accepted | 54ms | 38336 KiB | ||||
8 | Accepted | 100ms | 45888 KiB | ||||
subtask3 | 0/15 | ||||||
9 | Wrong answer | 14ms | 32260 KiB | ||||
10 | Wrong answer | 17ms | 33248 KiB | ||||
11 | Accepted | 19ms | 36512 KiB | ||||
12 | Wrong answer | 28ms | 39508 KiB | ||||
13 | Wrong answer | 81ms | 70280 KiB | ||||
14 | Wrong answer | 177ms | 109004 KiB | ||||
15 | Accepted | 328ms | 153568 KiB | ||||
subtask4 | 0/15 | ||||||
16 | Wrong answer | 17ms | 32784 KiB | ||||
17 | Wrong answer | 17ms | 33364 KiB | ||||
18 | Wrong answer | 20ms | 34480 KiB | ||||
19 | Wrong answer | 61ms | 40144 KiB | ||||
20 | Wrong answer | 105ms | 46964 KiB | ||||
subtask5 | 0/15 | ||||||
21 | Accepted | 13ms | 32828 KiB | ||||
22 | Accepted | 14ms | 32740 KiB | ||||
23 | Accepted | 14ms | 33872 KiB | ||||
24 | Wrong answer | 13ms | 32804 KiB | ||||
25 | Wrong answer | 16ms | 32952 KiB | ||||
26 | Wrong answer | 14ms | 32836 KiB | ||||
subtask6 | 0/40 | ||||||
27 | Accepted | 13ms | 32596 KiB | ||||
28 | Wrong answer | 103ms | 47072 KiB | ||||
29 | Accepted | 14ms | 30816 KiB | ||||
30 | Accepted | 14ms | 31144 KiB | ||||
31 | Accepted | 21ms | 35784 KiB | ||||
32 | Accepted | 21ms | 33224 KiB | ||||
33 | Accepted | 54ms | 38336 KiB | ||||
34 | Accepted | 100ms | 45888 KiB | ||||
35 | Wrong answer | 14ms | 32260 KiB | ||||
36 | Wrong answer | 17ms | 33248 KiB | ||||
37 | Accepted | 19ms | 36512 KiB | ||||
38 | Wrong answer | 28ms | 39508 KiB | ||||
39 | Wrong answer | 81ms | 70280 KiB | ||||
40 | Wrong answer | 177ms | 109004 KiB | ||||
41 | Accepted | 328ms | 153568 KiB | ||||
42 | Wrong answer | 17ms | 32784 KiB | ||||
43 | Wrong answer | 17ms | 33364 KiB | ||||
44 | Wrong answer | 20ms | 34480 KiB | ||||
45 | Wrong answer | 61ms | 40144 KiB | ||||
46 | Wrong answer | 105ms | 46964 KiB | ||||
47 | Accepted | 13ms | 32828 KiB | ||||
48 | Accepted | 14ms | 32740 KiB | ||||
49 | Accepted | 14ms | 33872 KiB | ||||
50 | Wrong answer | 13ms | 32804 KiB | ||||
51 | Wrong answer | 16ms | 32952 KiB | ||||
52 | Wrong answer | 14ms | 32836 KiB | ||||
53 | Accepted | 296ms | 153920 KiB | ||||
54 | Wrong answer | 17ms | 33132 KiB | ||||
55 | Accepted | 19ms | 37652 KiB | ||||
56 | Wrong answer | 24ms | 34812 KiB | ||||
57 | Wrong answer | 71ms | 40204 KiB | ||||
58 | Wrong answer | 65ms | 41856 KiB | ||||
59 | Accepted | 277ms | 154420 KiB | ||||
60 | Accepted | 134ms | 46024 KiB | ||||
61 | Wrong answer | 136ms | 48248 KiB | ||||
62 | Wrong answer | 137ms | 49576 KiB |