Submission #65955

#TimeUsernameProblemLanguageResultExecution timeMemory
65955ikura355007 (CEOI14_007)C++14
30 / 100
386 ms17240 KiB
#include<bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const int inf = 1e9; struct node { int u,val; node(int _u = 0, int _val = 0) { u = _u; val = _val; } bool operator < (node a) const { return a.val<val; } }; int n,m,a,b,s1,s2; vector<int> way[maxn]; int len[maxn]; priority_queue<node> heap; int d1[maxn], d2[maxn]; int sssp(int u) { for(int i=1;i<=n;i++) len[i] = inf; len[u] = 0; heap.push(node(u,0)); while(!heap.empty()) { auto t = heap.top(); heap.pop(); int u = t.u, val = t.val; if(len[u]!=val) continue; for(auto v : way[u]) { if(len[v] > len[u] + 1) { len[v] = len[u] + 1; heap.push(node(v,len[v])); } } } } int main() { scanf("%d%d",&n,&m); scanf("%d%d%d%d",&a,&b,&s1,&s2); for(int i=1;i<=m;i++) { int u,v; scanf("%d%d",&u,&v); way[u].push_back(v); way[v].push_back(u); } sssp(a); for(int i=1;i<=n;i++) d1[i] = len[i]; sssp(b); for(int i=1;i<=n;i++) d2[i] = len[i]; if(d2[s1]<d1[s1] || d2[s2]<d1[s2]) printf("-1"); else { if(min(d2[s1]-d1[s1],d2[s2]-d1[s2])-1==-1) printf("0"); else printf("%d",min(d2[s1]-d1[s1], d2[s2]-d1[s2])-1); } }

Compilation message (stderr)

007.cpp: In function 'int sssp(int)':
007.cpp:38:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
007.cpp: In function 'int main()':
007.cpp:41: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:42:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d%d",&a,&b,&s1,&s2);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
007.cpp:44:17: 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...