Submission #82732

#TimeUsernameProblemLanguageResultExecution timeMemory
82732IOrtroiii007 (CEOI14_007)C++14
100 / 100
393 ms49688 KiB
#include <queue> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; const int N = 200005; int n, m, s, d, a, b; vector<int> g[N]; int fa[N], fb[N]; void bfs(int start, int f[]) { for (int i = 1; i <= n; ++i) f[i] = -1; f[start] = 0; queue <int> q; q.push(start); while(!q.empty()) { int u = q.front(); q.pop(); for (int v : g[u]) if (f[v] == -1) { f[v] = f[u] + 1; q.push(v); } } } int maxdep(int start) { vector<int> d(n + 1, -1); queue <int> q; q.push(start); d[start] = 0; int ans = 0; while(!q.empty()) { int u = q.front(); q.pop(); ans = max(ans, d[u]); for (int v : g[u]) if (fa[v] == fa[u] - 1 && fb[v] == fb[u] - 1 && d[v] == -1) { d[v] = d[u] + 1; q.push(v); } } return ans; } 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); } bfs(a, fa); bfs(b, fb); int wa = fa[d] - fa[s]; int wb = fb[d] - fb[s]; if (wa != wb) { cout << max(min(wa, wb), -1) << '\n'; } else { int maxs = maxdep(s), maxd = maxdep(d); cout << max(wa - (wa + maxs < maxd), -1) << '\n'; } }

Compilation message (stderr)

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