fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <algorithm>
  5. #include <stdio.h>
  6. using namespace std;
  7. int main()
  8. {
  9. int k=0,m[1000],fr;
  10. vector <string> s;
  11. string s1,s2;
  12. int testcase,i,j;
  13. long int n;
  14. scanf("%d",&testcase);
  15. scanf("%ld",&n);
  16. for(i=0;i<testcase;i++)
  17. {
  18. for(j=0;j<n;j++)
  19. {
  20. k=0;
  21. fr=2;
  22. cin >> s1 >> s2;
  23. if(j>0)
  24. {
  25. vector <string>::const_iterator si;
  26. for(si=s.begin();si!=s.end();si++)
  27. {
  28. k++;
  29. if((*si==s1)||(*si==s2))
  30. { printf("shabaa");
  31. fr+=m[k-1];
  32. }
  33. }
  34. }
  35. s.push_back(s1);
  36. s.push_back(s2);
  37. m[j]=fr-1;
  38. printf("%d\n",fr);
  39. }
  40. }
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 2864KB
stdin
1
3
Fred Barney
Barney Betty
Betty Wilma
stdout
2
shabaa2
shabaa2