alexjercan/bugnet huggingface dataset:
Problem p00884 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

struct group {
  string name;
  vector<string> members;

  group() {}
  ~group() {}
};

vector<group> groups;
set<string> checked;
set<string> employee;

void rec(string name) {
  if (checked.find(name) != end(checked)) {
    return;
  }
  checked.insert(name);
  for (group g : groups) {
    if (name == g.name) {
      for (string s : g.members) {
        rec(s);
      }
      return;
    }
  }
  employee.insert(name);
}

bool solve() {
  int n;
  cin >> n;
  if (n == 0) {
    return false;
  }
  groups.clear();
  checked.clear();
  employee.clear();
  for (int j = 0; j < n; ++j) {
    string data;
    stringstream ss;

    cin >> data;
    replace(begin(data), end(data), ':', ' ');
    replace(begin(data), end(data), ',', ' ');
    replace(begin(data), end(data), '.', ' ');
    ss << data;

    group g;
    ss >> g.name;

    while (!ss.eof()) {
      string member;
      ss >> member;
      if (member == "") {
        continue;
      }

      g.members.push_back(member);
    }

    ss.clear();
    groups.push_back(g);
  }

  rec(groups[0].name);
  cout << employee.size() << endl;
  return true;
}

int main() {
  while (solve())
    ;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

struct group {
  string name;
  vector<string> members;

  group() {}
  ~group() {}
};

vector<group> groups;

set<string> rec(string name) {
  for (group g : groups) {
    if (name == g.name) {
      set<string> ret;
      for (string s : g.members) {
        auto m = rec(s);
        for (auto it : m) {
          ret.insert(it);
        }
      }
      return ret;
    }
  }
  return {name};
}

bool solve() {
  int n;
  cin >> n;
  if (n == 0) {
    return false;
  }
  groups.clear();
  for (int j = 0; j < n; ++j) {
    string data;
    stringstream ss;

    cin >> data;
    replace(begin(data), end(data), ':', ' ');
    replace(begin(data), end(data), ',', ' ');
    replace(begin(data), end(data), '.', ' ');
    ss << data;

    group g;
    ss >> g.name;

    while (!ss.eof()) {
      string member;
      ss >> member;
      if (member == "") {
        continue;
      }
      g.members.push_back(member);
    }

    ss.clear();
    groups.push_back(g);
  }

  auto ans = rec(groups[0].name);
  cout << ans.size() << endl;

  return true;
}

int main() {
  while (solve())
    ;
  return 0;
}
Problem p00884 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <vector>

using namespace std;

map<string, vector<string>> e;
set<string> vis;
set<string> cnt;

int rec(string s) {
  int sum = 0;
  vis.insert(s);
  vector<string> v = e[s];
  for (int i = 0; i < v.size(); ++i) {
    if (vis.count(v[i]))
      continue;
    if (e.find(v[i]) == e.end())
      cnt.insert(v[i]);
    else
      sum += rec(v[i]);
  }
  return sum;
}

int main(void) {
  int n;
  while (cin >> n && n) {
    cnt.clear();
    e.clear();
    vis.clear();
    string f = "";
    for (int i = 0; i < n; ++i) {
      string s;
      cin >> s;
      for (int j = 0; j < s.size(); ++j) {
        if (s[j] == ':' || s[j] == ',' || s[j] == '.')
          s[j] = ' ';
      }
      istringstream iss(s);
      string src, dst;
      vector<string> v;
      for (iss >> src; iss >> dst; v.push_back(dst))
        ;
      e[src] = v;
      if (f.size() == 0)
        f = src;
      // cout << src << " : "; for(int j=0; j<v.size(); ++j)cout << v[j] << ' ';
      // cout << endl;
    }
    rec(f);
    cout << cnt.size() << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

vector<int> g;
vector<int> name[20];
map<string, int> id;

set<int> rec(int p) {
  set<int> s;
  for (int i = 0; i < name[p].size(); ++i) {
    for (int j = 0; j < g.size(); ++j) {
      if (g[j] == name[p][i]) {
        set<int> t = rec(j);
        for (set<int>::iterator it = t.begin(); it != t.end(); ++it) {
          s.insert(*it);
        }
        break;
      }
      if (j + 1 == g.size()) {
        s.insert(name[p][i]);
      }
    }
  }
  return s;
}

int main() {
  int N;
  while ((cin >> N) && N) {
    g.clear();
    for (int i = 0; i < N; ++i)
      name[i].clear();
    id.clear();
    string line;
    getline(cin, line);
    for (int i = 0; i < N; ++i) {
      getline(cin, line);
      string str = "";
      int p = 0;
      while (p < line.size()) {
        if (line[p] == ':') {
          if (id.find(str) == id.end()) {
            int tmp = id.size();
            id[str] = tmp;
          }
          g.push_back(id[str]);
          str = "";
        } else if (line[p] == ',' || line[p] == '.') {
          if (id.find(str) == id.end()) {
            int tmp = id.size();
            id[str] = tmp;
          }
          name[i].push_back(id[str]);
          str = "";
        } else {
          str += line[p];
        }
        ++p;
      }
    }
    cout << rec(0).size() << endl;
  }
  return 0;
}
Problem p00884 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

class Problem {
private:
  map<string, vector<string>> m;
  set<string> num, vis;

public:
  Problem() {
    int n;
    cin >> n;
    if (n == 0)
      exit(0);
    string first;
    for (int i = 0; i < n; ++i) {
      string s;
      cin >> s;
      replace(s.begin(), s.end(), ':', ' ');
      replace(s.begin(), s.end(), ',', ' ');
      replace(s.begin(), s.end(), '.', ' ');
      stringstream ss(s);
      string group;
      ss >> group;
      if (first.empty())
        first = group;
      string name;
      while (ss >> name) {
        m[group].push_back(name);
      }
    }
    cout << rec(first) << endl;
  }

  int rec(const string &s) {
    vis.insert(s);
    if (!m.count(s))
      return 1;
    int res = 0;
    for (int i = 0; i < m[s].size(); ++i) {
      if (vis.count(m[s][i]))
        continue;
      res += rec(m[s][i]);
    }
    return res;
  }
};

int main() {
  while (1)
    Problem p;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

void rec(const string &s, map<string, vector<string>> &m, set<string> &vis) {
  if (!m.count(s)) {
    vis.insert(s);
    return;
  }
  for (int i = 0; i < m[s].size(); ++i) {
    rec(m[s][i], m, vis);
  }
}

int main() {
  for (int n; cin >> n && n;) {
    string first;
    map<string, vector<string>> m;
    for (int i = 0; i < n; ++i) {
      string s;
      cin >> s;
      replace(s.begin(), s.end(), ':', ' ');
      replace(s.begin(), s.end(), ',', ' ');
      replace(s.begin(), s.end(), '.', ' ');
      stringstream ss(s);
      string group;
      ss >> group;
      if (first.empty())
        first = group;
      string name;
      while (ss >> name) {
        m[group].push_back(name);
      }
    }
    set<string> vis;
    rec(first, m, vis);
    cout << vis.size() << endl;
  }
  return 0;
}
Problem p00884 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
#include <set>
#include <string>
using namespace std;
set<string> S;
map<string, int> M;
int n;
string str[101];

int saiki(int ima) {
  int sum = 0;
  string a;
  for (int i = 0; i < str[ima].size(); i++) {
    if (str[ima][i] == ',') {
      if (M.count(a) == 1 && S.count(a) == 0)
        S.insert(a), sum += saiki(M[a]);
      else if (S.count(a) == 0)
        sum++;
      S.insert(a);
      a = "";
      continue;
    }
    a += str[ima][i];
  }
  return sum;
}

int main() {

  while (1) {
    cin >> n;
    if (n == 0)
      break;
    S.clear(), M.clear();
    for (int i = 0; i < n; i++) {
      cin >> str[i];
      string a, b;
      for (int j = 0; j < str[i].size(); j++) {
        if (str[i][j] == ':')
          M[a] = i, a = "";
        if (str[i][j] != ':')
          a += str[i][j];
      }
      str[i] = a;
      str[i][str[i].size() - 1] = ',';
    }
    cout << saiki(0) << endl;
    ;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <map>
#include <set>
#include <string>
using namespace std;
set<string> S;
map<string, int> M;
int n;
string str[101];

int saiki(int ima) {
  int sum = 0;
  string a;
  for (int i = 0; i < str[ima].size(); i++) {
    if (str[ima][i] == ',') {
      if (M.count(a) == 1)
        S.insert(a), sum += saiki(M[a]);
      else if (S.count(a) == 0)
        sum++;
      S.insert(a);
      a = "";
      continue;
    }
    a += str[ima][i];
  }
  return sum;
}

int main() {

  while (1) {
    cin >> n;
    if (n == 0)
      break;
    S.clear(), M.clear();
    for (int i = 0; i < n; i++) {
      cin >> str[i];
      string a, b;
      for (int j = 0; j < str[i].size(); j++) {
        if (str[i][j] == ':')
          M[a] = i, a = "";
        if (str[i][j] != ':')
          a += str[i][j];
      }
      str[i] = a;
      str[i][str[i].size() - 1] = ',';
    }
    cout << saiki(0) << endl;
    ;
  }
  return 0;
}
Problem p00884 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define loop(n, i) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

vector<string> split(char d, string s) {
  istringstream iss(s);
  string tmp;
  vector<string> res;
  while (getline(iss, tmp, d))
    res.push_back(tmp);
  return res;
}

unordered_map<string, vector<string>> gs;
unordered_map<string, vector<string>> memo;

vector<string> dfs(string r) {
  if (memo.find(r) != memo.end())
    return memo[r];
  unordered_set<string> ans;
  for (auto name : gs[r]) {
    if (gs.find(name) == gs.end())
      ans.insert(name);
    else {
      for (auto m : dfs(name))
        ans.insert(m);
    }
  }
  memo[r] = vector<string>(all(ans));
  return memo[r];
}

int main() {
  while (1) {
    int n;
    cin >> n;
    if (!n)
      break;
    gs.clear();
    memo.clear();

    string root;
    loop(n, i) {
      string l;
      cin >> l;
      auto vs = split(':', l);
      auto mems = split(',', vs[1]);
      auto lst = mems.back();
      mems[mems.size() - 1] = lst.substr(0, lst.length() - 1);
      if (!i)
        root = vs[0];
      gs[vs[0]] = mems;
    }

    cout << dfs(root).size() << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define loop(n, i) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

vector<string> split(char d, string s) {
  istringstream iss(s);
  string tmp;
  vector<string> res;
  while (getline(iss, tmp, d))
    res.push_back(tmp);
  return res;
}

unordered_map<string, vector<string>> gs;

vector<string> dfs(string r) {
  unordered_set<string> ans;
  for (auto name : gs[r]) {
    if (gs.find(name) == gs.end())
      ans.insert(name);
    else {
      for (auto m : dfs(name))
        ans.insert(m);
    }
  }
  return vector<string>(all(ans));
}

int main() {
  while (1) {
    int n;
    cin >> n;
    if (!n)
      break;

    string root;
    loop(n, i) {
      string l;
      cin >> l;
      auto vs = split(':', l);
      auto mems = split(',', vs[1]);
      auto lst = mems.back();
      mems[mems.size() - 1] = lst.substr(0, lst.length() - 1);
      if (!i)
        root = vs[0];
      gs[vs[0]] = mems;
    }

    cout << dfs(root).size() << endl;
  }
  return 0;
}
Problem p00884 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

#define for_(i, a, b) for (int i = a; i < b; ++i)
#define allof(a) a.begin(), a.end()
#define minit(a, b) memset(a, b, sizeof(a))
#define size_of(t) (int)t.size()

typedef long long lint;
typedef pair<int, int> pii;

int n;
string group[110];

vector<string> split_all(string s, string t) {
  vector<string> res;
  for (int p = 0; (p = s.find(t)) != -1;) {
    res.push_back(s.substr(0, p));
    s = s.substr(p + size_of(t));
  }
  res.push_back(s);
  return res;
}

string gname[110];
vector<string> g_member[110];

set<string> ans;
bool look[110];

void rec(int i) {
  if (look[i])
    return;
  look[i] = true;

  int g_size = g_member[i].size();

  for_(j, 0, g_size) {
    string member = g_member[i][j];
    bool flag = false;

    for_(k, 0, n) {
      if (gname[k] == member) {
        rec(k);
        flag = true;
        break;
      }
    }

    if (!flag)
      ans.insert(member);
  }
}

void solve() {
  for_(i, 0, n) {
    vector<string> split = split_all(group[i], ":");
    gname[i] = split[0];
    g_member[i] = split_all(split[1].substr(0, size_of(split[1]) - 1), ",");
  }

  ans.clear();
  minit(look, 0);
  rec(0);

  cout << size_of(ans) << endl;
}

int main() {
  while (cin >> n, n) {
    for_(i, 0, n) cin >> group[i];
    solve();
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define for_(i, a, b) for (int i = a; i < b; ++i)
#define allof(a) a.begin(), a.end()
#define minit(a, b) memset(a, b, sizeof(a))
#define size_of(t) (int)t.size()

typedef long long lint;
typedef pair<int, int> pii;

int n;
string group[1100];

vector<string> split_all(string s, string t) {
  vector<string> res;
  for (int p = 0; (p = s.find(t)) != -1;) {
    res.push_back(s.substr(0, p));
    s = s.substr(p + size_of(t));
  }
  res.push_back(s);
  return res;
}

string gname[1100];
string member[1100];

void solve() {
  set<string> groups;
  for_(i, 0, n) {
    vector<string> split = split_all(group[i], ":");
    gname[i] = split[0];
    groups.insert(gname[i]);
    member[i] = split[1].substr(0, size_of(split[1]) - 1);
  }

  for_(k, 0, 100) {
    for_(i, 1, n) {
      for_(j, 0, n) {
        if (i == j)
          continue;
        int p = member[j].find(gname[i]);
        if (p == -1)
          continue;
        member[j] = member[j].substr(0, p) + member[i] +
                    member[j].substr(p + size_of(gname[i]));
      }
    }
  }

  vector<string> vs = split_all(member[0], ",");

  set<string> ans;
  int v_size = size_of(vs);
  for_(i, 0, v_size) if (groups.find(vs[i]) == groups.end()) ans.insert(vs[i]);
  cout << size_of(ans) << endl;
}

int main() {
  while (cin >> n, n) {
    for_(i, 0, n) cin >> group[i];
    solve();
  }
  return 0;
}
Problem p00884 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <sstream>
#include <vector>

using namespace std;

struct Edge {
  int src, dst;
  Edge() {}
  Edge(int s, int d) : src(s), dst(d) {}
};
typedef vector<vector<Edge>> Graph;

void dfs(const Graph &g, int v, vector<int> &flg) {
  if (flg[v])
    return;
  flg[v] = 1;
  for (Edge e : g[v])
    dfs(g, e.dst, flg);
}

int main() {
  for (int n; cin >> n, n;) {
    map<string, int> ntoi;
    Graph g;
    for (int i = 0; i < n; i++) {
      string line;
      cin >> line;
      for (char &c : line)
        if (c == ':' || c == ',' || c == '.')
          c = ' ';
      istringstream iss(line);
      vector<int> temp;
      for (string name; iss >> name;) {
        if (!ntoi.count(name)) {
          ntoi.insert(make_pair(name, ntoi.size()));
          g.resize(g.size() + 1);
        }
        temp.push_back(ntoi[name]);
      }
      for (int i = 1; i < temp.size(); i++)
        g[temp[0]].emplace_back(temp[0], temp[i]);
    }

    int m = g.size();
    vector<int> flg(m);
    dfs(g, 0, flg);

    int res = 0;
    for (int i = 0; i < m; i++)
      if (flg[i] && g[i].size() == 0)
        res++;
    cout << res << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <sstream>
#include <vector>

using namespace std;

struct Edge {
  int src, dst;
  Edge() {}
  Edge(int s, int d) : src(s), dst(d) {}
};
typedef vector<vector<Edge>> Graph;

void dfs(const Graph &g, int v, vector<int> &flg) {
  flg[v] = 1;
  for (Edge e : g[v])
    dfs(g, e.dst, flg);
}

int main() {
  for (int n; cin >> n, n;) {
    map<string, int> ntoi;
    Graph g;
    for (int i = 0; i < n; i++) {
      string line;
      cin >> line;
      for (char &c : line)
        if (c == ':' || c == ',' || c == '.')
          c = ' ';
      istringstream iss(line);
      vector<int> temp;
      for (string name; iss >> name;) {
        if (!ntoi.count(name)) {
          ntoi.insert(make_pair(name, ntoi.size()));
          g.resize(g.size() + 1);
        }
        temp.push_back(ntoi[name]);
      }
      for (int i = 1; i < temp.size(); i++)
        g[temp[0]].emplace_back(temp[0], temp[i]);
    }

    int m = g.size();
    vector<int> flg(m);
    dfs(g, 0, flg);

    int res = 0;
    for (int i = 0; i < m; i++)
      if (flg[i] && g[i].size() == 0)
        res++;
    cout << res << endl;
  }
}
Problem p00884 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define MAX 1500

vector<int> G[MAX];
set<int> st;
bool visited[MAX];

void solve(int v) {
  if (st.count(v))
    return;
  if (visited[v])
    return;
  visited[v] = true;
  if (G[v].size() == 0) {
    st.insert(v);
  }
  for (int i = 0; i < (int)G[v].size(); i++) {
    solve(G[v][i]);
  }
}

int main() {
  int N;
  while (cin >> N, N) {
    for (int i = 0; i < MAX; i++) {
      G[i].clear();
      visited[i] = false;
    }
    int idx = 0;
    string s;
    map<string, int> mp;
    for (int i = 0; i < N; i++) {
      cin >> s;
      int p = s.find(":");
      string s1, s2;
      s1 = s.substr(0, p);
      s2 = s.substr(p + 1);
      s2.resize(s2.size() - 1);
      if (mp.find(s1) == mp.end()) {
        mp[s1] = idx++;
      }
      stringstream ss(s2);
      while (getline(ss, s2, ',')) {
        if (mp.find(s2) == mp.end()) {
          mp[s2] = idx++;
        }
        G[mp[s1]].push_back(mp[s2]);
      }
    }
    st.clear();
    solve(0);
    cout << st.size() << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define MAX 1500

vector<int> G[MAX];
set<int> st;

void solve(int v) {
  if (st.count(v))
    return;
  if (G[v].size() == 0) {
    st.insert(v);
  }
  for (int i = 0; i < (int)G[v].size(); i++) {
    solve(G[v][i]);
  }
}

int main() {
  int N;
  while (cin >> N, N) {
    for (int i = 0; i < MAX; i++) {
      G[i].clear();
    }
    int idx = 0;
    string s;
    map<string, int> mp;
    for (int i = 0; i < N; i++) {
      cin >> s;
      int p = s.find(":");
      string s1, s2;
      s1 = s.substr(0, p);
      s2 = s.substr(p + 1);
      s2.resize(s2.size() - 1);
      if (mp.find(s1) == mp.end()) {
        mp[s1] = idx++;
      }
      stringstream ss(s2);
      while (getline(ss, s2, ',')) {
        if (mp.find(s2) == mp.end()) {
          mp[s2] = idx++;
        }
        G[mp[s1]].push_back(mp[s2]);
      }
    }
    st.clear();
    solve(0);
    cout << st.size() << endl;
  }
  return 0;
}
Problem p00884 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
const int maxn = 112345;
int n, cnt, ans;
bool vis[maxn];
map<string, int> mp;
vector<int> G[maxn];
void init() {
  for (int i = 0; i < maxn; i++)
    G[i].clear();
  mp.clear();
  memset(vis, 0, sizeof(vis));
  cnt = ans = 0;
}
int get_ID(string s) {
  if (!mp.count(s))
    return mp[s] = ++cnt;
  else
    return mp[s];
}
void dfs(int u) {
  vis[u] = 1;
  if (G[u].size() == 0)
    ans++;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (!vis[v]) {
      dfs(v);
    }
  }
}
int main() {
  string s;
  while (~scanf("%d", &n) && n) {
    init();
    for (int i = 0; i < n; i++) {
      cin >> s;
      int last = 0, now = 0;
      while (now < s.size()) {
        int t, v;
        if (s[now] == ':') {
          v = get_ID(s.substr(last, now - last));
          last = ++now;
        }
        if (s[now] == ',' || s[now] == '.') {
          t = get_ID(s.substr(last, now - last));
          G[v].push_back(t);
          last = ++now;
        }
        now++;
      }
    }
    dfs(1);
    printf("%d\\n", ans);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
const int maxn = 110;
int n, cnt, ans;
bool vis[maxn];
map<string, int> mp;
vector<int> G[maxn];
void init() {
  for (int i = 0; i < maxn; i++)
    G[i].clear();
  mp.clear();
  memset(vis, 0, sizeof(vis));
  cnt = ans = 0;
}
int get_ID(string s) {
  if (!mp.count(s))
    return mp[s] = ++cnt;
  else
    return mp[s];
}
void dfs(int u) {
  vis[u] = 1;
  if (G[u].size() == 0)
    ans++;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (!vis[v]) {
      dfs(v);
    }
  }
}
int main() {
  string s;
  while (~scanf("%d", &n) && n) {
    init();
    for (int i = 0; i < n; i++) {
      cin >> s;
      int last = 0, now = 0;
      while (now < s.size()) {
        int t, v;
        if (s[now] == ':') {
          v = get_ID(s.substr(last, now - last));
          last = ++now;
        }
        if (s[now] == ',' || s[now] == '.') {
          t = get_ID(s.substr(last, now - last));
          G[v].push_back(t);
          last = ++now;
        }
        now++;
      }
    }
    dfs(1);
    printf("%d\\n", ans);
  }
  return 0;
}