XDDD YY了半天的点双联通忽略了最初点双的性质—-割点可能属于多个块
代码施工中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
#include <cstdio> #include <algorithm> #include <cstring> #include <vector> #include <cstdlib> #define ll long long #define p(x) ('0'<=x&&x<='9') #define For(i,l,r) for(int i=l;i<=r;i++) char cc; int C; template <class T> void read( T &x ) { x=0; cc=getchar(); C=1; while(!p(cc)) { if(cc=='-') C=-1; cc=getchar(); } while(p(cc)) { x=x*10+cc-48; cc=getchar(); } x*=C; } using namespace std; #define SIZ 1010 #define N 1000 struct node { int fa,dfn,mn,childcnt; bool iscut; vector <int> belong; void init() { belong.clear(); fa=dfn=mn=childcnt=iscut=0; } }pool[SIZ]; #define FA pool[x].fa #define MN pool[x].mn #define DFN pool[x].dfn #define CNT pool[x].childcnt #define ISCUT pool[x].iscut struct Tedge { int from,to; bool use; Tedge(int _=0,int __=0,bool ___=false) { from=_; to=__; use=false; } bool operator != (const Tedge &x) { return (from!=x.from||to!=x.to); } } edge[N<<1],STA[N]; int TOP; #define E edge[i] #define TO E.to int e_tot,fst[SIZ],cur[SIZ],NXT[N<<1]; void add_e(int a,int b) { edge[e_tot]=Tedge(a,b,false); NXT[e_tot]=fst[a]; fst[a]=e_tot++; edge[e_tot]=Tedge(b,a,false); NXT[e_tot]=fst[b]; fst[b]=e_tot++; } vector <int> BCC[SIZ]; int siz[SIZ],cnt[SIZ],tot; int sta[SIZ],top; bool use[SIZ]; unsigned ll ans1,ans2; // void init(int n) { memset(fst,-1,sizeof(fst)); memset(siz,0,sizeof(siz)); memset(cnt,0,sizeof(cnt)); e_tot=0; tot=0; ans1=0; ans2=1; for(int i=1;i<=N;i++) BCC[i].clear(); int _,__; For(i,1,n) { read(_); read(__); use[_]|=1; use[__]|=1; add_e(_,__); } } void cp(int &x,int y) { x>y?x=y:x=x; } int cd; void tarjan(int x) { use[x]=false; DFN=MN=++cd; for(int i=fst[x];~i;i=NXT[i]) { if(TO==FA) continue; if(edge[i].use) continue; STA[++TOP]=E; E.use=true; i^=1; E.use=true; i^=1; if(!use[TO]) cp(MN,pool[TO].dfn); else { CNT++; pool[TO].fa=x; tarjan(TO); MN=min(MN,pool[TO].mn); if(pool[TO].mn>=DFN) { Tedge cur; tot++; ISCUT=true; do { cur=STA[TOP--]; if(pool[cur.from].belong.size()==0||pool[cur.from].belong.back()!=tot) { pool[cur.from].belong.push_back(tot); BCC[tot].push_back(cur.from); } if(pool[cur.to].belong.size()==0||pool[cur.to].belong.back()!=tot) { pool[cur.to].belong.push_back(tot); BCC[tot].push_back(cur.to); } } while(cur!=E); } } } if(CNT<2&&!FA) ISCUT=false; } int time; void Main(int _) { time++; init(_); For(i,1,1000) cur[i]=fst[i],pool[i].init(); For(i,1,1000) if(use[i]) tarjan(i); For(i,1,1000) { if(!pool[i].dfn) continue; if(!pool[i].iscut) { siz[pool[i].belong[0]]++; continue; } for(int j=0;j<pool[i].belong.size();j++) cnt[pool[i].belong[j]]++,siz[pool[i].belong[j]]++; } For(i,1,tot) if(cnt[i]==1) { ans1++; ans2*=(unsigned ll)(siz[i]==1?1:(siz[i]-1)); } else if(cnt[i]==0) { ans1+=min(siz[i],2); ans2*=(unsigned ll)siz[i]*(siz[i]-1)/2; } printf("Case %d: %llu %llu\n",time,ans1,ans2); } int main() { freopen("BZOJ2730.in","r",stdin); memset(cur,-1,sizeof(cur)); int T; read(T); for(;T;read(T)) Main(T); return 0; } |