HDUOJ----2647Reward
Reward
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3129 Accepted Submission(s): 944
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.
/*@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的更多相关文章
- hduoj 1455 && uva 243 E - Sticks
http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...
- 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 ...
- 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 ...
- hdu-oj 1874 畅通工程续
最短路基础 这个题目hdu-oj 1874可以用来练习最短路的一些算法. Dijkstra 无优化版本 #include<cstdio> #include<iostream> ...
- C#版 - HDUoj 5391 - Zball in Tina Town(素数) - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. HDUoj 5 ...
- C++版 - HDUoj 2010 3阶的水仙花数 - 牛客网
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C++版 - ...
- HDUOJ题目HTML的爬取
HDUOJ题目HTML的爬取 封装好的exe/app的GitHub地址:https://github.com/Rhythmicc/HDUHTML 按照系统选择即可. 其实没什么难度,先爬下来一个题目的 ...
- hduoj 1251 统计难题
http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory ...
- hduoj 1286 找新朋友
http://acm.hdu.edu.cn/showproblem.php?pid=1286 找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- hduoj 1285 确定比赛名次
http://acm.hdu.edu.cn/showproblem.php?pid=1285 确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory ...
随机推荐
- Derby安装,创建数据库,在Java程序中使用Derby
1,下载并安装Derby: 下载地址:http://db.apache.org/derby /derby_downloads.html,下载最新版本. 我用的是10.5.3.0. 解压缩到任意文件夹, ...
- 15个具有高度影响力的Apache开源项目
自1999年创立以来,Apache软件基金会如今已成了众多重要的开源软件项目之家.其中成功的项目有Geronimo,有Tomcat,有Hadoop,有如今成了大数据王国关键车毂的分布式计算系统. 虽然 ...
- [实时更新]jquery全部版本号下载
jquery-2.1.0 注!不再支持IE 6/7/8 直接引用地址: 开发版地址1: <script src="http://code.jquery.com/jquery-2. ...
- post文件的html
<HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio& ...
- poj 1469 COURSES 题解
COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21515 Accepted: 8455 Descript ...
- C# 实现PNG文件的背景透明显示,解决动态显示闪烁问题 【转】
http://blog.sina.com.cn/s/blog_402c071e0102x4rl.html 以下内容,对于想要使用C#实现PNG图片背景透明显示,同时动态显示时无闪烁问题的人来说, ...
- Log 日志工具类 保存到文件 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- IE6与CSS样式兼容问题汇总
1.PNG半透明图片的问题 虽然可以通过JS等方式解决,但依然存在载入速度等问题,所以,这个上能不要用还是尽量不要用.以达到网站最大优化. 2.IE6下的圆角 IE6不支持CSS3的圆角属性,比较好的 ...
- Android之AlarmManager
Android平台中,Alarm Manager Service控制着闹钟和唤醒功能.和其他系统服务一样,提供了一个辅助管理类-AlarmManager,我们只需要使用AlarmManager即可调用 ...
- SELinux安全系统基础
一.SELinux简介 SELinux(Secure Enhanced Linux)安全增强的Linux是由美国国家安全局NSA针对计算机基础结构安全开发的一个全新的Linux安全策略机制.SELin ...