#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)->unordered_map<int,int>{
if(!a[i]){
exit(1);
}
unordered_map<int,int>s;
for(int x:q[i]){
s[x]=0;
}
for(int j:c[i]){
if(j==p){
continue;
}
unordered_map<int,int>t;
for(int k:cc[j]){
if(k==i||!a[k]){
continue;
}
auto z=self(self,k,j);
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();
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]+cc[j].size();
t.erase(x);
}
else{
t[x]=0;
}
}
}
if(s.size()<t.size()){
swap(s,t);
}
for(auto[x,y]:t){
if(s.count(x)){
ans[x]=s[x]+y+cc[j].size();
s.erase(x);
}
else{
s[x]=y+cc[j].size()-1;
}
}
}
return s;
};
dfs2(dfs2,1,-1);
for(int i:ans){
cout<<i-2<<'\n';
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Wrong answer | 3ms | 1828 KiB | ||||
2 | Wrong answer | 168ms | 44444 KiB | ||||
subtask2 | 0/15 | ||||||
3 | Accepted | 4ms | 2828 KiB | ||||
4 | Wrong answer | 4ms | 3524 KiB | ||||
5 | Wrong answer | 7ms | 6428 KiB | ||||
6 | Accepted | 14ms | 6976 KiB | ||||
7 | Accepted | 75ms | 23652 KiB | ||||
8 | Wrong answer | 178ms | 44672 KiB | ||||
subtask3 | 0/15 | ||||||
9 | Wrong answer | 4ms | 3392 KiB | ||||
10 | Wrong answer | 4ms | 3984 KiB | ||||
11 | Wrong answer | 8ms | 6604 KiB | ||||
12 | Wrong answer | 14ms | 7692 KiB | ||||
13 | Wrong answer | 78ms | 28100 KiB | ||||
14 | Wrong answer | 199ms | 53600 KiB | ||||
15 | Wrong answer | 317ms | 113340 KiB | ||||
subtask4 | 0/15 | ||||||
16 | Wrong answer | 6ms | 4556 KiB | ||||
17 | Wrong answer | 8ms | 5424 KiB | ||||
18 | Wrong answer | 16ms | 8228 KiB | ||||
19 | Wrong answer | 82ms | 24988 KiB | ||||
20 | Wrong answer | 172ms | 46424 KiB | ||||
subtask5 | 0/15 | ||||||
21 | Accepted | 3ms | 4496 KiB | ||||
22 | Wrong answer | 3ms | 4628 KiB | ||||
23 | Wrong answer | 4ms | 5616 KiB | ||||
24 | Wrong answer | 3ms | 4776 KiB | ||||
25 | Wrong answer | 4ms | 5016 KiB | ||||
26 | Wrong answer | 4ms | 5124 KiB | ||||
subtask6 | 0/40 | ||||||
27 | Wrong answer | 3ms | 4684 KiB | ||||
28 | Wrong answer | 189ms | 46840 KiB | ||||
29 | Accepted | 4ms | 2828 KiB | ||||
30 | Wrong answer | 4ms | 3524 KiB | ||||
31 | Wrong answer | 7ms | 6428 KiB | ||||
32 | Accepted | 14ms | 6976 KiB | ||||
33 | Accepted | 75ms | 23652 KiB | ||||
34 | Wrong answer | 178ms | 44672 KiB | ||||
35 | Wrong answer | 4ms | 3392 KiB | ||||
36 | Wrong answer | 4ms | 3984 KiB | ||||
37 | Wrong answer | 8ms | 6604 KiB | ||||
38 | Wrong answer | 14ms | 7692 KiB | ||||
39 | Wrong answer | 78ms | 28100 KiB | ||||
40 | Wrong answer | 199ms | 53600 KiB | ||||
41 | Wrong answer | 317ms | 113340 KiB | ||||
42 | Wrong answer | 6ms | 4556 KiB | ||||
43 | Wrong answer | 8ms | 5424 KiB | ||||
44 | Wrong answer | 16ms | 8228 KiB | ||||
45 | Wrong answer | 82ms | 24988 KiB | ||||
46 | Wrong answer | 172ms | 46424 KiB | ||||
47 | Accepted | 3ms | 4496 KiB | ||||
48 | Wrong answer | 3ms | 4628 KiB | ||||
49 | Wrong answer | 4ms | 5616 KiB | ||||
50 | Wrong answer | 3ms | 4776 KiB | ||||
51 | Wrong answer | 4ms | 5016 KiB | ||||
52 | Wrong answer | 4ms | 5124 KiB | ||||
53 | Wrong answer | 314ms | 115764 KiB | ||||
54 | Wrong answer | 6ms | 5440 KiB | ||||
55 | Wrong answer | 8ms | 8720 KiB | ||||
56 | Accepted | 19ms | 9000 KiB | ||||
57 | Wrong answer | 116ms | 28268 KiB | ||||
58 | Wrong answer | 97ms | 29436 KiB | ||||
59 | Wrong answer | 384ms | 137120 KiB | ||||
60 | Wrong answer | 252ms | 51776 KiB | ||||
61 | Wrong answer | 241ms | 52640 KiB | ||||
62 | Wrong answer | 275ms | 53044 KiB |