Submission #65039

#TimeUsernameProblemLanguageResultExecution timeMemory
65039bazsi700007 (CEOI14_007)C++14
30 / 100
459 ms15980 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n,m,s,d,a,b; cin >> n >> m >> s >> d >> a >> b; vector<vector<int> > graph(n+1,vector<int>()); for(int i = 0; i < m; i++) { int x,y; cin >> x >> y; graph[x].push_back(y); graph[y].push_back(x); } vector<bool> wass(n+1,false); vector<int> dists(n+1,0); vector<bool> wasd(n+1,false); vector<int> distd(n+1,0); wass[s] = true; queue<int> q; q.push(s); while(!q.empty()) { int v = q.front(); q.pop(); for(int u : graph[v]) { if(!wass[u]) { wass[u] = true; q.push(u); dists[u] = dists[v]+1; } } } wasd[d] = true; q.push(d); while(!q.empty()) { int v = q.front(); q.pop(); for(int u : graph[v]) { if(!wasd[u]) { wasd[u] = true; q.push(u); distd[u] = distd[v]+1; } } } if(dists[a] == dists[b] && distd[a] == distd[b]) { cout << max(min(distd[a]-dists[a],distd[b]-dists[b])-1,-1); } else { cout << max(min(distd[a]-dists[a],distd[b]-dists[b]),-1); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...