fork download
  1. // SIGMA BOY hihihihihihihi
  2.  
  3. #define se second
  4. #define fi first
  5. #define pb push_back
  6. #define pob pop_back
  7. #define bitebi __builtin_popcountll
  8. #include <bits/stdc++.h>
  9.  
  10. using namespace std ;
  11. typedef long long ll;
  12. typedef long double ld;
  13. typedef pair<ll,ll> pll;
  14. typedef pair<int,int> pii;
  15. const ll Mod = 1e9+7;
  16. const ll Maxn = 1e5+69;
  17. const ll oo = 1e18;
  18.  
  19.  
  20. ll dist[Maxn],t,w;
  21. int parent[Maxn],n,m,u,v,f[Maxn],d[Maxn],vert;
  22. vector<int> child[Maxn];
  23. vector<pii> ke[Maxn];
  24.  
  25. struct cmp{
  26. bool operator()(const ll &a , const ll &b)
  27. {
  28. return dist[a]>dist[b];
  29. }
  30. };
  31.  
  32. priority_queue<int,vector<int>,cmp> pq;
  33.  
  34. void Dequytinhf( int vert )
  35. {
  36. if(child[vert].empty()) return; // lá của cây
  37. for ( auto x : child[vert] )
  38. {
  39. Dequytinhf(x);
  40. f[vert]+=f[x];
  41. }
  42. }
  43.  
  44. void Solvef()
  45. {
  46. for(int i = 1 ; i <= n ; ++i)
  47. child[parent[i]].pb(i);
  48. Dequytinhf(1);
  49. }
  50.  
  51. void Dijiska ()
  52. {
  53. pq.push(1);
  54. dist[1]=0;
  55. fill(d+1,d+1+n,0);
  56. while(!pq.empty())
  57. {
  58. auto x = pq.top();
  59. pq.pop();
  60. for (auto Friend : ke[x])
  61. {
  62. vert = Friend.fi, w = Friend.se;
  63. if(dist[vert]>dist[x]+w)
  64. {
  65. dist[vert] = dist[x]+w;
  66. pq.push(vert);
  67. parent[vert] = x ;
  68. }
  69. else if (parent[vert]>x&&dist[vert]==dist[x]+w) parent[vert] = x ;
  70. }
  71. }
  72. Solvef();
  73. // Thiết lập mảng f (mảng tính số lượng những thằng học sinh đã đi qua từng vị trí
  74.  
  75. }
  76.  
  77. void Do()
  78. {
  79. cin >> n >> m >> t ;
  80. fill(dist+1,dist+1+n,oo);
  81. for (int i = 1 ; i <= n ; ++i) cin >> f[i];
  82. for (int i = 1 ; i <= m ; ++i)
  83. {
  84. cin >> u >> v >> w ;
  85. ke[u].pb({v,w});
  86. ke[v].pb({u,w});
  87. }
  88. Dijiska();
  89. ll ans = 0 , curtime,slhs;
  90. for (int i = 1 ; i <= n ; ++i)
  91. {
  92. curtime = dist[i];
  93. slhs = f[i];
  94. ans = max(ans,(curtime-t)*slhs);
  95. }
  96. cout << ans;
  97. }
  98.  
  99. signed main ()
  100. {
  101. ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  102. #define task "test"
  103. if(fopen(task".inp", "r")){
  104. freopen(task".inp", "r", stdin);
  105. freopen(task".out", "w", stdout);
  106. }
  107. int ntest=1;
  108. while(ntest--) Do();
  109.  
  110. cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms\n";
  111. }
  112.  
Success #stdin #stdout #stderr 0.01s 9204KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Time elapsed: 7ms