Advertisement
Andre1314

Untitled

Sep 24th, 2023
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.46 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4. #include <map>
  5.  
  6. #define pll pair<ll,pair<ll,ll>>
  7.  
  8. #define ll long long
  9.  
  10. using namespace std;
  11.  
  12. const int maxx = 100000;
  13. vector<pair<ll, ll> > a[maxx];
  14. ll used[maxx], parent[maxx], res[maxx];
  15. ll m, v, a1, a2, a3;
  16.  
  17. pair<ll, pair<ll, ll> > p1;
  18.  
  19. priority_queue< pll, vector<pll>, greater<pll>> q;
  20.  
  21. int main()
  22. {
  23.     map<pair<vector<ll>, vector<ll>>, vector<ll>> map1;
  24.     int n, I, J;
  25.     cin >> n;
  26.     cin >> I >> J;
  27.     for (int i = 1; i <= n; ++i) {
  28.  
  29.         vector<ll> v1(3), v2(3), v3(3);
  30.         pair<vector<ll>, vector<ll>> pair1;
  31.         cin >> v1[0] >> v1[1] >> v1[2];
  32.         cin >> v2[0] >> v2[1] >> v2[2];
  33.         cin >> v3[0] >> v3[1] >> v3[2];
  34.  
  35.  
  36.         pair1.first = v1;
  37.         pair1.second = v2;
  38.         map1[pair1].push_back(i);
  39.  
  40.  
  41.         pair1.first = v1;
  42.         pair1.second = v3;
  43.         map1[pair1].push_back(i);
  44.  
  45.  
  46.         pair1.first = v2;
  47.         pair1.second = v3;
  48.         map1[pair1].push_back(i);
  49.  
  50.         pair1.first = v2;
  51.         pair1.second = v1;
  52.         map1[pair1].push_back(i);
  53.  
  54.  
  55.         pair1.first = v3;
  56.         pair1.second = v1;
  57.         map1[pair1].push_back(i);
  58.  
  59.  
  60.         pair1.first = v3;
  61.         pair1.second = v2;
  62.         map1[pair1].push_back(i);
  63.  
  64.     }
  65.  
  66.     vector<pair<vector<ll>, vector<ll>>> key;
  67.     vector<vector<ll>> value;
  68.     for (auto it = map1.begin(); it != map1.end(); ++it) {
  69.         key.push_back(it->first);
  70.         value.push_back(it->second);
  71.     }
  72.  
  73.     for (const auto& i : value) {
  74.         if (i.size() > 1) {
  75.             for (int j = 0; j < i.size() - 1; j++) {
  76.                 for (int k = j + 1; k < i.size(); k++) {
  77.                     a[i[j] - 1].emplace_back(i[k] - 1, 1);
  78.                     a[i[k] - 1].emplace_back(i[j] - 1, 1);
  79.                 }
  80.             }
  81.         }
  82.     }
  83.     res[I - 1] = 0;
  84.     res[J - 1] = 0;
  85.     q.push({ 0,{I - 1,-1} });
  86.     while (!q.empty()) {
  87.         int dist = q.top().first;
  88.         ll v = q.top().second.first;
  89.         ll from = q.top().second.second;
  90.         q.pop();
  91.         if (used[v] == 1)continue;
  92.         res[v] = dist;
  93.         parent[v] = from;
  94.         used[v] = 1;
  95.         for (int i = 0; i < a[v].size(); i++) {
  96.             ll to = a[v][i].first;
  97.             ll weight = a[v][i].second;
  98.             if (used[to] == 0) {
  99.                 q.push({ dist + weight,{to,v} });
  100.             }
  101.         }
  102.     }
  103.  
  104.     cout << res[J - 1] << endl;
  105.  
  106.     return 0;
  107. }
  108.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement