cf427c Checkposts

网友投稿 598 2022-08-29

cf427c Checkposts

cf427c  Checkposts

​​ C. Checkposts time limit per test 2 seconds

memory limit per test 256 megabytes

input standard input

output standard output

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.

Input 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 andvi (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.

Output 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).

Examples input 3 1 2 3 3 1 2 2 3 3 2 output 3 1 input 5 2 8 0 6 0 6 1 4 1 3 2 4 3 4 4 5 5 1 output 8 2 input 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 output 15 6 input 2 7 91 2 1 2 2 1 output 7 1 求出每个强联通的最小值得个数和最小值是什么

#include#include#define N 110000#define mod 1000000007#define inf 0x7f7f7f7finline int read(){ int x=0,f=1;char ch=getchar(); while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();} while (ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();} return x*f;}struct node{ int y,z,next;}data[330000];int dfn[N],low[N],num,size[N],a[N],h[N],s,b[N],n,m,min1[N];bool stackf[N];inline int min(int x,int y){ return x q;void tarjan(int x){ dfn[x]=++num;low[x]=num;q.push(x);stackf[x]=true; for (int i=h[x];i;i=data[i].next){ int y=data[i].y; if (!dfn[y]) tarjan(y),low[x]=min(low[x],low[y]);else if (stackf[y]) low[x]=min(low[x],dfn[y]); } if (dfn[x]==low[x]){ int y;s++;min1[s]=inf; do{ y=q-();b[y]=s;q.pop();stackf[y]=false; if (a[y]

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:bzoj4000 [TJOI2015]棋盘
下一篇:PHP代码简洁之道——SOLID原则
相关文章

 发表评论

暂时没有评论,来抢沙发吧~