程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> uva 10305

uva 10305

編輯:C++入門知識

\


<喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PC9wPgo8cHJlIGNsYXNzPQ=="brush:java;">/************************************************************************* File Name: 10305four.cpp Author: yubo Mail: [email protected] Created Time: 2014年06月02日 星期一 00時23分06秒 學習重點: reference John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already been executed. Input The input will consist of several instances of the problem. Each instance begins with a line containing two integers, 1 <= n <= 100 and m. n is the number of tasks (numbered from 1 to n) and m is the number of direct precedence relations between tasks. After this, there will be m lines with two integers i and j, representing the fact that task i must be executed before task j. An instance with n = m = 0 will finish the input. Output For each instance, print a line with n integers representing the tasks in a possible order of execution. Sample Input 5 4 1 2 2 3 1 3 1 5 0 0 Sample Output 1 4 2 5 3: http://sbp810050504.blog.51cto.com/2799422/901022 ************************************************************************/ #include #include #include #include using namespace std; #define MAXN 105 //have time according to text to write struct ArcNode{ int to; struct ArcNode* next; }; ArcNode* List[MAXN]; int n,m; int counts[MAXN]; int output[MAXN]; void toposort() { stack s; memset(output,0,sizeof(output)); for(int i=0;ito; counts[f]--; if(counts[f]==0){ s.push(f); } temp=temp->next; } } }if(bcycle) printf("The Network has a cycle\n"); else { for(int l=0;lnext; delete temp; temp=List[i]; } } } int main() { //freopen("in.txt","r",stdin); int u,v; while(scanf("%d%d",&n,&m)){ if(!n&&!m) break; memset(List,0,sizeof(List)); memset(counts,0,sizeof(counts)); for(int i=0;ito=v; temp->next=NULL; if(temp==NULL) List[u]=temp; else{ temp->next=List[u]; List[u]=temp; } } ArcNode* temp=new ArcNode; toposort(); del(); } }

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved