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的值.然后 ...
随机推荐
- java 日期格式化
DateFormat DateFormat 是日期/时间格式化子类的抽象类,它以与语言无关的方式格式化并解析日期或时间. SimpleDateFormat SimpleDateFormat 是一个以与 ...
- java.io.FileNotFoundException:my-release-key.keyStore拒绝访问
安卓生成APK的时候,生成密钥的时候报java.io.FileNotFoundException:my-release-key.keyStore拒绝访问的错误 这是因为权限问题:你的jdk目录在c盘, ...
- Geometric regularity criterion for NSE: the cross product of velocity and vorticity 4: $u\cdot \om$
在 [Berselli, Luigi C.; Córdoba, Diego. On the regularity of the solutions to the 3D Navier-Stokes eq ...
- python 写代码笔记 2017.6.15
其实并不是越复杂的代码越好,简单高效才是好. 关键是思路和逻辑,还有多看别人写的代码. 学习到了:)
- Pytorch中的自动求导函数backward()所需参数含义
摘要:一个神经网络有N个样本,经过这个网络把N个样本分为M类,那么此时backward参数的维度应该是[N X M] 正常来说backward()函数是要传入参数的,一直没弄明白backward需要传 ...
- luogu P5289 [十二省联考2019]皮配
传送门 首先考虑一个正常的dp,设\(f_{i,j,k}\)为前\(i\)个学校,\(j\)人在\(\color{#0000FF}{蓝阵营}\),\(k\)人在\(\color{#654321}{吔} ...
- WebService - 术语介绍
一.WebService是什么? 1. 基于Web的服务:服务器端整出一些资源让客户端应用访问(获取数据) 2. 一个跨语言.跨平台的规范(抽象) 3. 多个跨平台.跨语言的应用间通信整合的方案(实际 ...
- day14 带参装饰器、迭代器、生成器
""" 今日内容: 1.带参装饰器及warps 2.迭代器 3.生成器 """ """ # 一.带参装饰器及w ...
- Beta 冲刺(1/7)
目录 摘要 团队部分 个人部分 摘要 队名:小白吃 组长博客:hjj 作业博客:beta冲刺(1/7) 团队部分 后敬甲(组长) 过去两天完成了哪些任务 团队完成测试答辩 整理博客 复习接口 接下来的 ...
- activiti 涉及的内容
1 JAVA 委派模式(Delegate) https://blog.csdn.net/mayaofr/article/details/52082665 2 Activiti中的activiti:ex ...