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
题目链接:戳我 大概题意:给一棵树,然后每次可以删除一个子树,问你期望多少次能把整棵树都删完? 概率和期望是个神仙..我不会 对于这个题,我们要有一个前置知识--期望的线性性,就是说总期望的值等于各个 ...
随机推荐
- autoit 《FAQ 大全》
常见问题: Q1 如何调试脚本? MsgBox(0,"测试",$var) ConsoleWrite("var=" & $var & @CRLF ...
- 【快学springboot】12.实现拦截器
前言 之前在[快学springboot]6.WebMvcConfigurer配置静态资源和解决跨域里有用到WebMvcConfigurer接口来实现静态资源的映射和解决跨域请求,并且在文末还说了Web ...
- pytorch神经网络解决回归问题(非常易懂)
对于pytorch的深度学习框架,在建立人工神经网络时整体的步骤主要有以下四步: 1.载入原始数据 2.构建具体神经网络 3.进行数据的训练 4.数据测试和验证 pytorch神经网络的数据载入,以M ...
- python中提取位图信息(AttributeError: module 'struct' has no attribute 'unstack')
前言 今天这篇博文有点意思,它是从一个例子出发,从而体现出在编程中的种种细节和一些知识点的运用.和从前一样,我是人,离成神还有几十万里,所以无可避免的出现不严谨的地方甚至错误,请酌情阅读. 0x00 ...
- 七 异常处理的两种方式(创建全局异常处理器&自定义异常)
1 创建全局异常处理器 实现HandlerExceptionResolve接口 package com.springmvc01; import javax.servlet.http.HttpServl ...
- 使用 sp_attach_db 系统存储过程附加数据库时---转载
//附加数据库 sp_attach_db 当使用 sp_attach_db 系统存储过程附加数据库时. sp_attach_db:将数据库附加到服务器. 语法 sp_attach_db [ @dbna ...
- 如何给Sqlite添加复合主键
如果是想两个字段组成一个复合主键的话可以如下.SQL code sqlite> create table t2 ( ...> id1 int , ...> id2 int, ...& ...
- LeetCode 297.序列化二叉树 - JavaScript
题目描述 序列化是将一个数据结构或者对象转换为连续的比特位的操作,进而可以将转换后的数据存储在一个文件或者内存中,同时也可以通过网络传输到另一个计算机环境,采取相反方式重构得到原数据. 请设计一个算法 ...
- 用go语言实现磁力猫一样的磁力搜索网站
1.页面展示 演示站点 2.程序架构 名称 用途 server 收集torrent数据 worker 收集Hash信息 web 数据展示 Tool 工具 3.安装 在安装环境前您需要配置golang环 ...
- 利用Powerdesigner16.5(64位)连接64位oracle 配置系统odbc驱动
利用Powerdesigner16.5(64位)连接64位oracle逆向工程数据库 记录一次Powerdesigner通过odbc连接64位oracle数据库.林林总总国内看到都是些乱七八糟没几个靠 ...