Submission #666167

#TimeUsernameProblemLanguageResultExecution timeMemory
666167bin9638007 (CEOI14_007)C++17
0 / 100
209 ms18680 KiB
#include<bits/stdc++.h> using namespace std; #define N 200010 #define ll long long #define ii pair<int,int> #define fs first #define sc second #define pb push_back int dp[N][5],f[5],n,m; vector<int>g[N]; deque<int>dq; void build(int id) { dp[f[id]][id]=0; dq.pb(f[id]); while(!dq.empty()) { int u=dq.front(); dq.pop_front(); for(auto v:g[u]) if(dp[v][id]>dp[u][id]+1) { dp[v][id]=dp[u][id]+1; dq.pb(v); } } } int main() { // freopen("A.inp","r",stdin); // freopen("A.out","w",stdout); ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin>>n>>m>>f[1]>>f[2]>>f[3]>>f[4]; for(int i=1;i<=m;i++) { int u,v; cin>>u>>v; g[u].pb(v); g[v].pb(u); } memset(dp,0x3f3f,sizeof(dp)); for(int i=1;i<=2;i++) build(i); int val=min(dp[f[3]][2]-dp[f[3]][1],dp[f[4]][2]-dp[f[4]][1]); if(val<0) cout<<-1; else cout<<val; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...