题目链接:http://codeforces.com/contest/764/problem/C 题意:给出一个树,然后各个节点有对应的颜色,问是否存在以一个点为根节点子树的颜色都一样. 这里的子树颜色都一样表示分出来的子树各自颜色一样. 就是随意找一个树叶节点然后一直遍历,直到找到一个和他颜色不一样的节点,那么要么取不一样的节点 为根或者取最后一个一样的节点为根.然后就dfs一遍. #include <iostream> #include <cstring> #include &…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that they paint all the n its vertices, so that the…
题目链接:http://codeforces.com/contest/620/problem/E E. New Year Tree time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output The New Year holidays are over, but Resha doesn't want to throw away the N…
题意:给出一棵树,共有n个节点,其中根节点是Kefa的家,叶子是restaurant,a[i]....a[n]表示i节点是否有猫,问:Kefa要去restaurant并且不能连续经过m个有猫的节点有多少条路径: 思路:先用vector数组建树: 再dfs..(第一次用vector建树,还看了别人的代码,果然是zz): 代码: #include <bits/stdc++.h> #define ll long long #define MAXN 100000+10 using namespace…
题目链接: C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic r…
http://codeforces.com/problemset/problem/760/C 题意:有n个盘子,每个盘子有一块肉,当肉路过这个盘子的时候,当前朝下的这一面会被煎熟,每个盘子有两个数,pi代表接下来去第pi个盘子,bi为1的话,这块肉会被反面,0的话这块肉不变.对于每块肉,要让它的两面都在每个盘子里面煎过,问最少的修改次数. 思路:有两个条件:1.让图变得连通最少需要修改的方案.2.要让肉两边都被煎到要怎么考虑. 1.这个简单就是一遍DFS求出连通块数,如果连通块数是1的话,就不需…
题目链接:http://codeforces.com/contest/760/problem/C 题意:一共有N个烤炉,有N个烤串,一开始正面朝上放在N个位子上.一秒之后,在位子i的串串会移动到pi位子上,并且如果bi为1,那么我们还要将烤串翻个面.现在要求每个烤串的正反两面要经历所有位置,然而现在的机制不一定能够完成任务,让你修改最少的操作,使得满足这个操作. 显然要满足只有一个环才能实现经历所有位置,而且要经历正反面所以一趟循环下来变化次数必须为奇数,不然回到原来位置时还是同样的朝向 #in…
地址:http://codeforces.com/contest/764/problem/C 题目: C. Timofey and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Each New Year Timofey and his friends cut down a tree of n vertices…
A. Timofey and a tree 题意:给一棵树,要求判断是否存在一个点,删除这个点后,所有连通块内颜色一样.$N,C \le 10^5$ 想法:这个叫换根吧.先求出一个点合法即其儿子的子树内颜色一样,非该点子树的点颜色都一样.可以用DFS序解决. #include< cstdio > typedef long long ll; template inline void read(T&x) { x=0;bool f=0;char c=getchar(); while((c&l…
Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that they paint all the n its vertices, so that the i-th vertex gets color ci. Now it's time for Timofey birthday, and his mother asked him to remove the tre…