#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(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(n + 1);
p.resize(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 | 3ms | 632 KiB | ||||
2 | Accepted | 101ms | 25780 KiB | ||||
subtask2 | 0/15 | ||||||
3 | Accepted | 3ms | 612 KiB | ||||
4 | Accepted | 4ms | 868 KiB | ||||
5 | Runtime error | 4ms | 1604 KiB | ||||
6 | Accepted | 10ms | 2916 KiB | ||||
7 | Accepted | 43ms | 13152 KiB | ||||
8 | Accepted | 93ms | 25468 KiB | ||||
subtask3 | 0/15 | ||||||
9 | Runtime error | 3ms | 880 KiB | ||||
10 | Runtime error | 4ms | 916 KiB | ||||
11 | Runtime error | 6ms | 1656 KiB | ||||
12 | Runtime error | 8ms | 2224 KiB | ||||
13 | Runtime error | 32ms | 8728 KiB | ||||
14 | Runtime error | 76ms | 16900 KiB | ||||
15 | Runtime error | 78ms | 24772 KiB | ||||
subtask4 | 15/15 | ||||||
16 | Accepted | 4ms | 1036 KiB | ||||
17 | Accepted | 6ms | 1508 KiB | ||||
18 | Accepted | 10ms | 3200 KiB | ||||
19 | Accepted | 46ms | 12956 KiB | ||||
20 | Accepted | 100ms | 25696 KiB | ||||
subtask5 | 0/15 | ||||||
21 | Accepted | 3ms | 632 KiB | ||||
22 | Accepted | 3ms | 540 KiB | ||||
23 | Runtime error | 3ms | 1036 KiB | ||||
24 | Accepted | 3ms | 784 KiB | ||||
25 | Accepted | 3ms | 620 KiB | ||||
26 | Accepted | 3ms | 760 KiB | ||||
subtask6 | 0/40 | ||||||
27 | Accepted | 2ms | 356 KiB | ||||
28 | Accepted | 97ms | 23712 KiB | ||||
29 | Accepted | 3ms | 612 KiB | ||||
30 | Accepted | 4ms | 868 KiB | ||||
31 | Runtime error | 4ms | 1604 KiB | ||||
32 | Accepted | 10ms | 2916 KiB | ||||
33 | Accepted | 43ms | 13152 KiB | ||||
34 | Accepted | 93ms | 25468 KiB | ||||
35 | Runtime error | 3ms | 880 KiB | ||||
36 | Runtime error | 4ms | 916 KiB | ||||
37 | Runtime error | 6ms | 1656 KiB | ||||
38 | Runtime error | 8ms | 2224 KiB | ||||
39 | Runtime error | 32ms | 8728 KiB | ||||
40 | Runtime error | 76ms | 16900 KiB | ||||
41 | Runtime error | 78ms | 24772 KiB | ||||
42 | Accepted | 4ms | 1036 KiB | ||||
43 | Accepted | 6ms | 1508 KiB | ||||
44 | Accepted | 10ms | 3200 KiB | ||||
45 | Accepted | 46ms | 12956 KiB | ||||
46 | Accepted | 100ms | 25696 KiB | ||||
47 | Accepted | 3ms | 632 KiB | ||||
48 | Accepted | 3ms | 540 KiB | ||||
49 | Runtime error | 3ms | 1036 KiB | ||||
50 | Accepted | 3ms | 784 KiB | ||||
51 | Accepted | 3ms | 620 KiB | ||||
52 | Accepted | 3ms | 760 KiB | ||||
53 | Runtime error | 76ms | 26736 KiB | ||||
54 | Accepted | 4ms | 996 KiB | ||||
55 | Runtime error | 4ms | 1636 KiB | ||||
56 | Accepted | 14ms | 3172 KiB | ||||
57 | Accepted | 64ms | 13876 KiB | ||||
58 | Accepted | 57ms | 15712 KiB | ||||
59 | Runtime error | 82ms | 28944 KiB | ||||
60 | Accepted | 146ms | 26972 KiB | ||||
61 | Accepted | 136ms | 27364 KiB | ||||
62 | Accepted | 135ms | 27436 KiB |