sicily 1424 獎金..

現在這麼水機試腫麼辦啊啊啊啊啊哭

#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;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章