vector <string> countDescendants(vector <string> parentData) { f = true; vector <string> ret, fail; ST tmp = ""; tr(it, parentData) tmp += *it; while(tmp.length() > 0) { int idx = tmp.find(' '); vs.pb(tmp.substr(0, idx)); if(idx == string::npos) break; tmp = tmp.substr(idx+1); } sort(all(vs)); vs.resize(unique(all(vs)) - vs.begin()); tr(it, vs) { int idx = it->find(','); ST ch = it->substr(0, idx), par = it->substr(idx+1); cnt[ch] = cnt[par] = 0; g[par].pb(ch); }