Show all threads Hide all threads Show all messages Hide all messages | Page 2 | crash | viktor | 1022. Genealogical Tree | 10 Mar 2007 16:16 | 1 | crash viktor 10 Mar 2007 16:16 Why do I get access violation? here's the code(top_sort with pointers) type pok=^mars; mars=record redbr:integer; sleden:pok; end; var i,j,k,l,n,m,gl,r,pm,pm1:integer; brdeca,z,odg:array[1..100]of integer; p1,p2,p3,pom,prv:pok; toc:boolean; vl,kon,vl1:array[1..200]of integer; deca:array[1..150,1..150]of integer; t,tc,ozn:array[1..200]of boolean; procedure stavi(y:integer); begin if prv=nil then begin new(p1); prv:=p1; p1^.redbr:=y; p1^.sleden:=nil; kon[y]:=gl; gl:=gl+1; end else begin pom:=prv; while pom^.sleden<>nil do pom:=pom^.sleden; new(p2); pom^.sleden:=p2; p2^.sleden:=nil; p2^.redbr:=y; kon[y]:=gl; gl:=gl+1; end; end; procedure dfs(x:integer); begin if tc[x]=false then begin tc[x]:=true; for j:=1 to brdeca[x] do vl[deca[x,j]]:=vl[deca[x,j]]+1; for j:=1 to brdeca[x] do if tc[deca[x,j]]=false then dfs(deca[x,j]); end; end; procedure vadi; begin r:=prv^.redbr; for i:=1 to brdeca[prv^.redbr] do vl[deca[r,i]]:=vl[deca[r,i]]-1; pom:=prv; prv:=prv^.sleden; dispose(pom); end; begin readln(n); for i:=1 to n do ozn[i]:=false; for i:=1 to n do vl[i]:=0; for i:=1 to n do brdeca[i]:=1; i:=1; while i<n+1 do begin read(deca[i,brdeca[i]]); if deca[i,brdeca[i]]<>0 then brdeca[i]:=brdeca[i]+1 else begin brdeca[i]:=brdeca[i]-1; i:=i+1; end; end; gl:=0; for i:=1 to n do tc[i]:=false; for i:=1 to n do dfs(i); for i:=1 to n do vl1[i]:=vl[i]; toc:=true; new(prv); prv^.sleden:=nil; for i:=1 to n do if vl[i]=0 then stavi(i); while toc do begin vadi; for i:=1 to brdeca[r] do if vl[deca[r,i]]=0 then stavi(deca[r,i]); if prv=nil then toc:=false; end; for i:=1 to n do z[i]:=i; for i:=1 to n-1 do begin for j:=i+1 to n do begin if kon[i]>kon[j] then begin pm:=z[i]; pm1:=kon[i]; z[i]:=z[j]; kon[i]:=kon[j]; z[j]:=pm; kon[j]:=pm1; end; end; end; for i:=1 to n-1 do write(z[i],' '); write(z[n]); end. | WA#6 | Izual | 1022. Genealogical Tree | 4 Mar 2007 00:49 | 1 | WA#6 Izual 4 Mar 2007 00:49 Sorry for poor english... I think that this code is true (but it's not topsort!): const INF=2000000000; var a : array [1..100] of integer; n,i,j,now,k,min : integer; begin read(n); for i:=1 to n do a[i]:=i; for i:=1 to n do begin read(k); min:=INF; while k<>0 do begin for j:=1 to n do if (a[j]=k) and (min>j) then min:=j; read(k); end; if min<>INF then begin for j:=1 to n do if a[j]=i then now:=j; if now>min then begin for j:=now downto min+1 do a[j]:=a[j-1]; a[min]:=i; end; end; end; write(a[1]); for i:=2 to n do write(' ',a[i]); end. May you give me some bad for my algorithm tests? Thanks for your attention. Edited by author 04.03.2007 00:54 Edited by author 04.03.2007 00:55 | WA#6 Help, please!!! | [SSAU_#617]snipious aka Pimenov Sergey Nikolaevich | 1022. Genealogical Tree | 2 Feb 2009 22:25 | 12 | input: 100 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 1 4 5 9 2 3 0 10 0 11 0 12 4 5 6 7 8 9 0 13 0 14 0 15 0 16 0 17 0 18 0 2 3 4 28 5 6 1 7 8 9 10 11 12 13 17 19 0 0 2 0 0 0 15 0 0 0 0 14 13 12 11 0 0 0 33 34 30 0 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 1 4 5 9 2 3 0 10 0 11 0 12 4 5 6 7 8 9 0 13 0 14 0 15 0 16 0 17 0 18 0 2 3 4 28 5 6 1 7 8 9 10 11 12 13 17 19 0 0 2 0 0 0 15 0 0 84 0 0 14 13 12 11 0 0 0 33 34 30 0 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 1 4 5 9 2 3 0 10 0 11 0 12 4 5 6 7 8 9 0 13 0 14 0 15 0 16 0 17 0 18 0 2 3 4 28 5 6 1 7 8 9 10 11 12 13 17 19 0 0 2 0 0 0 15 0 0 0 0 14 13 12 11 0 0 0 33 34 30 0 0 92 84 11 0 My program outputs: 20 53 86 19 52 85 18 51 100 84 17 50 83 16 25 49 58 82 91 15 29 48 62 81 95 14 47 80 13 46 79 12 45 78 11 44 77 10 43 76 9 42 75 8 41 74 7 40 73 6 39 72 5 38 71 4 37 70 3 22 36 55 69 88 2 35 68 1 21 23 24 26 27 28 32 65 98 30 31 33 34 54 56 57 59 60 61 63 64 66 67 87 89 90 92 93 94 96 97 99 Why is it wrong??? I think it's true, but I have WA#6!!! Edited by author 03.01.2007 09:11 Can anyone give me a true answer??? Edited by author 03.01.2007 09:11 No subject [SSAU_#617]snipious_#1 aka Pimenov Sergey Nikolaevich 9 Jan 2007 00:28 [text deleted by author] Edited by author 09.01.2007 00:30 No subject [SSAU_#617]snipious_#1 aka Pimenov Sergey Nikolaevich 9 Jan 2007 00:28 [text deleted by author] Edited by author 09.01.2007 00:30 may be anyone can find an error in my code??? [code deleted by author]. Edited by author 29.01.2007 12:48 On your test my AC prog outputs 20 21 22 23 24 25 26 27 29 31 32 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 85 86 19 18 28 87 88 89 90 91 93 94 95 96 97 98 30 33 34 99 100 84 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 92 Good Luck!) My AC programm gets: 86 53 20 100 85 60 52 19 84 51 18 83 50 17 91 82 58 49 25 6 95 81 62 48 29 15 80 47 14 79 46 13 78 45 12 77 44 11 76 43 10 75 42 9 74 41 8 73 40 7 72 39 6 71 38 5 70 37 4 88 69 55 36 22 3 98 68 65 35 32 2 99 97 96 94 3 92 90 89 87 67 66 64 63 61 59 57 56 54 34 33 31 30 28 27 26 24 23 21 1 So there are a lot of posibilities on this huge test. Edited by author 11.01.2007 16:00 Now I have AC!!! I have one stupid error!!! My answer is: 20 53 86 19 52 85 18 51 100 60 84 17 50 83 16 25 49 58 82 91 15 29 48 62 81 95 14 47 80 13 46 79 12 45 78 11 44 77 10 43 76 9 42 75 8 41 74 7 40 73 6 39 72 5 38 71 4 37 70 3 22 36 55 69 88 2 35 68 1 21 23 24 26 27 28 32 65 98 30 31 33 34 54 56 57 59 61 63 64 66 67 87 89 90 92 93 94 96 97 99 My program gives the following answer: 100 92 99 98 97 96 95 94 93 91 90 89 88 87 86 85 83 82 81 80 79 78 77 76 75 73 72 71 70 69 68 67 66 65 64 63 62 61 60 84 59 58 57 56 55 54 53 52 51 50 49 47 46 45 44 43 42 41 40 39 38 37 36 35 32 34 33 30 31 29 27 26 25 24 23 22 21 28 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 I thought, that the answer is not true, but have sent my solution and has got AC.... It looks a litle strange, isn't it?) P. S. I used topological sorting My AC prog outputs (not like that, but in one line, of course) 53 20 86 100 19 52 85 60 84 18 51 17 83 50 49 58 25 91 16 82 95 81 29 48 62 15 47 14 80 13 46 79 45 12 78 77 44 11 43 10 76 42 75 9 74 41 8 73 7 40 72 6 39 71 5 38 4 98 65 32 70 27 69 88 22 55 3 36 2 68 35 94 99 1 97 96 89 87 92 93 90 30 28 33 31 27 23 21 26 24 34 64 63 67 66 61 56 54 59 57 When I used this test,I got the same answer as yours!! At first,I thought we were right. But if you see the answer carefully,you'll that 60 should be front of 84,and 84 should be in front of 17.so,we were both wrong. Now I have got AC.I think you should pay attention to the link between the old and the young. For example ,if 60 if older than 84,and 84 is older than 17,then ,60 is older than 17.It's what the test doesn't tell us but is important to the program. Good luck!! Edited by author 27.08.2008 12:45 my programm have 20 21 22 23 24 25 26 27 29 31 32 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 19 18 17 16 28 89 90 91 92 93 15 94 95 96 97 14 13 12 11 10 9 8 7 6 5 4 3 2 1 98 99 100 30 33 34 | topologic sort | ITStepDnepr | 1022. Genealogical Tree | 11 Dec 2006 19:07 | 2 | i used topologic sort, described here -> http://en.wikipedia.org/wiki/Topological_sorting, but got wa on second test. (i believe i implemented algo correctly.) maybe there is something important, that they did not mention? Edited by author 11.12.2006 17:46This algorithm is right, check your program again. Edited by author 11.12.2006 19:07 | test#5 | savage | 1022. Genealogical Tree | 13 Sep 2008 04:32 | 5 | test#5 savage 7 Oct 2006 14:48 The test#5 is: 35 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 1 4 5 9 2 3 0 10 0 11 0 12 4 5 6 7 8 9 0 13 0 14 0 15 0 16 0 17 0 18 0 2 3 4 28 5 6 1 7 8 9 10 11 12 13 17 19 0 0 2 0 0 0 15 0 0 0 0 14 13 12 11 0 0 0 33 34 30 0 0 0 0 what's the correct answer for test#5? Thx i suppose that correct answer is: 35 32 30 34 33 31 29 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 28 Or: 20 19 18 17 16 21 22 23 24 25 15 26 27 28 29 14 13 12 11 10 9 8 7 6 5 4 3 2 1 31 32 30 33 34 35 or: 20 19 18 17 16 25 15 29 14 13 12 11 10 9 8 7 6 5 4 3 22 2 1 21 23 24 26 27 28 32 30 31 33 34 35 or: 35 32 34 33 30 31 29 27 26 25 24 23 22 21 20 28 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 | test#4 | azadeh | 1022. Genealogical Tree | 19 Mar 2009 21:32 | 3 | test#4 azadeh 22 Aug 2006 12:01 what is the output of this input? 20 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 1 4 5 9 2 3 0 10 0 11 0 12 4 5 6 7 8 9 0 13 0 14 0 15 0 16 0 17 0 18 0 2 3 4 5 6 1 7 8 9 10 11 12 13 17 19 0 the output is: 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 | Is it correct input in example? | Vitaliy_Ivashchenko | 1022. Genealogical Tree | 9 Aug 2006 17:55 | 2 | input: 5 0 4 5 1 0 1 0 5 3 0 3 0 output: 2 4 5 3 1 but where is 2 in input? It means that 2 has no parents among member of Planetary Council ;) | WA Test # 6 Help me please !! | Temp | 1022. Genealogical Tree | 30 Oct 2007 00:10 | 5 | It's N=100. Edited by author 16.12.2006 03:29 | Problem with 4-th test... | chez | 1022. Genealogical Tree | 22 Aug 2006 13:29 | 2 | Somebody has solved this task? And how it to solve? I can not any more. When I check, all normal, but the system shows, that on the fourth test a error. yes,i have problem with this test(test #4) too. what is your programe's output on this input?: 20 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 1 4 5 9 2 3 0 10 0 11 0 12 4 5 6 7 8 9 0 13 0 14 0 15 0 16 0 17 0 18 0 2 3 4 5 6 1 7 8 9 10 11 12 13 17 19 0 Edited by author 22.08.2006 13:30 | This may sound silly, but I don't get the output | Angel | 1022. Genealogical Tree | 27 Jan 2006 00:32 | 2 | Sample Input 5 0 4 5 1 0 1 0 5 3 0 3 0 Sample Output 2 4 5 3 1 WHERE DIN THE "2" come from???? THE "2" is the oldest martian, so he should speak first. What is unclear? | test #5 | Kokan Ivan | 1022. Genealogical Tree | 30 Aug 2005 03:51 | 2 | test #5 Kokan Ivan 21 Aug 2005 18:17 can someone give me the test case #5? i got wa on that case. i'm using method of giving points to each person, so that every child has more points than his father. i'm doing that with bfs: if points[child] <= points[parent] points[child] = points[parent] + 1; bfs (child); i think method is right. you can find other tests here: http://timustests.lx.rotest 5: 35 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 1 4 5 9 2 3 0 10 0 11 0 12 4 5 6 7 8 9 0 13 0 14 0 15 0 16 0 17 0 18 0 2 3 4 28 5 6 1 7 8 9 10 11 12 13 17 19 0 0 2 0 0 0 15 0 0 0 0 14 13 12 11 0 0 0 33 34 30 0 0 0 0 | I've got a WA on Test#6.Please look at my code... | PoiNT | 1022. Genealogical Tree | 15 Aug 2005 10:37 | 2 | #include <iostream> using namespace std; //------------------------------------------------------------------- class TStack { public: TStack* Insert(int Value); TStack* Add(int x); TStack * Next; int Value; TStack(); }; bool Find(int Value, TStack *ptr); void deleteStack(TStack *ptr); //------------------------------------------------------------------- int main() { TStack * Head = new TStack(); TStack * ptr; ptr = Head; int N; cin >> N; for(int i=0;i<N;i++) { TStack * HeadArray = new TStack(); TStack * ptrArray = HeadArray; int Ai; cin >> Ai; while(Ai != 0) { ptrArray = ptrArray->Add(Ai); cin >> Ai; } ptr = Head; bool flag = true; while(flag) { if(i == 0) { ptr->Add(i+1); flag = false; } else { bool change = true; while(ptr->Next != NULL && change) { ptrArray = HeadArray; if(Find(ptr->Next->Value,ptrArray)) { ptr->Insert(i+1); change = false; } else { ptr = ptr->Next; } } if(change) { ptr->Add(i+1); } flag = false; } } deleteStack(HeadArray); } ptr = Head->Next; while(ptr != NULL) { cout << ptr->Value << " "; ptr = ptr->Next; } deleteStack(Head); cin >> N; return 0; }; //------------------------------------------------------------------- bool Find(int Value, TStack *ptr) { bool result = false; while(ptr != NULL && !result) { if(ptr->Value == Value) result = true; else { ptr = ptr->Next; } } return result; } //------------------------------------------------------------------- TStack::TStack() { Next = NULL; Value = 0; } //------------------------------------------------------------------- TStack* TStack::Add(int x) { TStack * ptrValue = new TStack(); ptrValue->Value = x; Next = ptrValue; return ptrValue; } //------------------------------------------------------------------- TStack* TStack::Insert(int Value) { TStack *ptrValue = new TStack(); ptrValue->Value = Value; ptrValue->Next = Next; Next = ptrValue; return ptrValue; } //------------------------------------------------------------------- void deleteStack(TStack *ptr) { while(ptr != NULL) { TStack *ptrBuff = ptr; ptr = ptr->Next; delete ptrBuff; } return; } | Please give me Test#6 | PoiNT | 1022. Genealogical Tree | 9 Aug 2005 18:52 | 1 | If someone have the test#6, please send to kilobyte@nm.ru. | is my algorithm efficient?? | michel mizrahi | 1022. Genealogical Tree | 30 Apr 2005 08:57 | 1 | (first...sorry for my english) I am a beginner in this field, and this is the first problem I solve using "graph theory" I got ac in 0.001s and 74 KB of memory I just do a topological sort, but I have never seen an implementation of this, so I did what it seems to be the more effective way to me. here is my code: #include <stdio.h> char g[101][101]; init(int n){ int i,j; for(i=1;i<=n;i++) for(j=1;j<=n;j++) g[i][j]=0; } topological_sort(int n){ int i,j,k,u,v=0; for(k=1;;k++) for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ if(g[j][i]==1) break; if(j==n){ v++; if(v==n){ printf("%d\n",i); return 0; } printf("%d ",i); for(u=1;u<=n;u++) g[i][u]=0; for(u=1;u<=n;u++) g[u][i]=1; } } } } int main(){ int n,i,j,t; scanf("%d",&n); init(n); for(i=1;i<=n;i++) for(j=1;;j++){ scanf("%d",&t); if(t==0) break; g[i][t]=1; } topological_sort(n); return 0; } if someone can help me I would appreciatevery much and please if someone doesn't understand my ugly code, please ask me (I know maybe many of my codes are ugly ,slow and hard to understand ) thanks for all! byeee Edited by author 30.04.2005 08:59 | Why I am not right | vlad | 1022. Genealogical Tree | 9 Apr 2005 19:04 | 3 | {$APPTYPE CONSOLE} var n,i,j,p:integer; c:array[1..2,1..100] of integer; a:array[1..100,0..100] of integer; procedure sort(l,r: integer); var i,j,x,y: integer; begin i:=l; j:=r; x:=c[1,(l+r) DIV 2]; repeat while X<c[1,i] do i:=i+1; while x>c[1,j] do j:=j-1; if i<=j then begin y:=c[1,i]; c[1,i]:=c[1,j]; c[1,j]:=y; y:=c[2,i]; c[2,i]:=c[2,j]; c[2,j]:=y; i:=i+1; j:=j-1; end; until i>j; if l<j then sort(l,j); if i<r then sort(i,r); end; function count(nom:integer):integer; var i:integer; var kol:integer; begin if c[1,nom]<> 0 then count:=c[1,nom] else begin kol:=0; inc(kol); for i:=1 to a[nom,0] do inc(kol,count(a[nom,i])); c[1,nom]:=kol; count:=kol; end; end; begin assign(Input,'input.txt'); assign(Output,'output.txt'); { reset(Input); rewrite(Output);} readln(n); for i:=1 to n do begin j:=0; while not eoln do begin inc(j); read(a[i,j]); end; a[i,0]:=j-1; readln; end; for i:=1 to n do begin c[1,i]:=count(i); c[2,i]:=i; end; sort(1,n); for i:=1 to n do write(c[2,i],' '); writeln; {close(Input); close(Output);} end. ACM vlad 9 Apr 2005 19:04 | Why I got WA? Program is here, I'm sure, it's correct!!! | Akshin | 1022. Genealogical Tree | 14 Jul 2006 00:21 | 5 | Here is my program, I dont why I get WA? My algorithm is correct! var a:array[1..100,1..100] of integer; b:array[1..100] of integer; i,j,nn,n,k:integer; procedure readdata; begin readln(n); for i:=1 to n do begin j:=0; repeat inc(j); read(a[i,j]); until a[i,j]=0; a[i,j]:=-1; end; end; procedure writedata; begin for i:=1 to n do write(b[i],' '); end; function check(i,nn:integer):boolean; var j:integer; begin j:=1; check:=false; if a[nn,j]<>-1 then repeat if a[nn,j]=i then begin check:=true; exit; end; inc(j); until a[nn,j]=-1; end; procedure push(k,nn:integer); var x,m,j,i:integer; begin j:=1; while (b[j]<>k) do inc(j); m:=j; { x:=b[k];} for j:=nn downto k do if (j-1<1) then break else b[j]:=b[j-1]; { b[nn]:=x;} { j:=nn; while (b[j]<>m) do begin b[j]:=b[j-1]; dec(j); end;} b[m]:=nn; end; begin readdata; repeat inc(nn); b[nn]:=nn; k:=0; for i:=nn downto 1 do if (i<>nn) and (check(i,nn)) then k:=i; if k<>0 then push(k,nn); until nn=n; writedata; end. I shall not assort your algorithm, but I shall offer the. Search for number present which is not present in a file and deduce him, then remove this element. And all this in a cycle. { I badly know English. } Here are some tests: Test #2: 6 0 0 5 0 0 0 0 Test #3: 2 0 1 0 Test #7: 1 0 You just have to use topological sort | Who can tell me why I got TLE?? | akademi | 1022. Genealogical Tree | 30 Oct 2004 16:31 | 6 | Program ural1022; Const maxn=110; Var list,num:array[0..maxn] of longint; map:array[0..maxn,0..maxn] of byte; i,m,n,ptr,j,c:longint; Procedure Pre; Begin fillchar(num,sizeof(num),0); for i:=1 to n do for j:=1 to n do if map[j,i]=1 then inc(num[ i ]); ptr:=0; for i:=1 to n do if num[ i ]=0 then begin inc(ptr); list[ptr]:=i end End; Procedure work; Begin pre; while ptr<n do begin m:=list[ptr]; for i:=1 to n do if map[m,i]=1 then begin dec(num[ i ]); if num[ i ]=0 then begin inc(ptr); list[ptr]:=i end end end End; Procedure out; Begin for i:=1 to ptr do if i<>ptr then write(list[ i ],' ') else writeln(list[ i ]) End; Begin { assign(input,'input.txt'); reset(input);} readln(n); fillchar(map,sizeof(map),0); for i:=1 to n do begin read(c); while c<>0 do begin map[i,c]:=1; read(c) end; readln end; work; out End. Hint: Use topological sort. My prog used topological sort,but I also got TLE. If you give me your E-mail i will send you some tests. Edited by author 29.10.2004 20:03 I find error in your algorithm. Topological sort in your code is wrong: m:=list[ptr]; for i:=1 to n do if map[m,i]=1 then begin dec(num[ i ]); if num[ i ]=0 then begin inc(ptr); list[ptr]:=i end end You must check not only last (m) but every vertex in your list. For example, on this test your program get TLE: 3 3 0 0 0 Answer: 1 2 3 Good luck :) | I want to ask a interesting question about this problem. | Sarby Liang | 1022. Genealogical Tree | 9 Aug 2004 13:37 | 2 | In the sample input: It is said that 3 is 5's child,and 3 is 4's child,and 5 is 4's child. It is an illegal relationship in the realistic, isn't it? It seems that 5 is 4's child,and 5 and 4 are 3's parents! Maybe Martians don't think that it is strange. :) | Help, I don't know wtf is wrong with my code | Oscar | 1022. Genealogical Tree | 29 Jul 2003 08:30 | 1 | Hello guys, This problem doesn't seem to be so complicated, and my code works find in all the cases that I have tried, can anyone give me some extreme cases or take a look at the source? Thanks in advanced Oscar //------------------------------------------------------------ #include <stdio.h> #include <string.h> short tree[101][101], list[101], n, i, j,l; void inicializa(void); void lee_valores(void); void hazlo(int v); void main(void) { scanf("%d", &n); inicializa(); lee_valores(); for (i=1; i<n+1; i++){ if (!visitado[i]) hazlo(i); } } void hazlo(int v) { visitado[v]=1; for (j=n; j>0; j--) if ((tree[j][v]) && (!visitado[j])) hazlo(j); printf("%d ", v); } void inicializa(void) { memset(tree, 0, sizeof(tree)); memset(list, 0, sizeof(list)); memset(visitado, 0, sizeof(visitado)); } void lee_valores(void) { int temp; for(i=1; i<n+1; i++){ for(j=1; j<n+1; j++){ scanf("%d", &temp); if (temp == 0) break; tree[i][temp] = 1; } } } | What's wrong? I got CE! | Borech | 1022. Genealogical Tree | 25 Jul 2003 03:05 | 2 | #include <iostream.h> const int max=100; int N, G[max][max], color[max], sorted[max], last_sorted; ///////////////////////////////////////
void DFS_VISIT(int i) { color[i]=1; for(int j=1;G[i][j]!=0;j++) { if (color[G[i][j]]==0) DFS_VISIT(G[i][j]); } color[i]=2; last_sorted++; sorted[last_sorted]=i; } void DFS() { for(int i=1;i<=N;i++) { color[i]=0; } for(i=1;i<=N;i++) if (color[i]==0) DFS_VISIT(i); } ////////////////////////////////////// int main() { cin >> N;
for(int i=1;i<=N;i++) { int x=1; for(int j=1;x!=0;j++) { cin >> x; G[i][j]=x; } }
last_sorted=0; DFS();
for(i=last_sorted;i>0;i--) cout << sorted[i] << ' '; return 0; } |
|
|