# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
391848 |
2021-04-20T03:41:16 Z |
8e7 |
007 (CEOI14_007) |
C++14 |
|
254 ms |
15660 KB |
//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#define ll long long
#define maxn 200005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);
using namespace std;
//#include <bits/extc++.h>
//using namespace __gnu_pbds;
//template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_upate>;
vector<int> adj[maxn];
int dep[maxn];
bool found[maxn];
void bfs(int s) {
queue<int> que;
que.push(s);
dep[s] = 0;
while (que.size()) {
int cur = que.front();
que.pop();
found[cur] = 1;
for (int v:adj[cur]) {
if (!found[v]) {
found[v] = 1;
dep[v] = dep[cur] + 1;
que.push(v);
}
}
}
}
int main() {
io
int n, m;
cin >> n >> m;
int pa, pb, st, st2;
cin >> pa >> pb >> st >> st2;
for (int i = 0;i < m;i++) {
int u, v;
cin >> u>> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
bfs(st);
//cout << dep[pb] << " " << dep[pa] << endl;
int ans = dep[pb] - dep[pa];
for (int i = 1;i <= n;i++) found[i] = 0;
bfs(st2);
//cout << dep[pb] << " " << dep[pa] << endl;
ans = min(ans, dep[pb] - dep[pa]);
cout << (ans >= 0 ? ans : -1) << "\n";
}
/*
6 6
1 2 3 4
1 5
5 6
6 3
6 4
1 2
3 4
6 7
5 6 1 2
6 3
1 2
1 3
2 3
1 5
2 4
5 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4944 KB |
Output is correct |
4 |
Incorrect |
3 ms |
4944 KB |
Output isn't correct |
5 |
Incorrect |
4 ms |
4940 KB |
Output isn't correct |
6 |
Correct |
3 ms |
4940 KB |
Output is correct |
7 |
Correct |
4 ms |
4940 KB |
Output is correct |
8 |
Incorrect |
3 ms |
4940 KB |
Output isn't correct |
9 |
Correct |
4 ms |
4940 KB |
Output is correct |
10 |
Correct |
4 ms |
4940 KB |
Output is correct |
11 |
Correct |
3 ms |
4940 KB |
Output is correct |
12 |
Incorrect |
3 ms |
4940 KB |
Output isn't correct |
13 |
Correct |
5 ms |
4940 KB |
Output is correct |
14 |
Incorrect |
4 ms |
4940 KB |
Output isn't correct |
15 |
Correct |
4 ms |
4944 KB |
Output is correct |
16 |
Incorrect |
4 ms |
4940 KB |
Output isn't correct |
17 |
Incorrect |
4 ms |
4940 KB |
Output isn't correct |
18 |
Incorrect |
4 ms |
4940 KB |
Output isn't correct |
19 |
Correct |
4 ms |
4940 KB |
Output is correct |
20 |
Correct |
4 ms |
4940 KB |
Output is correct |
21 |
Correct |
3 ms |
4940 KB |
Output is correct |
22 |
Correct |
3 ms |
4940 KB |
Output is correct |
23 |
Correct |
3 ms |
4940 KB |
Output is correct |
24 |
Incorrect |
4 ms |
5028 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
6476 KB |
Output is correct |
2 |
Incorrect |
29 ms |
7096 KB |
Output isn't correct |
3 |
Correct |
22 ms |
6476 KB |
Output is correct |
4 |
Incorrect |
29 ms |
7220 KB |
Output isn't correct |
5 |
Correct |
24 ms |
6300 KB |
Output is correct |
6 |
Correct |
22 ms |
6652 KB |
Output is correct |
7 |
Correct |
25 ms |
6780 KB |
Output is correct |
8 |
Correct |
25 ms |
6732 KB |
Output is correct |
9 |
Incorrect |
36 ms |
7112 KB |
Output isn't correct |
10 |
Correct |
142 ms |
11424 KB |
Output is correct |
11 |
Incorrect |
46 ms |
8208 KB |
Output isn't correct |
12 |
Correct |
65 ms |
9012 KB |
Output is correct |
13 |
Incorrect |
55 ms |
8536 KB |
Output isn't correct |
14 |
Correct |
45 ms |
7884 KB |
Output is correct |
15 |
Correct |
64 ms |
9156 KB |
Output is correct |
16 |
Correct |
71 ms |
9316 KB |
Output is correct |
17 |
Correct |
56 ms |
8864 KB |
Output is correct |
18 |
Incorrect |
64 ms |
8860 KB |
Output isn't correct |
19 |
Correct |
92 ms |
10024 KB |
Output is correct |
20 |
Incorrect |
172 ms |
12904 KB |
Output isn't correct |
21 |
Incorrect |
86 ms |
10824 KB |
Output isn't correct |
22 |
Correct |
81 ms |
10024 KB |
Output is correct |
23 |
Correct |
90 ms |
10692 KB |
Output is correct |
24 |
Correct |
88 ms |
10588 KB |
Output is correct |
25 |
Incorrect |
84 ms |
10328 KB |
Output isn't correct |
26 |
Correct |
85 ms |
10052 KB |
Output is correct |
27 |
Correct |
96 ms |
10700 KB |
Output is correct |
28 |
Correct |
113 ms |
10808 KB |
Output is correct |
29 |
Correct |
125 ms |
11460 KB |
Output is correct |
30 |
Incorrect |
194 ms |
13576 KB |
Output isn't correct |
31 |
Incorrect |
117 ms |
11588 KB |
Output isn't correct |
32 |
Correct |
119 ms |
10624 KB |
Output is correct |
33 |
Correct |
107 ms |
10832 KB |
Output is correct |
34 |
Incorrect |
111 ms |
11120 KB |
Output isn't correct |
35 |
Incorrect |
92 ms |
10892 KB |
Output isn't correct |
36 |
Incorrect |
96 ms |
11200 KB |
Output isn't correct |
37 |
Correct |
119 ms |
12048 KB |
Output is correct |
38 |
Correct |
124 ms |
11912 KB |
Output is correct |
39 |
Correct |
136 ms |
11912 KB |
Output is correct |
40 |
Incorrect |
176 ms |
13412 KB |
Output isn't correct |
41 |
Correct |
254 ms |
15660 KB |
Output is correct |