比赛 4043级2023省选练习赛6 评测结果 AAAAAAAAAA
题目名称 矿场搭建 最终得分 100
用户昵称 zxhhh 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2023-03-15 20:52:21
显示代码纯文本
#include <bits/stdc++.h>

using namespace std;

const int N = 305;
typedef long long ll;

int n;
int dfn[N], low[N], is_cut[N], t, stk[N], ed;
int flag[N], mk[N]; 
ll ans, minn;

int dcc_cnt, dcc_idx[N], s[N], dd[N];
vector <int> edges[N], dcc[N];

void tarjan (int p) {
//	cout << p << endl;
//	cout<< p;
	dfn[p] = low[p] = ++t; stk[ed++] = p; int d = (p == 1 ? 0 : 1), st = 0;
	for (int i = 0;i < edges[p].size();i++) {
		int y = edges[p][i];
		if (dfn[y]) low[p] = min(low[p], dfn[y]);
		else {
			if (!st) st = y;
			d++; tarjan(y); low[p] = min(low[p], low[y]); 
			if (low[y] >= dfn[p] && d > 1) {
//				cout << p << " " << y << endl;
				int x; dcc_cnt++; is_cut[p] = 1;
				do {
					x = stk[--ed];
					dcc_idx[x] = dcc_cnt;
					dcc[dcc_cnt].push_back(x);
				} while (x != y);
				dcc[dcc_cnt].push_back(p);
			}
		}
	}
	if (p == 1 && st) {
		if (low[st] >= dfn[p] && d > 1) {
			int x; dcc_cnt++; is_cut[p] = 1;
			do {
				x = stk[--ed];
				dcc_idx[x] = dcc_cnt;
				dcc[dcc_cnt].push_back(x);
			} while (x != st);
			dcc[dcc_cnt].push_back(p);
		}
	}
	if (p == 1 && !is_cut[p]) {
		int x; dcc_cnt++;
		do {
			x = stk[--ed];
			dcc_idx[x] = dcc_cnt;
			dcc[dcc_cnt].push_back(x);
		} while (x != p);
	}
//	cout << p << endl;
} 

void make_graph () {
	for (int i = 1;i <= dcc_cnt;i++) {
		for (int j = 0;j < dcc[i].size();j++) {
			int p = dcc[i][j];
			if (is_cut[p]) dd[i]++;
			else s[i]++;
		}
	}
	for (int i = 1;i <= dcc_cnt;i++) if (dd[i] == 1) minn++, ans = ans*((ll)s[i]);
}

int main () {
	freopen("bzoj_2730.in", "r", stdin);
	freopen("bzoj_2730.out", "w", stdout);
	for (int Tidx = 1;;Tidx++) {
		memset(mk, 0, sizeof(mk)); memset(flag, 0, sizeof(flag)); memset(dd, 0, sizeof(dd)); memset(dfn, 0, sizeof(dfn)); memset(low, 0, sizeof(low)); memset(is_cut, 0, sizeof(is_cut)); memset(s, 0, sizeof(s)); 
		t = dcc_cnt = ed = minn = 0; ans = 1; ll cnt = 0;
		for (int i = 1;i < N;i++) edges[i].clear(), dcc[i].clear();
		cin >> n;
		if (!n) break;
		for (int i = 1;i <= n;i++) {
			int s, t;
			cin >> s >> t;
			if (!mk[s]) mk[s] = 1, cnt++;
			if (!mk[t]) mk[t] = 1, cnt++;
			edges[s].push_back(t); edges[t].push_back(s);
		}
		tarjan(1);
//		cout << dcc_cnt << endl;
//		cout << idx << endl;
		if (dcc_cnt == 1) minn = 2, ans = (ll)cnt*(cnt-1)/2;
		else make_graph();
//		for (int i = 1;i <= dcc_cnt;i++) {
//			cout << s[i] << endl;
//			for (int j = 0;j < dcc[i].size();j++) {
//				int y = dcc[i][j]; cout << y << " ";
//			}
//			cout << endl;
//		}
		printf("Case %d: %d %lld\n", Tidx, minn, ans);
	}
	return 0;
}