Is It A Tree? Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28399   Accepted: 9684 Description A tree is a well-known data structure that is either empty (null, void, nothing) or is a set of one or more nodes connected by directed edge…
Genealogical tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7285   Accepted: 4704   Special Judge Description The system of Martians' blood relations is confusing enough. Actually, Martians bud when they want and where they want. T…
Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2738 Accepted: 1838 Special Judge Description The system of Martians' blood relations is confusing enough. Actually, Martians bud when they want and where they want. They ga…
Triangle LOVE Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 3566    Accepted Submission(s): 1395 Problem Description Recently, scientists find that there is love between any of two people. For…
和LeetCode 207. Course Schedule(拓扑排序-求有向图中是否存在环)类似. 注意到.在for (auto p: prerequistites)中特判了输入中可能出现的平行边或自环. 代码: class Solution { public: vector<int> findOrder(int numCourses, vector<pair<int, int>>& prerequisites) { // [0, {1, 2, 3}], me…
//拓扑排序判断是否有环 #include<cstdio> #include<algorithm> #include<string.h> #include<math.h> #include<queue> using namespace std; typedef long long ll; ; int G[maxn][maxn]; int in[maxn]; void init() { memset(G,,sizeof(G)); //图 memse…
Description An ascending sorted sequence of distinct values is one in which some form of a less-than operator is used to order the elements from smallest to largest. For example, the sorted sequence A, B, C, D implies that A < B, B < C and C < D.…
火星人的血缘关系很奇怪,一个人可以有很多父亲,当然一个人也可以有很多孩子.有些时候分不清辈分会产生一些尴尬.所以写个程序来让n个人排序,长辈排在晚辈前面. 输入:N 代表n个人 1~n 接下来n行 第i行表示第i个人的孩纸,无序排列,可能为空.0代表一行输入结束. (大概我的智商真的不合适,否则怎么这么久了连个拓扑排序都写不好,T了三次..) 代码: /******************************************** Problem: 2367 User: Memory:…
题意:大概意思是--有一个家族聚集在一起,现在由家族里面的人讲话,辈分高的人先讲话.现在给出n,然后再给出n行数 第i行输入的数表示的意思是第i行的子孙是哪些数,然后这些数排在i的后面. 比如样例 5 0 4 5 1 0 1 0 5 3 0 3 0 1后面没有数 2后面有4 5 1 3后面有1 4后面有5 3 5后面有3 拓扑排序的一点小体会 (1)先把图储存下来,然后储存相应顶点的度数 (2)在图中选择没有前驱的点(即入度为0的点),加入队列中 (3)将以这一点为起点的边删去(将这一点指向的点…
poj 1094 Sorting It All Out Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%lld & %llu Description An ascending sorted sequence of distinct values is one in which some form of a less-than operator is used to order the elements from sm…