P1113-杂务

女爷i 2023-06-01 08:47 126阅读 0赞
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define pb push_back
  4. #define _for(i,a,b) for(int i = (a);i < (b);i ++)
  5. #define INF 100000003
  6. #define ll long long
  7. inline ll read()
  8. {
  9. ll ans = 0;
  10. char ch = getchar(), last = ' ';
  11. while(!isdigit(ch)) last = ch, ch = getchar();
  12. while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
  13. if(last == '-') ans = -ans;
  14. return ans;
  15. }
  16. inline void write(ll x)
  17. {
  18. if(x < 0) x = -x, putchar('-');
  19. if(x >= 10) write(x / 10);
  20. putchar(x % 10 + '0');
  21. }
  22. vector<int> G[10003];
  23. int T[10003];
  24. int con[10003];
  25. int n;
  26. int main()
  27. {
  28. n = read();
  29. _for(i,1,n+1)
  30. {
  31. read();
  32. T[i] = read();
  33. int t;
  34. while(t = read())
  35. {
  36. if(!t)
  37. break;
  38. else
  39. G[t].pb(i);
  40. con[i] ++;
  41. }
  42. }
  43. int t = 0;
  44. queue<int> q;
  45. q.push(1);
  46. q.push(0);
  47. while(q.size()!=1)
  48. {
  49. while(q.front())
  50. {
  51. int x = q.front();
  52. q.pop();
  53. T[x]--;
  54. if(T[x])
  55. q.push(x);
  56. else
  57. _for(i,0,G[x].size())
  58. {
  59. con[G[x][i]] --;
  60. if(!con[G[x][i]])
  61. q.push(G[x][i]);
  62. }
  63. }
  64. q.pop();
  65. q.push(0);
  66. t ++;
  67. }
  68. write(t);
  69. return 0;
  70. }

转载于:https://www.cnblogs.com/Asurudo/p/11526774.html

发表评论

表情:
评论列表 (有 0 条评论,126人围观)

还没有评论,来说两句吧...

相关阅读

    相关 洛谷 P1113 杂务

    洛谷 P1113 杂务 Description `John`的农场在给奶牛挤奶前有很多杂务要完成,每一项杂务都需要一定的时间来完成它。比如:他们要将奶牛集合起