hdu2647 && TOJ3648 Reward
来源:互联网 发布:复旦金融硕士 知乎 编辑:程序博客网 时间:2024/06/02 18:59
Reward
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2862 Accepted Submission(s): 844
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.
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.
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
Author
dandelion
Source
曾是惊鸿照影来
#include <iostream>#include <queue>#include <string>#include <cstdio>#include <cstring>#include <vector>#include <stack>#include <algorithm>using namespace std;const int maxn = 10010;//这道题目在TOJ上提交RE,表示无奈.int gn, gm;int mon[maxn];vector<int> g[maxn];int du[maxn];int num;bool vis[maxn];//标记点的存在.int counter;//统计一共有多少不同的人,应有多少人出队入队.void init() { int i; counter = 0; num = 0;//记录出队多少人. memset(du, 0, sizeof(du)); memset(vis, false, sizeof(vis)); memset(mon, 0, sizeof(mon)); for(i = 0; i < maxn; i++) { g[i].clear(); }}void work() { int i; queue<int> Q; while(!Q.empty()) Q.pop(); for(i = 1; i <= gn; i++) { if(!du[i] && vis[i]) { Q.push(i); } if(vis[i]) counter++; } while(!Q.empty()) { int x = Q.front(); Q.pop(); num++; for(i = 0; i < (int)g[x].size(); i++) { int t = g[x][i]; mon[t] = max(mon[t], mon[x]+1); du[t]--; if(!du[t]) { Q.push(t); } } } if(num == counter) { int tot = 0; for(i = 0; i < maxn; i++) { tot += mon[i]; } tot += gn*888; printf("%d\n", tot); } else { printf("-1\n"); }}int main(){ int i; int from, to; while(scanf("%d%d", &gn, &gm) != EOF) { init(); for(i = 1; i <= gm; i++) { scanf("%d%d", &to, &from); vis[from] = true; vis[to] = true; g[from].push_back(to); du[to]++; } if(gn==0) { printf("0\n"); continue; } work(); } return 0;}
- hdu2647 && TOJ3648 Reward
- HDU2647 Reward
- hdu2647:Reward
- HDU2647---Reward
- hdu2647 Reward
- HDU2647-Reward
- hdu2647 Reward (拓扑排序)
- HDU2647 Reward 【拓扑排序】
- hdu2647 - Reward (拓扑排序)
- hdu2647——Reward
- HDU2647 Reward 【拓扑排序】
- HDU2647 Reward 拓扑排序
- hdu2647 Reward (拓扑排序)
- hdu2647 Reward--拓扑排序
- HDU2647:Reward(拓扑排序)
- hdu2647 Reward 拓扑排序
- HDU2647 Reward(拓扑排序)
- hdu2647 Reward【拓扑排序】
- Visual Assist X 最有用的快捷键
- shell脚本中蛮量替换(将命令运行结果存入变量中)
- Java UML类图浅析
- hdu 4090 GemAnd Prince dfs+bfs+最优性剪枝
- struts2下的“Exception starting filter struts2”错误的问题
- hdu2647 && TOJ3648 Reward
- hdu 1372 Knight Moves
- SQL SERVER中的CHECKPOINT
- oracle 传输表空间
- Linux进程状态
- 离散化+树状数组 求逆序数POJ2299
- http协议学习系列教程
- hdu 4089 Activation(概率dp)
- 计算机原理学习(1)-- 冯诺依曼体系和CPU工作原理