#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);
return 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>{
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;
}
}
}
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 | Runtime error | 3ms | 1976 KiB | ||||
2 | Runtime error | 158ms | 42528 KiB | ||||
subtask2 | 0/15 | ||||||
3 | Runtime error | 4ms | 2856 KiB | ||||
4 | Runtime error | 4ms | 3412 KiB | ||||
5 | Runtime error | 7ms | 5512 KiB | ||||
6 | Runtime error | 14ms | 6576 KiB | ||||
7 | Runtime error | 74ms | 22840 KiB | ||||
8 | Runtime error | 180ms | 43168 KiB | ||||
subtask3 | 0/15 | ||||||
9 | Runtime error | 4ms | 3460 KiB | ||||
10 | Runtime error | 4ms | 3928 KiB | ||||
11 | Runtime error | 7ms | 5944 KiB | ||||
12 | Runtime error | 12ms | 7252 KiB | ||||
13 | Runtime error | 56ms | 23904 KiB | ||||
14 | Runtime error | 134ms | 45016 KiB | ||||
15 | Runtime error | 145ms | 69204 KiB | ||||
subtask4 | 0/15 | ||||||
16 | Runtime error | 4ms | 4488 KiB | ||||
17 | Runtime error | 7ms | 5156 KiB | ||||
18 | Runtime error | 14ms | 7356 KiB | ||||
19 | Runtime error | 76ms | 23512 KiB | ||||
20 | Runtime error | 180ms | 43992 KiB | ||||
subtask5 | 0/15 | ||||||
21 | Runtime error | 3ms | 3516 KiB | ||||
22 | Runtime error | 3ms | 3872 KiB | ||||
23 | Runtime error | 4ms | 4664 KiB | ||||
24 | Runtime error | 3ms | 4004 KiB | ||||
25 | Runtime error | 4ms | 4368 KiB | ||||
26 | Runtime error | 4ms | 4232 KiB | ||||
subtask6 | 0/40 | ||||||
27 | Runtime error | 3ms | 3832 KiB | ||||
28 | Runtime error | 177ms | 44040 KiB | ||||
29 | Runtime error | 4ms | 2856 KiB | ||||
30 | Runtime error | 4ms | 3412 KiB | ||||
31 | Runtime error | 7ms | 5512 KiB | ||||
32 | Runtime error | 14ms | 6576 KiB | ||||
33 | Runtime error | 74ms | 22840 KiB | ||||
34 | Runtime error | 180ms | 43168 KiB | ||||
35 | Runtime error | 4ms | 3460 KiB | ||||
36 | Runtime error | 4ms | 3928 KiB | ||||
37 | Runtime error | 7ms | 5944 KiB | ||||
38 | Runtime error | 12ms | 7252 KiB | ||||
39 | Runtime error | 56ms | 23904 KiB | ||||
40 | Runtime error | 134ms | 45016 KiB | ||||
41 | Runtime error | 145ms | 69204 KiB | ||||
42 | Runtime error | 4ms | 4488 KiB | ||||
43 | Runtime error | 7ms | 5156 KiB | ||||
44 | Runtime error | 14ms | 7356 KiB | ||||
45 | Runtime error | 76ms | 23512 KiB | ||||
46 | Runtime error | 180ms | 43992 KiB | ||||
47 | Runtime error | 3ms | 3516 KiB | ||||
48 | Runtime error | 3ms | 3872 KiB | ||||
49 | Runtime error | 4ms | 4664 KiB | ||||
50 | Runtime error | 3ms | 4004 KiB | ||||
51 | Runtime error | 4ms | 4368 KiB | ||||
52 | Runtime error | 4ms | 4232 KiB | ||||
53 | Runtime error | 149ms | 76460 KiB | ||||
54 | Runtime error | 4ms | 4636 KiB | ||||
55 | Runtime error | 7ms | 6852 KiB | ||||
56 | Runtime error | 14ms | 8012 KiB | ||||
57 | Runtime error | 78ms | 24148 KiB | ||||
58 | Runtime error | 93ms | 27436 KiB | ||||
59 | Runtime error | 125ms | 84688 KiB | ||||
60 | Runtime error | 187ms | 44928 KiB | ||||
61 | Runtime error | 167ms | 42700 KiB | ||||
62 | Runtime error | 158ms | 42692 KiB |