Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- #include <map>
- #define pll pair<ll,pair<ll,ll>>
- #define ll long long
- using namespace std;
- const int maxx = 100000;
- vector<pair<ll, ll> > a[maxx];
- ll used[maxx], parent[maxx], res[maxx];
- ll m, v, a1, a2, a3;
- pair<ll, pair<ll, ll> > p1;
- priority_queue< pll, vector<pll>, greater<pll>> q;
- int main()
- {
- map<pair<vector<ll>, vector<ll>>, vector<ll>> map1;
- int n, I, J;
- cin >> n;
- cin >> I >> J;
- for (int i = 1; i <= n; ++i) {
- vector<ll> v1(3), v2(3), v3(3);
- pair<vector<ll>, vector<ll>> pair1;
- cin >> v1[0] >> v1[1] >> v1[2];
- cin >> v2[0] >> v2[1] >> v2[2];
- cin >> v3[0] >> v3[1] >> v3[2];
- pair1.first = v1;
- pair1.second = v2;
- map1[pair1].push_back(i);
- pair1.first = v1;
- pair1.second = v3;
- map1[pair1].push_back(i);
- pair1.first = v2;
- pair1.second = v3;
- map1[pair1].push_back(i);
- pair1.first = v2;
- pair1.second = v1;
- map1[pair1].push_back(i);
- pair1.first = v3;
- pair1.second = v1;
- map1[pair1].push_back(i);
- pair1.first = v3;
- pair1.second = v2;
- map1[pair1].push_back(i);
- }
- vector<pair<vector<ll>, vector<ll>>> key;
- vector<vector<ll>> value;
- for (auto it = map1.begin(); it != map1.end(); ++it) {
- key.push_back(it->first);
- value.push_back(it->second);
- }
- for (const auto& i : value) {
- if (i.size() > 1) {
- for (int j = 0; j < i.size() - 1; j++) {
- for (int k = j + 1; k < i.size(); k++) {
- a[i[j] - 1].emplace_back(i[k] - 1, 1);
- a[i[k] - 1].emplace_back(i[j] - 1, 1);
- }
- }
- }
- }
- res[I - 1] = 0;
- res[J - 1] = 0;
- q.push({ 0,{I - 1,-1} });
- while (!q.empty()) {
- int dist = q.top().first;
- ll v = q.top().second.first;
- ll from = q.top().second.second;
- q.pop();
- if (used[v] == 1)continue;
- res[v] = dist;
- parent[v] = from;
- used[v] = 1;
- for (int i = 0; i < a[v].size(); i++) {
- ll to = a[v][i].first;
- ll weight = a[v][i].second;
- if (used[to] == 0) {
- q.push({ dist + weight,{to,v} });
- }
- }
- }
- cout << res[J - 1] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement