SSL2829 2017年11月2日提高组T1 Tree
来源:互联网 发布:apache cgi bin 编辑:程序博客网 时间:2024/05/19 00:47
2017年11月2日提高组T1 Tree
Description
Input
Output
Sample Input
10
1 1 0 0 1 0 0 0 0 0
1 2
2 3
2 4
4 5
2 6
6 7
7 8
7 9
4 10
Sample Output
1 3 4 5 6
Hint
分析:如果一个点的颜色和父节点不同就要改变这个点的颜色,因为只有这样才能使它的颜色与父亲相同,所以标记一下就好啦。
代码
#include <cstdio>#define maxn 600000using namespace std;int a[maxn],n;bool f[maxn];int main(){// freopen("tree.in","r",stdin);// freopen("tree.out","w",stdout); scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%d",&a[i]); if (a[1]==1) f[1]=true; for (int i=1;i<n;i++) { int x,y; scanf("%d%d",&x,&y); if (a[x]!=a[y]) f[y]=true; } for (int i=1;i<=n;i++) if (f[i]) printf("%d ",i); fclose(stdin); fclose(stdout);}
阅读全文
0 0
- SSL2829 2017年11月2日提高组T1 Tree
- 2017年11月2日提高组T1 Sequence
- 2017年11月4日提高组T1 背包
- SSL2828 2017年11月2日提高组T1 Sequence(kmp)
- 2017年8月7日提高组T1 呵呵
- 2017年8月7日提高组T1 呵呵
- 2017年8月7日提高组T1 呵呵
- 2017年8月7日提高组T1 根
- 2017年8月8日提高组T1 作业
- 2017年8月8日提高组T1 作业
- 2017年8月9日提高组T1 水题
- 2017年8月8日提高组T1 作业
- 2017年8月9日提高组T1 水题
- 2017年8月10日提高组T1 数学
- 2017年8月10日提高组T1 数学
- 2017年8月14日提高组T1 跳跃
- 2017年8月15日提高组T1 字符串
- 2017年8月10日提高组T1 数学
- 从request获取各种路径总结 request.getRealPath("url")
- 5.10判断闰年与平年的月天数
- 同步 异步传输
- Linux查看端口对应的PID
- CS231N学习笔记2 Assignment1_Q1: k-Nearest Neighbor classifier
- SSL2829 2017年11月2日提高组T1 Tree
- 眼底图像血管增强与分割--(5)基于Hessian矩阵的Frangi滤波算法
- Android自定义view画圆和view组合
- cocos3.10俄罗斯方块规则核心源码
- Spring集成Jersey开发,实现rest约束例子
- CCF考试——201609-1最大波动
- codeforces 672A Summer Camp
- html浮动定位相关知识
- c语言实现两个数的平均值