题目链接

第一道场上自己做出来的E题...虽然是div3,而且是原题...

当时做完ABC,D题没有思路就去怼E了,然后发现貌似原题?

事实上就是原题...

给个原题链接...

[HNOI2003]消防局的设立

还有[Usaco2008 Jan]电话网络

第二个我还写过题解...题解链接

其实就是一个贪心,首先深度在2以内的就不用管它了

对于深度大于2的点,我们显然只能拉一条边在他那里或者他的父亲那里,同样的,显然我们把那条边放在他父亲那里更划算,因为可以到达更多的点

所以一遍dfs处理出深度,然后按深度放入大根堆里面,每次取出一个点,对它的父亲的周围节点染色,遇到被染色过的直接continue掉就好

然后我当时没有给该节点的祖父染色...事实上是要染的...然后就WA8了5次,罚时爆炸...

复杂度$O(nlogn)$

#include <bits/stdc++.h>
#define ll long long
#define inf 1<<30
#define il inline
#define in1(a) read(a)
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d)
il void readl(ll &x){
x=;ll f=;char c=getchar();
while(c<''||c>''){if(c=='-')f=-f;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
x*=f;
}
il void read(int &x){
x=;int f=;char c=getchar();
while(c<''||c>''){if(c=='-')f=-f;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
x*=f;
}
using namespace std;
/*===================Header Template=====================*/
#define N 1000010
int n,head[N],cnt;
struct edge{
int to,nxt;
}e[N];
struct node {
int id,dep,fa;
bool operator < (const node &x)const {
return x.dep>dep;
}
}a[N];
void ins(int u,int v){
e[++cnt].to=v;e[cnt].nxt=head[u];head[u]=cnt;
e[++cnt].to=u;e[cnt].nxt=head[v];head[v]=cnt;
}
void dfs(int x,int f,int dep){
a[x].fa=f;
a[x].id=x;
a[x].dep=dep;
for(int i=head[x];i;i=e[i].nxt){
if(e[i].to==f)continue;
dfs(e[i].to,x,dep+);
}
}
bool vis[N];
priority_queue<node>q;
int main(){
in1(n);
for(int i=;i<n;i++){
int x,y;
in2(x,y);
ins(x,y);
}
dfs(,,);
for(int i=;i<=n;i++){
if(a[i].dep>)q.push(a[i]);
else vis[i]=;
}
int ans=;
while(!q.empty()){
node t=q.top();q.pop();
if(vis[t.id])continue;
ans++;
int f=t.fa;
vis[t.id]=vis[f]=;
for(int i=head[f];i;i=e[i].nxt){
vis[e[i].to]=;
}
}
printf("%d\n",ans);
return ;
}

CodeForces 1029E div3的更多相关文章

  1. Codeforces #550 (Div3) - G.Two Merged Sequences(dp / 贪心)

    Problem  Codeforces #550 (Div3) - G.Two Merged Sequences Time Limit: 2000 mSec Problem Description T ...

  2. codeforces #579(div3)

    codeforces #579(div3) A. Circle of Students 题意: 给定一个n个学生的编号,学生编号1~n,如果他们能够在不改变顺序的情况下按编号(无论是正序还是逆序,但不 ...

  3. [Codeforces #615 div3]1294E Obtain a Permutation

    Before the Beginniing 本文为 Clouder 原创文章,原文链接为Click,转载时请将本段放在文章开头显眼处.如进行了二次创作,请明确标明. 由本人转载于博客园. 题意分析 C ...

  4. Codeforces #624 div3 C

    You want to perform the combo on your opponent in one popular fighting game. The combo is the string ...

  5. codeforces 1029E Tree with Small Distances【思维+贪心】 【非原创】

    题目:戳这里 学习博客:戳这里 题意:给一个树加最少的边,使得1到所有点的距离小于等于2. 解题思路:分析样例3可以看出,如果一个点到1的距离大于2,那么建立1到该点的父亲节点的边将比直接与该点建边更 ...

  6. Twist the Permutation 数列的轮换题 Codeforces 776 div3

    这是一道比较经典的将数列中的数字轮换的题目,我们先看题干: 题干分析:先浅浅地分析一下题目是要我们干什么,我们会默认有一个已经升序排序地1~n的排列,然后我们会给定一个新排列是在原有排列的基础上进行o ...

  7. 记一次神奇的codeforces

    今天有一场codeforces的div3,时间挺合适,于是就想打.结果发现rating超过1600就不能报名.虽然shzr好久不打CF了而且很菜,但是毕竟还是到了1600的,于是和ZUTTER_一起用 ...

  8. CodeForces Round #527 (Div3) B. Teams Forming

    http://codeforces.com/contest/1092/problem/B There are nn students in a university. The number of st ...

  9. 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3

    ◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...

随机推荐

  1. Storyboard Reference

    在某些情况下.你开发的应用可能包括有各种各样的复杂界面,假设你使用Storyboard来管理这些界面,通常你会将这些界面依照对应的逻辑分成很多子模块,放在不同的storyboard里,比方注冊相关的放 ...

  2. Python模块:配置文件解析器configparser

    版权声明:本文为博主皮皮http://blog.csdn.net/pipisorry原创文章,未经博主同意不得转载. https://blog.csdn.net/pipisorry/article/d ...

  3. 创建list方法总结

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/sheismylife/article/details/28878593 构建一个list 注意要标记 ...

  4. 1.cassandra的搭建

    参考: https://blog.csdn.net/ch648966459/article/details/51671276

  5. [py]面向对象图解assignment

    python的chained assignment 在python中 a is b is c 等价于 a is b and b is c 所以,猜猜 False is False is False # ...

  6. visualSVN server安装使用

    SVN服务推荐使用visualSVN server,安装完成之后自动设置开机启动服务,具体使用如下图:

  7. [LeetCode] 103. Binary Tree Zigzag Level Order Traversal _ Medium tag: BFS

    Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to ...

  8. [LeetCode] 438. Find All Anagrams in a String_Easy

    438. Find All Anagrams in a String DescriptionHintsSubmissionsDiscussSolution   Pick One Given a str ...

  9. selenium webdriver显示等待时间

    当页面加载很慢时,推荐使用显示等待:等到需要操作的那个元素加载成功之后就直接操作这个元素,不需要等待其他元素的加载 WebDriverWait wait = new WebDriverWait(dri ...

  10. iOS 网易彩票-3常见设置

    Navigation导航设置 为了统一管理导航控制器,需要自定义导航控制器MJNavigationController,继承于UINavigationController.分别设置5个Navigati ...