CF893C Rumor

有n个人,其中有m对朋友,现在你有一个秘密你想告诉所有人,第i个人愿意出价a[i]买你的秘密,获得秘密的人会免费告诉它的所有朋友(他朋友的朋友也会免费知道),现在他们想出最少的价钱买秘密,那么你最少能得到多少钱?

刷水利于身心健康。

code:

#include <iostream>
#include <cstdio>
#include <cstring> #define int long long using namespace std; const int wx=100017; inline int read(){
int sum=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
while(ch>='0'&&ch<='9'){sum=(sum<<1)+(sum<<3)+ch-'0'; ch=getchar();}
return sum*f;
} int head[wx],dfn[wx],low[wx],belong[wx];
int a[wx],val[wx],st[wx];
int n,m,ans,num,tot,top,col; struct e{
int nxt,to;
}edge[wx*2]; void add(int from,int to){
edge[++num].nxt=head[from];
edge[num].to=to;
head[from]=num;
} void Tarjan(int u){
dfn[u]=low[u]=++tot; st[++top]=u;
for(int i=head[u];i;i=edge[i].nxt){
int v=edge[i].to;
if(!dfn[v]){
Tarjan(v);
low[u]=min(low[u],low[v]);
}
else if(!belong[v]){
low[u]=min(low[u],dfn[v]);
}
}
if(dfn[u]==low[u]){
belong[u]=++col;
while(st[top]!=u){
belong[st[top]]=col;
top--;
}top--;
}
} signed main(){
n=read(); m=read();
for(int i=1;i<=n;i++)a[i]=read();
for(int i=1;i<=m;i++){
int x,y; x=read(); y=read();
add(x,y); add(y,x);
}
for(int i=1;i<=n;i++)if(!dfn[i])Tarjan(i);
for(int i=1;i<=col;i++)val[i]=1e18;
for(int i=1;i<=n;i++)val[belong[i]]=min(val[belong[i]],a[i]);
for(int i=1;i<=col;i++)ans+=val[i];
printf("%lld\n",ans);
return 0;
}

缩点 CF893C Rumor的更多相关文章

  1. POJ 2186 Popular Cows(Targin缩点)

    传送门 Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 31808   Accepted: 1292 ...

  2. poj2186--tarjan+缩点

    题目大意:       每一头牛的愿望就是变成一头最受欢迎的牛.现在有N头牛,给你M对整数(A,B),表示牛A认为牛B受欢迎. 这 种关系是具有传递性的,如果A认为B受欢迎,B认为C受欢迎,那么牛A也 ...

  3. POJ3160 Father Christmas flymouse[强连通分量 缩点 DP]

    Father Christmas flymouse Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 3241   Accep ...

  4. UVA11324 The Largest Clique[强连通分量 缩点 DP]

    UVA - 11324 The Largest Clique 题意:求一个节点数最大的节点集,使任意两个节点至少从一个可以到另一个 同一个SCC要选一定全选 求SCC 缩点建一个新图得到一个DAG,直 ...

  5. POJ1236Network of Schools[强连通分量|缩点]

    Network of Schools Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16571   Accepted: 65 ...

  6. hihoCoder 1185 连通性·三(Tarjan缩点+暴力DFS)

    #1185 : 连通性·三 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 暑假到了!!小Hi和小Ho为了体验生活,来到了住在大草原的约翰家.今天一大早,约翰因为有事要出 ...

  7. POJ 1236 Network of Schools(Tarjan缩点)

    Network of Schools Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16806   Accepted: 66 ...

  8. Instantaneous Transference--POJ3592Tarjan缩点+搜索

    Instantaneous Transference Time Limit: 5000MS Memory Limit: 65536K Description It was long ago when ...

  9. King's Quest —— POJ1904(ZOJ2470)Tarjan缩点

    King's Quest Time Limit: 15000MS Memory Limit: 65536K Case Time Limit: 2000MS Description Once upon ...

随机推荐

  1. [C++] static member variable and static const member variable

    static member variable[可读可写] 可以通过指针间接修改变量的值 static const member variable[只读] 压根就不可以修改变量的值,会报错

  2. [SoapUI] SoapUI+Groovy中"org.apache.xmlbeans.XmlException: error:

    把 def holder = groovyUtils.getXmlHolder("Get Token#Response") 改为 def holder = groovyUtils. ...

  3. Oracle——分页查询

    查询员工表中,工资排名在10-20之间的员工信息. select * from( select rownum rn ,employee_id,salary from ( select employee ...

  4. 白盒测试实践项目(day3)

    李建文同学的白盒缺陷报告已经提交,正在由组长胡俊辉同学进行审阅,查看并发现是否有什么不足,再由小组讨论补充. 汪鸿同学的静态代码工具熟悉已经初步完成,并且准备撰写文档. 杨瑞丰同学的Mock测试方法也 ...

  5. 给初学者的总结:jquery选择器

    刚学jquery的时候是又渣又蠢的小白,而且把js和jquery混淆在一起. 把jquery的全部选择器总结在一起,才发现和css选择器好一部分都很像,并且有些选择器还很少用过. 我学习前端的路程是先 ...

  6. 研究wireshark遇到的问题

    说起来有一些惭愧,研究wireshark有一段时间了,但是对源代码的分析却至今没有什么进展... 最初想要研究wireshark是因为我的开题是基于wireshark来做的. 现在有很多抓包工具,wi ...

  7. 【转】彻底理解ThreadLocal

    ThreadLocal是什么 早在JDK 1.2的版本中就提供Java.lang.ThreadLocal,ThreadLocal为解决多线程程序的并发问题提供了一种新的思路.使用这个工具类可以很简洁地 ...

  8. 从jvm运行机制来分析 String对象负值

    测试1: 代码 public class Test { public static void main(String[] args) { String s1="aaa"; f(s1 ...

  9. Introducing .NET Standard

    https://blogs.msdn.microsoft.com/dotnet/2016/10/18/the-week-in-net-bond-the-gallery/ .NET Standard s ...

  10. redis的安装使用

    安装过程:http://www.cnblogs.com/littlehb/archive/2013/04/24/3040476.html 配置文件参考:http://redis.io/topics/c ...