Submission #101446

#TimeUsernameProblemLanguageResultExecution timeMemory
101446cheeheng007 (CEOI14_007)C++14
30 / 100
393 ms15932 KiB
#include <bits/stdc++.h> using namespace std; vector<int> AdjList[200005]; int dist[200005]; int main(){ int N, M; int s, d, a, b; scanf("%d%d%d%d%d%d", &N, &M, &s, &d, &a, &b); for(int i = 0; i < M; i ++){ int x, y; scanf("%d%d", &x, &y); AdjList[x].push_back(y); AdjList[y].push_back(x); } memset(dist, -1, sizeof(dist)); queue<int> q; q.push(s); dist[s] = 0; while(!q.empty()){ int u = q.front(); q.pop(); for(int v: AdjList[u]){ if(dist[v] == -1){ dist[v] = dist[u] + 1; q.push(v); } } } int sa = dist[a]; int sb = dist[b]; memset(dist, -1, sizeof(dist)); q = queue<int>(); q.push(d); dist[d] = 0; while(!q.empty()){ int u = q.front(); q.pop(); for(int v: AdjList[u]){ if(dist[v] == -1){ dist[v] = dist[u] + 1; q.push(v); } } } int da = dist[a]; int db = dist[b]; //printf("%d %d %d %d\n", sa, sb, da, db); int resA = min(da-sa, db-sa-1); int resB = min(da-sb-1, da-sb); int res = max(resA, resB); int ans = max(res, -1); printf("%d", ans); }

Compilation message (stderr)

007.cpp: In function 'int main()':
007.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d%d%d%d", &N, &M, &s, &d, &a, &b);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...