#include <cstdio> #include <iostream> using namespace std; #define init(n) { for (int i=0 ; i<=n ; i++) { visit[i] = false; for (int j=0 ; j<=n ; j++) adj[i][j] = adj[j][i] = false; } } int n, dep[200], root[200], adj[200][200]; bool visit[200]; int dfs_visit(int s, int src) { root[s] = src; dep[s] = 0; for (int i=1 ; i<=n ; i++) { if (!visit[i] && adj[s][i]) { visit[i] = true; dep[s] += (dfs_visit(i,src)+1); } } return dep[s]; } void dfs() { for (int i=1 ; i<=n ; i++) { for (int j=0 ; j<=n ; j++) visit[j] = false; dfs_visit(i,i); } } int main( void ) { int t, x, maxdepi, maxdep; while (scanf("%d",&n)==1 && n) { init(n); for (int i=1 ; i<=n ; i++) { scanf("%d",&t); for (int j=0 ; j<t ; j++) { scanf("%d",&x); adj[i][x] = true; } } dfs(); maxdep = -1000; for (int i=1 ; i<=n ; i++) { if (dep[i]>maxdep) { maxdep = dep[i]; maxdepi = i; } } printf("%d\n",maxdepi); } return 0; }
Friday, February 15, 2013
[UVa] 10926 - How many dependencies
Subscribe to:
Post Comments (Atom)
Connect Rapoo MT750S with Linux (Tested on Manjaro)
I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...
-
I like coding a lot, keeps me glued to the PC for hours. For that reason it's a need to edit the Syntax Highlighter to suit my eyes for...
-
I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...
-
Install MinGW GCC Port on Windows. 1. Just go to this address [ http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/ ]...
No comments:
Post a Comment
Post your comment here. If you want to say something about programming problems, scripts, software etc, please try to be as descriptive as possible.