zoukankan      html  css  js  c++  java
  • P1351 联合权值

    #include <bits/stdc++.h>
    using namespace std;
    const int maxn = 200005;
    vector<int> son[maxn];
    int v[maxn], s[maxn], w[maxn];
    int main() {
    	freopen("input.in", "r", stdin);
    	int n, m;
    	cin >> n;
    	memset(s, 0,sizeof(s));
    	for(int i = 1; i <= n-1; i++) {
    		int x, y;
    		cin >> x >> y;
    		son[x].push_back(y);
    		son[y].push_back(x);
    	}
    	for(int i = 1; i <= n; i++) {
    		cin >> v[i];
    	}	
    	int first[maxn], second[maxn];
    	for(int i = 1; i <= n; i++) {
    		vector<int>::iterator it;
    		for(it = son[i].begin(); it != son[i].end(); it++) {
    			s[i] += v[*it];
    			if(v[*it] > first[i]) { second[i] = first[i];first[i] = v[*it];} 
    			else if(v[*it] > second[i]) second[i] = v[*it];
    		}
    	}
    	int maxx = 0, sum = 0;
    	for(int i = 1; i <= n; i++) maxx = max(maxx,first[i] * second[i]);
    	for(int i = 1; i <= n; i++) {
    		vector<int>::iterator it;
    		for(it = son[i].begin(); it != son[i].end(); it++) {
    			w[i] += ((s[i] - v[*it]) * v[*it])%10007;
    		}
    		sum += w[i] % 10007;
    	}
    	cout << maxx << ' ' << sum % 10007 << endl;
    }
    
  • 相关阅读:
    shell
    RANDOM随机数
    docker网络管理
    Oracle-28001密码过期问题及28000账户被锁解决
    Oracle数据泵导入导出(expdb/impdb)
    mysql多实例部署
    sed命令基本使用
    MySQL5.7.x二进制安装
    每日日报
    每日日报
  • 原文地址:https://www.cnblogs.com/gengchen/p/6040767.html
Copyright © 2011-2022 走看看