fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define sz 100100
  4. #define MOD 1000000007
  5. #define ll long long
  6. vector<pair<int, int>>adj[sz];
  7. int minedges[sz];
  8. int maxedges[sz];
  9. ll dist[sz];
  10. int main()
  11. {
  12. ios::sync_with_stdio(0);
  13. cin.tie(0); cout.tie(0);
  14. int n, m; cin >> n >> m;
  15. while (m--)
  16. {
  17. int a, b, c; cin >> a >> b >> c;
  18. adj[a].push_back({b, c});
  19. }
  20. priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>>pq;
  21. for (ll i = 1; i <= n; i++)
  22. dist[i] = 1e16;
  23. minedges[1] = maxedges[1] = 0;
  24. pq.push({0, 1});
  25. ll cnt = 0;
  26. while (!pq.empty())
  27. {
  28. pair<ll, int>cur = pq.top();
  29. pq.pop();
  30. if (cur.first > dist[cur.second])
  31. continue;
  32. for (auto it : adj[cur.second])
  33. {
  34. if (it.second + cur.first == dist[it.first])
  35. {
  36. minedges[it.first] = min(minedges[it.first], minedges[cur.second] + 1);
  37. maxedges[it.first] = max(maxedges[it.first], maxedges[cur.second] + 1);
  38. pq.push({cur.first + it.second, it.first});
  39. if (it.first == n)
  40. cnt = cnt + 1;
  41. }
  42. else if (it.second + cur.first < dist[it.first])
  43. {
  44. minedges[it.first] = minedges[cur.second] + 1;
  45. maxedges[it.first] = maxedges[cur.second] + 1;
  46. dist[it.first] = it.second + cur.first;
  47. pq.push({cur.first + it.second, it.first});
  48. if (it.first == n)
  49. cnt = 1;
  50. }
  51. }
  52. }
  53. cout << dist[n] << " " << cnt << " " << minedges[n] << " " << maxedges[n];
  54. return 0;
  55. }
Success #stdin #stdout 0s 5924KB
stdin
4 5
1 4 5
1 2 4
2 4 5
1 3 2
3 4 3
stdout
5 2 1 2