呵呵呵,直接判断是不是一个点连起来所有的特殊边(连接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. yum软件仓库常用命令

    一.PRM简化安装软件的复杂度 安装软件的命令格式 prm -ivh filename.rpm 升级软件的命令格式 prm -Uvh filename.rpm 卸载软件的命令格式 prm -e fil ...

  2. Python 基础之linux基础相关

    一: python3.6.x在Ubuntu16.04下安装过程 #(1)保证网络正常连接 sudo add-apt-repository ppa:jonathonf/python-3.6  (如果超时 ...

  3. MySQL操作之DDL

    目录 SQL语句的分类 DDL语句 SQL语句的分类 DDL(Data Definition Languages)语句:数据定义语言.这些语句定义了不同的数据段. 数据库.表.列.索引等数据库对象的定 ...

  4. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:块级按钮(拉伸至父元素100%的宽度)

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  5. 基于Phoenix对HBase建索引

    参考: Phoenix与HBase集成进行数据分析 HBase查询速度慢原因排查 操作1,执行查询,如下: : jdbc:phoenix:node3::/hbase> SELECT * FROM ...

  6. .net设置浏览器缓存和跨域的几种方法

    .自定义过滤器属性 public class NoCacheAttribute : FilterAttribute, IActionFilter { public void OnActionExecu ...

  7. Linux CentOS7 VMware 安装软件包的三种方法、rpm包介绍、rpm工具用法、yum工具用法、yum搭建本地仓库

    一.安装软件包的三种方法 Linux下游三种安装方法,rpm工具.yum工具.源码包.rpm按装一个程序包时,有可能因为该程序包依赖另一个程序包而无法安装:yum工具,可以连同依赖的程序包一起安装. ...

  8. Kotlin 学习 (一)

    开始学习kotlin mark入门资料一篇: Kotlin入门第一课:从对比Java开始 未完待续...

  9. SQL SERVER查询数据库所有的表名/字段

    SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='subject' --表名 1.利用sysobjects系统表 在这个表中,在数据 ...

  10. 51nod 1391:01串

    1391 01串 题目来源: Codility 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题  收藏  关注 给定一个01串S,求出它的一个尽可能长的子串S[i. ...