题目链接

  • 题意:

    给定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的更多相关文章

  1. Codeforces Round #244 (Div. 2)D (后缀自己主动机)

    Codeforces Round #244 (Div. 2)D (后缀自己主动机) (标号为0的节点一定是null节点,不管怎样都不能拿来用,切记切记,以后不能再错了) 这题用后缀自己主动机的话,对后 ...

  2. Codeforces Round #244 (Div. 2) C. Checkposts (tarjan 强连通分量)

    题目:http://codeforces.com/problemset/problem/427/C 题意:给你n座城市,m条有向道路,然后有一个机制,你在某一个城市设置检查点,那么被设置的检查点受保护 ...

  3. Codeforces Round #244 (Div. 2)

    今天是水题集啊.... A. Police Recruits time limit per test 1 second memory limit per test 256 megabytes inpu ...

  4. 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 ...

  5. Codeforces Round #244 (Div. 2) B. Prison Transfer

    题目是选出c个连续的囚犯,而且囚犯的级别不能大于t #include <iostream> using namespace std; int main(){ int n,t,c; cin ...

  6. Codeforces Round #244 (Div. 2) A. Police Recruits

    题目的意思就是找出未能及时处理的犯罪数, #include <iostream> using namespace std; int main(){ int n; cin >> ...

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

  8. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  9. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

随机推荐

  1. sum (bestcoder)

    sum Accepts: 640 Submissions: 1744 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/13107 ...

  2. 28、Django实战第28天:个人信息展示

    从今天开始,我来完成个人中心部分,前端页面如下 1.浏览这些页面可以发现,它们和base.html是有区别的,因此,它们需要新建一个模板usercenter-base.html 2.把usercent ...

  3. CentOS 7.1 中文正式版下载 - 最流行的免费开源企业级 Linux 服务器操作系统

    如果说 Ubuntu 是现今最受桌面用户欢迎的 Linux 操作系统,那么 CentOS 就是最受公司.企业.IDC 喜爱的 Linux 发行版了.得益于极为出色的稳定性,全球范围内无数著名网站均选用 ...

  4. 【贪心】【线性基】bzoj2460 [BeiJing2011]元素 / bzoj3105 [cqoi2013]新Nim游戏

    p2460: #include<cstdio> #include<algorithm> using namespace std; #define N 1001 typedef ...

  5. 集合视图UICollectionView 介绍及其示例程序

    UICollectionView是一种新的数据展示方式,简单来说可以把它理解成多列的UITableView.如果你用过iBooks的话,可 能你还对书架布局有一定印象,一个虚拟书架上放着你下载和购买的 ...

  6. 搭建redis集群环境

    Redis的集群机制 ============================= 转自http://lib.csdn.net/article/redis/39999 别人写的,写得不错,转了. Red ...

  7. "0" 并不一定是 假 (false)

    写习惯C/C++系代码的人应该很习惯看见类似这样的代码: 1 2 3 4 5 int i = 0; ...... if(i){    //这里代码不会被执行 } 因此写习惯以后会想当然地觉得其他语言里 ...

  8. gulp的入门浅析

    阅读目录 介绍gulp 安装gulp gulpfile.js 运行gulp 介绍gulp的api 介绍gulp gulp是基于Nodejs的自动任务运行器, 她能自动化地完成 javascript/c ...

  9. http://zhidao.baidu.com/link?url=3tJ_i5gyYLrd7rFPk0eRYre_oxjCZvTOMOutp89LGhUgi6Ic6Ncama_GMAHnwfF73SVYGqy364vDfv6AY4ERPa

    http://zhidao.baidu.com/link?url=3tJ_i5gyYLrd7rFPk0eRYre_oxjCZvTOMOutp89LGhUgi6Ic6Ncama_GMAHnwfF73SV ...

  10. win7系统下ping不是内部或外部命令

    win7下ping不是内部或外部命令,在使用java设置变量环境时,可能会遇到这样的问题,出现win7下ping不是内部或外部命令,是在设置变量环境是把一些设置删掉了的原因,请看在win7下怎么还原. ...