题目需要求啥很明确了。主要思想是先计算机联通块,然后每个块内找到一个最小值(以及该值的次数)。最小值和结果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. RedHat7 SELinux

    SELinux(Security-Enhanced Linux) 是美国国家安全局(NSA)对于强制访问控制的实现,是 Linux历史上最杰出的新安全子系统.NSA是在Linux社区的帮助下开发了一种 ...

  2. C#将DataTable导出Execl、Word、Xml

        /// <summary>     /// 将DT转换为Execl的方法     /// </summary>     /// <param name=" ...

  3. C#一般处理程序获取Session

    如果需要用ajax去动态校验验证码,如何获取Session保存的值呢? 你需要做两步: 一.在你的一般处理程序中添加命名空间 (using System.Web.SessionState;) 二.在你 ...

  4. 如何在OpenWRT环境下做开发

    1.搭建开发环境 首先,在执行make menuconfig后,会出现下图: 其中,图中红框部分是我定制路由器的系统版本,大家可以根据不同的路由器进行不同的选择:绿框部分表示我们需要编译一个SDK开发 ...

  5. Angularjs中编写指令模版

    angular.module('moduleName', []).directive( 'namespaceDirectiveName', [ function() { return { restri ...

  6. 站点下的GridView的RowCommand事件的设置,与站点应用不一样

    <ItemTemplate>                                                                    <%--<a ...

  7. 【原创】win7同局域网下共享文件

    本文章用于解决win7局域网共享文件问题: 首先保证两台机器可以ping通: 检测方法: win+R输入cmd打开命令行,输入ping  对方主机ip 不知对方ip可以在在命令行中输入ipconfig ...

  8. 滑动开关效果 css3滑动开关】纯CSS3代码实现滑动开关效果-css3滑动效果-css3左右滑动

    今天看到一篇有关 css3事件的博文,一时兴起便整理下相关的资料. 点击按钮,可以实现开关的滑动效果. 今天看到一篇有关 css3事件的博文,一时兴起便整理下相关的资料. 点击按钮,可以实现开关的滑动 ...

  9. SSD: Single Shot MultiBox Detector

    By Wei Liu, Dragomir Anguelov, Dumitru Erhan, Christian Szegedy, Scott Reed, Cheng-Yang Fu, Alexande ...

  10. windows下使用cxfreeze打包python3程序

    1:下载适合版本的cxfreeze http://sourceforge.net/projects/cx-freeze/files/4.3.2/ 2:安装,注意python版本是否正确 3:安装完成后 ...