66分求调
查看原帖
66分求调
768239
Tou_ch楼主2023/7/1 13:23

WA了1、8、9点

#include <bits/stdc++.h>

using namespace std;

struct node {
	int id = 1;
	node *parent = nullptr;
	int width = 0;
	bool has = false;
	bool vis = false;
};

struct side {
	int width;
	node *n;
};

vector<side> sides[1001];
node nodes[101];


void dfs(node *n) {
	n->vis = true;
	for(side& s : sides[n->id]) {
		s.n->width = max(s.n->width, min(n->width, s.width));
		if(!(s.n->vis)) {
			dfs(s.n);
		}
	}
}

inline bool cmp(const node &a, const node &b) {
	return a.width < b.width;
}

int main() {
	ios::sync_with_stdio(false);
	int N, K, M;
	cin>>N>>M>>K;
	for(int i = 0; i < K; i++) {
		int j;
		cin>>j;
		nodes[j].has = true;
	}
	for(int i = 1; i <= N; i++) {
		nodes[i].id = i;
	}
	for(int i = 1; i <= M; i++) {
		int a, b, c;
		cin>>a>>b>>c;
		sides[a].push_back({c, nodes + b});
		sides[b].push_back({c, nodes + a});
	}
    nodes[1].width = ~(1 << 31);
	dfs(nodes + 1);
	sort(nodes + 1, nodes + N + 1, cmp);
	int ans = 0;
	int width = 0;
	for(int i = 1; i <= N; i++) {
		if(nodes[i].vis) {
			if(nodes[i].width >= width + 1 && nodes[i].has) {
				ans++;
				width++;
			}
		}
	}
	cout<<ans;
	return 0;
}
2023/7/1 13:23
加载中...