然而似乎我一开始抄的白书的板子哪里抄错了?还是本身哪里不对……(可能是不适用于这道题?因为这题要求求出每个BCC的大小。。?

  膜拜了ydc的写法= =

  其实两次dfs也并没有比lrj的麻烦到哪里去……感觉反而更清晰易懂,不容易出bug

  大家都是NOIP之前就会求割点了……只有我比较傻逼……

  核心是 $low[son]\geq dfn[fa] \Rightarrow fa 是割点$

 

  嗯如果只有一个BCC那么只需要两个出口,然后如果一个BCC连接着两个(及以上?)割点(这里将两个割点直接相连可以看作是一个BCC?)那么它内部就不用建出口,否则需要建一个……当然方案数直接乘就好啦= =(size[x],按表示方式不同,可能需要-1减去割点)

 1 /**************************************************************
 2     Problem: 2730
 3     User: Tunix
 4     Language: C++
 5     Result: Accepted
 6     Time:0 ms
 7     Memory:1308 kb
 8 ****************************************************************/
 9  
10 //BZOJ 2730
11 #include<vector>
12 #include<cstdio>
13 #include<cstring>
14 #include<cstdlib>
15 #include<iostream>
16 #include<algorithm>
17 #define rep(i,n) for(int i=0;i<n;++i)
18 #define F(i,j,n) for(int i=j;i<=n;++i)
19 #define D(i,j,n) for(int i=j;i>=n;--i)
20 #define CC(a,b) memset(a,b,sizeof(a))
21 using namespace std;
22 typedef long long LL;
23 inline int getint(){
24     int r=1,v=0; char ch=getchar();
25     for(;!isdigit(ch);ch=getchar()) if (ch=='-') r=-1;
26     for(; isdigit(ch);ch=getchar()) v=v*10-'0'+ch;
27     return r*v;
28 }
29 const int N=510;
30 /*******************template********************/
31  
32 struct edge{int x,y,next;}E[N<<1],st[N<<1];
33 int n,m,head[N],cnt;
34 void add(int x,int y){
35     E[++cnt]=(edge){x,y,head[x]}; head[x]=cnt;
36     E[++cnt]=(edge){y,x,head[y]}; head[y]=cnt;
37 }
38 int dfn[N],low[N],dfs_clock,bccno[N],have[N],size[N],bcc,top;
39 bool iscut[N];
40  
41 void tarjan(int x,int fa){
42     low[x]=dfn[x]=++dfs_clock;
43     int child=0;
44     for(int i=head[x];i;i=E[i].next){
45         int y=E[i].y;
46         if (!dfn[y]){
47             child++;
48             tarjan(y,x);
49             low[x]=min(low[y],low[x]);
50             if (low[y]>=dfn[x]) iscut[x]=1;
51         }else low[x]=min(low[x],dfn[y]);
52     }
53     if (fa<0 && child==1) iscut[x]=0;
54 }
55  
56 bool vis[N];
57 void dfs(int x){
58     vis[x]=1; size[bcc]++;
59     for(int i=head[x];i;i=E[i].next)
60         if (!vis[E[i].y]){
61             if (!iscut[E[i].y]) dfs(E[i].y);
62             else if(bccno[E[i].y]!=bcc)
63                 bccno[E[i].y]=bcc,have[bcc]++;
64         }
65 }
66 void Clear(){
67     CC(head,0); CC(bccno,0);
68     CC(dfn,0); CC(low,0);
69     CC(have,0); CC(size,0);
70     CC(iscut,0); CC(vis,0);
71     n=cnt=dfs_clock=bcc=top=0;
72 }
73 int main(){
74 #ifndef ONLINE_JUDGE
75     freopen("2730.in","r",stdin);
76     freopen("2730.out","w",stdout);
77 #endif 
78     int cs=0;
79     while(scanf("%d",&m)!=EOF && m){
80         printf("Case %d: ",++cs);
81         Clear();
82         F(i,1,m){
83             int x=getint(),y=getint();
84             n=max(x,n); n=max(y,n);
85             add(x,y);
86         }
87         F(i,1,n) if (!dfn[i]) tarjan(i,-1);
88         LL ans1=0,ans2=1;
89         F(i,1,n)
90             if (!vis[i] && !iscut[i]){
91                 ++bcc,dfs(i);
92                 if (have[bcc]==1) ans1++,ans2*=size[bcc];
93             }
94         if (bcc==1) ans1=2,ans2=(LL)n*(n-1)/2;
95         printf("%lld %lld\n",ans1,ans2);
96     }
97     return 0;
98 }
View Code

相关文章:

  • 2021-07-02
  • 2021-05-20
  • 2021-05-17
  • 2021-12-18
  • 2021-10-14
猜你喜欢
  • 2021-07-16
  • 2021-08-09
  • 2021-08-24
  • 2021-12-21
  • 2022-12-23
  • 2021-12-04
  • 2021-07-31
相关资源
相似解决方案