#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g, comp, g2;
vector<int> t, l;
vector<bool> c;
stack<int> s;
int tim = 0, k = 0;
void dfs(int v, int pa)
{
t[v] = l[v] = ++tim;
s.push(v);
for(auto x : g[v])
{
if(x == pa) continue;
if(t[x] == 0)
{
dfs(x, v);
l[v] = min(l[v], l[x]);
if(l[x] < t[v]) continue;
//cout << x << "\n";
if(t[v] != 1 || t[x] != 2) c[v] = 1;
comp.push_back({});
comp[k].push_back(v);
while(s.top() != x)
{
comp[k].push_back(s.top());
s.pop();
}
comp[k].push_back(x);
s.pop();
k++;
}
else l[v] = min(l[v], t[x]);
}
}
vector<int> pref, d;
vector<vector<int> > p;
void dfs2(int v, int pa)
{
d[v] = d[pa] + 1;
p[v][0] = pa;
pref[v] = pref[pa] + (v >= k ? -1 : comp[v].size());
for(int j = 1; j < 20; j++)
{
p[v][j] = p[p[v][j - 1]][j - 1];
}
for(auto x : g2[v])
{
if(x == pa) continue;
dfs2(x, v);
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
g.resize(n + 1);
t.resize(n + 1);
l.resize(n + 1);
c.resize(n + 1);
for(int i = 0; i < m; i++)
{
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
dfs(1, 0);
g2.resize(2 * n + 1);
vector<int> ind(n + 1);
vector<int> id(n + 1);
int z = k;
for(int i = 1; i <= n; i++)
{
if(c[i]) ind[i] = z++, id[i] = ind[i];
}
for(int i = 0; i < k; i++)
{
for(auto x : comp[i])
{
if(c[x])
{
int pos = ind[x];
g2[pos].push_back(i);
g2[i].push_back(pos);
}
else id[x] = i;
}
}
pref.resize(2 * n + 1);
d.resize(2 * n + 1);
p.resize(2 * n + 1, vector<int>(20));
dfs2(0, z);
while(q--)
{
int x, y;
cin >> x >> y;
int ans = 0;
if(!c[x]) ans--;
if(!c[y]) ans--;
x = id[x];
y = id[y];
ans += pref[x] + pref[y];
if(d[y] < d[x]) swap(x, y);
int diff = d[y] - d[x];
for(int j = 0; j < 20; j++)
{
if((diff >> j) & 1)
{
y = p[y][j];
}
}
for(int j = 19; j >= 0; j--)
{
if(p[x][j] != p[y][j])
{
x = p[x][j];
y = p[y][j];
}
}
if(x != y)
{
x = p[x][0];
}
ans -= pref[x];
ans -= pref[p[x][0]];
cout << ans << "\n";
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 2ms | 360 KiB | ||||
2 | Accepted | 112ms | 38260 KiB | ||||
subtask2 | 15/15 | ||||||
3 | Accepted | 4ms | 892 KiB | ||||
4 | Accepted | 4ms | 1252 KiB | ||||
5 | Accepted | 8ms | 2916 KiB | ||||
6 | Accepted | 12ms | 4232 KiB | ||||
7 | Accepted | 54ms | 19316 KiB | ||||
8 | Accepted | 101ms | 38140 KiB | ||||
subtask3 | 15/15 | ||||||
9 | Accepted | 4ms | 1004 KiB | ||||
10 | Accepted | 6ms | 1268 KiB | ||||
11 | Accepted | 8ms | 2956 KiB | ||||
12 | Accepted | 17ms | 5196 KiB | ||||
13 | Accepted | 96ms | 23904 KiB | ||||
14 | Accepted | 189ms | 47588 KiB | ||||
15 | Accepted | 375ms | 59924 KiB | ||||
subtask4 | 15/15 | ||||||
16 | Accepted | 4ms | 1272 KiB | ||||
17 | Accepted | 7ms | 2096 KiB | ||||
18 | Accepted | 13ms | 4320 KiB | ||||
19 | Accepted | 52ms | 19296 KiB | ||||
20 | Accepted | 122ms | 38264 KiB | ||||
subtask5 | 15/15 | ||||||
21 | Accepted | 3ms | 360 KiB | ||||
22 | Accepted | 3ms | 484 KiB | ||||
23 | Accepted | 4ms | 1124 KiB | ||||
24 | Accepted | 3ms | 612 KiB | ||||
25 | Accepted | 4ms | 784 KiB | ||||
26 | Accepted | 3ms | 888 KiB | ||||
subtask6 | 40/40 | ||||||
27 | Accepted | 3ms | 496 KiB | ||||
28 | Accepted | 130ms | 38324 KiB | ||||
29 | Accepted | 4ms | 892 KiB | ||||
30 | Accepted | 4ms | 1252 KiB | ||||
31 | Accepted | 8ms | 2916 KiB | ||||
32 | Accepted | 12ms | 4232 KiB | ||||
33 | Accepted | 54ms | 19316 KiB | ||||
34 | Accepted | 101ms | 38140 KiB | ||||
35 | Accepted | 4ms | 1004 KiB | ||||
36 | Accepted | 6ms | 1268 KiB | ||||
37 | Accepted | 8ms | 2956 KiB | ||||
38 | Accepted | 17ms | 5196 KiB | ||||
39 | Accepted | 96ms | 23904 KiB | ||||
40 | Accepted | 189ms | 47588 KiB | ||||
41 | Accepted | 375ms | 59924 KiB | ||||
42 | Accepted | 4ms | 1272 KiB | ||||
43 | Accepted | 7ms | 2096 KiB | ||||
44 | Accepted | 13ms | 4320 KiB | ||||
45 | Accepted | 52ms | 19296 KiB | ||||
46 | Accepted | 122ms | 38264 KiB | ||||
47 | Accepted | 3ms | 360 KiB | ||||
48 | Accepted | 3ms | 484 KiB | ||||
49 | Accepted | 4ms | 1124 KiB | ||||
50 | Accepted | 3ms | 612 KiB | ||||
51 | Accepted | 4ms | 784 KiB | ||||
52 | Accepted | 3ms | 888 KiB | ||||
53 | Accepted | 358ms | 59632 KiB | ||||
54 | Accepted | 4ms | 1124 KiB | ||||
55 | Accepted | 8ms | 2860 KiB | ||||
56 | Accepted | 16ms | 4336 KiB | ||||
57 | Accepted | 75ms | 19552 KiB | ||||
58 | Accepted | 71ms | 23304 KiB | ||||
59 | Accepted | 444ms | 62612 KiB | ||||
60 | Accepted | 156ms | 38620 KiB | ||||
61 | Accepted | 158ms | 39156 KiB | ||||
62 | Accepted | 172ms | 39176 KiB |