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
题目链接:戳我 大概题意:给一棵树,然后每次可以删除一个子树,问你期望多少次能把整棵树都删完? 概率和期望是个神仙..我不会 对于这个题,我们要有一个前置知识--期望的线性性,就是说总期望的值等于各个 ...
随机推荐
- Rcnn/Faster Rcnn/Faster Rcnn的理解
基于候选区域的目标检测器 1. 滑动窗口检测器 根据滑动窗口从图像中剪切图像块-->将剪切的图像块warp成固定大小-->cnn网络提取特征-->SVM和regressor进行分类 ...
- Vue和vue-template-compiler版本不一致
vue项目,package.json中Vue和vue-template-compiler版本不一致时,执行npm run dev有时会报错, 提示vue和vue-template-compiler版本 ...
- redhat 7.6 find 命令
1.按名字查找 find ./ -name filename //精确查找 ,./ 代表当前目录 -name 查询名称 filename具体文件名称 find ./ -na ...
- Python 基础之面向对象之常用魔术方法
一.__init__魔术属性 触发时机:实例化对象,初始化的时候触发功能:为对象添加成员,用来做初始化的参数:参数不固定,至少一个self参数返回值:无 1.基本用法 #例:class MyClass ...
- 135、Java中的静态块,构造方法和构造块
01.代码如下: package TIANPAN; class Book { static String msg; // static属性,暂不封装 public Book() { // 构造方法 S ...
- Numpy 为运算
Numpy “bitwise_” 开头的函数是位运算函数: Numpy 位运算包括以下几个函数: 函数 描述 bitwise_and 对数组元素执行位与操作 bitwise_or 对数组元素执行 ...
- Codeforces 1196D2 RGB Substring (Hard version) 题解
题面 \(q\) 个询问,每个询问给出一个字符串 \(s\),要你在 \(s\) 中用最小替换得到无穷字符串 RGBRGBRGB... 的长度为定值 \(k\) 的子串. 题解 一眼看过去可能是编辑距 ...
- RabbitMq学习笔记——概念
1.RabbitMQ简介 MQ全称为Message Queue(消息队列),是一种“应用程序”<—>“应用程序”的通信方法.MQ是一个典型的“消费”<—>“生产者”模型的代表, ...
- JDBC--DBUtils的使用
1.commons-dbutils是Apache组织提供的一个开源JDBC工具类库,它是对JDBC的简单封装,学习成本极低,并且使用dbutils能极大简化jdbc编码的工作量,同时也不会影响程序的性 ...
- Windows Mysql Server重启, log-bin路径配置
Windows Mysql Server重启, log-bin路径配置 分类: mysql数据库2014-03-16 14:49 1313人阅读 评论(0) 收藏 举报 Mysqlmysql serv ...