Submission #613864

#TimeUsernameProblemLanguageResultExecution timeMemory
613864andrei_boaca007 (CEOI14_007)C++14
30 / 100
225 ms17544 KiB
#include <bits/stdc++.h> using namespace std; int n,m,s,d,a,b; vector<int> muchii[200005]; int dist[5][200005]; void bfs(int start,int index) { for(int i=1;i<=n;i++) dist[index][i]=1e9; dist[index][start]=0; queue<int> coada; coada.push(start); while(!coada.empty()) { int nod=coada.front(); coada.pop(); for(int i:muchii[nod]) if(dist[index][i]>dist[index][nod]+1) { dist[index][i]=dist[index][nod]+1; coada.push(i); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>n>>m>>s>>d>>a>>b; for(int i=1;i<=m;i++) { int x,y; cin>>x>>y; muchii[x].push_back(y); muchii[y].push_back(x); } bfs(a,1); bfs(b,2); bfs(d,3); bfs(s,4); int minim=1e9; for(int i=1;i<=n;i++) { bool good; if((dist[1][i]>=dist[1][s]&&dist[2][i]>=dist[2][s])) good=1; else good=0; if(!good) minim=min(minim,dist[3][i]-2); } cout<<max(-1,minim); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...