#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef CB
freopen("be2.txt","r",stdin);
// freopen("ki.txt","w",stdout);
#endif
int N,M,K;
cin>>N>>M>>K;
vector<vector<int>>g(N+1);
for(int i=0;i<M;i++){
int a,b;
cin>>a>>b;
g[a].push_back(b);
g[b].push_back(a);
}
vector<int>v(N+1),w(N+1),p(N+1),a(N+1);
vector<vector<int>>c(N+1),cc;
auto dfs=[&](auto self,int i)->unordered_set<int>{
unordered_set<int>s;
w[i]=v[i];
for(int j:g[i]){
if(j==p[i]){
continue;
}
if(v[j]){
if(v[j]<v[i]){
w[i]=min(w[i],v[j]);
}
continue;
}
v[j]=v[i]+1;
p[j]=i;
auto z=self(self,j);
if(w[j]>=v[i]){
a[i]=1;
z.insert(i);
for(int k:z){
c[k].push_back(cc.size());
}
cc.emplace_back(z.begin(),z.end());
}
else{
w[i]=min(w[i],w[j]);
if(s.size()<z.size()){
swap(s,z);
}
s.insert(z.begin(),z.end());
}
}
s.insert(i);
return s;
};
v[1]=1;
dfs(dfs,1);
vector<vector<int>>q(N+1);
for(int i=0;i<K;i++){
int a,b;
cin>>a>>b;
q[a].push_back(i);
q[b].push_back(i);
}
vector<int>ans(K,-1);
auto dfs2=[&](auto self,int i,int p,int d)->unordered_map<int,int>{
unordered_map<int,int>s;
for(int x:q[i]){
s[x]=d;
}
for(int j:c[i]){
if(j==p){
continue;
}
int dd=d+cc[j].size()-1;
unordered_map<int,int>t;
for(int k:cc[j]){
if(k==i||!a[k]){
continue;
}
auto z=self(self,k,j,dd);
if(t.size()<z.size()){
swap(t,z);
}
for(auto[x,y]:z){
if(t.count(x)){
ans[x]=t[x]+y+cc[j].size()-dd*2;
t.erase(x);
}
else{
t[x]=y;
}
}
}
for(int k:cc[j]){
if(k==i||a[k]){
continue;
}
for(int x:q[k]){
if(t.count(x)){
ans[x]=t[x]+1;
t.erase(x);
}
else{
t[x]=dd;
}
}
}
if(s.size()<t.size()){
swap(s,t);
}
for(auto[x,y]:t){
if(s.count(x)){
ans[x]=s[x]+y+1-d*2;
s.erase(x);
}
else{
s[x]=y;
}
}
}
return s;
};
dfs2(dfs2,1,-1,0);
for(int i:ans){
cout<<i-2<<'\n';
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1832 KiB | ||||
2 | Accepted | 173ms | 44460 KiB | ||||
subtask2 | 15/15 | ||||||
3 | Accepted | 4ms | 2844 KiB | ||||
4 | Accepted | 4ms | 3456 KiB | ||||
5 | Accepted | 8ms | 6512 KiB | ||||
6 | Accepted | 14ms | 7320 KiB | ||||
7 | Accepted | 79ms | 24104 KiB | ||||
8 | Accepted | 180ms | 45340 KiB | ||||
subtask3 | 15/15 | ||||||
9 | Accepted | 4ms | 3948 KiB | ||||
10 | Accepted | 4ms | 4400 KiB | ||||
11 | Accepted | 8ms | 7036 KiB | ||||
12 | Accepted | 14ms | 8232 KiB | ||||
13 | Accepted | 85ms | 28296 KiB | ||||
14 | Accepted | 201ms | 53840 KiB | ||||
15 | Accepted | 391ms | 116528 KiB | ||||
subtask4 | 0/15 | ||||||
16 | Accepted | 6ms | 4708 KiB | ||||
17 | Wrong answer | 8ms | 5888 KiB | ||||
18 | Accepted | 14ms | 8632 KiB | ||||
19 | Accepted | 79ms | 25700 KiB | ||||
20 | Accepted | 192ms | 47064 KiB | ||||
subtask5 | 0/15 | ||||||
21 | Accepted | 3ms | 4884 KiB | ||||
22 | Wrong answer | 3ms | 5004 KiB | ||||
23 | Accepted | 4ms | 6064 KiB | ||||
24 | Wrong answer | 3ms | 5220 KiB | ||||
25 | Accepted | 4ms | 5464 KiB | ||||
26 | Accepted | 4ms | 5464 KiB | ||||
subtask6 | 0/40 | ||||||
27 | Accepted | 3ms | 5204 KiB | ||||
28 | Accepted | 174ms | 47592 KiB | ||||
29 | Accepted | 4ms | 2844 KiB | ||||
30 | Accepted | 4ms | 3456 KiB | ||||
31 | Accepted | 8ms | 6512 KiB | ||||
32 | Accepted | 14ms | 7320 KiB | ||||
33 | Accepted | 79ms | 24104 KiB | ||||
34 | Accepted | 180ms | 45340 KiB | ||||
35 | Accepted | 4ms | 3948 KiB | ||||
36 | Accepted | 4ms | 4400 KiB | ||||
37 | Accepted | 8ms | 7036 KiB | ||||
38 | Accepted | 14ms | 8232 KiB | ||||
39 | Accepted | 85ms | 28296 KiB | ||||
40 | Accepted | 201ms | 53840 KiB | ||||
41 | Accepted | 391ms | 116528 KiB | ||||
42 | Accepted | 6ms | 4708 KiB | ||||
43 | Wrong answer | 8ms | 5888 KiB | ||||
44 | Accepted | 14ms | 8632 KiB | ||||
45 | Accepted | 79ms | 25700 KiB | ||||
46 | Accepted | 192ms | 47064 KiB | ||||
47 | Accepted | 3ms | 4884 KiB | ||||
48 | Wrong answer | 3ms | 5004 KiB | ||||
49 | Accepted | 4ms | 6064 KiB | ||||
50 | Wrong answer | 3ms | 5220 KiB | ||||
51 | Accepted | 4ms | 5464 KiB | ||||
52 | Accepted | 4ms | 5464 KiB | ||||
53 | Accepted | 268ms | 120156 KiB | ||||
54 | Accepted | 6ms | 6148 KiB | ||||
55 | Accepted | 8ms | 9680 KiB | ||||
56 | Wrong answer | 19ms | 9656 KiB | ||||
57 | Wrong answer | 119ms | 28784 KiB | ||||
58 | Wrong answer | 97ms | 29960 KiB | ||||
59 | Accepted | 395ms | 142716 KiB | ||||
60 | Accepted | 254ms | 52396 KiB | ||||
61 | Wrong answer | 244ms | 53100 KiB | ||||
62 | Wrong answer | 250ms | 53692 KiB |