40求调
查看原帖
40求调
1419487
_yin_wei_ta_shan_楼主2025/2/3 12:58
#include <iostream>
#include <queue>
using namespace std;

int value[301];
bool tree[301][301];
queue<int> unh;

int main() {
	int n, p;
	cin >> n >> p;
	for (int i = 1; i <= p; i++) {
		int a, b;
		cin >> a >> b;
		tree[a][b] = tree[b][a] = 1;
	}
	for (int i = n; i >= 1; i--) {
		int v = 1;
		for (int j = 1; j <= n; j++) {
			if (tree[i][j]) {
				v += value[j];
			}
		}
		value[i] = v;
	}
	int ans = 1;
	unh.push(1);
	while (!unh.empty()) {
		int maxn = 0, maxcur = 0, now = unh.front();
		unh.pop();
		for (int j = now + 1; j <= n; j++) {
			if (tree[now][j]) {
				if (value[j] > maxn) {
					maxn = value[j];
					maxcur = j;
				}
			}
		}
		for (int j = now + 1; j <= n; j++) {
			if (tree[now][j] && j != maxcur) {
				unh.push(j);
				ans++;
			}
		}
	}
	cout << ans << endl;
}
#1#2#3#4#5#6#7#8#9#10
WAACACACWAWAACWAWAWA
2025/2/3 12:58
加载中...