比赛 2024暑假C班集训C 评测结果 WWWWWWWWWW
题目名称 喵星人集会 最终得分 0
用户昵称 LikableP 运行时间 0.028 s
代码语言 C++ 内存使用 3.42 MiB
提交时间 2024-07-12 09:58:07
显示代码纯文本
#include <iostream>
#include <fstream>
#include <random>
using namespace std;

struct EDGE {
	int to, next;
} edge[110];
int head[60], edgeNum;
void AddEdge(int from, int to) {
	edgeNum++;
	edge[edgeNum].to = to;
	edge[edgeNum].next = head[from];
	head[from] = edgeNum;
}

int n;
int catCount;
int miao[60];

int main() {
	freopen("party.in", "r", stdin);
	freopen("party.out", "w", stdout);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		char x;
		cin >> x;
		if (x == '1') miao[i] = 1, catCount++;
	}
	default_random_engine engine(time(nullptr));
	uniform_real_distribution <double> distribution(0, n + 1 - catCount - 1e-6);
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		AddEdge(u, v);
		AddEdge(v, u);
	}
	if (catCount == n || catCount == 1) {
		cout << 0;
		return 0;
	}  else if (2 <= catCount && catCount <= n - 3) {
		cout << (int)distribution(engine);
	} else {
		cout << "QwQ";
	}
	return 0;
}