답안 #65965

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
65965 2018-08-09T07:50:15 Z ikura355 007 (CEOI14_007) C++14
9 / 100
5 ms 1112 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]));
			}
		}
	}
}

//bool check(int val) {
//    sssp(a,val);
//    for(int i=1;i<=n;i++) d1[i] = len[i];
//    sssp(b,0,a);
//    for(int i=1;i<=n;i++) d2[i] = len[i];
//    if(d2[s1]<d1[s1] || d2[s2]<d1[s2]) return 0;
//    return 1;
//}

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 {
        int res = min(d2[s1]-d1[s1], d2[s2]-d1[s2]);
        if(res==0) printf("0");
        else if((d1[s1]>d1[s2])!=(d2[s1]>d2[s2])) printf("%d",res);
        else printf("%d",res-1);
	}
}

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:50: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:51: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:53: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);
            ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Partially correct 3 ms 484 KB Partially correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 3 ms 568 KB Output is correct
5 Correct 2 ms 568 KB Output is correct
6 Partially correct 3 ms 640 KB Partially correct
7 Partially correct 3 ms 640 KB Partially correct
8 Correct 3 ms 640 KB Output is correct
9 Partially correct 2 ms 640 KB Partially correct
10 Correct 3 ms 640 KB Output is correct
11 Correct 3 ms 640 KB Output is correct
12 Correct 2 ms 640 KB Output is correct
13 Partially correct 3 ms 640 KB Partially correct
14 Correct 2 ms 640 KB Output is correct
15 Partially correct 3 ms 640 KB Partially correct
16 Correct 4 ms 664 KB Output is correct
17 Correct 3 ms 664 KB Output is correct
18 Correct 3 ms 664 KB Output is correct
19 Partially correct 3 ms 664 KB Partially correct
20 Partially correct 3 ms 664 KB Partially correct
21 Correct 3 ms 664 KB Output is correct
22 Partially correct 4 ms 664 KB Partially correct
23 Partially correct 4 ms 664 KB Partially correct
24 Correct 3 ms 664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 720 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 3 ms 816 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 4 ms 816 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 3 ms 984 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 3 ms 984 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 3 ms 984 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 3 ms 1044 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 4 ms 1044 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 3 ms 1044 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 3 ms 1044 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 2 ms 1044 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 4 ms 1044 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 3 ms 1044 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 3 ms 1044 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 3 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 4 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 3 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 3 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 3 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 4 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
21 Runtime error 3 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
22 Runtime error 3 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Runtime error 3 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
24 Runtime error 3 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
25 Runtime error 3 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
26 Runtime error 4 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
27 Runtime error 4 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
28 Runtime error 4 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
29 Runtime error 3 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
30 Runtime error 3 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
31 Runtime error 3 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
32 Runtime error 3 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
33 Runtime error 3 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
34 Runtime error 4 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
35 Runtime error 4 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
36 Runtime error 2 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
37 Runtime error 3 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
38 Runtime error 3 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
39 Runtime error 5 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
40 Runtime error 3 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
41 Runtime error 3 ms 1112 KB Execution killed with signal 11 (could be triggered by violating memory limits)