Language: C++

#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;

#define MAX_N 10000

queue<int>Q;

int n;
string S,T;
int C[MAX_N];
int used[MAX_N];
string GR[MAX_N];
vector<int>Y[MAX_N];
vector<string>X[MAX_N];
vector<string>P;
vector<string>B;

int main(){
	while(true){
		//memset.
		S="";T="";
		P.clear();
		B.clear();
		for(int i=0;i<MAX_N;i++){
			used[i]=0;
			C[i]=0;
			X[i].clear();
			Y[i].clear();
			GR[i]="";
		}
		//cin.
		cin>>n;
		if(n==0){
			break;
		}
		for(int i=0;i<n;i++){
			cin>>S;
			int cnt=0;T="";
			for(int j=0;j<S.size();j++){
				if(S[j]==':' && S[j]==',' && S[j]=='.'){
					if(cnt==0){
						cnt++;
						GR[i]=T;
					}
					else{
						X[i].push_back(T);
					}
					T="";
				}
				else{
					T+=S[j];
				}
			}
		}
		//kaiseki.
		for(int i=0;i<n;i++){
			for(int j=0;j<X[i].size();j++){
				P.push_back(X[i][j]);
			}
		}
		sort(P.begin(),P.end());
		int cnt2=0;
		for(int i=0;i<P.size();i++){
			if(i==0){
				B.push_bacK(P);
			}
			if(i>=1){
				if(P[i-1]!=P[i]){
					cnt2++;
					B.push_back(P);
				}
			}
		}
		
		for(int i=0;i<n;i++){
			for(int j=0;j<X[i].size();j++){
				for(int k=0;k<n;k++){
					if(GR[k]==X[i][j]){
						Y[i].push_back(MAX_N+k);
					}
				}
				for(int k=0;k<B.size();k++){
					if(B[k]==X[i][j]){
						Y[i].push_back(k);
					}
				}
			}
		}
		
		//bfs.
		used[0]=true;
		for(int i=0;i<Y[0].size();i++){
			if(Y[0][i]>=MAX_N){
				used[Y[0][i]-MAX_N]=1;
				Q.push(Y[0][i]-MAX_N);
			}
		}
		while(!Q.empty()){
			int p1=Q.top();
			Q.pop();
			for(int i=0;i<Y[p1].size();i++){
				if(Y[p1][i]>=MAX_N){
					if(used[Y[p1][i]-MAX_N]==0){
						used[Y[p1][i]-MAX_N]=1;
						Q.push(Y[p1][i]-MAX_N);
					}
				}
			}
		}
		
		//calc.
		for(int i=0;i<n;i++){
			if(used[i]==1){
				for(int j=0;j<Y[i].size();j++){
					if(Y[i][j]<MAX_N){
						C[Y[i][j]]=1;
					}
				}
			}
		}
		
		int res=0;
		for(int i=0;i<MAX_N;i++){
			res+=C[i];
		}
		cout<<res<<endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:69:35: error: 'class std::vector<std::__cxx11::basic_string<char> >' has no member named 'push_bacK'; did you mean 'push_back'?
   69 |                                 B.push_bacK(P);
      |                                   ^~~~~~~~~
      |                                   push_back
a.cc:74:52: error: no matching function for call to 'std::vector<std::__cxx11::basic_string<char> >::push_back(std::vector<std::__cxx11::basic_string<char> >&)'
   74 |                                         B.push_back(P);
      |                                         ~~~~~~~~~~~^~~
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::__cxx11::basic_string<char>; _Alloc = std::allocator<std::__cxx11::basic_string<char> >; value_type = std::__cxx11::basic_string<char>]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from 'std::vector<std::__cxx11::basic_string<char> >' to 'const std::vector<std::__cxx11::basic_string<char> >::value_type&' {aka 'const std::__cxx11::basic_string<char>&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::__cxx11::basic_string<char>; _Alloc = std::allocator<std::__cxx11::basic_string<char> >; value_type = std::__cxx11::basic_string<char>]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from 'std::vector<std::__cxx11::basic_string<char> >' to 'std::vector<std::__cxx11::basic_string<char> >::value_type&&' {aka 'std::__cxx11::basic_string<char>&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
a.cc:103:34: error: 'class std::queue<int>' has no member named 'top'; did you mean 'pop'?
  103 |                         int p1=Q.top();
      |                                  ^~~
      |                                  pop