1424. 奖金
Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
Description
由于无敌的凡凡在2005年世界英俊帅气男总决选中胜出,Yali Company总经理Mr.Z心情好,决定给每位员工发奖金。公司决定以每个人本年在公司的贡献为标准来计算他们得到奖金的多少。
于是Mr.Z下令召开m方会谈。每位参加会谈的代表提出了自己的意见:“我认为员工a的奖金应该比b高!”Mr.Z决定要找出一种奖金方案,满足各位代表的意见,且同时使得总奖金数最少。每位员工奖金最少为100元。
【数据范围】
数据满足n<=10000,m<=20000。
Input
第一行两个整数n,m,表示员工总数和代表数;
以下m行,每行2个整数a,b,表示某个代表认为第a号员工奖金应该比第b号员工高。
Output
若无法找到合法方案,则输出“Poor Xed”;否则输出一个数表示最少总奖金。
Sample Input
2 1 1 2
Sample Output
201
// Problem#: 1424
// Submission#: 3254632
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int MAX_N = 10005;
int N, M;
vector<vector<int> > G;
int award[MAX_N];
int inDegree[MAX_N];
int main() {
std::ios::sync_with_stdio(false);
cin >> N >> M;
G.resize(N + 1);
for (int i = 0; i < M; i++) {
int bigger, smaller;
cin >> bigger >> smaller;
G[smaller].push_back(bigger);
inDegree[bigger]++;
}
queue<int> q;
for (int i = 1; i <= N; i++) {
award[i] = 100;
if (inDegree[i] == 0) {
q.push(i);
}
}
int counter = 0;
while (!q.empty()) {
int now = q.front();
q.pop();
counter++;
int nowSize = G[now].size();
for (int i = 0; i < nowSize; i++) {
if (award[now] + 1 > award[G[now][i]]) award[G[now][i]] = award[now] + 1;
inDegree[G[now][i]]--;
if (inDegree[G[now][i]] == 0) q.push(G[now][i]);
}
}
if (counter != N) {
cout << "Poor Xed" << endl;
} else {
int ans = 0;
for (int i = 1; i <= N; i++) {
ans += award[i];
}
cout << ans << endl;
}
//getchar();
//getchar();
return 0;
}