Reward

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3129    Accepted Submission(s): 944

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
 
拓扑排序:
代码

 /*@coder 龚细军*/
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<vector> //动态的二维数组
#include<iostream>
using namespace std;
const int maxn=;
int n,m;
int cnt[maxn],outd[maxn];
vector< vector<int> >map(maxn);
void tp_sort(int tol)
{
int i;
queue<int>st;
for(i=;i<=n;i++)
{
if(!outd[i])
{
outd[i]--;
st.push(i);
break;
}
}
//环如何消除
while(!st.empty())
{
int temp=st.front();
vector<int>::iterator it;
for(it=map[temp].begin();it!=map[temp].end();it++)
{
outd[*it]--;
if(cnt[*it]<=cnt[temp])
cnt[*it]=cnt[temp]+;
}
st.pop();
for(i=;i<=n;i++)
{
if(!outd[i])
{
outd[i]--;
st.push(i);
break;
}
}
}
for(i=;i<=n;i++)
{
if(outd[i]!=-)
{
puts("-1");
return ;
}
}
int ans=;
for(i=;i<=n;i++)
{
ans+=cnt[i];
}
if(ans)
printf("%d\n",n*+ans);
else
puts("-1"); } int main()
{
int a,b,i;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=;i<=n;i++) map[i].clear();
memset(outd,,sizeof(outd));
memset(cnt,,sizeof(cnt));
i=;
while(m--)
{
scanf("%d%d",&a,&b);
map[b].push_back(a);
outd[a]++; /*out++*/
} tp_sort(i);
}
return ;
}

HDUOJ----2647Reward的更多相关文章

  1. hduoj 1455 && uva 243 E - Sticks

    http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...

  2. hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

  3. hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup

    hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...

  4. hdu-oj 1874 畅通工程续

    最短路基础 这个题目hdu-oj 1874可以用来练习最短路的一些算法. Dijkstra 无优化版本 #include<cstdio> #include<iostream> ...

  5. C#版 - HDUoj 5391 - Zball in Tina Town(素数) - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. HDUoj 5 ...

  6. C++版 - HDUoj 2010 3阶的水仙花数 - 牛客网

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C++版 - ...

  7. HDUOJ题目HTML的爬取

    HDUOJ题目HTML的爬取 封装好的exe/app的GitHub地址:https://github.com/Rhythmicc/HDUHTML 按照系统选择即可. 其实没什么难度,先爬下来一个题目的 ...

  8. hduoj 1251 统计难题

    http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory ...

  9. hduoj 1286 找新朋友

    http://acm.hdu.edu.cn/showproblem.php?pid=1286 找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  10. hduoj 1285 确定比赛名次

    http://acm.hdu.edu.cn/showproblem.php?pid=1285 确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory ...

随机推荐

  1. 发布设置setting.xml

    <?xml version="1.0" encoding="UTF-8"?> <!-- User-specific configuration ...

  2. MAC之find与grep

    小白,新手.有错请指出. grep一般是搜指定文件中的内容:而find是搜对应的文件 find:1. 找出当前文件目录及其子目录含有开头a的文件.  “.”是当前目录   “-ls”显示详细信息fin ...

  3. 使用Artful MySQL模块出错

    总是报错: root@gitlab:/opt# newlisp newLISP v.10.6.0 64-bit on Linux IPv4/6 UTF-8 libffi, options: newli ...

  4. 我所遭遇过的游戏中间件--PhysX

    我所遭遇过的游戏中间件--PhysX PhysX现在是Nvidia的物理中间件.其特点是简练且功能强大.当我最初拿到PHYSX的SDK时,就发现这个物理中间件比Havok要小很多,但该有的功能都有,甚 ...

  5. go语言基础之new函数

    1.new函数 表达式new(T)将创建一个T类型的匿名变量,所做的是为T类型的新值分配并清零一块内存空间,然后将这块内存空间的地址作为结果返回,而这个结果就是指向这个新的T类型值的指针值,返回的指针 ...

  6. Mysql之sql语句操作

    一.数据库级别操作 1.显示数据库 1 SHOW DATABASES; 默认数据库: mysql - 用户权限相关数据 test - 用于用户测试数据 information_schema - MyS ...

  7. ubuntu14.04开启root用户 设置root密码 配置国内镜像源 设置分辨率

    一.Ubuntu 默认是不允许 root 通过 ssh 直接登录的,可以修改 /etc/ssh/sshd_config,设置 1 PermitRootLogin yes 然后重启 ssh 服务即可 1 ...

  8. WF4.0(3)----变量与参数

    已经写了两篇关于WF4.0的博客,算是基础博客,如果是WF比较熟悉就直接跳过吧,如果你对工作流不是很熟悉,或者想了解一下基础的东西,本文还是比较适合你的.工作流中变量,参数,表达式属于数据模型中概念, ...

  9. 【BZOJ2662】【BeiJing wc2012】冻结 分层图 裸的!

    我都不好意思发题解了,看这篇博吧.(飞行路线的,基本一样) http://blog.csdn.net/vmurder/article/details/40075989 同学做了好久.我害怕题里有坑,又 ...

  10. Postgresql监控pgwatch的搭建

    一,需要环境: You will need a handful of components to make this work: - Apache (webserver) #apache搭建web页面 ...