奖金

// 奖金.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

/*
http://ybt.ssoier.cn:8088/problem_show.php?pid=1352

由于无敌的凡凡在2005年世界英俊帅气男总决选中胜出,Yali Company总经理Mr.Z心情好,决定给每位员工发奖金。
公司决定以每个人本年在公司的贡献为标准来计算他们得到奖金的多少。

于是Mr.Z下令召开m方会谈。每位参加会谈的代表提出了自己的意见:“我认为员工a的奖金应该比b高!”Mr.Z决定要找出一种奖金方案,
满足各位代表的意见,且同时使得总奖金数最少。每位员工奖金最少为100元。

【输入】
第一行两个整数n,m,表示员工总数和代表数;

以下m行,每行2个整数a,b,表示某个代表认为第a号员工奖金应该比第b号员工高。

【输出】
若无法找到合理方案,则输出“Poor Xed”;否则输出一个数表示最少总奖金。

【输入样例】
2 1
1 2
【输出样例】
201

4 4
1 2
1 3
3 4
2 4

6 6
1 2
1 3
2 4
2 5
4 6
5 6

6 6
1 2
1 2
1 2
3 4
5 6
5 6

9 13
6 8
7 5
3 7
7 6
9 8
3 4
6 8
3 8
7 9
1 3
7 9
5 6
4 9

【提示】
【数据规模】
80%的数据满足:n≤1000,m≤2000;
100%的数据满足:n≤10000,m≤20000。
*/

#include <iostream>
#include <queue>
#include <vector>
#include <cstring>

using namespace std;

const int N = 20010, M = 40010;
int h[N], e[M], ne[M], idx;
int n, m;
int din[N], dout[N];
int ans[N];
vector<int> v;


void add(int a, int b) {
	e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}

void topsort() {
	queue<pair<int,int>> q;
	for (int i = 1; i <= n; i++) {
		if (din[i] == 0) q.push({i,0});
	}
	
	while (q.size()) {
		int curr = q.front().first; int step = q.front().second;
		q.pop();
		
		ans[curr] = max(ans[curr], step);
		v.push_back(curr);
		for (int i = h[curr]; i != -1; i = ne[i]) {
			int j = e[i];
			din[j]--;
			if (din[j] == 0) {
				q.push({ j,ans[curr] + 1 });
			}
		}
	}

	return;
}



int main()
{
	cin >> n >> m;
	memset(h, -1, sizeof h);
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		add(b, a);
		din[a]++; dout[b]++;
	}

	topsort();

	if (v.size() == n) {
		long long sum = 100 * n;
		for (int i = 1; i <= n; i++) {
			sum += ans[i];
		}	

		cout << sum << endl;
	}
	else {
		cout << "Poor Xed" << endl;
	}

	return 0;
}

posted on   itdef  阅读(7)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示