Submission #110778

#TimeUsernameProblemLanguageResultExecution timeMemory
110778ckodser007 (CEOI14_007)C++14
0 / 100
386 ms23860 KiB
#include<bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define ld long double #define F first #define S second #define pii pair<ll,ll> using namespace :: std; const ll mod=1e9+7; const ll maxn=2e5+500; const ll inf=1e9+900; vector<ll> ger[maxn]; ll fs[maxn]; ll fd[maxn]; bool vis[maxn]; void bfs(ll a,ll* f){ queue<ll> qu; memset(vis,0,sizeof vis); qu.push(a); vis[a]=1; while(qu.size()){ ll v=qu.front(); qu.pop(); for(auto u:ger[v]){ if(!vis[u]){ vis[u]=1; f[u]=f[v]+1; qu.push(u); } } } } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); ll n,m; cin>>n>>m; ll s,d,a,b; cin>>s>>d>>a>>b; for(ll i=0;i<m;i++){ ll a,b; cin>>a>>b; ger[a].pb(b); ger[b].pb(a); } bfs(s,fs); bfs(d,fd); if(fd[a]!=fd[b]){ ll r1=fd[a]; ll r2=fd[b]; ll w1=fs[a]; ll w2=fs[b]; if(r1>r2){ swap(r1,r2); swap(w1,w2); } ll ans=min(r1-w1,r2-w2); if(ans<0){ ans=-1; } cout<<ans<<endl; }else{ cout<<"WTF?"; exit(1); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...