题目链接:http://lx.lanqiao.cn/problem.page?gpid=T35
题意:中文题诶~
思路:dfs
假设star 和 end之间总路径数目为ans, 那么若经过路径上某点到达终点的路径数为ans,则此点必为割点(所有路径都要经过此点,去掉了s就到不了e了嘛~);
所以我们只要找出经过各个点到达终点的路径数目问题也就解决了,很显然直接dfs就好啦;
代码:
1 #include <stdio.h> 2 #include <iostream> 3 #include <vector> 4 #define MAXN 1010 5 using namespace std; 6 7 vector<int> mp[MAXN]; 8 int vis[MAXN], ans=0;//vis记录经过点i能到达终结点的路径数目 9 int pre[MAXN];//记录路径 10 bool flag[MAXN]; 11 12 void dfs(int cnt, int e, int n){ 13 pre[n]=cnt;//记录当前点 14 if(cnt==e){ 15 ans++; 16 for(int i=0; i<=n; i++){//当前路径上的所有节点的vis值加一 17 vis[pre[i]]++; 18 } 19 return; 20 } 21 for(int i=0; i<mp[cnt].size(); i++){ 22 if(!flag[mp[cnt][i]]){ 23 flag[mp[cnt][i]]=true; 24 dfs(mp[cnt][i], e, n+1); 25 flag[mp[cnt][i]]=false; 26 } 27 } 28 } 29 30 void solve(int n, int s, int e){ 31 int cnt=0; 32 for(int i=1; i<=n; i++){ 33 if(vis[i]>=ans&&i!=s&&i!=e){//若到达终结点的所有路径都经过节点i且节点i不为起点和终点,则其为割点 34 cnt++; 35 } 36 } 37 printf("%d ", cnt); 38 } 39 40 int main(void){ 41 int n, m, x, y; 42 scanf("%d%d", &n, &m); 43 while(m--){ 44 scanf("%d%d", &x, &y); 45 mp[x].push_back(y); 46 mp[y].push_back(x); 47 } 48 int s, e; 49 scanf("%d%d", &s, &e); 50 flag[s]=true; 51 dfs(s, e, 0); 52 solve(n, s, e); 53 return 0; 54 }