Submission #65953

# Submission time Handle Problem Language Result Execution time Memory
65953 2018-08-09T07:07:13 Z ikura355 007 (CEOI14_007) C++14
0 / 100
27 ms 1228 KB
#include<bits/stdc++.h>
using namespace std;

const int maxn = 2e3 + 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 printf("%d",min(d2[s1]-d1[s1], d2[s2]-d1[s2]) - (d2[s1] != d2[s2]));
}

Compilation message

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 time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Partially correct 3 ms 376 KB Partially correct
3 Correct 3 ms 444 KB Output is correct
4 Incorrect 2 ms 504 KB Output isn't correct
5 Incorrect 2 ms 704 KB Output isn't correct
6 Correct 2 ms 704 KB Output is correct
7 Correct 2 ms 704 KB Output is correct
8 Incorrect 3 ms 704 KB Output isn't correct
9 Correct 2 ms 704 KB Output is correct
10 Correct 2 ms 704 KB Output is correct
11 Partially correct 3 ms 704 KB Partially correct
12 Incorrect 2 ms 704 KB Output isn't correct
13 Correct 2 ms 704 KB Output is correct
14 Incorrect 2 ms 704 KB Output isn't correct
15 Correct 3 ms 704 KB Output is correct
16 Incorrect 3 ms 744 KB Output isn't correct
17 Incorrect 5 ms 744 KB Output isn't correct
18 Incorrect 3 ms 744 KB Output isn't correct
19 Correct 3 ms 744 KB Output is correct
20 Correct 3 ms 880 KB Output is correct
21 Partially correct 3 ms 880 KB Partially correct
22 Correct 4 ms 880 KB Output is correct
23 Correct 27 ms 880 KB Output is correct
24 Incorrect 3 ms 880 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 1032 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 3 ms 1032 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 3 ms 1032 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 3 ms 1032 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 3 ms 1088 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 3 ms 1124 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 3 ms 1124 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 3 ms 1124 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 3 ms 1124 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 2 ms 1124 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 2 ms 1124 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 3 ms 1192 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 3 ms 1192 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 2 ms 1192 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 2 ms 1192 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 2 ms 1192 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 2 ms 1192 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 3 ms 1220 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 4 ms 1220 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 2 ms 1220 KB Execution killed with signal 11 (could be triggered by violating memory limits)
21 Runtime error 3 ms 1220 KB Execution killed with signal 11 (could be triggered by violating memory limits)
22 Runtime error 2 ms 1220 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Runtime error 2 ms 1220 KB Execution killed with signal 11 (could be triggered by violating memory limits)
24 Runtime error 3 ms 1220 KB Execution killed with signal 11 (could be triggered by violating memory limits)
25 Runtime error 3 ms 1228 KB Execution killed with signal 11 (could be triggered by violating memory limits)
26 Runtime error 3 ms 1228 KB Execution killed with signal 11 (could be triggered by violating memory limits)
27 Runtime error 2 ms 1228 KB Execution killed with signal 11 (could be triggered by violating memory limits)
28 Runtime error 3 ms 1228 KB Execution killed with signal 11 (could be triggered by violating memory limits)
29 Runtime error 3 ms 1228 KB Execution killed with signal 11 (could be triggered by violating memory limits)
30 Runtime error 3 ms 1228 KB Execution killed with signal 11 (could be triggered by violating memory limits)
31 Runtime error 4 ms 1228 KB Execution killed with signal 11 (could be triggered by violating memory limits)
32 Runtime error 3 ms 1228 KB Execution killed with signal 11 (could be triggered by violating memory limits)
33 Runtime error 2 ms 1228 KB Execution killed with signal 11 (could be triggered by violating memory limits)
34 Runtime error 2 ms 1228 KB Execution killed with signal 11 (could be triggered by violating memory limits)
35 Runtime error 2 ms 1228 KB Execution killed with signal 11 (could be triggered by violating memory limits)
36 Runtime error 3 ms 1228 KB Execution killed with signal 11 (could be triggered by violating memory limits)
37 Runtime error 2 ms 1228 KB Execution killed with signal 11 (could be triggered by violating memory limits)
38 Runtime error 2 ms 1228 KB Execution killed with signal 11 (could be triggered by violating memory limits)
39 Runtime error 3 ms 1228 KB Execution killed with signal 11 (could be triggered by violating memory limits)
40 Runtime error 2 ms 1228 KB Execution killed with signal 11 (could be triggered by violating memory limits)
41 Runtime error 3 ms 1228 KB Execution killed with signal 11 (could be triggered by violating memory limits)