fork download
  1. #include<bits/stdc++.h>
  2.  
  3. #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  4. #define ll long long
  5. #define pii pair<int,int>
  6. #define pill pair<int,ll>
  7. #define pll pair<ll,ll>
  8. #define pb push_back
  9. #define fi first
  10. #define se second
  11. #define ff fi.fi
  12. #define fs fi.se
  13. #define sf se.fi
  14. #define ss se.se
  15. #define MASK(x) (((1)<<(x))-1)
  16. #define getbit(x,k) (((x)>>(k))&1)
  17.  
  18. using namespace std;
  19.  
  20. const int maxn=1e5+5,mod=1e9+7;
  21. const ll inf=1e18;
  22.  
  23. int n,m;
  24. vector<pii>eg[maxn];
  25.  
  26.  
  27. ll d[maxn],w[maxn],mn[maxn],mx[maxn];
  28. void dijkstra()
  29. {
  30. fill(d+1,d+1+n,inf);d[1]=0;w[1]=1;
  31. priority_queue<pll,vector<pll>,greater<pll>>pQ;
  32. pQ.push({d[1],1});
  33. while(pQ.size())
  34. {
  35. pll u=pQ.top();pQ.pop();
  36. if(u.fi!=d[u.se]) continue;
  37. for(pii v:eg[u.se])
  38. {
  39. if(u.fi+v.se<d[v.fi])
  40. {
  41. d[v.fi]=u.fi+v.se;
  42. w[v.fi]=w[u.se];
  43. mn[v.fi]=mn[u.se]+1;
  44. mx[v.fi]=mx[u.se]+1;
  45. pQ.push({d[v.fi],v.fi});
  46. }
  47. else if(u.fi+v.se==d[v.fi])
  48. {
  49. w[v.fi]=(w[v.fi]+w[u.se])%mod;
  50. mn[v.fi]=min(mn[v.fi],mn[u.se]+1);
  51. mx[v.fi]=max(mx[v.fi],mx[u.se]+1);
  52. }
  53. }
  54. }
  55. }
  56. int main()
  57. {
  58. cin>>n>>m;
  59. for(int i=1;i<=m;i++)
  60. {
  61. int u,v,c;cin>>u>>v>>c;
  62. eg[u].pb({v,c});
  63. }
  64. dijkstra();
  65. if(d[n]==inf) cout<<-1;
  66. else cout<<d[n]<<' '<<w[n]<<' '<<mn[n]<<' '<<mx[n];
  67. }
  68.  
Success #stdin #stdout 0.01s 9068KB
stdin
Standard input is empty
stdout
0 0 0 0