제출 #82365

#제출 시각아이디문제언어결과실행 시간메모리
82365DrumpfTheGodEmperor007 (CEOI14_007)C++14
0 / 100
320 ms15928 KiB
#include <bits/stdc++.h> #define bp __builtin_popcountll #define pb push_back #define in(s) freopen(s, "r", stdin); #define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\ freopen((string(s) + "." + end2).c_str(), "w", stdout); #define fi first #define se second #define bw(i, r, l) for (int i = r - 1; i >= l; i--) #define fw(i, l, r) for (int i = l; i < r; i++) #define fa(i, x) for (auto i: x) using namespace std; const int mod = 1e9 + 7, inf = 1061109567; const long long infll = 4557430888798830399; typedef pair<int, int> ii; const int N = 2e5 + 5; int n, m, s, d, a, b, dist[N]; vector<int> g[N]; ii bfs(int st) { memset(dist, 63, sizeof dist); queue<int> q; q.push(st); dist[st] = 0; while (!q.empty()) { int u = q.front(); q.pop(); fa (v, g[u]) if (dist[u] + 1 < dist[v]) { dist[v] = dist[u] + 1; q.push(v); } } return ii(dist[a], dist[b]); } signed main() { #ifdef BLU in("blu.inp"); #endif ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m >> s >> d >> a >> b; s--, d--, a--, b--; fw (i, 0, m) { int u, v; cin >> u >> v; u--, v--; g[u].pb(v), g[v].pb(u); } ii dists = bfs(s), distd = bfs(d); int sa = dists.fi, sb = dists.se, da = distd.fi, db = distd.se; int tmp1 = da - sa, tmp2 = db - sb; int ans = min(tmp1, tmp2); if (ans < 0) cout << "-1"; else cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...