呵呵呵,直接判断是不是一个点连起来所有的特殊边(连接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的更多相关文章

  1. 763A - Timofey and a tree

    A. Timofey and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  2. Codeforces 763A. Timofey and a tree

    A. Timofey and a tree 题意:给一棵树,要求判断是否存在一个点,删除这个点后,所有连通块内颜色一样.$N,C \le 10^5$ 想法:这个叫换根吧.先求出一个点合法即其儿子的子树 ...

  3. 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 ...

  4. 【codeforces 764C】Timofey and a tree

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 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 ...

  6. 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 ...

  7. 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,求每个子树中最长的边,满 ...

  8. 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,求所有操作完毕后,所有节点的值 ...

  9. CF|codeforces 280C Game on Tree

    题目链接:戳我 大概题意:给一棵树,然后每次可以删除一个子树,问你期望多少次能把整棵树都删完? 概率和期望是个神仙..我不会 对于这个题,我们要有一个前置知识--期望的线性性,就是说总期望的值等于各个 ...

随机推荐

  1. 奈奎斯特采样定理(Nyquist)

    采样定理在1928年由美国电信工程师H.奈奎斯特首先提出来的,因此称为奈奎斯特采样定理. 1933年由苏联工程师科捷利尼科夫首次用公式严格地表述这一定理,因此在苏联文献中称为科捷利尼科夫采样定理. 1 ...

  2. kill和raise

    kill向特定的进程和进程组发送信号 raise向进程自身发送信号

  3. SAP BO WebI 如何连接webi server folder下面的EXCEL文件作为数据源

    昨天做Webi Report,需要连接一个在Webi Server Folder下面的EXCEL文件作为数据源,然后再去生成相应的报表,找了半天才找到可以连接Webi Server Folder的EX ...

  4. 题解 LG P2264

    这是题解P2264 先讲一下Trie,其实Trie也名前缀树,就是说:如果Trie中某串是某串的前缀,那么我们可以共用这个串也就是这样: 插入h.hk.jc,jcfa 那么,h节点会给h和hk共用,j ...

  5. c++中比较好用的“黑科技”

    切入正题,上黑科技 一.黑科技函数(常用的我就不写了,例如sort函数) 1.next_permutation(a+1,a+1+n) a[1-n]全排列 2.reverse(a+1,a+1+n) 将a ...

  6. Unity 公告板 Billboard

    创建脚本如下 Billboard.cs using UnityEngine; using System.Collections; public class Billboard : MonoBehavi ...

  7. 单词统计——基本Java实现(无特殊设置)

    日期:2019.5.4 博客期:066 星期六 今天写了统计一篇文章中的单词数量,把出现最多的前几个显示出来,差不多就是这么个程序! 实现思想: 分布处理: 1.读取文件,将文件里的字符串按照换行符和 ...

  8. 多门店4s管理系统

    下载 系统登录用户名与密码:manage/123456

  9. spring中的@Transactional注解

    前几天灿哥问我,在做程序的时候,有没有考虑到事务,如果一个函数在中间执行过程中报错了,它会回滚么?我查了一查,spring确实有这样一个注解,能快速帮助我们配置事务管理.下面我就简单介绍一下这个注解. ...

  10. SciPy 信号处理

    章节 SciPy 介绍 SciPy 安装 SciPy 基础功能 SciPy 特殊函数 SciPy k均值聚类 SciPy 常量 SciPy fftpack(傅里叶变换) SciPy 积分 SciPy ...