Advertisement
Saleh127

Light oj(LO) 1002

Feb 3rd, 2021
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. ///Light OJ 1002
  2. /// idea: modified dijkstra
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5. #define ll long long
  6. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  7. vector<pair<ll,ll>>g[100005];
  8.  
  9. int main()
  10. {
  11. ios_base::sync_with_stdio(0);
  12. cin.tie(0);
  13. cout.tie(0);
  14.  
  15. test
  16. {
  17.  
  18. ll n,m,i,j,k,l,a,b,c;
  19.  
  20. cin>>n>>m;
  21.  
  22. ll cost[n+5];
  23.  
  24. for(i=0; i<n+5; i++)
  25. {
  26. cost[i]=100000000000000;
  27. }
  28.  
  29. while(m--)
  30. {
  31. cin>>a>>b>>c;
  32. g[a].push_back({b,c});
  33. g[b].push_back({a,c});
  34. }
  35.  
  36. cin>>k;
  37.  
  38. cost[k]=0;
  39.  
  40. priority_queue<ll>q;
  41.  
  42. q.push(k);
  43.  
  44. while(q.empty()==false)
  45. {
  46. ll u=q.top();
  47. q.pop();
  48.  
  49. for(auto i:g[u])
  50. {
  51. if(cost[i.first]> max(cost[u],i.second))
  52. {
  53. ///relaxation;
  54. cost[i.first]= max(cost[u],i.second);
  55. q.push(i.first);
  56. }
  57. }
  58.  
  59. }
  60.  
  61. cout<<"Case "<<cs<<":"<<endl;
  62.  
  63. for(i=0; i<n; i++)
  64. {
  65. if(cost[i]==100000000000000) cout<<"Impossible"<<endl;
  66. else cout<<cost[i]<<endl;
  67. g[i].clear();
  68. cost[i]=100000000000000;
  69. }
  70.  
  71.  
  72. }
  73. return 0;
  74. }
  75.  
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement