Submission #82362

#TimeUsernameProblemLanguageResultExecution timeMemory
82362FutymyClone007 (CEOI14_007)C++14
0 / 100
10 ms6940 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, m, s, d, a, b, dist[2][N]; vector <int> g[N]; queue <int> q; void bfs (int type){ if (!type) memset(dist, 0x3f, sizeof(dist)); dist[type][(type == 0) ? d : s] = 0; q.push((type == 0) ? d : s); while (!q.empty()) { int u = q.front(); q.pop(); for (auto v: g[u]) { if (type == 0 && v == s) continue; if (dist[type][v] > dist[type][u] + 1) { dist[type][v] = dist[type][u] + 1; q.push(v); } } } } int main(){ #ifndef Futymy freopen("SPY.inp", "r", stdin); freopen("SPY.out", "w", stdout); #endif // Futymy 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(0); bfs(1); //for (int i = 1; i <= n; i++) cout << dist[0][i] << " "; //cout << "\n"; int Min = min(dist[0][a], dist[0][b]); //cout << dist[0][a] << " " << dist[0][b] << "\n"; if (Min > 1e9) printf("%d", dist[1][d]); else { if (dist[0][a] < 1e9 && dist[0][b] > 1e9) { if (dist[1][a] > dist[0][a]) printf("%d", -1); else printf("%d", min(dist[1][d], dist[0][a] - dist[1][a])); } else if (dist[0][a] > 1e9 && dist[0][b] < 1e9) { if (dist[1][b] > dist[0][b]) printf("%d", -1); else printf("%d", min(dist[1][d], dist[0][b] - dist[1][b])); } else { if (dist[1][b] > dist[0][b] || dist[1][a] > dist[0][a]) printf("%d", -1); else printf("%d", min(dist[0][a] - dist[1][a], dist[0][b] - dist[1][b])); } } return 0; }

Compilation message (stderr)

007.cpp: In function 'int main()':
007.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("SPY.inp", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
007.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("SPY.out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:32: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:33: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:36: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...