「CF427C」Checkposts
Your city has n junctions. There are m one-way roads between the junctions. As a mayor of the city, you have to ensure the security of all the junctions.
To ensure the security, you have to build some police checkposts. Checkposts can only be built in a junction. A checkpost at junction ican protect junction j if either i = j or the police patrol car can go to j from i and then come back to i.
Building checkposts costs some money. As some areas of the city are more expensive than others, building checkpost at some junctions might cost more money than other junctions.
You have to determine the minimum possible money needed to ensure the security of all the junctions. Also you have to find the number of ways to ensure the security in minimum price and in addition in minimum number of checkposts. Two ways are different if any of the junctions contains a checkpost in one of them and do not contain in the other.
In the first line, you will be given an integer n, number of junctions (1 ≤ n ≤ 105). In the next line, n space-separated integers will be given. The ith integer is the cost of building checkpost at the ith junction (costs will be non-negative and will not exceed 109).
The next line will contain an integer m (0 ≤ m ≤ 3·105). And each of the next m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n; u ≠ v). A pair ui, vi means, that there is a one-way road which goes from ui to vi. There will not be more than one road between two nodes in the same direction.
Print two integers separated by spaces. The first one is the minimum possible money needed to ensure the security of all the junctions. And the second one is the number of ways you can ensure the security modulo 1000000007 (109 + 7).
1 2 3 4 5 6 |
3 1 2 3 3 1 2 2 3 3 2 |
1 |
3 1 |
1 2 3 4 5 6 7 8 9 |
5 2 8 0 6 0 6 1 4 1 3 2 4 3 4 4 5 5 1 |
1 |
8 2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
10 1 3 2 2 1 3 1 4 10 10 12 1 2 2 3 3 1 3 4 4 5 5 6 5 7 6 4 7 3 8 9 9 10 10 9 |
1 |
15 6 |
1 2 3 4 5 |
2 7 91 2 1 2 2 1 |
1 |
7 1 |
题解
找强连通分量,然后在一个连通块中找最小值以及最小值的个数
然后乘法原理。。。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #define inf 0x7fffffff #define ll long long #define N 100001 #define M 300001 #define mod 1000000007 using namespace std; struct data{int to,next;}e[M]; int head[N]; int n,m,now,cnt,top; int v[N],dfn[N],low[N],q[N]; int scc,mn[N],belong[N],num[N]; bool vis[N],inq[N]; ll ans1=1,ans2; void dfs(int a) { vis[a]=inq[a]=1; low[a]=dfn[a]=++cnt; q[++top]=a; int c=head[a]; while(c) { if(!vis[e[c].to]) { dfs(e[c].to); low[a]=min(low[a],low[e[c].to]); } else if(inq[e[c].to])low[a]=min(low[a],dfn[e[c].to]); c=e[c].next; } if(low[a]==dfn[a]) { scc++; belong[a]=scc; mn[scc]=inf; do { now=q[top--]; inq[now]=0; belong[now]=scc; if(v[now]<mn[scc]){mn[scc]=v[now];num[scc]=0;} if(v[now]==mn[scc])num[scc]++; } while(now!=a); } } void tarjan() { for(int i=1;i<=n;i++) if(!vis[i])dfs(i); } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&v[i]); scanf("%d",&m); for(int i=1;i<=m;i++) { int x,y; scanf("%d%d",&x,&y); e[i].to=y; e[i].next=head[x]; head[x]=i; } tarjan(); for(int i=1;i<=scc;i++) { ans1*=num[i];ans2+=mn[i]; ans1%=1000000007; } printf("%I64d %I64d",ans2,ans1); return 0; } |
分类目录
热门文章
- 16757 「BZOJ1123」[POI2008] BLO
- 12006PKU2019数据结构与算法实习期末考试
- 10486「BZOJ1797」[Ahoi2009] Mincut 最小割
- 10329「BZOJ1051」[HAOI2006] 受欢迎的牛
- 7543「BZOJ1093」[ZJOI2007] 最大半连通子图
- 6661PKU2019数据结构与算法实习作业 11~21
- 6587 「BZOJ2427」[HAOI2010] 软件安装
- 6361「BZOJ1179」[Apio2009] 抢掠计划atm
- 6236「BZOJ1924」[SDOI2010] 所驼门王的宝藏
- 6172「BZOJ2208」[JSOI2010] 连通数
- 61142017ACM萧山训练第2场(NWERC 2008)
- 6102「BZOJ2730」[HNOI2012] 矿场搭建
- 5983「BZOJ2438」[中山市选2011] 杀人游戏
- 5644PKU2019数据结构与算法实习模板
- 5456「CF1276X」Codeforces Round #606 (Div. 1)
- 5344「CF506B」Mr. Kitayuta's Technology
- 5336「BZOJ2893」征服王
- 5214「BZOJ1194」[HNOI2006] 潘多拉的盒子
- 5147「BZOJ1529」[POI2005] ska Piggy banks
- 4865「CF403C」Strictly Positive Matrix
- 4649「图论练习」easy
- 4402usaco 刷水。。。
- 4243「BZOJ1589」[Usaco2008 Dec] Trick or Treat on the Farm 采集糖果
- 3907「CODEVS2822」爱在心中
- 3803「NOIP模拟赛」交通
- 3786「BZOJ3391」[Usaco2004 Dec] Tree Cutting网络破坏
- 3549「图论练习」medium
- 3453「uoj #67」新年的毒瘤
- 3337「NOIP模拟赛」上白泽慧音
- 3313「CF467D」Fedor and Essay
- 3311「CF427C」Checkposts
近期评论
- 匿名发表在《留言板》
- 匿名发表在《hzwer.com 博客导航》
- 匿名发表在《hzwer.com 博客导航》
- 匿名发表在《hzwer.com 博客导航》
- 匿名发表在《留言板》