現在這麼水機試腫麼辦啊啊啊啊啊
#include <iostream>
#include <vector>
#include <queue>
#include <memory.h>
using namespace std;
const int MAX = 10050;
vector<int> graph[MAX];
int inDegree[MAX];
queue<int> zeroVertex;
int money[MAX];
// 最低工資的排在前面...
void topologicalSort(int vertexNum, int edgeNum)
{
int topNode;
int edges = edgeNum;
while (!zeroVertex.empty())
{
topNode = zeroVertex.front();
zeroVertex.pop();
vector<int> topAdj = graph[topNode];
for (int i = 0; i < topAdj.size(); i++)
{
int adjNode = topAdj[i];
inDegree[adjNode]--;
edges--;
if (inDegree[adjNode] == 0)
{
zeroVertex.push(adjNode);
money[adjNode] = money[topNode] + 1;
}
}
}
if (edges == 0)
{
int total = 0;
for (int i = 1; i <= vertexNum; i++)
{
total += money[i];
}
cout << total << endl;
}
else
cout << "Poor Xed" << endl;
}
int main()
{
int peopleNum;
int repreNum;
int start;
int end;
while (cin >> peopleNum >> repreNum)
{
memset(inDegree, 0, sizeof(inDegree));
while (!zeroVertex.empty())
{
zeroVertex.pop();
}
for (int i = 1; i <= peopleNum; i++)
{
money[i] = 100;
graph[i].clear();
}
for (int i = 1; i <= repreNum; i++)
{
cin >> start >> end;
graph[end].push_back(start);
inDegree[start]++;
}
for (int i = 1; i <= peopleNum; i++)
{
if (inDegree[i] == 0)
zeroVertex.push(i);
}
topologicalSort(peopleNum, repreNum);
}
return 0;
}