缩点 CF893C Rumor
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的更多相关文章
- POJ 2186 Popular Cows(Targin缩点)
传送门 Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 31808 Accepted: 1292 ...
- poj2186--tarjan+缩点
题目大意: 每一头牛的愿望就是变成一头最受欢迎的牛.现在有N头牛,给你M对整数(A,B),表示牛A认为牛B受欢迎. 这 种关系是具有传递性的,如果A认为B受欢迎,B认为C受欢迎,那么牛A也 ...
- POJ3160 Father Christmas flymouse[强连通分量 缩点 DP]
Father Christmas flymouse Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 3241 Accep ...
- UVA11324 The Largest Clique[强连通分量 缩点 DP]
UVA - 11324 The Largest Clique 题意:求一个节点数最大的节点集,使任意两个节点至少从一个可以到另一个 同一个SCC要选一定全选 求SCC 缩点建一个新图得到一个DAG,直 ...
- POJ1236Network of Schools[强连通分量|缩点]
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16571 Accepted: 65 ...
- hihoCoder 1185 连通性·三(Tarjan缩点+暴力DFS)
#1185 : 连通性·三 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 暑假到了!!小Hi和小Ho为了体验生活,来到了住在大草原的约翰家.今天一大早,约翰因为有事要出 ...
- POJ 1236 Network of Schools(Tarjan缩点)
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16806 Accepted: 66 ...
- Instantaneous Transference--POJ3592Tarjan缩点+搜索
Instantaneous Transference Time Limit: 5000MS Memory Limit: 65536K Description It was long ago when ...
- King's Quest —— POJ1904(ZOJ2470)Tarjan缩点
King's Quest Time Limit: 15000MS Memory Limit: 65536K Case Time Limit: 2000MS Description Once upon ...
随机推荐
- 对称二叉树 · symmetric binary tree
[抄题]: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). ...
- Part2_lesson1---arm家族大检阅
芯片(比如2440.6410.210等等)包含ARM核. 指令结构和ARM核有关系: ARM9对应指令架构版本ARMV4 ARM11对应指令架构版本ARMV6 cortex A8对应指令架构版本ARM ...
- xStream完美转换XML、JSON(转)
xStream框架 xStream可以轻易的将Java对象和xml文档相互转换,而且可以修改某个特定的属性和节点名称,而且也支持json的转换: 前面有介绍过json-lib这个框架,在线博文:htt ...
- 4619 Warm up 2
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; ][]; ...
- HUST数媒1501班第2周作业成绩公布
说明 本次公布的成绩对应的作业为: 第2周个人作业:WordCount编码和测试 如果同学对作业成绩存在异议,在成绩公布的72小时内(截止日期4月26日0点)可以进行申诉,方式如下: 毕博平台的第二周 ...
- InteliJ中文乱码;IDE快捷键使用
启动服务器的时候出现如图 解决方法: 对服务器的位置进行编辑 增加如图的信息 -Dfile.encoding=UTF-8
- 更改文本的编码jsp.xml.java
JSP改为UTF-8编码 更改xml workspace resource
- HDU 5977 Garden of Eden (树分治+状态压缩)
题意:给一棵节点数为n,节点种类为k的无根树,问其中有多少种不同的简单路径,可以满足路径上经过所有k种类型的点? 析:对于路径,就是两类,第一种情况,就是跨过根结点,第二种是不跨过根结点,分别讨论就好 ...
- sql 两大类 DDL数据定义语言 和DCL数据控制语言
SQL分为五大类: DDL:数据定义语言 DCL:数据控制语言 DML:数据的操纵语言 DTL:数据事务语言 DQL:数据查询语言. DDL (date definition lang ...
- Find out your Java heap memory size
In this article, we will show you how to use the -XX:+PrintFlagsFinal to find out your heap size det ...