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

Problem Description
Dandelion's uncle is a boss of a factory. As the spring festival is coming , he wants to distribute rewards to his workers. Now he has a trouble about how to distribute the rewards.
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.
 
Input
One line with two integers n and m ,stands for the number of works and the number of demands .(n<=10000,m<=20000)
then m lines ,each line contains two integers a and b ,stands for a's reward should be more than b's.
 
Output
For every case ,print the least money dandelion 's uncle needs to distribute .If it's impossible to fulfill all the works' demands ,print -1.
 
Sample Input
2 1
1 2
2 2
1 2
2 1
 
Sample Output
1777
-1
 
Author
dandelion
 
Source
 
Recommend
yifenfei   |   We have carefully selected several similar problems for you:  1285 1811 2680 2112 2094 
 
记录每一层的人数,统计答案。。。
唉,蒟蒻就是弱、、边的方向搞错了调半天。。。
 #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的更多相关文章

  1. ACM: hdu 2647 Reward -拓扑排序

    hdu 2647 Reward Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Des ...

  2. hdu 2647 Reward

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2647 Reward Description Dandelion's uncle is a boss o ...

  3. HDU.2647 Reward(拓扑排序 TopSort)

    HDU.2647 Reward(拓扑排序 TopSort) 题意分析 裸的拓扑排序 详解请移步 算法学习 拓扑排序(TopSort) 这道题有一点变化是要求计算最后的金钱数.最少金钱值是888,最少的 ...

  4. 题解报告:hdu 2647 Reward(拓扑排序)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 Problem Description Dandelion's uncle is a boss ...

  5. HDU 3613 Best Reward 正反两次扩展KMP

    题目来源:HDU 3613 Best Reward 题意:每一个字母相应一个权值 将给你的字符串分成两部分 假设一部分是回文 这部分的值就是每一个字母的权值之和 求一种分法使得2部分的和最大 思路:考 ...

  6. HDU 2647 Reward (拓扑排序)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 题意是给你n点m条有向边,叶子点(出度为0)上的值为888,父亲点为888+1,依次计算... ...

  7. HDU 2647 Reward(拓扑排序+判断环+分层)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 题目大意:要给n个人发工资,告诉你m个关系,给出m行每行a b,表示b的工资小于a的工资,最低工 ...

  8. HDU 2647 Reward(图论-拓扑排序)

    Reward Problem Description Dandelion's uncle is a boss of a factory. As the spring festival is comin ...

  9. hdu 2647 Reward(拓扑排序,反着来)

    Reward Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submis ...

随机推荐

  1. Spark脚本调用

    Spark提供了多个脚本来作为程序的入口,其中最常用的是交互脚本 spark-shell, pyspark,还有spark sql的客户端spark-sql. 这些脚本最后都会归结到对SparkSub ...

  2. LOJ #10121 与众不同 (RMQ+二分)

    题目大意 :给你一个整数序列,定义一个合法子串为子串内所有数互不相同,会有很多询问,求区间$[L,R]$内最长连续合法子串长度 一道思维不错的$RMQ$题,NOIP要是考这种题可能会考挂一片 预处理出 ...

  3. keepalive安装配置

    安装 Centos7.4 yum install keepalived 配置 Master服务器配置 [root@wsjy-proxy01 keepalived]# cat keepalived.co ...

  4. vue+element-ui+slot-scope或原生实现可编辑表格(日历)

    你们公司的产品是不是还在做一个可编辑表格功能? 1.前言 咱开发拿到需求大多数是去网上找成型的组件,找不到再看原生的方法能否实现,大牛除外哈,大牛一般喜欢封装组件框架. 2.思路 可编辑表格在后台管理 ...

  5. Android端通过HttpURLConnection上传文件到server

    Android端通过HttpURLConnection上传文件到server 一:实现原理 近期在做Androidclient的应用开发,涉及到要把图片上传到后台server中.自己选择了做Sprin ...

  6. Ubuntu 10.04 右上角网络管理图标消失的解决的方法

           那个显示网络状态的那个图标.叫做:network-manager.假设是有线网络连接的话.是上下两个箭头,假设是无线网络的话.是一个发射信号的形状. sudo gedit /etc/Ne ...

  7. AVEVA PDMS to DIALux

    AVEVA PDMS to DIALux eryar@163.com   Abstract. DIAL develops DIALux - the world's leading software f ...

  8. HDU 2112 HDU Today &lt;SPFA算法+map函数&gt;

    HDU Today Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. angularjs 自定义服务

    <!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...

  10. thinkphp5项目--个人博客(四)

    thinkphp5项目--个人博客(四) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...