fork(2) download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <cstdlib>
  7. #include <vector>
  8. #include <set>
  9. #include <map>
  10. #include <queue>
  11. #include <stack>
  12. #include <list>
  13. #include <cmath>
  14. #include <iomanip>
  15. #define dibs reserve
  16. #define OVER9000 1234567890
  17. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  18. #define tisic 47
  19. #define soclose 1e-8
  20. #define chocolate win
  21. // so much chocolate
  22. #define patkan 9
  23. #define ff first
  24. #define ss second
  25. #define abs(x) ((x < 0)?-(x):x)
  26. #define uint unsigned int
  27. #define dbl long double
  28. using namespace std;
  29. // mylittledoge
  30.  
  31. int main() {
  32. cin.sync_with_stdio(0);
  33. cin.tie(0);
  34. string s;
  35. map<string,int> M;
  36. vector< vector<int> > dep;
  37. vector<int> name;
  38. vector<int> akt;
  39. while(cin >> s) {
  40. if(s == "0") {
  41. dep.push_back(akt);
  42. akt.clear();}
  43. else {
  44. int x =(M.find(s) == M.end())?M.size():M[s];
  45. M[s] =x;
  46. if(name.size() == dep.size()) name.push_back(x);
  47. else akt.push_back(x);}
  48. }
  49. int N =M.size();
  50. vector< vector<int> > G(N);
  51. vector<int> D(N,-OVER9000);
  52. for(int i =0; i < name.size(); i++) D[name[i]] =0;
  53. for(int i =0; i < dep.size(); i++) ALL_THE(dep[i],it) {
  54. G[*it].push_back(name[i]);
  55. D[name[i]]++;}
  56.  
  57. queue<int> q;
  58. for(int i =0; i < N; i++) if(D[i] == 0) q.push(i);
  59.  
  60. int ans =0;
  61. while(!q.empty()) {
  62. ans++;
  63. int a =q.front();
  64. ALL_THE(G[a],it) {
  65. D[*it]--;
  66. if(D[*it] == 0) q.push(*it);}
  67. q.pop();}
  68.  
  69. cout << ans << "\n";
  70. return 0;}
  71.  
  72. // look at my code
  73. // my code is amazing
  74.  
Success #stdin #stdout 0s 3484KB
stdin
Standard input is empty
stdout
0