Language: C++

#include<bits/stdc++.h>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

map<string, vector<string>> data;
string startkey;

bool input(){

  data.clear();
  int n;
  cin>>n;
  if(n==0)return false;

  rep(i,n){
    string str;
    cin>>str;

    string key;
    vector<string> val;
    int keypos = 0;
    rep(j,str.size()){
      if(str[j]==':'){
	key = str.substr(0,j);
	keypos= j+1;
      }
      if(str[j]==',' || str[j]=='.'){
	val.push_back(str.substr(keypos, j-keypos));
	keypos = j+1;
      }
    }
    if(i==0)startkey = key;
    data[key]=val;
  }
  return true;
}


set<string> rec(string key){
  set<string> ret;

  if(data[key].size()==0){
    ret.insert(key);
  }else{
    for(auto i:data[key]){
      set<string> result = rec(i);
      for(auto j:result){
	ret.insert(j);
      }
    }
  }
  return ret;
}

int solve(){

  // for(auto i: data){
  //   cout<<"||"<<i.first<<endl;
  //   for(auto j: i.second){
  //     cout<<j<<endl;
  //   }
  // }

  set<string> res = rec(startkey);

  // for(auto i: res){
  //   cout<<"res | "<<i<<endl;
  // }
  return res.size();
}

int main(){
  while(input())cout<<solve()<<endl;
}

Compiler output:
a.cc: In function 'bool input()':
a.cc:13:3: error: reference to 'data' is ambiguous
   13 |   data.clear();
      |   ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:8:29: note:                 'std::map<std::__cxx11::basic_string<char>, std::vector<std::__cxx11::basic_string<char> > > data'
    8 | map<string, vector<string>> data;
      |                             ^~~~
a.cc:36:5: error: reference to 'data' is ambiguous
   36 |     data[key]=val;
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:8:29: note:                 'std::map<std::__cxx11::basic_string<char>, std::vector<std::__cxx11::basic_string<char> > > data'
    8 | map<string, vector<string>> data;
      |                             ^~~~
a.cc: In function 'std::set<std::__cxx11::basic_string<char> > rec(std::string)':
a.cc:45:6: error: reference to 'data' is ambiguous
   45 |   if(data[key].size()==0){
      |      ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:8:29: note:                 'std::map<std::__cxx11::basic_string<char>, std::vector<std::__cxx11::basic_string<char> > > data'
    8 | map<string, vector<string>> data;
      |                             ^~~~
a.cc:48:16: error: reference to 'data' is ambiguous
   48 |     for(auto i:data[key]){
      |                ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:8:29: note:                 'std::map<std::__cxx11::basic_string<char>, std::vector<std::__cxx11::basic_string<char> > > data'
    8 | map<string, vector<string>> data;
      |                             ^~~~