Advertisement
jeff69

Untitled

Aug 13th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef long long ll;
  5. typedef long double ld;
  6. typedef short sh;
  7. const int MX=1e5+3;
  8.  
  9. struct zz
  10. {
  11. ll f;
  12. ll s;
  13. int th;
  14. } ;
  15. int n,m;
  16. priority_queue<zz> pq;
  17. map<pair<ll,ll> ,ll> edg[2];
  18. vector<int> adj[MX][2];
  19.  
  20. bool operator<(const zz &x,const zz&y)
  21. {
  22. if(x.f!=y.f)return x.f<y.f;
  23. return x.s<y.s;
  24.  
  25. }
  26. bool vis[MX];
  27. int main(){
  28.  
  29. int t;
  30. cin>>t;
  31. while(t--){
  32. for(int i=0;i<MX;i++){
  33. adj[i][0].clear();
  34. adj[i][1].clear();
  35. vis[i]=0;
  36. }
  37. edg[0].clear();
  38. edg[1].clear();
  39. scanf("%d%d",&n,&m);
  40. for(int i=0;i<m;i++)
  41. {
  42. int a,b,c,d;
  43. scanf("%d%d%d%d",&a,&b,&c,&d);
  44. adj[a][d-1].push_back(b);
  45. swap(a,b);
  46. adj[a][d-1].push_back(b);
  47. if(d==1){
  48. if(edg[0][{a,b}]!=0)
  49. if(c>=edg[0][{a,b}])continue;
  50. edg[0][{a,b}]=edg[0][{b,a}]=c;
  51.  
  52. }
  53. else {
  54. if(edg[1][{a,b}]!=0)
  55. if(edg[1][{a,b}]<=c)continue;
  56. edg[1][{a,b}]=edg[1][{b,a}]=c;
  57. }
  58.  
  59.  
  60. }
  61.  
  62. int h1,h2;
  63. scanf("%d%d",&h1,&h2);
  64. zz p={(ll)0,(ll)0,h1};
  65.  
  66. pq.push(p);
  67. pair<ll,ll>ans={1e12,1e12};
  68.  
  69. while(!pq.empty())
  70. {
  71. zz piece=pq.top();
  72. pq.pop();
  73. int x=piece.th;
  74.  
  75.  
  76. ll ldis=-piece.s;
  77. ll lwalk=-piece.f;
  78. if(x==h2)
  79. { // cout<<lwalk<<' '<<ldis<<' '<<x<<endl;;
  80. pair<ll,ll> pp={lwalk,ldis};
  81. // cout<<ans.second<<"$$"<<endl;
  82. ans=min(ans,pp);
  83. // cout<<ans.second<<"$$"<<endl;
  84.  
  85. continue;
  86. }if(vis[x])continue;
  87. vis[x]=1;
  88. for(int v=0;v<2;v++)
  89. for(int i=0;i<adj[x][v].size();i++)
  90. {
  91. int y=adj[x][v][i];
  92.  
  93. ll w=edg[v][{x,y}];
  94. if(w==0)continue;
  95. w=abs(w);
  96. //cout<<' '<<v<<' '<<x<<' '<<y<< ' '<<w<<endl;
  97. pq.push({-1*(lwalk+(1-v)*w),-1*(ldis+w),y});
  98.  
  99. }
  100.  
  101. }
  102. while(!pq.empty())
  103. pq.pop();
  104.  
  105. if(ans.first==1e12)
  106. {
  107. printf("-1\n");
  108. continue;
  109. }
  110. printf("%I64d %I64d\n",ans.first,ans.second);
  111. }return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement