157212025-02-24 17:04:18TaxiradioÚtvonalakcpp17Wrong answer 0/1001.101s32668 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
#include <ios>
using namespace std;

#define int int64_t

vector<vector<int>> g , g2;
vector<int> c , l , vis , cs;
vector<bool> d;

stack<int> e;

int t = 0 , ci;

void dfs(int h , int p){
    e.push(h);
    l[h] = vis[h] = t++;
    for(int x : g[h]){
        if(x == p)continue;
        if(vis[x] == -1){
            dfs(x , h);
            if(l[x] >= vis[h]){
                d[h] = 1;
                c[h] = h;
                cs[h] = -1;
                cs[ci]++;
                g2[ci].push_back(h);
                g2[h].push_back(ci);
                while(e.top() != h && l[e.top()] >= vis[h]){
                    cs[ci]++;
                    if(!d[e.top()]){
                        c[e.top()] = ci;
                    }else{
                        g2[ci].push_back(e.top());
                        g2[e.top()].push_back(ci);
                    }
                    e.pop();
                }
                ci++;
            }
            l[h] = min(l[h] , l[x]);
        }else{
            l[h] = min(l[h] , vis[x]);
        }
    }
}

int dfs2(int h , int v , int p , int e){
    v += cs[h];
    if(e == h)return v;
    for(int x : g2[h]){
        if(x == p)continue;
        int k = dfs2(x , v , h , e);
        if(k!= -1)return k;
    }
    return -1;
}


int32_t main() {
    ios_base::sync_with_stdio(0);
    cout.tie(0);
	int n , m , q; cin >> n >> m >> q;
    ci = n;
    g.resize(n);
    g2.resize(2*n);
    cs.resize(2*n);
    c.resize(n);
    l.resize(n);
    vis.resize(n , -1);
    d.resize(n , 0);
    for(int i = 0; i < m; i++){
        int a , b; cin >> a >> b;a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(0 , -1);
    for(int i = 0; i < q; i++){
        int a , b; cin >> a >> b;a--;b--;
        cout << dfs2(c[a] , 0 , -1, c[b])+d[a]+d[b]-2 << "\n";
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
2Wrong answer162ms16300 KiB
subtask20/15
3Wrong answer2ms564 KiB
4Wrong answer2ms564 KiB
5Accepted4ms1332 KiB
6Wrong answer8ms2048 KiB
7Wrong answer37ms8248 KiB
8Wrong answer81ms16160 KiB
subtask30/15
9Accepted3ms564 KiB
10Accepted8ms820 KiB
11Accepted46ms1672 KiB
12Accepted178ms2356 KiB
13Time limit exceeded1.1s10260 KiB
14Time limit exceeded1.101s20460 KiB
15Time limit exceeded1.085s32308 KiB
subtask40/15
16Wrong answer4ms564 KiB
17Wrong answer6ms1096 KiB
18Wrong answer14ms1844 KiB
19Wrong answer50ms8368 KiB
20Wrong answer112ms16508 KiB
subtask50/15
21Wrong answer1ms508 KiB
22Wrong answer1ms316 KiB
23Accepted3ms564 KiB
24Wrong answer1ms316 KiB
25Wrong answer2ms568 KiB
26Wrong answer2ms564 KiB
subtask60/40
27Accepted1ms316 KiB
28Wrong answer179ms16420 KiB
29Wrong answer2ms564 KiB
30Wrong answer2ms564 KiB
31Accepted4ms1332 KiB
32Wrong answer8ms2048 KiB
33Wrong answer37ms8248 KiB
34Wrong answer81ms16160 KiB
35Accepted3ms564 KiB
36Accepted8ms820 KiB
37Accepted46ms1672 KiB
38Accepted178ms2356 KiB
39Time limit exceeded1.1s10260 KiB
40Time limit exceeded1.101s20460 KiB
41Time limit exceeded1.085s32308 KiB
42Wrong answer4ms564 KiB
43Wrong answer6ms1096 KiB
44Wrong answer14ms1844 KiB
45Wrong answer50ms8368 KiB
46Wrong answer112ms16508 KiB
47Wrong answer1ms508 KiB
48Wrong answer1ms316 KiB
49Accepted3ms564 KiB
50Wrong answer1ms316 KiB
51Wrong answer2ms568 KiB
52Wrong answer2ms564 KiB
53Time limit exceeded1.088s31280 KiB
54Wrong answer4ms564 KiB
55Accepted111ms1732 KiB
56Wrong answer26ms2084 KiB
57Wrong answer279ms8624 KiB
58Wrong answer122ms9904 KiB
59Time limit exceeded1.082s32668 KiB
60Wrong answer268ms16812 KiB
61Time limit exceeded1.088s16984 KiB
62Time limit exceeded1.078s16484 KiB