|
|
вернуться в форумWhat's wrong? I got CE! Послано Borech 24 июл 2003 22:14 #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; } Don't use "max" identifier - it's standard function of 32-bit C/C++ compilers (-) |
|
|