Submission #668539

#TimeUsernameProblemLanguageResultExecution timeMemory
668539RambaXGorilla007 (CEOI14_007)C++17
0 / 100
220 ms22284 KiB
#include<cstdio> #include<algorithm> #include<utility> #include<vector> #include<queue> using namespace std; typedef pair <int,int> ii; int N, M, S, D, A, B; vector <int> adj[200010]; queue <ii> near; bool vis[200010] = {}; ii bfs(int X){ ii servers; near.push(ii(X, 0)); while(!near.empty()){ int node = near.front().first; int dist = near.front().second; near.pop(); if(vis[node]) continue; vis[node] = true; if(node == A) servers.first = dist; else if(node == B) servers.second = dist; for(int i : adj[node]){ near.push(ii(i, dist + 1)); } } fill(vis, vis + 200010, false); return servers; } int main(){ scanf("%d%d%d%d%d%d",&N,&M,&S,&D,&A,&B); for(int i = 0;i < M;i++){ int a, b; scanf("%d%d",&a,&b); adj[a].push_back(b); adj[b].push_back(a); } ii agent = bfs(S); ii doctor = bfs(D); printf("%d",max(min(doctor.first - agent.first, doctor.second - agent.second), -1)); }

Compilation message (stderr)

007.cpp: In function 'int main()':
007.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     scanf("%d%d%d%d%d%d",&N,&M,&S,&D,&A,&B);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         scanf("%d%d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...