题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
typedef pair<int, int> PII;
const int N = 10010, M = 20010;
int n, m;
int h[N], e[M], ne[M], idx;
int din[N];
int dist[N];
int cnt;
void topsort()
{
for (int i = 1; i <= n; i ++) dist[i] = 100;
queue<PII> q;
for (int i = 1; i <= n; i ++)
if (!din[i])
q.push({100, i});
while(q.size())
{
auto t = q.front();
q.pop();
cnt ++;
for (int i = h[t.second]; ~i; i = ne[i])
{
int j = e[i];
dist[j] = max(dist[j], t.first + 1);
if (-- din[j] == 0)
q.push({dist[j], j});
}
}
}
void add(int a, int b)
{
e[idx] = b, ne[idx] = h[a], h[a] = idx ++;
}
int main()
{
cin >> n >> m;
memset(h, -1, sizeof h);
while(m --)
{
int a, b;
cin >> a >> b;
add(b, a);
din[a] ++;
}
topsort();a
if (cnt < n) puts("Poor Xed");
else
{
int res = 0;
for (int i = 1; i <= n; i ++) res += dist[i];
cout << res;
}
return 0;
}