题目需要求啥很明确了。主要思想是先计算机联通块,然后每个块内找到一个最小值(以及该值的次数)。最小值和结果1,次数乘积为结果2。联通块tarjan可解。

 /* 427C */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 const int maxn = 1e5+;
const int mod = 1e9+;
vi vc[maxn];
int low[maxn], bn[maxn], pre[maxn];
int S[maxn], top;
int dfs_clock, block;
int n, m;
int C[maxn];
int mn[maxn], cnt[maxn]; void init() {
memset(pre, , sizeof(pre));
memset(bn, , sizeof(bn));
memset(mn, 0x3f, sizeof(mn));
memset(cnt, , sizeof(cnt));
dfs_clock = block = top = ;
} void tarjan(int u) {
int v; S[top++] = u;
pre[u] = low[u] = ++dfs_clock;
rep(i, , SZ(vc[u])) {
v = vc[u][i];
if (!pre[v]) {
tarjan(v);
low[u] = min(low[u], low[v]);
} else if (!bn[v]) {
low[u] = min(low[u], pre[v]);
}
} if (low[u] == pre[u]) {
++block;
do {
bn[S[--top]] = block;
} while (S[top]!=u);
}
} void solve() {
rep(i, , n+)
if (!pre[i])
tarjan(i);
int b, c; rep(i, , n+) {
b = bn[i];
c = C[i];
if (c< mn[b]) {
mn[b] = c;
cnt[b] = ;
} else if (c == mn[b]) {
++cnt[b];
}
} __int64 ans = , cost = ;
rep(i, , block+) {
cost += mn[i];
ans = (ans * cnt[i])%mod;
} printf("%I64d %I64d\n", cost, ans);
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif int u, v; scanf("%d", &n);
rep(i, , n+)
scanf("%d", &C[i]);;
scanf("%d", &m);
while (m--) {
scanf("%d %d", &u, &v);
vc[u].pb(v);
} init();
solve(); #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}

【CF】244C Checkposts的更多相关文章

  1. 【CF】438E. The Child and Binary Tree

    http://codeforces.com/contest/438/problem/E 题意:询问每个点权值在 $c_1, c_2, ..., c_m$ 中,总权值和为 $s$ 的二叉树个数.请给出每 ...

  2. 【CF】148D Bag of mice

    http://codeforces.com/problemset/problem/148/D 题意:w个白b个黑,公主和龙轮流取,公主先取,等概率取到一个.当龙取完后,会等概率跳出一只.(0<= ...

  3. 【CF】328 D. Super M

    这种图论题已经变得简单了... /* D */ #include <iostream> #include <string> #include <map> #incl ...

  4. 【CF】323 Div2. D. Once Again...

    挺有意思的一道题目.考虑长度为n的数组,重复n次,可以得到n*n的最长上升子序列.同理,也可以得到n*n的最长下降子序列.因此,把t分成prefix(上升子序列) + cycle(one intege ...

  5. 【CF】7 Beta Round D. Palindrome Degree

    manacher+dp.其实理解manacher就可以解了,大水题,dp就是dp[i]=dp[i>>1]+1如何满足k-palindrome条件. /* 7D */ #include &l ...

  6. 【CF】86 B. Petr#

    误以为是求满足条件的substring总数(解法是KMP分别以Sbeg和Send作为模式串求解满足条件的position,然后O(n^2)或者O(nlgn)求解).后来发现是求set(all vali ...

  7. 【CF】121 Div.1 C. Fools and Roads

    题意是给定一棵树.同时,给定如下k个查询: 给出任意两点u,v,对u到v的路径所经过的边进行加计数. k个查询后,分别输出各边的计数之和. 思路利用LCA,对cnt[u]++, cnt[v]++,并对 ...

  8. 【CF】310 Div.1 C. Case of Chocolate

    线段树的简单题目,做一个离散化,O(lgn)可以找到id.RE了一晚上,额,后来找到了原因. /* 555C */ #include <iostream> #include <str ...

  9. 【CF】110 Div.1 B. Suspects

    这题目乍眼一看还以为是2-sat.其实很水的,O(n)就解了.枚举每个人,假设其作为凶手.观察是否满足条件.然后再对满足的数目分类讨论,进行求解. /* 156B */ #include <io ...

随机推荐

  1. git 删除配置的远程地址

    删除(origin 名称需根据你本地查询出来的想删除的名字, 查询命令为 git remote -v) git remote rm origin 添加(origin 名称可根据需要添加) git re ...

  2. linux 上不去网

    linux 上不去网   ip dns无误 ping可以到达网关 可能原因 网卡睡眠 ethtool eht0  //查看eht0网口基本设置 mii-tool -w eth0

  3. System Operations on AWS - Lab 7 - CloudFormation

    CloudFormation模板:创建一个VPC(包含Public子网,Private子网,分别在不同的AZ),创建NAT,Bastion Server在Public子网. 1. 修改并运行AWS C ...

  4. ubuntu15.10下sublime text3 无法输入中文解决办法

    原文链接:http://geek.csdn.net/news/detail/44464 1.首先保证你的电脑有c++编译环境 如果没有,通过以下指令安装 sudo apt-get install bu ...

  5. C#图片处理高级应用(裁剪,缩放,清晰度,水印)

    转自:http://wu-jian.cnblogs.com/ 前言 需求源自项目中的一些应用,比如相册功能,通常用户上传相片后我们都会针对该相片再生成一张缩略图,用于其它页面上的列表显示.随便看一下, ...

  6. [转]eclipse github 提交代码

    1 git add2 git commit3 git pull  (会产生冲突) 分成自动合并和手动合并4 处理冲突的文件 5 git push 本次commit 我用的是Eclipse的插件EGit ...

  7. json解析异常 - net.sf.json.JSONException: java.lang.reflect.InvocationTargetException

    注:在项目中, 我使用原生的ajax请求数据的时候, JSONObject没能帮我解析, 当却不给我报错, 我是在junit单元测试中测试的时候, 发现的.发现好多时候, 特别是通过ajax请求, 不 ...

  8. HDU 1074 Doing Homework (dp+状态压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:学生要完成各科作业, 给出各科老师给出交作业的期限和学生完成该科所需时间, 如果逾期一 ...

  9. nullptr和NULL 区别

    注:本文内容摘自网络,准确性有待验证,现阶段仅供学习参考.尊重作品作者成果,原文链接 :http://www.2cto.com/kf/201302/190008.html 1.为什要有nullptr ...

  10. ACM hdu 1008 Elavator

    Elevator其实是一道水题,思路也很简单,但不知道怎么也不能AC,后来看了别人的再比较自己的以后找到错误. 在判断奇偶数之后的语句时,我用了if()  else if(),这是不能AC的原因,这种 ...