Codeforces Round #244 (Div. 2)——Checkposts
- 题意:
给定n个点,每一个点有一个权值的有向图。如今须要选定一些点,使得这些点权值和最小。且满足:假设i能到达j且j能到达i,那么i、j能够仅仅选一个 - 分析:
强联通模板题
//使用时仅仅更新G完毕构图
//scc_cnt从1開始计数 //pre[]表示点在DFS树中的先序时间戳
//lowlink[]表示当前点和后代能追溯到的最早祖先的pre值
//sccno[]表示点所在的双连通分量编号
//vector<int> G保存每一个点相邻的下一个点序号
//stack<Edge> S是算法用到的栈
const int MAXV = 310000; vector<int> G[MAXV];
int pre[MAXV], lowlink[MAXV], sccno[MAXV], dfs_clock, scc_cnt;
stack<int> S; void init(int n)
{
REP(i, n) G[i].clear();
} void dfs(int u)
{
pre[u] = lowlink[u] = ++dfs_clock;
S.push(u);
for(int i = 0; i < G[u].size(); i++)
{
int v = G[u][i];
if(!pre[v])
{
dfs(v);
lowlink[u] = min(lowlink[u], lowlink[v]);
}
else if(!sccno[v])
{
lowlink[u] = min(lowlink[u], pre[v]);
}
}
if(lowlink[u] == pre[u])
{
scc_cnt++;
for(;;)
{
int x = S.top();
S.pop();
sccno[x] = scc_cnt;
if(x == u) break;
}
}
} void find_scc(int n)
{
dfs_clock = scc_cnt = 0;
memset(sccno, 0, sizeof(sccno));
memset(pre, 0, sizeof(pre));
for(int i = 0; i < n; i++)
if(!pre[i]) dfs(i);
}; int cost[MAXV];
vector<int> vt[MAXV];
int Min[MAXV]; int main()
{
// freopen("in.txt", "r", stdin);
int n, e, a, b;
while (~RI(n))
{
init(n);
REP(i, MAXV) vt[i].clear();
CLR(Min, INF); REP(i, n) RI(cost[i]);
RI(e);
REP(i, e)
{
RII(a, b); a--; b--;
G[a].push_back(b);
}
find_scc(n); REP(i, n)
{
int no = sccno[i];
vt[no].push_back(i);
Min[no] = min(Min[no], cost[i]);
}
LL v = 0, ans = 1;
REP(i, MAXV)
{
if (vt[i].size() > 0)
{
int cnt = 0;
REP(j, vt[i].size())
{
if (cost[vt[i][j]] == Min[i]) cnt++;
}
ans *= cnt;
ans %= MOD;
v += Min[i];
}
}
cout << v << ' ' << ans << endl;
}
return 0;
}
Codeforces Round #244 (Div. 2)——Checkposts的更多相关文章
- Codeforces Round #244 (Div. 2)D (后缀自己主动机)
Codeforces Round #244 (Div. 2)D (后缀自己主动机) (标号为0的节点一定是null节点,不管怎样都不能拿来用,切记切记,以后不能再错了) 这题用后缀自己主动机的话,对后 ...
- Codeforces Round #244 (Div. 2) C. Checkposts (tarjan 强连通分量)
题目:http://codeforces.com/problemset/problem/427/C 题意:给你n座城市,m条有向道路,然后有一个机制,你在某一个城市设置检查点,那么被设置的检查点受保护 ...
- Codeforces Round #244 (Div. 2)
今天是水题集啊.... A. Police Recruits time limit per test 1 second memory limit per test 256 megabytes inpu ...
- Codeforces Round #244 (Div. 2) B. Prison Transfer 线段树rmq
B. Prison Transfer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/pro ...
- Codeforces Round #244 (Div. 2) B. Prison Transfer
题目是选出c个连续的囚犯,而且囚犯的级别不能大于t #include <iostream> using namespace std; int main(){ int n,t,c; cin ...
- Codeforces Round #244 (Div. 2) A. Police Recruits
题目的意思就是找出未能及时处理的犯罪数, #include <iostream> using namespace std; int main(){ int n; cin >> ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
随机推荐
- 【bzoj2142】【礼物】拓展Lucas定理+孙子定理
(上不了p站我要死了,侵权度娘背锅) Description 一年一度的圣诞节快要来到了.每年的圣诞节小E都会收到许多礼物,当然他也会送出许多礼物.不同的人物在小E 心目中的重要性不同,在小E心中分量 ...
- python基础-文件处理与函数
1. 文件处理 1.1 文件处理流程 1.打开文件,得到文件句柄并赋值给一个变量 2.通过句柄对文件进行操作 3.关闭文件 1.2 文件读取模式r r文本模式的读,在文件不存在,不会创建新文件 f = ...
- Linux下date常用格式化输出
date "+%Y-%m-%d" --date "+%H:%M:%S" ::date "+%Y-%m-%d %H:%M:%S" -- ::d ...
- TQ2440学习笔记——Linux上I2C驱动的两种实现方法(1)
作者:彭东林 邮箱:pengdonglin137@163.com 内核版本:Linux-3.14 u-boot版本:U-Boot 2015.04 硬件:TQ2440 (NorFlash:2M Na ...
- 下载谷歌浏览器(Chrome)扩展离线安装包crx文件最简单的方法
转:http://alyzq.com/?p=627 如果不会使用,请看下面的操作步骤 引言(可以不看): 下面介绍一下,下载谷歌浏览器(Google Chrome)扩展的离线安装包crx文件最简单的方 ...
- 【mybatis】mybatis使用java实体中定义的常量,或静态方法
mybatis使用java实体中定义的常量 示例代码: <select id="findDealerInfo" parameterType="com.pisen.c ...
- Ext js 应用例子
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 关于接口 RandomAccess
今天看到java.util.Collections这个工具类中的 public static <T> void fill(List<? super T> list, T obj ...
- easyui datagrid checkbox的相关属性整理
DataGrid其中与选择,勾选相关 DataGrid属性: singleSelect boolean 如果为true,则只允许选择一行. false ctrlSelect boolean 在启用多行 ...
- Linux-C网络编程之epoll函数
上文中说到假设从100的不同的地方取外卖,那么epoll相当于一部手机,当外卖到达后,送货员能够通知你.从而达到每去必得,少走非常多路. 它是怎样实现这些作用的呢? epoll的功能 epoll是se ...