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的更多相关文章
- cf444E. DZY Loves Planting(并查集)
题意 题目链接 Sol 神仙题啊Orzzzzzz 考场上的时候直接把树扔了对着式子想,想1h都没得到啥有用的结论. 然后cf正解居然是网络流??出给NOIP模拟赛T1???¥%--&((--% ...
- CF444C. DZY Loves Colors[线段树 区间]
C. DZY Loves Colors time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces444C DZY Loves Colors(线段树)
题目 Source http://codeforces.com/problemset/problem/444/C Description DZY loves colors, and he enjoys ...
- CodeForces445A DZY Loves Chessboard
A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input stand ...
- BZOJ 3309: DZY Loves Math
3309: DZY Loves Math Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 761 Solved: 401[Submit][Status ...
- CF 444C DZY Loves Physics(图论结论题)
题目链接: 传送门 DZY Loves Chemistry time limit per test1 second memory limit per test256 megabytes Des ...
- CF 445B DZY Loves Chemistry(并查集)
题目链接: 传送门 DZY Loves Chemistry time limit per test:1 second memory limit per test:256 megabytes D ...
- hdu.5195.DZY Loves Topological Sorting(topo排序 && 贪心)
DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 ...
- 【UER #1】[UOJ#12]猜数 [UOJ#13]跳蚤OS [UOJ#14]DZY Loves Graph
[UOJ#12][UER #1]猜数 试题描述 这一天,小Y.小D.小C正在愉快地玩耍. 小Y是个数学家,他一拍脑袋冒出了一个神奇的完全平方数 n. 小D是个机灵鬼,很快从小Y嘴里套出了 n的值.然后 ...
随机推荐
- Vue笔记:使用 axios 中 this 指向问题
问题背景 在vue中使用axios做网络请求的时候,会遇到this不指向vue,而为undefined. 如下图所示,我们有一个 login 方法,希望在登录成功之后路由到主页,但通过 this.$r ...
- mysql中replace替换字符串更改方法
MySQL中update替换部分字符串replace的简单用法 近日,遇到了需要将部分字符串替换为另外的字符,平时用的最多的是直接update整个字段值,在这种情况下效率比较低,而且容易出错.其实my ...
- create table as 和create table like的区别
create table as 和create table like的区别 对于MySQL的复制相同表结构方法,有create table as 和create table like 两种,区别是什么 ...
- Redis的Cluster配置
Redis的Cluster配置 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.安装Redis并启动 1>.修改Redis的配置文件(本实验只有三个节点) [root@no ...
- jvisualvm安装visualgc插件
jdk1.7自带jvisualvm可以对java应用进行监控.其中有个插件visualgc可以查看jvm垃圾回收的具体信息.安装插件的步骤是打开jvisualvm,点击工具->插件,在可用插件列 ...
- sqlserver 获取所有表的字段类型等信息
USE [MultipleAnalysisDataFY] GO /****** Object: View [dbo].[selectfieldtype] Script Date: 2018/11/7 ...
- 使用echarts-for-react 绘制折线图 报错:`series.type should be specified `
解决办法: 在动态获取值的函数前面加 访问器属性 get ,去获取对象的属性 @inject('commonStore', 'reportUIStore') @observer class Line ...
- Oracle 关键字、高级函数的使用
1.序列.唯一标识 查询时,可以添加递增序列 rownum 表的数据每一行都有一个唯一的标识 rowid 2.函数 单行:查询多条数据 如:to_date() 多行:查询总结数据,一般用于group ...
- python模块 - pywinauto(windows自动化安装软件)
GUI 窗口查询工具 spy++lite pywinauto 模块 原理: https://www.cnblogs.com/testlife007/p/4710599.html pywhinayto ...
- Ubuntu18.04 VMtools的安装与卸载
VM不推荐在Ubuntu中使用VMtools而是open-vm-tools,原文地址https://kb.vmware.com/s/article/2073803 安装方式 1 更新系统源 sudo ...