Submission #101470

#TimeUsernameProblemLanguageResultExecution timeMemory
101470shenxy007 (CEOI14_007)C++11
0 / 100
353 ms16988 KiB
#include <cstdio> #include <algorithm> #include <vector> #include <queue> using namespace std; const int INF = 1000000000; int main() { int N, M, s, d, a, b, u, v; scanf("%d %d", &N, &M); scanf("%d %d %d %d", &s, &d, &a, &b); s -= 1, d -= 1, a -= 1, b -= 1; vector<int> adjlist[N]; for (int i = 0; i < M; i++) { scanf("%d %d", &u, &v); adjlist[u - 1].push_back(v - 1); adjlist[v - 1].push_back(u - 1); } int dists[N]; fill_n(dists, N, INF); dists[s] = 0; queue<int> q; q.push(s); while (!q.empty()) { int u = q.front(); q.pop(); for (int i = 0; i < adjlist[u].size(); i++) { if (dists[adjlist[u][i]] == INF) { dists[adjlist[u][i]] = dists[u] + 1; q.push(adjlist[u][i]); } } } int distd[N]; fill_n(distd, N, INF); distd[d] = 0; q.push(d); while (!q.empty()) { int u = q.front(); q.pop(); for (int i = 0; i < adjlist[u].size(); i++) { if (distd[adjlist[u][i]] == INF) { distd[adjlist[u][i]] = distd[u] + 1; q.push(adjlist[u][i]); } } } printf("%d", min(distd[a] - dists[a], distd[b] - dists[b]) >= 0 ? min(distd[a] - dists[a], distd[b] - dists[b]): -1); return 0; }

Compilation message (stderr)

007.cpp: In function 'int main()':
007.cpp:26:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < adjlist[u].size(); i++) {
                         ~~^~~~~~~~~~~~~~~~~~~
007.cpp:40:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < adjlist[u].size(); i++) {
                         ~~^~~~~~~~~~~~~~~~~~~
007.cpp:9: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:10: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:14: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...