CF444E. DZY Loves Planting
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF444E. DZY Loves Planting相关的知识,希望对你有一定的参考价值。
?????????amp tin opera print pre [1] http putchar cti
????????????
??????
??????..???????????????
??????
???????????????????????????
?????????????????????????????????
??????????????????????????????????????????
?????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????
?????????????????????
??????
#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的主要内容,如果未能解决你的问题,请参考以下文章
codeforces - 444c DZY Loves Colors(线段树+染色)
Codeforces 444C DZY Loves Colors(线段树)