1 #include 2 #include 3 using namespace std; 4 5 #include 6 #define loop(i, n) for (int i = 0; i < n; i++) 7 #define loopfrom1(i, n) for (int i =1; i < n; i++) 8 #define pb(a) push_back(a) 9 #define SZ size()10 #define getint(n) scanf("%d", &n)11 12 #define MAXX 10513 #define looptill(i, n) for (int i = 0; i <= n; i++)14 15 vector Graph[MAXX];16 bool visited[MAXX];17 int inaccessible;18 19 void dfs(int u)20 {21 int len = Graph[u].SZ;22 int v;23 loop(i, len)24 {25 v = Graph[u][i];26 if( ! visited[v] )27 {28 visited[v] = true;29 inaccessible --;30 dfs(v);31 }32 }33 }34 35 int main()36 {37 int number_of_nodes, total_nodes;38 int node1, node2;39 while(true)40 {41 getint(total_nodes);42 if(total_nodes == 0) break;43 looptill(i, total_nodes)44 {45 Graph[i].clear();46 }47 48 while(true)49 {50 getint(node1);51 if(node1 == 0) break;52 while(true)53 {54 getint (node2);55 if(node2 == 0) break;56 Graph[node1].pb(node2);57 }58 }59 60 getint(number_of_nodes);61 loop(t, number_of_nodes)62 {63 looptill(i, total_nodes)64 {65 visited[i] = false;66 }67 68 getint(node1);69 inaccessible = total_nodes;70 dfs(node1);71 72 cout << inaccessible;73 74 for (int j = 1; j <= total_nodes; j++)75 {76 if( ! visited[j] )77 {78 cout <<" "<
1 // @BEGIN_OF_SOURCE_CODE 2 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include