[JLOI2015]管道连接,P3264,最小斯坦纳树

正题

      没做过板子题的先去做做板子题.

      发现这题唯一的区别就是只需要相同编号的点联通,那么我们在最后算答案的时候直接找频道点相同的集合的最小f值,然后加起来就可以了,注意这里要先把f[i][0]预设成0,不然可能会锅,题主用了比较蠢的方法,还搞了个子集max,不过时间复杂度是没问题的.

#include
using namespace std;

const int N=1010,M=3010,S=1<<10;
int n,m,k,t;
struct edge{
	int y,nex,c;
}s[M<<1];
int first[N],len=0;
int f[N][S],op[S];
bool vis[N];
priority_queue > q;

void ins(int x,int y,int c){s[++len]=(edge){y,first[x],c};first[x]=len;}

void dijkstra(int now){
	memset(vis,false,sizeof(vis));
	while(!q.empty()){
		pair x=q.top();q.pop();
		if(vis[x.second]) continue;vis[x.second]=true;
		for(int i=first[x.second];i;i=s[i].nex) {
			if(f[x.second][now]+s[i].c

 

你可能感兴趣的:(最小斯坦纳树)