题目描述:链接点此
这套题的github地址(里面包含了数据,题解,现场排名):点此
题目描述
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.
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
输入
4 1 2 2 3 3 4
输出
10
说明
For a chain, there are ten different connected subgraphs:
/* data:2018.04.22 author:gsw link:https://www.nowcoder.com/acm/contest/104#question tip:武大校赛--补题 */ #define IO ios::sync_with_stdio(false); #define ll long long #define mod 10000007 #define maxn 200005 #include<iostream> #include<string.h> #include<math.h> #include<stdio.h> #include<vector> #include<algorithm> using namespace std; int dp[maxn]; vector<int> g[maxn]; int a,b,n,ans=0; void init() { memset(dp,0,sizeof(dp)); } void dfs(int node,int fa) { ll t=1; for(int i=0;i<g[node].size();i++) { if(g[node][i]==fa)continue; dfs(g[node][i],node); t=(t+t*dp[g[node][i]])%mod; } dp[node]=t; ans=(ans+t)%mod; } int main() { init(); scanf("%d",&n); for(int i=0;i<n-1;i++) { scanf("%d%d",&a,&b); g[a].push_back(b);g[b].push_back(a); } dfs(1,0); printf("%d\n",ans); }