xtu summer individual 6 D - Checkposts
Checkposts
This problem will be judged on CodeForces. Original ID: 427C
64-bit integer IO format: %I64d Java class name: (Any)
To ensure the security, you have to build some police checkposts. Checkposts can only be built in a junction. A checkpost at junction i can 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 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.
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).
Sample Input
3
1 2 3
3
1 2
2 3
3 2
3 1
5
2 8 0 6 0
6
1 4
1 3
2 4
3 4
4 5
5 1
8 2
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
15 6
2
7 91
2
1 2
2 1
7 1
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
const LL mod = ;
vector<int>g[maxn];
stack<int>s;
int w[maxn],dfn[maxn],low[maxn],n,m,id,scc;
bool instack[maxn];
LL cnt[maxn],sum,ways;
void tarjan(int u){
dfn[u] = low[u] = ++id;
instack[u] = true;
s.push(u);
int v;
for(v = ; v < g[u].size(); v++){
if(!dfn[g[u][v]]){
tarjan(g[u][v]);
low[u] = min(low[u],low[g[u][v]]);
}else if(instack[g[u][v]] && low[u] > dfn[g[u][v]])
low[u] = dfn[g[u][v]];
}
if(dfn[u] == low[u]){
int theMin = INF;
do{
v = s.top();
s.pop();
if(w[v] < theMin){
theMin = w[v];
cnt[scc] = ;
}else if(w[v] == theMin){
cnt[scc]++;
}
instack[v] = false;
}while(v != u);
scc++;
sum += theMin;
}
}
int main() {
int i,j,u,v;
while(~scanf("%d",&n)){
for(i = ; i <= n; i++)
scanf("%d",w+i);
for(i = ; i <= n; i++){
g[i].clear();
instack[i] = false;
low[i] = dfn[i] = ;
cnt[i] = ;
}
scanf("%d",&m);
for(i = ; i < m; i++){
scanf("%d %d",&u,&v);
g[u].push_back(v);
}
while(!s.empty()) s.pop();
sum = scc = id = ;
for(i = ; i <= n; i++)
if(!dfn[i]) tarjan(i);
for(ways = ,i = ; i < scc; i++){
ways = ((ways%mod)*(cnt[i]%mod))%mod;
}
printf("%I64d %I64d\n",sum,ways);
}
return ;
}
xtu summer individual 6 D - Checkposts的更多相关文章
- xtu summer individual 4 C - Dancing Lessons
Dancing Lessons Time Limit: 5000ms Memory Limit: 262144KB This problem will be judged on CodeForces. ...
- xtu summer individual 3 C.Infinite Maze
B. Infinite Maze time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- xtu summer individual 2 E - Double Profiles
Double Profiles Time Limit: 3000ms Memory Limit: 262144KB This problem will be judged on CodeForces. ...
- xtu summer individual 2 C - Hometask
Hometask Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Origin ...
- xtu summer individual 1 A - An interesting mobile game
An interesting mobile game Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on H ...
- xtu summer individual 2 D - Colliders
Colliders Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Origi ...
- xtu summer individual 1 C - Design the city
C - Design the city Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu D ...
- xtu summer individual 1 E - Palindromic Numbers
E - Palindromic Numbers Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %l ...
- xtu summer individual 1 D - Round Numbers
D - Round Numbers Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u D ...
随机推荐
- _bzoj1051 [HAOI2006]受欢迎的牛【强联通】
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1051 保存tarjan模版. 求强联通分量,缩点. #include <cstdio& ...
- vijos1846 [NOIP2013] 华容道【最短路】
传送门:https://vijos.org/p/1983 (其实noip的题各个oj都会有的,就不贴其它传送门了) 这道题真的是,怎么说,我都不知道怎么评价了= =.果然数据量小的题怎么暴力都可以过. ...
- 414 Third Maximum Number 第三大的数
给定一个非空数组,返回此数组中第三大的数.如果不存在,则返回数组中最大的数.要求算法时间复杂度必须是O(n).示例 1:输入: [3, 2, 1]输出: 1解释: 第三大的数是 1.示例 2:输入: ...
- 转】用Nodejs连接MySQL
原博文出自于: http://blog.fens.me/category/%E6%95%B0%E6%8D%AE%E5%BA%93/page/2/ 感谢! 用Nodejs连接MySQL 从零开始node ...
- Activiti工作流和shiro权限管理关系图
- 5.1点击4个按钮显示相应的div
事件:onclick 属性:display,className 用到for语句,index标记,this当前事件 先清空后附加 <!DOCTYPE html><html>< ...
- 数据库text字段存值用回车分隔
//查询 $sql = "SELECT attr_values FROM ecs_attribute WHERE attr_id=197"; $param_sel_sms = ar ...
- Java MVC框架性能比较
Java MVC框架性能比较 - by zvane 现在各种MVC框架很多,各框架的优缺点网络上也有很多的参考文章,但介绍各框架性能方面差别的文章却不多,本人在项目开发中,感觉到采用了struts2框 ...
- Elasticsearch の 查询类型
查询类型SearchType Es中一共有四种查询类型:QUERY_AND_FETCH.QUERY_THEN_FETCH.DFS_QUERY_AND_FETCH.DFS_QUERY_THEN_FETC ...
- Android(java)学习笔记190:ContentProvider使用之学习ContentProvider(内容提供者)的目的
1. 使用ContentProvider,把应用程序私有的数据暴露给别的应用程序,让别的应用程序完成对自己私有的数据库数据的增删改查的操作. 2. ContentProvider的应用场景: 获取手机 ...