• cf976f Minimal k-covering


    枚举 (k),对于每个点 (i) 我们最多删 (deg_i-k) 条边,就源点向第一部、第二部向汇点连边,容量是 (deg_i-k),原边连上,容量是 (1),这样每流过一条原边在网络流图中的边时,就代表这条边可以删掉。也即没有流过的边就是 (k) 时的答案

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <queue>
    using namespace std;
    int nu, nv, n, m, ss, tt, hea[4005], deg[4005], cnt, maxFlow, lev[4005], cur[4005];
    const int oo=0x3f3f3f3f;
    queue<int> d;
    vector<int> vec[4005];
    struct Edge{
    	int too, nxt, val;
    }edge[50005], orz[2005];
    void add_edge(int fro, int too, int val){
    	edge[cnt].nxt = hea[fro];
    	edge[cnt].too = too;
    	edge[cnt].val = val;
    	hea[fro] = cnt++;
    }
    void addEdge(int fro, int too, int val){
    	add_edge(fro, too, val);
    	add_edge(too, fro, 0);
    }
    bool bfs(){
    	memset(lev, 0, sizeof(lev));
    	lev[ss] = 1;
    	d.push(ss);
    	while(!d.empty()){
    		int x=d.front();
    		d.pop();
    		for(int i=hea[x]; i!=-1; i=edge[i].nxt){
    			int t=edge[i].too;
    			if(!lev[t] && edge[i].val>0){
    				lev[t] = lev[x] + 1;
    				d.push(t);
    			}
    		}
    	}
    	return lev[tt]!=0;
    }
    int dfs(int x, int lim){
    	if(x==tt)	return lim;
    	int addFlow=0;
    	for(int &i=cur[x]; i!=-1; i=edge[i].nxt){
    		int t=edge[i].too;
    		if(lev[t]==lev[x]+1 && edge[i].val){
    			int tmp=dfs(t, min(lim-addFlow, edge[i].val));
    			edge[i].val -= tmp;
    			edge[i^1].val += tmp;
    			addFlow += tmp;
    			if(addFlow==lim)	break;
    		}
    	}
    	return addFlow;
    }
    void dinic(){
    	while(bfs()){
    		for(int i=ss; i<=tt; i++)	cur[i] = hea[i];
    		maxFlow += dfs(ss, oo);
    	}
    }
    int main(){
    	memset(hea, -1, sizeof(hea));
    	cin>>nu>>nv>>m;
    	n = nu + nv;
    	ss = 0; tt = n + 1;
    	int minDeg=0x3f3f3f3f;
    	for(int i=1; i<=m; i++){
    		scanf("%d %d", &orz[i].too, &orz[i].nxt);
    		orz[i].nxt += nu;
    		deg[orz[i].too]++;
    		deg[orz[i].nxt]++;
    	}
    	for(int i=1; i<=n; i++)
    		minDeg = min(minDeg, deg[i]);
    	for(int i=1; i<=nu; i++)
    		addEdge(ss, i, deg[i]-minDeg-1);
    	for(int i=1; i<=nv; i++)
    		addEdge(nu+i, tt, deg[nu+i]-minDeg-1);
    	int tmp=cnt;
    	for(int i=1; i<=m; i++)
    		addEdge(orz[i].too, orz[i].nxt, 1);
    	for(int i=minDeg; i>=0; i--){
    		for(int j=0; j<tmp; j+=2)
    			edge[j].val++;
    		dinic();
    		for(int j=tmp; j<cnt; j+=2)
    			if(edge[j].val)
    				vec[i].push_back((j-tmp)/2+1);
    	}
    	for(int i=0; i<=minDeg; i++){
    		printf("%d ", vec[i].size());
    		for(int j=0; j<vec[i].size(); j++)
    			printf("%d ", vec[i][j]);
    		printf("
    ");
    	}
    	return 0;
    }
    
  • 相关阅读:
    advisor调优工具优化sql(基于sql_id)
    关于等待事件cursor: pin S
    队列等待之enq: TX
    HTML5+CSS3从入门到精通 中文pdf完整版[229MB] 下载
    unity 控制透明度
    unity 限制模型移动的边界
    unity监测按下键的键值并输出+unity键值
    unity EventTrigger与模型
    wpf 获取桌面上的鼠标位置
    unity 代码更换ugui中image的关联素材
  • 原文地址:https://www.cnblogs.com/poorpool/p/8988818.html
Copyright © 2020-2023  润新知