网站自己怎么做优化,专门做护肤品的网站是,合肥做网站公,网页设计学习心得reference way#xff1a;在图里面能延伸的越远#xff0c;deep越大#xff0c;说明它能从自己延伸很长到别的节点#xff08;别的节点一定有入度#xff09;#xff0c;它越可能没有入度。
way#xff1a;感觉和DFS1差不多#xff0c;只是从远变成了多。
#include在图里面能延伸的越远deep越大说明它能从自己延伸很长到别的节点别的节点一定有入度它越可能没有入度。
way感觉和DFS1差不多只是从远变成了多。
#includeiostream
#includevector
#includemap
#includeset
#includealgorithm
using namespace std;class Node
{
public:int label;vectorNode * neighbors;Node(){}Node(int x){labelx;}
};class Record
{
public:Node* node;long childs;Record(Node* n, long num){noden;childsnum;}
};Record* getRecord(Node *cur, mapNode *,Record *mp)
{if(mp.count(cur)) return mp[cur];long follow0;for(auto next: cur-neighbors){follow getRecord(next, mp)-childs;}Record *pnew Record(cur,follow1);mp[cur]p;return p;
}bool comp(Record *a, Record*b)
{return (a-childs)(b-childs);
}vectorNode* topoSort(vectorNode*graph)
{//获取所有节点的deep然后 map[Node*]Record*;mapNode*, Record*mp;for(auto node: graph){getRecord(node, mp);}//将Record*们放到vec中准备排序vectorRecord*vec;for(auto pa: mp){vec.push_back(pa.second);}sort(vec.begin(),vec.end(),comp);//放到答案数组中vectorNode*result;for(auto m: vec){result.push_back(m-node);}return result;
}
和前一篇图的拓扑序列DFS1)-CSDN博客对比着看。