记录编号 326540 评测结果 AAAAWWWTTT
题目名称 零食店 最终得分 40
用户昵称 GravatarMealy 是否通过 未通过
代码语言 C++ 运行时间 3.437 s
提交时间 2016-10-21 09:28:27 内存使用 0.64 MiB
显示代码纯文本
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <queue>
  5. #include <cstring>
  6. using namespace std;
  7.  
  8.  
  9. const int pomax=186;
  10. const int nmax=20086;
  11. const int INF=1<<29;
  12.  
  13.  
  14. int n,m,q;
  15. int tmpu,tmpv,tmplen;
  16. int tmps,pmax,emax;
  17. int cnt=0;
  18.  
  19.  
  20. class edge
  21. {
  22. public:
  23. int from,to;
  24. int len;
  25. };
  26.  
  27.  
  28. int val[pomax]={0};
  29. bool tag[pomax]={0};
  30. int dis[nmax];
  31. vector<edge> edges;
  32. vector<int > G[nmax];
  33.  
  34.  
  35. inline void PreDo()
  36. {
  37. scanf("%d%d%d",&n,&m,&q);
  38. for(int i=1;i<=n;i++)
  39. {
  40. scanf("%d",&val[i]);
  41. }
  42. for(int i=1;i<=m;i++)
  43. {
  44. scanf("%d%d%d",&tmpu,&tmpv,&tmplen);
  45. edges.push_back((edge){tmpu,tmpv,tmplen});
  46. G[tmpu].push_back(edges.size()-1);
  47. edges.push_back((edge){tmpv,tmpu,tmplen});
  48. G[tmpv].push_back(edges.size()-1);
  49. }
  50. }
  51.  
  52.  
  53. class T2
  54. {
  55. public:
  56. bool inqueue[nmax];
  57. queue<int > q;
  58. void SPFA(int tmps,int pmax,int emax)
  59. {
  60. cnt=0;
  61. for(int i=1;i<=n;i++)
  62. {
  63. dis[i]=INF;
  64. }
  65. dis[tmps]=0;
  66. memset(inqueue,0,sizeof(inqueue));
  67. q.push(tmps);
  68. inqueue[tmps]=1;
  69. while(!q.empty())
  70. {
  71. int tmpx=q.front();
  72. q.pop();
  73. inqueue[tmpx]=0;
  74. for(int i=0;i<G[tmpx].size();i++)
  75. {
  76. int tmpv=edges[G[tmpx][i]].to;
  77. if(dis[tmpv]>dis[tmpx]+edges[G[tmpx][i]].len)
  78. {
  79. dis[tmpv]=dis[tmpx]+edges[G[tmpx][i]].len;
  80. if(val[tmpv]<=pmax)
  81. {
  82. if(!inqueue[tmpv])
  83. {
  84. q.push(tmpv);
  85. inqueue[tmpv]=1;
  86. }
  87. }
  88. }
  89. }
  90. }
  91. }
  92. }FJ;
  93.  
  94.  
  95. int main()
  96. {
  97. freopen("snackstore.in","r",stdin);
  98. freopen("snackstore.out","w",stdout);
  99. PreDo();
  100. for(int x=1;x<=q;x++)
  101. {
  102. scanf("%d%d%d",&tmps,&pmax,&emax);
  103. FJ.SPFA(tmps,pmax,emax);
  104. for(int i=1;i<=n;i++)
  105. {
  106. if(dis[i]<=emax&&i!=tmps)
  107. {
  108. cnt++;
  109. }
  110. }
  111. printf("%d\n",cnt);
  112. cnt=0;
  113. }
  114. return 0;
  115. }
  116.