HDU——T 2647 Reward
http://acm.hdu.edu.cn/showproblem.php?pid=2647
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9821 Accepted Submission(s): 3136
The workers will compare their rewards ,and some one may have demands of the distributing of rewards ,just like a's reward should more than b's.Dandelion's unclue wants to fulfill all the demands, of course ,he wants to use the least money.Every work's reward will be at least 888 , because it's a lucky number.
then m lines ,each line contains two integers a and b ,stands for a's reward should be more than b's.
1 2
2 2
1 2
2 1
-1
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <queue> using namespace std; const int N(+);
const int M(+);
int sumedge,head[N];
struct Edge
{
int v,next;
Edge(int v=,int next=):v(v),next(next){}
}edge[M];
inline void ins(int u,int v)
{
edge[++sumedge]=Edge(v,head[u]);
head[u]=sumedge;
} queue<int>que;
int rd[N],ans,cnt,sum[N]; inline void init()
{
sumedge=;
for(;!que.empty();) que.pop();
memset(rd,,sizeof(rd));
memset(sum,,sizeof(sum));
memset(edge,,sizeof(edge));
memset(head,,sizeof(head));
} int AC()
{
for(int n,m,if_;~scanf("%d%d",&n,&m);init())
{
if_=n;ans=;cnt=;
for(int u,v;m--;)
{
scanf("%d%d",&u,&v);
ins(v,u); rd[u]++;
}
for(int i=;i<=n;i++)
if(!rd[i]) que.push(i);
for(int u,v;!que.empty();)
{
if_--;ans+=;
u=que.front(); que.pop();
for(int v,i=head[u];i;i=edge[i].next)
{
v=edge[i].v;
if(--rd[v]==)
sum[v]=sum[u]+,que.push(v);
}
}
for(int i=;i<=n;i++) ans+=sum[i];
if(if_) puts("-1");
else printf("%d\n",ans);
}
return ;
} int I_want_AC=AC();
int main(){;}
HDU——T 2647 Reward的更多相关文章
- ACM: hdu 2647 Reward -拓扑排序
hdu 2647 Reward Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Des ...
- hdu 2647 Reward
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2647 Reward Description Dandelion's uncle is a boss o ...
- HDU.2647 Reward(拓扑排序 TopSort)
HDU.2647 Reward(拓扑排序 TopSort) 题意分析 裸的拓扑排序 详解请移步 算法学习 拓扑排序(TopSort) 这道题有一点变化是要求计算最后的金钱数.最少金钱值是888,最少的 ...
- 题解报告:hdu 2647 Reward(拓扑排序)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 Problem Description Dandelion's uncle is a boss ...
- HDU 3613 Best Reward 正反两次扩展KMP
题目来源:HDU 3613 Best Reward 题意:每一个字母相应一个权值 将给你的字符串分成两部分 假设一部分是回文 这部分的值就是每一个字母的权值之和 求一种分法使得2部分的和最大 思路:考 ...
- HDU 2647 Reward (拓扑排序)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 题意是给你n点m条有向边,叶子点(出度为0)上的值为888,父亲点为888+1,依次计算... ...
- HDU 2647 Reward(拓扑排序+判断环+分层)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 题目大意:要给n个人发工资,告诉你m个关系,给出m行每行a b,表示b的工资小于a的工资,最低工 ...
- HDU 2647 Reward(图论-拓扑排序)
Reward Problem Description Dandelion's uncle is a boss of a factory. As the spring festival is comin ...
- hdu 2647 Reward(拓扑排序,反着来)
Reward Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submis ...
随机推荐
- Python 计算相似度
#计算相似度 #欧式距离 # npvec1, npvec2 = np.array(det_a), np.array(det_b) # similirity=math.sqrt(((npvec1 - n ...
- NetworkX-画图
参考:https://blog.csdn.net/qq951127336/article/details/54586869 1.创建图 networkx有四种图 Graph .DiGraph.Mult ...
- 转载:跟我一起写 Makefile
陈皓(http://my.csdn.net/haoel) 概述 —— 什么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你做了这个工作,但我觉得 ...
- Map的5种遍历方式
public class MapF { public static void main(String[] args) { Map<String, Integer> tempMap = ne ...
- linux上使用chrome自动化测试(无界面)
selenium自动化测试主要是用于有图形界面的系统上,对于无图形界面的情况可以通过以下方法来实现 服务器信息 [root@spider01 ~]# hostnamectl Static hostna ...
- perl脚本去除文件中重复数据
今天第一天写博客,写的不好请大家多多指教,废话不多说了,干货送上: ############################################################# #!/u ...
- HDU-1052 Tian Ji -- The Horse Racing 贪心 考虑特殊位置(首尾元素)的讨论
题目链接:https://cn.vjudge.net/problem/HDU-1052 题意 田忌赛马问题扩展版 给n匹马,马的能力可以相同 问得分最大多少 思路 贪心做得还是太少,一开始一点思虑都没 ...
- bootstrap 因跳页黑色背景无法关闭
只需要在跳页之前加上如下代码: $(".modal-backdrop").remove();
- 【codeforces 429D】Tricky Function
[题目链接]:http://codeforces.com/problemset/problem/429/D [题意] 给你n个数字; 让你求出一段区间[l,r] 使得 (r−l)2+(∑rl+1a[i ...
- 疯狂软件对Oracle放弃Java EE的看法
近日网络上出现了一些关于Oracle将要放弃Java EE的说法,在Java行业引起不小的关注,甚至有些人开始担心Java会不会就此消亡,但事实上这不过是杞人忧天,疯狂软件教学总监李刚根据多年来Jav ...