Submission #92921

#TimeUsernameProblemLanguageResultExecution timeMemory
92921Flying_dragon_02007 (CEOI14_007)C++14
100 / 100
325 ms17248 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair typedef pair<int, int> ii; const int N = 2e5 + 5; int n, m, s, d, a, b, dista[N], distb[N], dist[N]; vector<int> graph[N]; queue<int> q; int get(int f) { int res = 0; for(int i = 1; i <= N - 5; i++) dist[i] = N; dist[f] = 0; q.push(f); while(!q.empty()) { int u = q.front(); q.pop(); res = max(res, dist[u]); for(int i = 0; i < graph[u].size(); i++) { int v = graph[u][i]; if(dist[v] > dist[u] + 1 && dista[v] + 1 == dista[u] && distb[v] + 1 == distb[u]) { dist[v] = dist[u] + 1; q.push(v); } } } return res; } int main() { //freopen("test.inp", "r", stdin); 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); graph[u].pb(v); graph[v].pb(u); } for(int i = 1; i <= N - 5; i++) { dista[i] = N; distb[i] = N; } dista[a] = 0; q.push(a); while(!q.empty()) { int u = q.front(); q.pop(); for(int i = 0; i < graph[u].size(); i++) { int v = graph[u][i]; if(dista[v] > dista[u] + 1) { dista[v] = dista[u] + 1; q.push(v); } } } distb[b] = 0; q.push(b); while(!q.empty()) { int u = q.front(); q.pop(); for(int i = 0; i < graph[u].size(); i++) { int v = graph[u][i]; if(distb[v] > distb[u] + 1) { distb[v] = distb[u] + 1; q.push(v); } } } int w1 = dista[d] - dista[s], w2 = distb[d] - distb[s]; if(min(w1, w2) < 0) { printf("-1"); exit(0); } int ans; if(w1 != w2) { printf("%d", min(w1, w2)); exit(0); } else { int lmaoa = get(s), lmaob = get(d); if(lmaoa + w1 >= lmaob) ans = w1; else ans = w1 - 1; } if(ans < 0) printf("-1"); else printf("%d", ans); }

Compilation message (stderr)

007.cpp: In function 'int get(int)':
007.cpp:30:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < graph[u].size(); i++) {
                        ~~^~~~~~~~~~~~~~~~~
007.cpp: In function 'int main()':
007.cpp:60:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < graph[u].size(); i++) {
                        ~~^~~~~~~~~~~~~~~~~
007.cpp:73:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < graph[u].size(); i++) {
                        ~~^~~~~~~~~~~~~~~~~
007.cpp:43: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:44: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:47: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...