Submission #490319

#TimeUsernameProblemLanguageResultExecution timeMemory
490319SirCovidThe19th007 (CEOI14_007)C++17
30 / 100
1109 ms284944 KiB
#include <bits/stdc++.h> using namespace std; const int mx = 2e5 + 5; int n, m, s, v, a, b, dA[mx], dB[mx], ans; vector<int> adj[mx]; void bfs(int st, int *D){ queue<int> Q; fill(D, D + n + 1, -1); Q.push(st); D[st] = 0; while (!Q.empty()){ int i = Q.front(); Q.pop(); for (int j : adj[i]) if (D[j] == -1) D[j] = D[i] + 1, Q.push(j); } } int nearer(int src){ queue<int> Q; int D[n + 1], ret = 0; D[src] = 0; Q.push(src); while (!Q.empty()){ int i = Q.front(); Q.pop(); ret = max(ret, D[i]); for (int j : adj[i]) if (dA[j] < dA[i] and dB[j] < dB[i]) D[j] = D[i] + 1, Q.push(j); } return ret; } int main(){ cin >> n >> m >> s >> v >> a >> b; for (int i = 1; i <= m; i++){ int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } bfs(a, dA); bfs(b, dB); int wA = dA[v] - dA[s], wB = dB[v] - dB[s]; if (wA == wB) ans = (nearer(s) >= nearer(v) - wA) ? wA : wA - 1; else ans = min(wA, wB); cout<<max(ans, -1)<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...