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 153 154 155 156 157 158 159 160 161 162 163 164 165 166
| #include<bits/stdc++.h> using namespace std;
typedef long long ll;
typedef pair<int , int > pii; typedef unsigned long long ull;
namespace FastIO { template<typename T> inline T read(T& x) { x = 0; int f = 1; char ch; while (!isdigit(ch = getchar())) if (ch == '-') f = -1; while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); x *= f; return x; } template<typename T, typename... Args> inline void read(T& x, Args &...x_) { read(x); read(x_...); return; } inline ll read() { ll x; read(x); return x; } }; using namespace FastIO;
const int MaxV = 1010; const int MaxE = 510;
template<int N, int M> class Graph { private : struct Edge { int to, nt, wt; Edge() {} Edge(int to, int nt, int wt) : to(to), nt(nt), wt(wt) {} }e[M]; int hd[N], cnte; public : inline void clear() { memset(hd, 0, sizeof(hd)), cnte = 0; } inline void AddEdge(int u, int v, int w = 0) { e[++cnte] = Edge(v, hd[u], w); hd[u] = cnte; } inline int head(int u) { return hd[u]; } inline int nt(int u) { return e[u].nt; } inline int to(int u) { return e[u].to; } inline int wt(int u) { return e[u].wt; } };
int n, m; Graph< MaxV, MaxE << 1 >G;
inline void Input() { read(m); if(m == 0) return exit(0); int u, v; for(int i = 1; i <= m; i++) { read(u, v); n = max(n, max(u, v)); if(u == v) continue; G.AddEdge(u, v); G.AddEdge(v, u); } }
int dfn[MaxV], low[MaxV], cntd; stack<int >st; int cntc, col[MaxV], cut[MaxV]; vector<int >clb[MaxV];
void Tarjan(int u, int fa) { dfn[u] = low[u] = ++cntd; st.push(u); if(u == fa && G.head(u) == 0) { clb[++cntc].push_back(u); col[u] = cntc; return ; } int ch = 0; for(int i = G.head(u); i; i = G.nt(i)) { int v = G.to(i); if(!dfn[v]) { Tarjan(v, u); low[u] = min(low[u], low[v]); if(low[v] >= dfn[u]) { if(++ch > 1 || u != fa) cut[u] = 1; ++cntc; int now; do { now = st.top(); st.pop(); col[now] = cntc; clb[cntc].push_back(now); }while(now != v); clb[cntc].push_back(u); } } else if(v != fa) { low[u] = min(low[u], dfn[v]); } } }
inline void Work() { for(int i = 1; i <= n; i++) if(!dfn[i]) Tarjan(1, 1); ull ans = 0, way = 1; for(int i = 1; i <= cntc; i++) { ull cnt = 0; for(auto &u : clb[i]) { if(cut[u]) { cnt++; } } ull sz = clb[i].size(); if(sz == 1) { ans++; } else { if(cnt == 0) { ans += 2; way *= (sz * (sz - 1)) / 2; } else if(cnt == 1) { ans++; way *= (sz - cnt); } } } printf("%llu %llu\n", ans, way); }
inline void Clear() { G.clear(); memset(dfn, 0, sizeof(dfn)); memset(low, 0, sizeof(low)); memset(col, 0, sizeof(col)); memset(cut, 0, sizeof(cut)); while(!st.empty()) st.pop(); for(int i = 1; i <= cntc; i++) { clb[i].clear(); } cntc = 0; }
int main() { int T = -1, cnt = 0; while(T--) { Clear(); Input(); printf("Case %d: ", ++cnt); Work(); } return 0; }
|