Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ЗАПУСКАЕМ
- ░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
- ▄███▀░◐░░░▌░░░░░░░
- ░░░░▌░░░░░▐░░░░░░░
- ░░░░▐░░░░░▐░░░░░░░
- ░░░░▌░░░░░▐▄▄░░░░░
- ░░░░▌░░░░▄▀▒▒▀▀▀▀▄
- ░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
- ░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
- ░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
- ░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
- ░░░░░░░░░░░▌▌░▌▌░░░░░
- ░░░░░░░░░░░▌▌░▌▌░░░░░
- ░░░░░░░░░▄▄▌▌▄▌▌░░░░░
- */
- #include <iostream>
- #include <vector>
- #include <string>
- #include <iomanip>
- #include <queue>
- #include <cmath>
- #include <algorithm>
- #include <tuple>
- #include <iomanip>
- #include <stdio.h>
- #include <numeric>
- #include <map>
- #include <bitset>
- #include <set>
- #include <stack>
- #include <queue>
- //#define int long long
- #define ll long long
- #define ull unsigned long long
- #define all(a) a.begin(), a.end()
- #define pii pair<int, int>
- #define pb push_back
- #define ld long double
- //#pragma GCC optimize("O3");
- using namespace std;
- const int INF = 2e9;
- //const int mod = 2600000069;
- //const int p = 179;
- int n, r, a1, b1, a2, b2;
- vector<set<int>> g;
- vector<vector<pii>> g1(13000);
- set<pii> s;
- vector<int> d(13000, INF), p(13000, INF);
- int v;
- int one(int a, int b) {
- return (a << 7) + b;
- }
- void Dijkstra(int start) {
- s.insert({0, start});
- while (!s.empty()) {
- v = s.begin()->second;
- s.erase(s.begin());
- for (auto u: g1[v]) {
- if (d[u.first] == d[v] + u.second) {
- p[u.first] = min(p[u.first], p[v] + 1);
- } else if (d[u.first] > d[v] + u.second) {
- s.erase({d[u.first], u.first});
- d[u.first] = d[v] + u.second;
- p[u.first] = p[v] + 1;
- s.insert({d[u.first], u.first});
- }
- }
- }
- }
- signed main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cin >> n >> r >> a1 >> b1 >> a2 >> b2;
- a1--;b1--;a2--;b2--;
- g.resize(n);
- int x, y, start = one(a1, b1), finish = one(a2, b2);
- for (int i = 0; i < n; i++) g[i].insert(i);
- for (int i = 0; i < r; i++) {
- cin >> x >> y;
- x--;
- y--;
- g[x].insert(y);
- g[y].insert(x);
- }
- for (int s1 = 0; s1 < n; s1++) {
- for (int e1 = 0; e1 < n; e1++) {
- if (s1 == e1) continue;
- for (auto s2: g[s1]) {
- for (auto e2: g[e1]) {
- /*
- * 1 - первого отрезка нет
- * 2 - второго отрезка нет
- * 3 - один отрезок с разными концами
- * 4 - один отрезок
- */
- if (!g[s1].count(e1) || !g[s2].count(e2) || (s1 == e2 && s2 == e1) || (s1 == s2 && e1 == e2)) continue;
- if (s1 != s2 && e1 != e2) {
- g1[one(s1, e1)].pb({one(s2, e2), 2});
- } else {
- g1[one(s1, e1)].pb({one(s2, e2), 1});
- }
- }
- }
- }
- }
- d[start] = 0;
- p[start] = 1;
- Dijkstra(start);
- cout << d[finish] << " " << p[finish];
- }
- /*
- 4 5 1 2 2 1
- 1 2
- 2 3
- 3 4
- 4 1
- 1 3
- -> 3 3
- 4 4 1 4 3 4
- 1 2
- 2 3
- 3 4
- 1 4
- -> 4 3
- 5 5 1 2 5 4
- 1 2
- 2 3
- 3 4
- 4 5
- 2 5
- -> 4 3
- 6 7 1 2 6 5
- 1 2
- 2 3
- 3 4
- 4 1
- 4 6
- 5 6
- 5 3
- -> 4 3
- */
Advertisement
Add Comment
Please, Sign In to add comment