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;
    }
    
  • 相关阅读:
    关于ssh的一篇很好的文章
    课后作业--2 阅读计划及问题
    课后作业--1
    课后作业PPT 7
    大道至简 7、8、读后感
    第六章 读后感
    第五篇 读后感
    数组课后作业
    课后作业1:字串加密
    第四篇 读后感
  • 原文地址:https://www.cnblogs.com/gengchen/p/6040767.html
Copyright © 2011-2022 走看看