zoukankan      html  css  js  c++  java
  • POJ 3140 Contestants Division

    WA

    1. 忘了是无向图

    #include <iostream>
    #include <stdio.h>
    #include <memory.h>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <set>
    #include <string>
    #include <deque>
    #include <cstring>
    #define MIN(x,y) (x)<(y)?(x):(y)
    using namespace std;
    
    int total_weight;
    int weight[100100];
    vector<int> graph[100100];
    int min_cut;
    
    int dfs(int u, int pre) {
    	
    	int sum = 0;
    
    	for(int i = 0; i < graph[u].size(); i ++)  {
    		int v = graph[u][i];
    		if(v == pre)  continue;
    		int party = dfs(v, u);
    		sum += party;
    
    		min_cut = min(min_cut, total_weight-party);
    	}
    
    	return sum+weight[u];
    }
    
    int main() {
    	freopen("C:\Users\vincent\Dropbox\workplacce\joj\test.txt", "r", stdin);
    	
    	int n, m;
    	while(scanf("%d%d", &n, &m) != EOF && n != 0 && m != 0)  {
    		total_weight = 0;
    		for(int i = 0; i < n; i ++)  {
    			scanf("%d", weight+i+1);
    			total_weight += weight[i+1];
    		}
    
    		for(int i = 0; i < m; i ++)  {
    			int from, to;
    			scanf("%d%d", &from, &to);
    			graph[from].push_back(to);
    			graph[to].push_back(from);
    		}
    
    		min_cut = 0x3f3f3f3f;
    
    		dfs(1, -1);
    		printf("%d
    ", min_cut);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    Python 魔术方法
    Python 类和对象-上
    Python 日期时间相关
    Python OS模块
    Python文件操作
    Python集合操作
    Python字典操作
    为什么最小帧长度是64字节
    字典_ 三级菜单
    cart_购物车小程序
  • 原文地址:https://www.cnblogs.com/zhouzhuo/p/3677455.html
Copyright © 2011-2022 走看看