博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Reward HDU - 2647 (拓扑排序)
阅读量:4045 次
发布时间:2019-05-25

本文共 1489 字,大约阅读时间需要 4 分钟。

 

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 11 22 21 22 1

Sample Output

1777-1

题意: 

老板打算给员工们发奖励,但是员工会去存在一些要求,例如,输入a b 即a员工的奖励要比b员工的奖励多。老板决定每个员工的最低奖励为888元。老板想要知道自己最少需要多少钱俩奖励员工。所以最低工资为888,它的上一层的工资就是889,所以可以逆向建图,利于计算每个员工的工资。

代码:

#include
#include
#include
#include
#include
#include
using namespace std;const int maxn=10007;vector
path[maxn];int sum[maxn]; //记录每个员工的工资 int rudu[maxn]; //每个员工的入度,即要有几个人的工资比他低queue
q;int n,m;void tuopu(){ for(int i=1;i<=n;i++) { if(rudu[i]==0) //逆向建图,所以入度为0的工资最低 { q.push(i); sum[i]=888; rudu[i]--; } } while(!q.empty()) { int x=q.front(); q.pop(); for(int i=0;i

 

转载地址:http://hizci.baihongyu.com/

你可能感兴趣的文章
mysql 主从同步配置
查看>>
为什么很多程序员都选择跳槽?
查看>>
mongdb介绍
查看>>
mongdb安装使用
查看>>
mongdb在java中的应用
查看>>
区块链技术让Yotta企业云盘为行政事业服务助力
查看>>
Yotta企业云盘更好的为媒体广告业服务
查看>>
Yotta企业云盘助力旅游行业新发展
查看>>
Yotta企业云盘助力科技行业创高峰
查看>>
Yotta企业云盘更好地为教育行业服务
查看>>
Yotta企业云盘怎么帮助到能源化工行业
查看>>
企业云盘如何助力商业新发展
查看>>
医疗行业运用企业云盘可以带来什么样的提升
查看>>
教育数字智能化能为现有体系带来新的起点
查看>>
媒体广告业如何将内容资产进行高效地综合管理与利用
查看>>
能源化工要怎么管控核心数据
查看>>
媒体广告业如何运用云盘提升效率
查看>>
企业如何运用企业云盘进行数字化转型-实现新发展
查看>>
司法如何运用电子智能化加快现代化建设
查看>>
iSecret&nbsp;1.1&nbsp;正在审核中
查看>>