首页 > 其他分享 >CSU 1804 有向无环图

CSU 1804 有向无环图

时间:2022-11-09 19:31:33浏览次数:46  
标签:1804 const int rep 环图 CSU mod include define


Description


Bobo 有一个 n 个点,m 条边的有向无环图(即对于任意点 v,不存在从点 v 开始、点 v 结束的路径)。



为了方便,点用 1,2,…,n 编号。 设 count(x,y) 表示点 x 到点 y 不同的路径数量(规定 count(x,x)=0),Bobo 想知道






9+7) 的余数。


i,b j


Input


输入包含不超过 15 组数据。


5).


i,b i (0≤a i,b i≤10 9).


i,v i,代表一条从点 u i 到 v i 的边 (1≤u i,v i≤n)。


Output


对于每组数据,输出一个整数表示要求的值。


Sample Input

3 3
1 1
1 1
1 1
1 2
1 3
2 3
2 2
1 0
0 2
1 2
1 2
2 1
500000000 0
0 500000000
1 2

Sample Output

#include<set>
#include<map>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<bitset>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
#define loop(i,j,k) for (int i = j;i != -1; i = k[i])
#define lson x << 1, l, mid
#define rson x << 1 | 1, mid + 1, r
#define ff first
#define ss second
#define mp(i,j) make_pair(i,j)
#define pb push_back
#define pii pair<int,LL>
#define in(x) scanf("%d", &x);
using namespace std;
typedef long long LL;
const int low(int x) { return x&-x; }
const double eps = 1e-9;
const int INF = 0x7FFFFFFF;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
int T, n, m, x, y;
int a[N], b[N], ans[N];
int ft[N], nt[N], u[N], in[N], sz;

int main()
{
while (scanf("%d%d", &n, &m) != EOF)
{
rep(i, 1, n)
{
scanf("%d%d", &a[i], &b[i]);
ft[i] = -1, in[i] = 0;
ans[i] = 0;
}
sz = 0;
rep(i, 1, m)
{
scanf("%d%d", &x, &y);
u[sz] = x; nt[sz] = ft[y]; ft[y] = sz++; in[x]++;
}
LL res = 0;
queue<int> p;
rep(i, 1, n) if (!in[i]) p.push(i);
while (!p.empty())
{
int q = p.front(); p.pop();
loop(i, ft[q], nt)
{
(ans[u[i]] += (ans[q] + b[q]) % mod) %= mod;
if (!--in[u[i]]) p.push(u[i]);
}
}
rep(i, 1, n) (res += 1LL * a[i] * ans[i] % mod) %= mod;
printf("%lld\n", res);
}
return 0;
}

标签:1804,const,int,rep,环图,CSU,mod,include,define
From: https://blog.51cto.com/u_15870896/5838623

相关文章

  • CSU 1803 2016
    Description 给出正整数n和m,统计满足以下条件的正整数对(a,b)的数量:1.1≤a≤n,1≤b≤m;2.a×b是2016的倍数。Input......
  • 拓端tecdat|R语言GGPLOT2绘制圆环图雷达图/星形图/极坐标图/径向图Polar Chart可视化
    漂亮的圆形图。我不确定对数据分析师本身是否有额外的好处,但如果能吸引决策者的注意,那对我来说就是额外的价值。然而,用coord_polar()或偶尔发现的ggplot2中的coord_radar()......
  • csu 1554: SG Value 思维题
    ​​http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1554​​这题在比赛的时候居然没想出来,然后发现居然是做过的题目的变种!!!!先不考虑插入操作,就给定一堆数字,求出不能......
  • D - Simple String CSU - 1550
    ​​http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1550​​很久都没补这题,最近想学网络流,就看看,队友以前用网络流过的,Orz,但是这题只需要简单的判断,可能想起来有点麻......
  • csu 1552: Friends 二分图 + Miller_Rabin
    ​​http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1552​​把那n个数写两次,分成相同的两堆,判断相加是质数的,连一条边,然后找最大匹配,ans=最大匹配/2做的时候一直......
  • csu 1551: Longest Increasing Subsequence Again BIT + 思维
    预处理last[i]表示以第i个开始,的合法后缀。pre[i]表示以第i个结尾,的合法前缀。那么每一个数a[i],肯定是一个合法后缀last[i]+一个合法前缀,那么合法前缀的数字要小于a[i],并......
  • PXE无人值守安装ubuntu1804系统
       从以下截图可以看出,自动化安装ubuntu系统已经成功,进入安装软件包界面一开始错误原因: domain-name-servers配置错了,网络没通,后来改为114.114.114.114进行域名解......
  • ubuntu1804(Linux)默认office软件word excle LibreOffice
    Ubuntu18.04 默认安装office工具,LibreOffice 下载、安装:打开“Ubuntu软件”--点界面右上角“放大镜”来搜索--“LibreOffice”  - ......
  • 直播电商平台开发,顺序循环图片切换
    直播电商平台开发,顺序循环图片切换1.body <divclass="box">    <divclass="btnbox">    <buttonclass="active">顺序播放</button>    <bu......
  • ubuntu1804 pixel xl 编译安装lineage-18.1
    官方文档https://wiki.lineageos.org/devices/marlin/build下载源码repoinit-uhttps://github.com/LineageOS/android.git-blineage-18.1reposync-c此处需要梯......