Submission #90795

#TimeUsernameProblemLanguageResultExecution timeMemory
90795FutymyClone007 (CEOI14_007)C++14
0 / 100
291 ms17500 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, m, s, d, a, b, d1[N], d2[N]; vector <int> g[N]; void bfs1(){ memset(d1, 0x3f, sizeof(d1)); queue <int> q; d1[a] = 0; q.push(a); while (!q.empty()) { int u = q.front(); q.pop(); for (auto v: g[u]) { if (d1[v] > d1[u] + 1) { d1[v] = d1[u] + 1; q.push(v); } } } } void bfs2(){ memset(d2, 0x3f, sizeof(d2)); queue <int> q; d2[b] = 0; q.push(b); while (!q.empty()) { int u = q.front(); q.pop(); for (auto v: g[u]) { if (d2[v] > d2[u] + 1) { d2[v] = d2[u] + 1; q.push(v); } } } } int main(){ scanf("%d %d", &n, &m); scanf("%d %d %d %d", &s, &d, &a, &b); for (int i = 1; i <= m; i++) { int u, v; scanf("%d %d", &u, &v); g[u].push_back(v); g[v].push_back(u); } bfs1(); bfs2(); printf("%d", max(min(d1[d] - d1[s], d2[d] - d2[s]), -1)); return 0; } /* 6 6 1 2 3 4 1 5 5 6 6 3 6 4 1 2 3 4 6 7 5 6 1 2 6 3 1 2 1 3 2 3 1 5 2 4 5 4 */

Compilation message (stderr)

007.cpp: In function 'int main()':
007.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
007.cpp:40:10: 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:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &u, &v);
         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...