Evaluate the knowledge of simple storage of tree structures and search for [cpp] # include <iostream> # include <vector> # include <queue> int n, m; std: vector <std :: vector <int> edge; std: vector <int> BFS (int s) {std: queue <std: pair <int, int> q; q. push (std: make_pair (s, 0); int cur_step = 0; std: vector <int> ans; int cnt = 0; while (! Q. empty () {int u = q. front (). first; int step = q. front (). second; q. pop (); if (step> cur_step) {ans. push_back (cnt); cnt = 0; cur_step = step;} if (edge [u]. size () = 0) cnt ++; for (int I = 0; I <edge [u]. size (); ++ I) {int v = edge [u] [I]; q. push (std: make_pair (v, step + 1) ;}} ans. push_back (cnt); return ans;} int main () {while (scanf ("% d", & n, & m )! = EOF) {// input edges edge. clear (); edge. resize (n + 1); while (m --) {int a, k; scanf ("% d", & a, & k); while (k --) {int B; scanf ("% d", & B); edge [a]. push_back (B); // edge [B]. push_back (a) ;}} www.2cto.com std: vector <int> ans = BFS (1); // output for (int I = 0; I <ans. size (); ++ I) {if (I! = Ans. size ()-1) printf ("% d", ans [I]); else printf ("% d \ n", ans [I]);} return 0 ;}