题目链接:http://blog.csdn.net/popoqqq/article/details/45194103


写代码的时候也没有很清晰....具体看这里

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<queue>
using namespace std;
#define maxn 1001000
#define md 1000000007
#define llg long long
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,s,y,f[maxn],du[maxn],indu[maxn],ans,t;
struct node
{
llg po;
bool operator<(const node&a) const{
return du[a.po]<du[po];
}
}; vector<llg>a[maxn]; priority_queue<llg>q; llg inv(llg x)
{
llg b=md-;
llg sum=;
while (b)
{
if (b&) sum*=x,sum%=md;
x*=x; x%=md;
b/=;
}
return sum;
} void init()
{
llg x,y;
cin>>n>>m>>s>>t;
du[t]++,indu[t]++;
for (llg i=;i<=m;i++)
{
scanf("%lld%lld",&x,&y);
a[x].push_back(y),du[y]++; indu[y]++;
}
ans=;
f[t]=;
for (llg i=;i<=n;i++) ans*=indu[i],ans%=md,f[t]*=indu[i],f[t]%=md;
} void DP()
{
llg x;
for (llg i=;i<=n;i++) if (!du[i]) q.push(i);
du[t]--;
while (!q.empty())
{
x=q.top(); q.pop();
f[x]*=inv(indu[x]); f[x]%=md;
llg w=a[x].size();
for (llg i=;i<w;i++)
{
llg y=a[x][i];
f[y]+=f[x],f[y]%=md;
du[y]--;
if (!du[y]) q.push(y);
}
}
} int main()
{
yyj("tree");
init();
if (t==) {cout<<ans; return ;}
DP();
ans-=f[s]; ans+=md; ans%=md;
cout<<ans;
return ;
}

【BZOJ】4011: [HNOI2015]落忆枫音的更多相关文章

  1. BZOJ 4011: [HNOI2015]落忆枫音( dp )

    DAG上有个环, 先按DAG计数(所有节点入度的乘积), 然后再减去按拓扑序dp求出的不合法方案数(形成环的方案数). ---------------------------------------- ...

  2. BZOJ 4011: [HNOI2015]落忆枫音 计数 + 拓扑排序

    Description 「恒逸,你相信灵魂的存在吗?」 郭恒逸和姚枫茜漫步在枫音乡的街道上.望着漫天飞舞的红枫,枫茜突然问出 这样一个问题.  「相信吧.不然我们是什么,一团肉吗?要不是有灵魂……我们 ...

  3. BZOJ 4011 HNOI2015 落忆枫音 DAG上的dp(实际上重点在于分析)

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=4011 题意概述:给出一张N点的DAG(从1可以到达所有的点),点1的入度为0.现在加一条原 ...

  4. BZOJ 4011 HNOI2015 落忆枫音

    AC通道:http://www.lydsy.com/JudgeOnline/problem.php?id=4011 题目很长,写得也很有诗意与浪漫色彩,让我们不禁感叹出题人是一个多么英俊潇洒的人. 所 ...

  5. 4011: [HNOI2015]落忆枫音

    4011: [HNOI2015]落忆枫音 链接 分析: 原来是一个DAG,考虑如何构造树形图,显然可以给每个点找一个父节点,所以树形图的个数就是$\prod\limits_u deg[u]$. 那么加 ...

  6. bzoj4011[HNOI2015]落忆枫音 dp+容斥(?)

    4011: [HNOI2015]落忆枫音 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1125  Solved: 603[Submit][Statu ...

  7. [HNOI2015]落忆枫音 解题报告

    [HNOI2015]落忆枫音 设每个点入度是\(d_i\),如果不加边,答案是 \[ \prod_{i=2}^nd_i \] 意思是我们给每个点选一个父亲 然后我们加了一条边,最后如果还这么统计,那么 ...

  8. BZOJ4011: [HNOI2015]落忆枫音

    Description 「恒逸,你相信灵魂的存在吗?」 郭恒逸和姚枫茜漫步在枫音乡的街道上.望着漫天飞舞的红枫,枫茜突然问出 这样一个问题.  「相信吧.不然我们是什么,一团肉吗?要不是有灵魂……我们 ...

  9. [HNOI2015]落忆枫音

    题目描述 「恒逸,你相信灵魂的存在吗?」 郭恒逸和姚枫茜漫步在枫音乡的街道上.望着漫天飞舞的红枫,枫茜突然问出这样一个问题. 「相信吧.不然我们是什么,一团肉吗?要不是有灵魂......我们也不可能再 ...

随机推荐

  1. [转载]css3的一个控制背景的属性,background-size可以缩放大小啦

    background-size需要两个值,它的类型可以是像素(px).百分比(%)或是auto,还可以是cover和contain.第一个值为背景图的width,另外一个值用于指定背景图上的heigh ...

  2. The Little Prince-12/06

    The Little Prince-12/06 “That doesn't matter. Draw me a sheep.” When the prince ask the planet to dr ...

  3. 使用Holer将本地端口映射到公网

    What is holer Holerexposes local servers behind NATs and firewalls to the public internet over secur ...

  4. ads查询结果中文显示方框问题

    刚安装aqua data studio查询结果中文会变成小方框 选择File -->Options 找到General  -->Appearance,把Editor Font , Text ...

  5. Source Insight 如何将script等文件加入

    点击菜单栏Options -> Document Options , 然后再弹出的对话框中找到File filter,文件过滤的设置,里面肯能有*.c;*.h 你在后面添加Makefile,注意 ...

  6. Access is denied (user is anonymous); redirecting to authentication entry point

    Access is denied (user is anonymous); redirecting to authentication entry point org.springframework. ...

  7. Spring Boot(十二):spring boot如何测试打包部署

    Spring Boot(十二):spring boot如何测试打包部署 一.开发阶段 1,单元测试 在开发阶段的时候最重要的是单元测试了,springboot对单元测试的支持已经很完善了. (1)在p ...

  8. go开发工具及安装使用(Liteide)Liteide-centos6.8 安装

    开发工具介绍 LiteIDE https://github.com/visualfc/liteide/blob/master/liteidex/deploy/welcome/zh_CN/readme. ...

  9. sed/awk advance

    $ echo test.file [Group1]cacheways = 19 [Group2]cacheways = 19 $ ls test.sh FILE=test.file2 # Set Gr ...

  10. if语句学习

    #print("您好,我叫周星驰") ''' x=1+2+3 print(x*4) print(x**x) a=input("请输入相应的数字a") a=int ...