拓扑排序 hdu 2647 Reward
来源:互联网 发布:三星电话交换机编程 编辑:程序博客网 时间:2024/06/06 07:04
Reward
TimeLimit: 2000/1000 MS(Java/Others)Total Submission(s):868
Problem Description
Dandelion's uncle is a boss of a factory. As the spring festival iscoming , he wants to distribute rewards to his workers. Now he hasa trouble about how to distribute the rewards.
The workers will compare their rewards ,and some one may havedemands of the distributing of rewards ,just like a's reward shouldmore 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 willbe at least 888 , because it's a lucky number.
The workers will compare their rewards ,and some one may havedemands of the distributing of rewards ,just like a's reward shouldmore 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 willbe at least 888 , because it's a lucky number.
Input
One line with two integers n and m ,stands for the number of worksand the number of demands.(n<=10000,m<=20000)
then m lines ,each line contains two integers a and b ,stands fora's reward should be more than b's.
then m lines ,each line contains two integers a and b ,stands fora's reward should be more than b's.
Output
For every case ,print the least money dandelion 's uncle needs todistribute .If it's impossible to fulfill all the works' demands,print -1.
Sample Input
21
12
22
12
21
Sample Output
1777
-1
#include<stdio.h>
#include<string.h>
#include<malloc.h>
struct node
{
};
int getmax(int a,int b)
{
return a>b?a:b;
}
struct node a[10010];
int flag=1;
int mon[10010];
void Topsort(int T)
{
struct node *p;
j=1;
while(a[j].data!=0) j++;
if(j>T) flag=0;
for(p = a[j].next;p!=NULL;p=p->next)
{
a[p->data].data --;
mon[p->data]=getmax(mon[j]+1,mon[p->data]);
}
if(flag==1)
printf("%d\n",sum);
else printf("-1\n");
}
int main()
{
flag=1;
memset(mon,0,sizeof(mon));
for(i=1;i<=T;i++)
while(m--)
{
if(x!=y)
{
a[x].data++;
p->data=x;
p->next=NULL;
q=&a[y];
if(q->next==NULL)
q->next=p;
else
{
p->next=q->next;
q->next=p;
}
}
}
for(i=1;i<=T;i++)
{
mon[i]=888;
}
Topsort(T);
}
}
- 拓扑排序 hdu 2647 Reward
- ZZULI 1619 (HDU 2647) Reward …
- (拓扑排序 )hdu 2094 产生冠军
- 拓扑排序hdu 3342 Legal or Not
- Lesson 51 Reward …
- hdu 2647 Reward 拓扑排序
- hdu 2647 Reward 拓扑排序
- hdu 2647 Reward 拓扑排序
- hdu 2647 Reward 拓扑排序
- HDU 2647 Reward(拓扑排序)
- 【HDU】2647 Reward 拓扑排序
- hdu 2647 Reward 拓扑排序
- hdu 2647 Reward 拓扑排序。
- hdu 2647 Reward 拓扑排序
- HDU 2647--Reward【拓扑排序】
- hdu 2647 Reward(拓扑排序)
- HDU 2647 Reward(拓扑排序)
- #HDU 2647 Reward 【拓扑排序】
- 黑马程序员------面向对象(No.6)(接口、多态)
- 堆排序 hdu 2020 绝对值排序
- (拓扑排序 )hdu 2094 产生冠军
- 排序
- 拓扑排序hdu 3342 Legal or Not
- 拓扑排序 hdu 2647 Reward
- 【考研数学】数学满分秘籍、考研数…
- 阿牛的EOF牛肉串
- 最短路径问题 hdu 3790
- hdu 2544 最短路(dijkstra算法)
- hdu 1875 最小生成树(prim算法)…
- 那一口人间最温暖的粥啊……——95岁…
- 大整数加法 1002 A + B Problem II
- 大整数的四则运算代码(供新手学习…