# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
166438 |
2019-12-02T12:36:54 Z |
dolphingarlic |
007 (CEOI14_007) |
C++14 |
|
810 ms |
23928 KB |
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
vector<int> graph[200001];
int visited[200001], reachable[200001];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, s, d, a, b;
cin >> n >> m >> s >> d >> a >> b;
FOR(i, 0, m) {
int a, b;
cin >> a >> b;
graph[a].push_back(b);
graph[b].push_back(a);
}
memset(visited, -1, sizeof(visited));
queue<int> q;
visited[s] = 0;
q.push(s);
while (q.size()) {
int curr = q.front();
q.pop();
for (int i : graph[curr]) {
if (!(~visited[i])) {
q.push(i);
visited[i] = visited[curr] + 1;
}
}
}
int l = 0, r = 1000000;
while (l != r) {
int mid = (l + r + 1) / 2;
memset(reachable, -1, sizeof(reachable));
queue<int> q;
reachable[d] = 0;
q.push(d);
while (q.size()) {
int curr = q.front();
q.pop();
for (int i : graph[curr]) {
if (!(~reachable[i]) && reachable[curr] + 1 < visited[i] + mid) {
reachable[i] = reachable[curr] + 1;
q.push(i);
}
}
}
if (~reachable[a] || ~reachable[b]) r = mid - 1;
else l = mid;
}
memset(reachable, -1, sizeof(reachable));
reachable[d] = 0;
q.push(d);
while (q.size()) {
int curr = q.front();
q.pop();
for (int i : graph[curr]) {
if (!(~reachable[i]) && reachable[curr] + 1 < visited[i] + l) {
reachable[i] = reachable[curr] + 1;
q.push(i);
}
}
}
if (~reachable[a] || ~reachable[b]) cout << -1;
else cout << l;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
6648 KB |
Output is correct |
2 |
Correct |
9 ms |
6520 KB |
Output is correct |
3 |
Correct |
16 ms |
6648 KB |
Output is correct |
4 |
Incorrect |
12 ms |
6648 KB |
Output isn't correct |
5 |
Incorrect |
9 ms |
6776 KB |
Output isn't correct |
6 |
Correct |
9 ms |
6520 KB |
Output is correct |
7 |
Correct |
9 ms |
6520 KB |
Output is correct |
8 |
Incorrect |
9 ms |
6648 KB |
Output isn't correct |
9 |
Correct |
9 ms |
6648 KB |
Output is correct |
10 |
Correct |
10 ms |
6648 KB |
Output is correct |
11 |
Correct |
9 ms |
6520 KB |
Output is correct |
12 |
Incorrect |
9 ms |
6648 KB |
Output isn't correct |
13 |
Correct |
10 ms |
6648 KB |
Output is correct |
14 |
Incorrect |
9 ms |
6648 KB |
Output isn't correct |
15 |
Correct |
10 ms |
6648 KB |
Output is correct |
16 |
Incorrect |
10 ms |
6652 KB |
Output isn't correct |
17 |
Incorrect |
9 ms |
6648 KB |
Output isn't correct |
18 |
Incorrect |
9 ms |
6648 KB |
Output isn't correct |
19 |
Correct |
9 ms |
6648 KB |
Output is correct |
20 |
Correct |
10 ms |
6648 KB |
Output is correct |
21 |
Correct |
10 ms |
6648 KB |
Output is correct |
22 |
Correct |
10 ms |
6648 KB |
Output is correct |
23 |
Correct |
9 ms |
6648 KB |
Output is correct |
24 |
Incorrect |
11 ms |
6648 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
8312 KB |
Output is correct |
2 |
Incorrect |
119 ms |
9080 KB |
Output isn't correct |
3 |
Correct |
81 ms |
8568 KB |
Output is correct |
4 |
Incorrect |
107 ms |
9284 KB |
Output isn't correct |
5 |
Correct |
72 ms |
8312 KB |
Output is correct |
6 |
Correct |
67 ms |
8568 KB |
Output is correct |
7 |
Correct |
94 ms |
8740 KB |
Output is correct |
8 |
Correct |
108 ms |
8820 KB |
Output is correct |
9 |
Incorrect |
97 ms |
9592 KB |
Output isn't correct |
10 |
Correct |
322 ms |
18292 KB |
Output is correct |
11 |
Incorrect |
392 ms |
10616 KB |
Output isn't correct |
12 |
Correct |
419 ms |
11640 KB |
Output is correct |
13 |
Incorrect |
285 ms |
10872 KB |
Output isn't correct |
14 |
Correct |
210 ms |
10232 KB |
Output is correct |
15 |
Correct |
391 ms |
11776 KB |
Output is correct |
16 |
Correct |
550 ms |
11896 KB |
Output is correct |
17 |
Correct |
444 ms |
11384 KB |
Output is correct |
18 |
Incorrect |
416 ms |
11372 KB |
Output isn't correct |
19 |
Correct |
428 ms |
13816 KB |
Output is correct |
20 |
Incorrect |
469 ms |
19588 KB |
Output isn't correct |
21 |
Incorrect |
563 ms |
13656 KB |
Output isn't correct |
22 |
Correct |
495 ms |
12636 KB |
Output is correct |
23 |
Correct |
585 ms |
13620 KB |
Output is correct |
24 |
Correct |
477 ms |
13560 KB |
Output is correct |
25 |
Incorrect |
566 ms |
13176 KB |
Output isn't correct |
26 |
Correct |
660 ms |
12944 KB |
Output is correct |
27 |
Correct |
579 ms |
13660 KB |
Output is correct |
28 |
Correct |
588 ms |
13688 KB |
Output is correct |
29 |
Correct |
405 ms |
15736 KB |
Output is correct |
30 |
Incorrect |
407 ms |
20472 KB |
Output isn't correct |
31 |
Incorrect |
575 ms |
14840 KB |
Output isn't correct |
32 |
Correct |
508 ms |
13660 KB |
Output is correct |
33 |
Correct |
535 ms |
13944 KB |
Output is correct |
34 |
Incorrect |
575 ms |
14264 KB |
Output isn't correct |
35 |
Incorrect |
389 ms |
13816 KB |
Output isn't correct |
36 |
Incorrect |
398 ms |
14328 KB |
Output isn't correct |
37 |
Correct |
810 ms |
15352 KB |
Output is correct |
38 |
Correct |
592 ms |
15096 KB |
Output is correct |
39 |
Correct |
806 ms |
15096 KB |
Output is correct |
40 |
Incorrect |
476 ms |
18832 KB |
Output isn't correct |
41 |
Correct |
635 ms |
23928 KB |
Output is correct |