fork download
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. int n,e,t,m,graph[101][101],a[101];
  8.  
  9. bool visited[101];
  10.  
  11. int dijkstra()
  12. {
  13. int Min=30000,MinI;
  14.  
  15. for(int i=1;i<=n;i++)
  16. {
  17. if(a[i]<Min&&visited[i]==false)
  18. {
  19. Min=a[i];
  20.  
  21. MinI=i;
  22. }
  23. }
  24.  
  25. if(MinI==e)
  26. {
  27. return 0;
  28. }
  29.  
  30. visited[MinI]=true;
  31.  
  32. for(int i=1;i<=n;i++)
  33. {
  34. if(graph[MinI][i]>-1)
  35. {
  36. a[i]=min(a[i],a[MinI]+graph[MinI][i]);
  37. }
  38. }
  39.  
  40. dijkstra();
  41.  
  42. return 0;
  43. }
  44.  
  45. int main()
  46. {
  47. //freopen("input.txt","r",stdin);
  48.  
  49. cin >> n >> e >> t >> m;
  50.  
  51. for(int i=0;i<=n;i++)
  52. {
  53. for(int j=0;j<=n;j++)
  54. {
  55. graph[i][j]=-1;
  56. }
  57. }
  58.  
  59. int x,y,temp;
  60.  
  61. while(m--)
  62. {
  63. scanf("%d %d %d",&x,&y,&temp);
  64.  
  65. graph[x][y]=temp;
  66. }
  67.  
  68. int ans=0;
  69.  
  70. for(int i=1;i<=n;i++)
  71. {
  72. for(x=1;x<=n;x++)
  73. {
  74. visited[x]=false;
  75.  
  76. a[x]=30000;
  77. }
  78.  
  79. a[i]=0;
  80.  
  81. dijkstra();
  82.  
  83. if(a[e]<=t)
  84. {
  85. ans++;
  86. }
  87. }
  88.  
  89. cout << ans << endl;
  90.  
  91. return 0;
  92. }
Success #stdin #stdout 0s 3340KB
stdin
4 
2 
1
8
1 2 1
1 3 1
2 1 1
2 4 1
3 1 1
3 4 1
4 2 1
4 3 1
stdout
3