Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 8th, 2020 161 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int d[2005];
  6. int mark[2005];
  7. int m[2005][2005];
  8. int t=0;
  9. int cit[2005];
  10. vector<vector<int> > vec;
  11. vector <int> r;
  12.  
  13.  
  14.  
  15.  
  16.  
  17. int main(){
  18.     ios::sync_with_stdio(false);
  19.     cin.tie(0);
  20.     int n,p,q,s,f,v,a,b,w,e,k,c;
  21.     cin >> n >> e >> k >> s;
  22.     vec.resize(n+1);
  23.     for(int i=1; i<=k; i++) cin >> cit[i];
  24.  
  25.     for(int i=1; i<=e; i++){
  26.         cin >> a >> b >> c;
  27.         vec[a].push_back(b);
  28.         vec[b].push_back(a);
  29.         m[a][b]=c;
  30.         m[b][a]=c;
  31.     }
  32.     for(int i=1; i<=n; i++){
  33.         d[i]=100000000;
  34.     }
  35.     d[s]=0;
  36.     d[n+1]=100000000;
  37.     for(int i=1; i<=n; i++){
  38.       v=n+1;
  39.       for(int i=1; i<=n; i++){
  40.         if((d[i]<=d[v]) && (mark[i]==0)) v=i;
  41.       }
  42.       mark[v]=1;
  43.       if(vec[v].size()>=1)
  44.       for(int t=0; t<=vec[v].size()-1; t++){
  45.         w=vec[v][t];
  46.         d[w]=min(d[w], d[v]+m[v][w]);
  47.       }
  48.     }
  49.  
  50.  
  51.     for(int i=1; i<=k; k++){
  52.         for(int j=1; j<=k-1; j++){
  53.             if(d[cit[j+1]]<d[cit[j]]) swap(cit[j], cit[j+1]);
  54.         }
  55.     }
  56.     for(int i=1; i<=k; i++){
  57.         cout << i << " " << cit[i] << "\n";
  58.     }
  59.  
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top