Who killed Cock Robin?

I, said the Sparrow, With my bow and arrow,I killed Cock Robin.

Who saw him die?

I, said the Fly.With my little eye,I saw him die.

Who caught his blood?

I, said the Fish,With my little dish,I caught his blood.

Who'll make his shroud?

I, said the Beetle,With my thread and needle,I'll make the shroud.

.........

All the birds of the air

Fell a-sighing and a-sobbing.

When they heard the bell toll.

For poor Cock Robin.

March 26, 2018

Sparrows are a kind of gregarious animals,sometimes the relationship between them can be represented by a tree.

The Sparrow is for trial, at next bird assizes,we should select a connected subgraph from the whole tree of sparrows as trial objects.

Because the relationship between sparrows is too complex, so we want to leave this problem to you. And your task is to calculate how many different ways can we select a connected subgraph from the whole tree.

输入描述:

The first line has a number n to indicate the number of sparrows. n\le 2\times 10^5n≤2×10

5

The next n-1 row has two numbers x and y per row, which means there is an undirected edge between x and y.

输出描述:

The output is only one integer, the answer module 10000007 (107+7) in a line

简而言之 计算我们能用多少种不同的方式从整个树中选择一个连通的子图。


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=2e5+10,mod=1e7+7;
#define int long long
int Next[N*2],head[N],go[N*2],tot;
inline void add(int u,int v){
Next[++tot]=head[u];head[u]=tot;go[tot]=v;
Next[++tot]=head[v];head[v]=tot;go[tot]=u;
}
int dp[N][2],n;
inline void dfs(int u,int fa){
dp[u][1]=1,dp[u][0]=0;
for(int i=head[u];i;i=Next[i]){
int v=go[i];
if(v==fa)continue;
dfs(v,u);
dp[u][0]=dp[u][0]+(dp[v][1]+dp[v][0])%mod;
dp[u][1]=(dp[u][1]*(dp[v][1]+1))%mod;
}
}
signed main(){
cin>>n;
for(int i=1,u,v;i<n;i++){scanf("%lld%lld",&u,&v);add(u,v);}
dfs(1,1);
cout<<(dp[1][1]+dp[1][0])%mod<<endl;
}

牛客竞赛-Who killed Cock Robin的更多相关文章

  1. D. Who killed Cock Robin 湖北省大学程序设计竞赛

    链接:https://www.nowcoder.com/acm/contest/104/C来源:牛客网 The Sparrow is for trial, at next bird assizes,w ...

  2. 2020牛客竞赛 DP F 碎碎念

    作者:儒生雄才1链接:https://ac.nowcoder.com/discuss/366644来源:牛客网 题目连接:https://ac.nowcoder.com/acm/contest/300 ...

  3. 牛客竞赛&&mjt的毒瘤赛

    题目链接 https://ac.nowcoder.com/acm/contest/368/F 思路 询问可以离线. 然后每个节点上建32个权值线段树(权值不大,其实只要20颗) 记录每一位权值为x(如 ...

  4. 牛客竞赛(gcd,快速幂)

    一.最大公约数和最小公倍数问题 题目描述: 输入2个正整数x0,y0(2<=x0<100000,2<=y0<=1000000),求出满足下列条件的P,Q的个数. 条件:1.P, ...

  5. 2019牛客竞赛第六场D Move 宏观单调,部分不单调

    Move 题意 有k个体积相同的箱子,有个憨憨有固定的装箱策略,每次都只装可以装的重量中最大的东西,求箱子的最小提及 分析 看起来可以二分,但由于他的装箱策略有点蠢,所以只在宏观上满足单调性,在特别小 ...

  6. 牛客竞赛第二场D Kth Minimum Clique 贪心+bitmap

    Kth Minimum Clique 题意 给出n(n<100)个点的邻接表,和n个点的权值,求第k大的团(完全子图) 分析 n很小,并且好像没有什么算法和这个有关系,所以可以往暴力枚举的方向想 ...

  7. D. Who killed Cock Robin--“今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛)

    题目描述:链接点此 这套题的github地址(里面包含了数据,题解,现场排名):点此 题目描述 由于系统限制,C题无法在此评测,此题为现场赛的D题 Who killed Cock Robin? I, ...

  8. 牛客网 桂林电子科技大学第三届ACM程序设计竞赛 G.路径-带条件的树的直径变形-边权最大,边数偶数的树上的最长路径-树形dp

    链接:https://ac.nowcoder.com/acm/contest/558/G 来源:牛客网 路径 小猫在研究树. 小猫在研究路径. 给定一棵N个点的树,每条边有边权,请你求出最长的一条路径 ...

  9. 牛客网 桂林电子科技大学第三届ACM程序设计竞赛 D.寻找-树上LCA(树上a到b的路径上离c最近的点)

    链接:https://ac.nowcoder.com/acm/contest/558/D来源:牛客网 寻找 小猫在研究树. 小猫在研究树上的距离. 给定一棵N个点的树,每条边边权为1. Q次询问,每次 ...

随机推荐

  1. Android9.0 SystemUI 网络信号栏定制修改

    前情提要 Android 8.1平台SystemUI 导航栏加载流程解析 9.0 改动点简要说明 1.新增 StatusBarMobileView 替代 SignalClusterView,用以控制信 ...

  2. jQuery源码分析--为什么在参数列表中传入undefined

    (function(window, undefined){ //jQuery code; })(window); 为什么要传入undefined? 1.没有传入undefined: <!DOCT ...

  3. linux与Windows进程控制

    进程管理控制 这里实现的是一个自定义timer用于统计子进程运行的时间.使用方式主要是 timer [-t seconds] command arguments 例如要统计ls的运行时间可以直接输入t ...

  4. 在VMware通过挂载系统光盘搭建本地yum仓库

    1.首先需要有一个VMware虚拟机: 2.进去虚拟机(这里用Linux下deCentOS进行演示): 3.用root账号进行登录,否则在根目录下没有一些操作权限: 4.打开终端: 5,输入命令“cd ...

  5. 移动端vue页面禁止移动/滚动

    当需要在移动端中禁止页面滚动,加入:@touchmove.prevent即可,例子如下 <template> <div @touchmove.prevent> <h3 c ...

  6. PostGIS 结合Openlayers以及Geoserver实现最短路径分析(二)

    前文讲述了怎么用ArcMap制作了测试数据,并导入了PostGIS,接下来我们需要结合PgRouting插件,对入库的数据再进行一下处理. 1.在pgAdmin中,执行下面的sql语句 --添加起点字 ...

  7. PHP中echo与print语句的实例教程

    在 PHP 中,有两种基本的输出方法:echo 和 print. echo与print的差异 echo能够输出一个以上的字符串. print只能输出一个字符串,并始终返回 1. 提示:echo 比 p ...

  8. python3 之 面向对象(类)、继承、派生和多态

    类提供了一种 组合数据和功能 的方法.创建一个新类意味着:创建一个新 类型  的对象,从而允许创建一个该类型的新 实例. 每个类的实例可以拥有: 保存自己状态的属性. 一个类的实例也可以有改变自己状态 ...

  9. 2019-11-19:无返回的盲型xxe,使用带外读取数据

    文章资料来源于网络,仅供参考,学习使用 复现盲型xxe 实验环境:bwapp,xxe关,注释掉了返回值 准备读取的flag.txt文件为 通过利用服务器外带数据方法步骤 1,攻击机服务器新建两个文件, ...

  10. [ch04-02] 用梯度下降法解决线性回归问题

    系列博客,原文在笔者所维护的github上:https://aka.ms/beginnerAI, 点击star加星不要吝啬,星越多笔者越努力. 4.2 梯度下降法 有了上一节的最小二乘法做基准,我们这 ...