求调
查看原帖
求调
727556
wangziwenhk楼主2024/5/30 15:44

记录

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6+5;
map<int,vector<int>>graph;
int dfn[MAXN],low[MAXN],cnt=0,a,b;
bitset<MAXN>vis,flag;
void Tarjan(int x){
    vis[x]=true;
    dfn[x] = low[x] = ++cnt;
    for(auto i:graph[x]){
        if(!vis[i]){
            Tarjan(i);
            low[x] = min(low[x],low[i]);
            if(x!=a && low[i]>=dfn[x] && dfn[x]<=dfn[b]){
                flag[x] = true;
            }
        }
        else{
            low[x] = min(low[x],dfn[i]);
        }
    }
}
int main() {
    int n;
    scanf("%d",&n);
    while(1){
        int x,y;
        scanf("%d%d",&x,&y);
        graph[x].push_back(y);
        graph[y].push_back(x);
        if(!x && !y)break;
    }
    scanf("%d%d",&a,&b);
    Tarjan(a);
    for(int i=1;i<=n;i++){
        if(flag[i]){
            cout<<i;
            return 0;
        }
    }
    cout<<"No solution";
    return 0;
}

2024/5/30 15:44
加载中...