Submission #43412

#TimeUsernameProblemLanguageResultExecution timeMemory
43412Hassoony007 (CEOI14_007)C++14
0 / 100
376 ms17308 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MX=2e5+9; int n,m,a,b,s,d,dis[MX],dis1[MX],x,y,vis[MX]; vector<int>v[MX]; void bfs(int x,int y){ for(int i=1;i<=n;i++)dis[i]=MX,vis[i]=0; dis[x]=0; queue<int>q; q.push(x); while(!q.empty()){ int node=q.front();q.pop(); if(vis[node])continue; vis[node]=1; for(auto pp:v[node]){ if(pp==y)continue; if(dis[pp]==MX){ dis[pp]=dis[node]+1; q.push(pp); } } } } int main(){ scanf("%d%d",&n,&m); scanf("%d%d%d%d",&s,&d,&a,&b); for(int i=0;i<m;i++){ scanf("%d%d",&x,&y); v[x].push_back(y); v[y].push_back(x); } bfs(s,d); for(int i=1;i<=n;i++)dis1[i]=dis[i]; bfs(d,s); if(dis[a]<dis1[a]||dis[b]<dis1[b]){ puts("-1"); return 0; } bfs(s,0); for(int i=1;i<=n;i++)dis1[i]=dis[i]; bfs(d,0); if(dis[a]<dis[b]){ cout<<dis[a]-dis1[a]<<endl; } else cout<<dis[b]-dis1[b]<<endl; }

Compilation message (stderr)

007.cpp: In function 'int main()':
007.cpp:27:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
                        ^
007.cpp:28:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d%d",&s,&d,&a,&b);
                                  ^
007.cpp:30:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&x,&y);
                            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...