cf 763A. Timofey and a tree
呵呵呵,直接判断是不是一个点连起来所有的特殊边(连接2不同颜色的点的边)
(一开始还想各种各样奇怪的dfs。。。垃圾)
#include<bits/stdc++.h>
#define LL long long
#define N 100005
#define lowbit(x) x&(-x)
using namespace std;
inline int ra()
{
int x=,f=; char ch=getchar();
while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
return x*f;
}
int head[N],cnt;
struct node{
int next,to;
}e[N<<];
int n,col[N],tot;
void insert(int x, int y)
{
e[++cnt].next=head[x];
e[cnt].to=y;
head[x]=cnt;
}
void dfs(int x, int fa)
{
for (int i=head[x];i;i=e[i].next)
{
if (e[i].to==fa) continue;
if (col[e[i].to]!=col[x]) tot++;
dfs(e[i].to,x);
}
}
int main()
{
int n=ra();
for (int i=; i<n; i++)
{
int x=ra(),y=ra();
insert(x,y);
insert(y,x);
}
for (int i=; i<=n; i++)
col[i]=ra();
dfs(,);
for (int i=; i<=n; i++)
{
int sum=;
for (int j=head[i];j;j=e[j].next)
if (col[e[j].to]!=col[i]) sum++;
if (sum==tot)
{
cout<<"YES"<<endl<<i;
return ;
}
}
cout<<"NO";
return ;
}
cf 763A. Timofey and a tree的更多相关文章
- 763A - Timofey and a tree
		A. Timofey and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standa ... 
- Codeforces 763A. Timofey and a tree
		A. Timofey and a tree 题意:给一棵树,要求判断是否存在一个点,删除这个点后,所有连通块内颜色一样.$N,C \le 10^5$ 想法:这个叫换根吧.先求出一个点合法即其儿子的子树 ... 
- Codeforces Round #395 (Div. 2) C. Timofey and a tree
		地址:http://codeforces.com/contest/764/problem/C 题目: C. Timofey and a tree time limit per test 2 secon ... 
- 【codeforces 764C】Timofey and a tree
		time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ... 
- Codeforces 764C Timofey and a tree
		Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that th ... 
- CF 369C . Valera and Elections  tree dfs  好题
		C. Valera and Elections The city Valera lives in is going to hold elections to the city Parliament ... 
- CF 741D. Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths [dsu on tree 类似点分治]
		D. Arpa's letter-marked tree and Mehrdad's Dokhtar-kosh paths CF741D 题意: 一棵有根树,边上有字母a~v,求每个子树中最长的边,满 ... 
- CF E. Vasya and a Tree】 dfs+树状数组(给你一棵n个节点的树,每个点有一个权值,初始全为0,m次操作,每次三个数(v, d, x)表示只考虑以v为根的子树,将所有与v点距离小于等于d的点权值全部加上x,求所有操作完毕后,所有节点的值)
		题意: 给你一棵n个节点的树,每个点有一个权值,初始全为0,m次操作,每次三个数(v, d, x)表示只考虑以v为根的子树,将所有与v点距离小于等于d的点权值全部加上x,求所有操作完毕后,所有节点的值 ... 
- CF|codeforces 280C Game on Tree
		题目链接:戳我 大概题意:给一棵树,然后每次可以删除一个子树,问你期望多少次能把整棵树都删完? 概率和期望是个神仙..我不会 对于这个题,我们要有一个前置知识--期望的线性性,就是说总期望的值等于各个 ... 
随机推荐
- Django 学习 之路由层(URL)
			路由层(URL) 1.路由层简单配置 (1)path方法 写固定的url. (2)re_path方法 可以正则规则 例: urlpatterns = [ path('admin/', admin.si ... 
- uniGUI之学习方法(18)
			官方例子D:\Program Files\FMSoft\Framework\uniGUI\Demos\Desktop 在Design里Main上右键,View as Form看到变化的属性. 看出变化 ... 
- uniGUI读取文本文件(08)
			为了测试没有数据库下的简单入门例子 procedure TMainForm.UniButton2Click(Sender: TObject); // 读取 文本 var aStringlist: Ts ... 
- [PHP] PHP7已经删除了preg_replace的e修饰符
			官网提示是这样的,对/e修饰符的支持已删除.请改用preg_replace_callback()原因是/e 修正符使 preg_replace() 将 replacement 参数当作 PHP 代码( ... 
- [Linux] day05——命令行
			--------------------linux命令 实现某一功能指令或程序 命令行执行依赖于解释器linux命令的分类 内部命令 属于shell解释器一部分 /bin/bash 外部命令 独立与s ... 
- MVC PartialView使用
			https://blog.csdn.net/mss359681091/article/details/51181037 
- 利用TPL(任务并行库)构建Pipeline处理Dataflow
			https://www.cnblogs.com/CoderAyu/p/9757389.html 
- sqlplus导入sql,dmp导入导出
			1.创建表空间及用户名 1).用Oracle的EM做数据库的管理(表空间.用户及授权为例子) https://blog.csdn.net/anderslu/article/details/566701 ... 
- 三 基于Java数组手写循环队列
			Code: package dataStucture2.stackandqueue; /** * 手写循环队列 * * @param <E> */ public class MyLoopQ ... 
- String类与StringBuffer类
			String类与StringBuffer类 一.String类和StringBuffer类的区别 String类是不可变类,新建的对象为不可变对象(String类的内容和长度是固定的),一旦被创建 ... 
