题目链接

CF444E. DZY Loves Planting

题解

可以..二分网络流

可是

考虑边从小到大排序

考虑每条边能否成为答案

用并查集维护节点之间的联通性

对于一条边来说,如果这条边可以成为答案

那么当前已经合并的每个点,都需要给它分配一个未被合并的点

这就很好判定了

代码

#include<ctime>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#define rep(a,b,c) for(int a = b;a <= c;++ a)
#define per(a,b,c) for(int a = b;a >= c;-- a)
#define gc getchar()
#define pc putchar
using namespace std;
inline int read() {
int x = 0,f = 1;
char c = gc;
while(c < '0' || c > '9') { if(c == '-')f = - 1 ;c = gc; }
while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = gc;
return x * f;
}
#define LL long long
void print(int x) {
if(x >= 10) print(x / 10);
pc(x % 10 + '0');
}
const int maxn = 100007;
struct node {
int u,v,w;
bool operator < (const node&p)const {
return w < p.w;
} } e[maxn << 1];
int a[maxn],sum = 0,sz[maxn],fa[maxn];
bool judge = true;
int find(int x) {
if(fa[x] != x) fa[x] = find(fa[x]);
return fa[x];
}
void merge(int x,int y) {
x = find(x),y = find(y);
sz[x] += sz[y];
a[x] += a[y];
fa[y] = x;
if(sz[x] > sum - a[x]) judge = 0;
}
int main() {
int n = read();
for(int i = 1;i < n;++ i) e[i].u = read(),e[i].v = read(),e[i].w=read();
std::sort(e + 1,e + n);
for(int i = 1;i <= n;++ i)
a[i] = read(),sz[i] = 1,sum += a[i],fa[i] = i;
int ans = 0;
if(n == 1 && a[1] == 1) while(1){};
for(int i = 1;i < n;++ i) {
if(judge) ans = e[i].w;
merge(e[i].u,e[i].v);
}
print(ans);
}

CF444E. DZY Loves Planting的更多相关文章

  1. cf444E. DZY Loves Planting(并查集)

    题意 题目链接 Sol 神仙题啊Orzzzzzz 考场上的时候直接把树扔了对着式子想,想1h都没得到啥有用的结论. 然后cf正解居然是网络流??出给NOIP模拟赛T1???¥%--&((--% ...

  2. CF444C. DZY Loves Colors[线段树 区间]

    C. DZY Loves Colors time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. Codeforces444C DZY Loves Colors(线段树)

    题目 Source http://codeforces.com/problemset/problem/444/C Description DZY loves colors, and he enjoys ...

  4. CodeForces445A DZY Loves Chessboard

    A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input stand ...

  5. BZOJ 3309: DZY Loves Math

    3309: DZY Loves Math Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 761  Solved: 401[Submit][Status ...

  6. CF 444C DZY Loves Physics(图论结论题)

    题目链接: 传送门 DZY Loves Chemistry time limit per test1 second     memory limit per test256 megabytes Des ...

  7. CF 445B DZY Loves Chemistry(并查集)

    题目链接: 传送门 DZY Loves Chemistry time limit per test:1 second     memory limit per test:256 megabytes D ...

  8. hdu.5195.DZY Loves Topological Sorting(topo排序 && 贪心)

    DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 ...

  9. 【UER #1】[UOJ#12]猜数 [UOJ#13]跳蚤OS [UOJ#14]DZY Loves Graph

    [UOJ#12][UER #1]猜数 试题描述 这一天,小Y.小D.小C正在愉快地玩耍. 小Y是个数学家,他一拍脑袋冒出了一个神奇的完全平方数 n. 小D是个机灵鬼,很快从小Y嘴里套出了 n的值.然后 ...

随机推荐

  1. elastalert

    http://blog.51cto.com/kexiaoke/1977481 什么是? ElastAlert是一个简单的框架,用于从弹性搜索中的数据中提取异常,尖峰或其他感兴趣的模式.在Yelp,我们 ...

  2. Python之路(第十七篇)logging模块

    一.logging模块 (一).日志相关概念 日志是一种可以追踪某些软件运行时所发生事件的方法.软件开发人员可以向他们的代码中调用日志记录相关的方法来表明发生了某些事情.一个事件可以用一个可包含可选变 ...

  3. 2017-12-19python全栈9期第四天第二节之列表的增删查改之删除的pop和del和remove和clear

    #!/user/bin/python# -*- coding:utf-8 -*-li = ['zs','ls','ww','zl']# name = li.pop(1) #按索引位置删除有返回值# n ...

  4. 金融量化分析【day111】:Matplotib-图标标注

    一.图像标注 1.股票 df = pd.read_csv('601318.csv') df.plot() plt.plot([1,3,4,5]) plt.plot([5,8,7,9]) plt.tit ...

  5. Moving Average

    移动平均算法Demo #!/usr/bin/python2.7 # Fetch data from BD and analyse. import json import urllib import t ...

  6. Linux动态库生成与使用指南

    相关阅读: Linux静态库生成指南 Linux下动态库文件的文件名形如 libxxx.so,其中so是 Shared Object 的缩写,即可以共享的目标文件. 在链接动态库生成可执行文件时,并不 ...

  7. JavaScript复习

    一.常用对话框 1.alert(""):警告对话框,作用是弹出一个警告对话框 2.confirm(""):确定对话框,弹出一个带确定和取消按钮的对话框——确定返 ...

  8. 对评分矩阵进行分解,SVD与LSI

    摘自 推荐系统 https://www.cnblogs.com/lzllovesyl/p/5243370.html 一.SVD奇异值分解 1.SVD简介 SVD(singular value deco ...

  9. apache中 sed 指定文件中某字符串增加行

    #!/bin/bash #在 servername 域名 字符串后面添加指定字符串 servername=`grep ServerName httpd-vhosts.conf |awk '{print ...

  10. C++设计模式——外观模式

    前言 在实际开发时,面对一个大的系统,总是会将一个大的系统分成若干个子系统,等子系统完成之后,再分别调用对应的子系统来完成对应的整体功能,这样有利于降低系统的复杂性:最终进行实现某个具体的功能时,我们 ...