Submission #83999

#TimeUsernameProblemLanguageResultExecution timeMemory
83999aminra007 (CEOI14_007)C++17
0 / 100
406 ms45648 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const int infint = 1e9; const int MOD = (int)1e9 + 7; const int MAXN = (int)1e6 + 7; int dist1[MAXN], dist2[MAXN], dist3[MAXN], n, m, s, d, a, b; vector<int> G[MAXN]; void bfs(int s, int type) { if(type == 0) dist1[s] = 0; else if(type == 1) dist2[s] = 0; else dist3[s] = 0; queue<int> q; q.push(s); while(!q.empty()) { int st = q.front(); q.pop(); for (auto v : G[st]) { if(type == 0 && dist1[v] == -1) dist1[v] = dist1[st] + 1, q.push(v); else if(type == 1 && dist2[v] == -1) dist2[v] = dist2[st] + 1, q.push(v); else if(type == 2 && dist3[v] == -1) dist3[v] = dist3[st] + 1, q.push(v); } } } bool check(int u, int v) { if(dist1[v] < dist1[u] || dist2[v] < dist2[u]) return 0; return 1; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); memset(dist1, -1, sizeof dist1); memset(dist2, -1, sizeof dist2); memset(dist3, -1, sizeof dist3); cin >> n >> m >> s >> d >> a >> b; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; G[u].push_back(v); G[v].push_back(u); } bfs(a, 0); bfs(b, 1); bfs(d, 2); if(check(s, d) == 0) return cout << -1, 0; int L = 0, R = n + 1; while(R - L > 1) { int mid = (L + R) >> 1; bool c = 1; for (int i = 1; i <= n; i++) if(dist3[i] <= mid && check(s, i) == 0) c = 0; if(c) L = mid; else R = mid; } cout << L; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...