답안 #101174

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
101174 2019-03-17T08:06:17 Z square1001 007 (CEOI14_007) C++14
0 / 100
440 ms 15836 KB
#include <queue>
#include <vector>
#include <iostream>
using namespace std;
vector<int> shortest_path(int src, vector<vector<int> > &G) {
	int N = G.size();
	vector<int> dist(N, -1);
	queue<int> que;
	que.push(src);
	dist[src] = 0;
	while (!que.empty()) {
		int u = que.front(); que.pop();
		for (int i : G[u]) {
			if (dist[i] == -1) {
				dist[i] = dist[u] + 1;
				que.push(i);
			}
		}
	}
	return dist;
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	int S, D, A, B;
	cin >> S >> D >> A >> B; --S, --D, --A, --B;
	vector<vector<int> > G(N);
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b; --a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> da = shortest_path(A, G);
	vector<int> db = shortest_path(B, G);
	int s1 = min(da[D] - da[S], db[D] - da[S] - 1);
	int s2 = min(db[D] - db[S], da[D] - db[S] - 1);
	int ans = max(s1, s2) + 1;
	if (ans < 0) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Correct 2 ms 384 KB Output is correct
4 Incorrect 2 ms 384 KB Output isn't correct
5 Incorrect 2 ms 384 KB Output isn't correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Incorrect 2 ms 384 KB Output isn't correct
9 Correct 2 ms 384 KB Output is correct
10 Incorrect 2 ms 384 KB Output isn't correct
11 Incorrect 2 ms 384 KB Output isn't correct
12 Incorrect 3 ms 384 KB Output isn't correct
13 Correct 2 ms 384 KB Output is correct
14 Incorrect 3 ms 384 KB Output isn't correct
15 Correct 2 ms 356 KB Output is correct
16 Incorrect 2 ms 384 KB Output isn't correct
17 Incorrect 3 ms 384 KB Output isn't correct
18 Incorrect 3 ms 384 KB Output isn't correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Incorrect 3 ms 384 KB Output isn't correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Incorrect 2 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 2904 KB Output is correct
2 Incorrect 33 ms 4096 KB Output isn't correct
3 Correct 25 ms 3072 KB Output is correct
4 Incorrect 39 ms 4144 KB Output isn't correct
5 Incorrect 27 ms 2808 KB Output isn't correct
6 Incorrect 39 ms 3192 KB Output isn't correct
7 Correct 32 ms 3452 KB Output is correct
8 Correct 28 ms 3456 KB Output is correct
9 Incorrect 50 ms 3836 KB Output isn't correct
10 Correct 220 ms 8512 KB Output is correct
11 Incorrect 57 ms 6008 KB Output isn't correct
12 Correct 120 ms 7608 KB Output is correct
13 Incorrect 76 ms 6524 KB Output isn't correct
14 Correct 55 ms 5496 KB Output is correct
15 Correct 75 ms 7544 KB Output is correct
16 Incorrect 131 ms 8056 KB Output isn't correct
17 Correct 90 ms 7160 KB Output is correct
18 Incorrect 87 ms 7288 KB Output isn't correct
19 Correct 128 ms 8568 KB Output is correct
20 Incorrect 226 ms 11356 KB Output isn't correct
21 Incorrect 140 ms 10576 KB Output isn't correct
22 Correct 103 ms 9208 KB Output is correct
23 Incorrect 151 ms 10248 KB Output isn't correct
24 Correct 132 ms 10216 KB Output is correct
25 Incorrect 111 ms 9732 KB Output isn't correct
26 Incorrect 110 ms 9208 KB Output isn't correct
27 Correct 132 ms 10396 KB Output is correct
28 Correct 147 ms 10348 KB Output is correct
29 Correct 169 ms 10460 KB Output is correct
30 Incorrect 327 ms 12460 KB Output isn't correct
31 Incorrect 140 ms 11896 KB Output isn't correct
32 Correct 153 ms 10440 KB Output is correct
33 Incorrect 134 ms 10744 KB Output isn't correct
34 Incorrect 186 ms 11180 KB Output isn't correct
35 Incorrect 123 ms 10744 KB Output isn't correct
36 Incorrect 135 ms 11296 KB Output isn't correct
37 Incorrect 164 ms 12536 KB Output isn't correct
38 Correct 164 ms 12408 KB Output is correct
39 Correct 182 ms 12280 KB Output is correct
40 Incorrect 274 ms 13688 KB Output isn't correct
41 Correct 440 ms 15836 KB Output is correct