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的值.然后 ...
随机推荐
- PR视频剪辑
PR视频剪辑 新手问题1: 将素材导入到Adobe Premiere Pro CC后为什么无法拖入到时间轴上 解决办法:没有建立有序列所致,CC不会一开始就让你新建序列,图中间处写的好清楚“无序列”. ...
- 金融量化分析【day112】:双均线策略
一.双均线策略 1.什么是双均线策略? 2.实现代码 def initialize(context): set_benchmark('601318.XSHG') set_option('use_rea ...
- javax.websocket.DeploymentException: Multiple Endpoints may not be deployed to the same path [/websocket/{sid}] : existing endpoint was class com.sanyi.qibaobusiness.framework.webSocket.WebSocketServe
报错: javax.websocket.DeploymentException: Multiple Endpoints may not be deployed to the same path [/w ...
- [物理学与PDEs]第5章第2节 变形的描述, 应变张量 2.3 位移梯度张量与无穷小应变张量
1. 位移向量 $$\bex {\bf u}={\bf y}-{\bf x}. \eex$$ 2. 位移梯度张量 $$\bex \n_x{\bf u}={\bf F}-{\bf I}. \eex$ ...
- [物理学与PDEs]第1章第7节 媒质中的 Maxwell 方程组 7.1 媒质中的 Maxwell 方程组
1.媒质的极化 (1) 束缚电荷: 被束缚在原来位置上的电荷. (2) 在电磁场中, 束缚电荷会有一微小的运动, 而产生电偶极矩. 此即称为媒质的极化. (3) 设电极化强度 (单位体积的电偶极矩) ...
- 爬取qq音乐巅峰榜---内地音乐的榜单
import requestsimport jsonimport sys for i in range(0,10): url = "https://szc.y.qq.com/v8/fcg-b ...
- 华为mate10 UA
Dalvik/2.1.0 (Linux; U; Android 9; ALP-AL00 Build/HUAWEIALP-AL00) "user-agent": "Mozi ...
- .Net IOC框架入门之三 Autofac
一.简介 Autofac是.NET领域最为流行的IOC框架之一,传说是速度最快的一个 目的 1.依赖注入的目的是为了解耦. 2.不依赖于具体类,而依赖抽象类或者接口,这叫依赖倒置. 3.控制反转即 ...
- npm——安装教程、安装vue脚手架
npm:是随同NodeJS一起安装的包管理工具,能解决NodeJS代码部署上的很多问题.比如常用的有: 1)允许用户从NPM服务器下载别人编写的第三方包到本地使用. 2)允许用户从NPM服务器下载并安 ...
- 【算法】【python实现】二叉树深度、广度优先遍历
二叉树的遍历,分为深度优先遍历,以及广度优先遍历. 在深度优先遍历中,具体分为如下三种: 先序遍历:先访问根节点,再遍历左子树,再遍历右子树: 中序遍历:先遍历左子树,再访问根节点,再遍历右子树: 后 ...