Summer Holiday
Summer Holiday |
| Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) |
| Total Submission(s): 27 Accepted Submission(s): 20 |
|
Problem Description
To see a World in a Grain of Sand
And a Heaven in a Wild Flower, Hold Infinity in the palm of your hand And Eternity in an hour. —— William Blake 听说lcy帮大家预定了新马泰7日游,Wiskey真是高兴的夜不能寐啊,他想着得快点把这消息告诉大家,虽然他手上有所有人的联系方式,但是一个一个联系过去实在太耗时间和电话费了。他知道其他人也有一些别人的联系方式,这样他可以通知其他人,再让其他人帮忙通知一下别人。你能帮Wiskey计算出至少要通知多少人,至少得花多少电话费就能让所有人都被通知到吗? |
|
Input
多组测试数组,以EOF结束。
第一行两个整数N和M(1<=N<=1000, 1<=M<=2000),表示人数和联系对数。 接下一行有N个整数,表示Wiskey联系第i个人的电话费用。 接着有M行,每行有两个整数X,Y,表示X能联系到Y,但是不表示Y也能联系X。 |
|
Output
输出最小联系人数和最小花费。
每个CASE输出答案一行。 |
|
Sample Input
12 16 |
|
Sample Output
3 6 |
|
Author
威士忌
|
|
Source
HDOJ 2007 Summer Exercise(3)- Hold by Wiskey
|
|
Recommend
威士忌
|
/*
题意:略 初步思路:找出强连通,然后贪心
*/
#include<bits/stdc++.h>
using namespace std;
int cost[];
int u[],v[];
int allcost=;
int vis[];
int money[];
/**************************强连通模板******************************/
const int maxn = + ;
vector<int> G[maxn];
int n, m, k = , cnt = ;
int low[maxn];
int dfn[maxn];
int in[maxn];
stack<int> s; void tarjan(int u) {
low[u] = dfn[u] = ++k;
s.push(u);
for(int i = ; i < G[u].size(); ++i) {
int v = G[u][i];
if(!dfn[v]) {
tarjan(v);
low[u] = min(low[u], low[v]);
} else if(!in[v]) {
low[u] = min(low[u], dfn[v]);
}
}
int v;
if(dfn[u] == low[u]) {
cnt++;
do {
v = s.top(); s.pop();
in[v] = cnt;
} while(u != v);
}
}
/**************************强连通模板******************************/
void init(){
for(int i=;i<=n;i++){
G[i].clear();
}
k = , cnt = ;
memset(dfn,,sizeof dfn);
memset(low,,sizeof low);
memset(money,0x3f3f,sizeof money);
memset(in,,sizeof in);
while(!s.empty()) s.pop();
allcost=;
}
int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF){
init();
for(int i=;i<=n;i++){
scanf("%d",&cost[i]);
}
for(int i=;i<m;i++){
scanf("%d%d",&u[i],&v[i]);
G[u[i]].push_back(v[i]);
}
for(int i=;i<=n;i++){
if(!dfn[i]) tarjan(i);
}
for(int i=;i<=n;i++){
money[in[i]]=min(cost[i],money[in[i]]);
} for(int i=;i<=cnt;i++){
vis[i]=;
} for(int i=;i<m;i++){
if(in[u[i]]!=in[v[i]])
vis[in[v[i]]] = ;
} int ans=;
for(int i=;i<=cnt;i++){
if(vis[i]){
ans++;
allcost+=money[i];
}
}
// for(int i=1;i<=n;i++){
// cout<<vis[i]<<" ";
// }
// cout<<endl; printf("%d %d\n",ans,allcost);
}
return ;
}
Summer Holiday的更多相关文章
- 【UOJ #29】【IOI 2014】holiday
http://uoj.ac/problem/29 cdq四次处理出一直向左, 一直向右, 向左后回到起点, 向右后回到起点的dp数组,最后统计答案. 举例:\(fi\)表示一直向右走i天能参观的最多景 ...
- 水题 ZOJ 3876 May Day Holiday
题目传送门 /* 水题:已知1928年1月1日是星期日,若是闰年加1,总天数对7取余判断就好了: */ #include <cstdio> #include <iostream> ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest May Day Holiday
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5500 The 12th Zhejiang Provincial ...
- 第十二届浙江省大学生程序设计大赛-May Day Holiday 分类: 比赛 2015-06-26 14:33 10人阅读 评论(0) 收藏
May Day Holiday Time Limit: 2 Seconds Memory Limit: 65536 KB As a university advocating self-learnin ...
- HDU 4118 Holiday's Accommodation
Holiday's Accommodation Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 200000/200000 K (Jav ...
- hdoj 1827 Summer Holiday【强连通分量&&缩点】
Summer Holiday Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 4118 树形DP Holiday's Accommodation
题目链接: HDU 4118 Holiday's Accommodation 分析: 可以知道每条边要走的次数刚好的是这条边两端的点数的最小值的两倍. 代码: #include<iostrea ...
- Summer Holiday(强联通入度最小点)
Summer Holiday Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- IOI2014 day2 task4 Holiday
题目 题目链接 大意:从左到右有\(n\)个城市,一开始在城市\(start\),每一天有两种选择: 前往相邻的城市. 访问当前城市(每个城市只能访问一次),访问城市\(i\)可以获得\(attrac ...
- May Day Holiday
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit Status Practic ...
随机推荐
- [UIKit学习]06.懒加载,模型,自定义代码段,重写构造方法
懒加载 在get中加载,且只加载一次 - (NSArray *)shops { if (_shops == nil) { NSString *file = [[NSBundle mainBundle] ...
- 前后端分离,接口API,契约
前后端分离了,然后呢? http://icodeit.org/2015/06/whats-next-after-separate-frontend-and-backend/ Swagger - 前后端 ...
- JSP入门 导出文件
1.图片校验码 <img src="captcha.jpg" /> web.xml配置 <servlet> <servlet-name& ...
- Bmob云IM实现头像更换并存入Bmob云数据库中(1.拍照替换,2.相册选择)
看图效果如下: 1.个人资料界面 2.点击头像弹出对话框 3.点击拍照 4.切割图片,选择合适的部分 5.点击保存,头像替换完毕,下面看从相册中选择图片. 6.点击相册 7.任选一张图片 8.切割图片 ...
- HTTP库Axios
前面的话 本文将详细介绍HTTP库Axios 概述 Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中 [安装] 在Vue中使用,最好安装两个模块axios ...
- Print Article hdu 3507 一道斜率优化DP 表示是基础题,但对我来说很难
Print Article Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)To ...
- ssh项目访问路径及url请求书写
在ssh项目中配置好Struts后,一般可以采用两种方式进行后台请求: 1.html形式,包括a标签,form表单,ajax等.此时的访问链接必须写全路径,可以是相对路径,也可以是绝对路径 相对路径方 ...
- windows phone 模拟器
window phone 模拟器启动报错 修改Bios设置,我的是yoga pro 2,只修改 即可.启动成功
- ora-01440:要减小精度或标度,则要修改的列必须为空
--由于业务需求变更,需要对oracle数据库productinfo表的productPrcie结构进行修改.修改表结构,必须是在表空的情况下才可以修改表结构.具体操作步骤: --1.查看produc ...
- netfilter/iptables和firewalld的关系
1.netfilter 是linux 内核模块,其中包含了大量的内核规则,而要想对这些内核规则进行操作,就需要用户态的工具. iptables和firewalld就是一个用户态的工具. 2.iptab ...