zl程序教程

CodeForces 23E Tree

  • 【Codeforces 682C】Alyona and the Tree

    【Codeforces 682C】Alyona and the Tree

    【链接】 我是链接,点我呀:) 【题意】 题意 【题解】 设dis[v]表示v以上的点到达这个点的最大权值(肯定是它的祖先中的某个点到这个点) 类似于最大连续累加和 当往下走(x,y)这条边的时候,设其权值为w,以及到目前为止走过的最大权值和cur 如果cur<0,那么就不要之前的路径了,直接加上cur。 否则连着之前的路径加上去就好。 这样就能贪心地求出来dis[v]了

    日期 2023-06-12 10:48:40     
  • 【Codeforces 161D】Distance in Tree

    【Codeforces 161D】Distance in Tree

    【链接】 我是链接,点我呀:) 【题意】 问你一棵树上有多少条长度为k的路径 【题解】 树形dp 设 size[i]表示以节点i为根节点的子树的节点个数 dp[i][k]表示以i为根节点的子树里面距离节点i的距离为k的节点有多少个. 长度为k的路径有两种情况. 1.这个路径从x开始,只经过x的一个子树. 2.这个路径经过x,横跨x的两个子树. 第一种情况直接累加dp[x][k]即

    日期 2023-06-12 10:48:40     
  • 【Codeforces Round #453 (Div. 2) B】Coloring a Tree

    【Codeforces Round #453 (Div. 2) B】Coloring a Tree

    【链接】 我是链接,点我呀:) 【题意】 在这里输入题意 【题解】 从根节点开始。 显然它是什么颜色.就要改成对应的颜色。(如果上面已经有某个点传了值就不用改 然后往下传值。 【代码】 #include <bits/stdc++.h> using namespace std; const int N = 1e4; int n,c[N+10],ans; vect

    日期 2023-06-12 10:48:40     
  • 【13.91%】【codeforces 593D】Happy Tree Party

    【13.91%】【codeforces 593D】Happy Tree Party

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Bogdan has a birthday today and mom gave him a tree consisting of n vertecies. F

    日期 2023-06-12 10:48:40     
  • 【27.91%】【codeforces 734E】Anton and Tree

    【27.91%】【codeforces 734E】Anton and Tree

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Anton is growing a tree in his garden. In case you forgot, the tree is a connect

    日期 2023-06-12 10:48:40     
  • 【codeforces 791D】 Bear and Tree Jumps

    【codeforces 791D】 Bear and Tree Jumps

    【题目链接】:http://codeforces.com/contest/791/problem/D 【题意】 你可以从树上的节点一次最多走k条边。 (称为跳一次); 树为无权树; 然后问你任意两点之间的条的次数的和为多少; 【题解】 如果k=1的话; 问题就是求任意两点之间的距离的和了; 这个可以在O(N)的复杂度下搞出来; 即 枚举每一条边

    日期 2023-06-12 10:48:40     
  • 【codeforces 723F】st-Spanning Tree

    【codeforces 723F】st-Spanning Tree

    【题目链接】:http://codeforces.com/contest/723/problem/F 【题意】 给你一张图; 让你选择n-1条边; 使得这张图成为一颗树(生成树); 同时s的度数不超过ds且t的度数不超过dt 【题解】 先把s和t隔离开; 考虑其他点形成的若干个联通块; 因为一开始的图是联通的; 所以,那些不同的联通块,肯定是通过

    日期 2023-06-12 10:48:40     
  • codeforces 570 D. Tree Requests  树状数组+dfs搜索序

    codeforces 570 D. Tree Requests 树状数组+dfs搜索序

    链接:http://codeforces.com/problemset/problem/570/D D. Tree Requests time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Roman

    日期 2023-06-12 10:48:40     
  • CodeForces 383C Propagating tree

    CodeForces 383C Propagating tree

    Propagating tree Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 383C64-bit integer IO format: %I64d      Ja

    日期 2023-06-12 10:48:40     
  • 【CodeForces 614A】Link/Cut Tree

    【CodeForces 614A】Link/Cut Tree

    题 题意 给你一个区间,求里面有多少个数是k的次方。 分析 暴力,但是要注意这题范围会爆long long,当k=1e8; l=1;r=1e18时 k²=1e16,判断了是≤r,然后输出,再乘k就是1e24 , ULL 都存不下,就爆了。 所以当 t > r / k 时跳出循环 代码 AC代码 #include <stdio.h> unsigned long long l,r,k,

    日期 2023-06-12 10:48:40