题意:求最小割为1的割点的数量。
第一次做这样的题 ,不会做啊,,做了这道题我才发现我连最基本的图论都不会。这水平,太水了。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
const int N = 10009;
const int M = 20009;
struct LT {
int nex,to;
} L[M<<1];
int F[N],cnt;
void add(int f,int t)
{
L[cnt].to = t;
L[cnt].nex = F[f];
F[f] = cnt++;
}
int m,n;
int dfn[N],low[N],post[N],ind,cut[N];
void tarjan(int k,int pre)
{
int child = 0;
dfn[k] = low[k] = ind++;
post[k] = 1;
for(int i=F[k];i;i=L[i].nex)
{
int to = L[i].to;
if(to==pre) continue;
if(post[to]) low[k] = min(low[to],low[k]);
else {
child ++;
tarjan(to,k);
low[k] = min(low[k],low[to]);
if(low[to]>=dfn[k]) cut[k]=1;
}
}
if(pre==-1) cut[k] = child>1;
}
void solve()
{
memset(dfn,0,sizeof(dfn));
memset(low,0,sizeof(low));
memset(cut,0,sizeof(cut));
memset(post,0,sizeof(post));
ind = 1;
tarjan(1,-1);
int ans = 0;
for(int i=1;i<=n;i++) if(cut[i]) ans++;
printf("%d\n",ans);
}
int main()
{
freopen("in.txt","r",stdin);
int cas,T=1;
scanf("%d",&cas);
while(cas--)
{
scanf("%d%d",&n,&m);
int a,b;
memset(F,0,sizeof(F));cnt = 1 ;
for(int i=0;i<m;i++)
scanf("%d%d",&a,&b),add(a,b),add(b,a);
printf("Case %d: ",T++);
solve();
}
return 0;
}