# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
95411 |
2019-01-31T18:47:29 Z |
popovicirobert |
007 (CEOI14_007) |
C++14 |
|
282 ms |
16248 KB |
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44
using namespace std;
const int MAXN = (int) 2e5;
vector <int> g[MAXN + 1];
int dst[MAXN + 1][2];
inline void bfs(int nod, bool t) {
queue <int> Q;
dst[nod][t] = 1;
Q.push(nod);
while(Q.size()) {
nod = Q.front();
Q.pop();
for(auto it : g[nod]) {
if(dst[it][t] == 0) {
dst[it][t] = dst[nod][t] + 1;
Q.push(it);
}
}
}
}
int dfs(int nod) {
for(auto it : g[nod]) {
if(dst[nod][0] == dst[it][0] + 1 && dst[nod][1] == dst[it][1] + 1) {
return dfs(it) + 1;
}
}
return 0;
}
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, n, m, s, d, a, b;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
cin >> s >> d >> a >> b;
for(i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
bfs(a, 0);
bfs(b, 1);
if(dst[s][0] - dst[d][0] != dst[s][1] - dst[d][1]) {
cout << max(-1, min(dst[d][0] - dst[s][0], dst[d][1] - dst[s][1]));
return 0;
}
int cnt_s = dfs(s), cnt_d = dfs(d);
int ans = -1;
if(dst[s][0] <= dst[d][0]) {
if(cnt_s + dst[d][0] - dst[s][0] >= cnt_d) {
ans = max(ans, dst[d][0] - dst[s][0]);
}
else {
ans = max(ans, dst[d][0] - dst[s][0] - 1);
}
}
cout << ans;
//cin.close();
//cout.close();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Correct |
5 ms |
4984 KB |
Output is correct |
3 |
Correct |
6 ms |
4984 KB |
Output is correct |
4 |
Correct |
6 ms |
4988 KB |
Output is correct |
5 |
Correct |
6 ms |
4984 KB |
Output is correct |
6 |
Correct |
6 ms |
4984 KB |
Output is correct |
7 |
Correct |
5 ms |
4984 KB |
Output is correct |
8 |
Correct |
6 ms |
4984 KB |
Output is correct |
9 |
Correct |
6 ms |
4984 KB |
Output is correct |
10 |
Correct |
6 ms |
5112 KB |
Output is correct |
11 |
Correct |
6 ms |
4984 KB |
Output is correct |
12 |
Correct |
6 ms |
5112 KB |
Output is correct |
13 |
Correct |
5 ms |
5112 KB |
Output is correct |
14 |
Correct |
5 ms |
5112 KB |
Output is correct |
15 |
Correct |
5 ms |
4988 KB |
Output is correct |
16 |
Correct |
6 ms |
4984 KB |
Output is correct |
17 |
Correct |
6 ms |
5112 KB |
Output is correct |
18 |
Correct |
5 ms |
5112 KB |
Output is correct |
19 |
Correct |
1 ms |
5112 KB |
Output is correct |
20 |
Correct |
5 ms |
5112 KB |
Output is correct |
21 |
Correct |
5 ms |
5112 KB |
Output is correct |
22 |
Correct |
5 ms |
5116 KB |
Output is correct |
23 |
Correct |
5 ms |
5112 KB |
Output is correct |
24 |
Correct |
5 ms |
5112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
6648 KB |
Output is correct |
2 |
Correct |
26 ms |
7336 KB |
Output is correct |
3 |
Correct |
24 ms |
6776 KB |
Output is correct |
4 |
Correct |
27 ms |
7416 KB |
Output is correct |
5 |
Correct |
21 ms |
6520 KB |
Output is correct |
6 |
Correct |
21 ms |
6776 KB |
Output is correct |
7 |
Correct |
24 ms |
7004 KB |
Output is correct |
8 |
Correct |
24 ms |
7032 KB |
Output is correct |
9 |
Correct |
35 ms |
7416 KB |
Output is correct |
10 |
Correct |
127 ms |
11804 KB |
Output is correct |
11 |
Correct |
40 ms |
8568 KB |
Output is correct |
12 |
Correct |
57 ms |
9464 KB |
Output is correct |
13 |
Correct |
47 ms |
8952 KB |
Output is correct |
14 |
Correct |
37 ms |
8248 KB |
Output is correct |
15 |
Correct |
73 ms |
9720 KB |
Output is correct |
16 |
Correct |
57 ms |
9876 KB |
Output is correct |
17 |
Correct |
65 ms |
9464 KB |
Output is correct |
18 |
Correct |
49 ms |
9336 KB |
Output is correct |
19 |
Correct |
81 ms |
10488 KB |
Output is correct |
20 |
Correct |
163 ms |
13304 KB |
Output is correct |
21 |
Correct |
81 ms |
11384 KB |
Output is correct |
22 |
Correct |
84 ms |
10488 KB |
Output is correct |
23 |
Correct |
79 ms |
11256 KB |
Output is correct |
24 |
Correct |
81 ms |
11260 KB |
Output is correct |
25 |
Correct |
72 ms |
10872 KB |
Output is correct |
26 |
Correct |
69 ms |
10488 KB |
Output is correct |
27 |
Correct |
108 ms |
11344 KB |
Output is correct |
28 |
Correct |
93 ms |
11256 KB |
Output is correct |
29 |
Correct |
176 ms |
11868 KB |
Output is correct |
30 |
Correct |
189 ms |
13912 KB |
Output is correct |
31 |
Correct |
113 ms |
12280 KB |
Output is correct |
32 |
Correct |
122 ms |
11256 KB |
Output is correct |
33 |
Correct |
110 ms |
11556 KB |
Output is correct |
34 |
Correct |
109 ms |
11768 KB |
Output is correct |
35 |
Correct |
104 ms |
11600 KB |
Output is correct |
36 |
Correct |
121 ms |
11768 KB |
Output is correct |
37 |
Correct |
128 ms |
12664 KB |
Output is correct |
38 |
Correct |
133 ms |
12408 KB |
Output is correct |
39 |
Correct |
161 ms |
12408 KB |
Output is correct |
40 |
Correct |
206 ms |
14148 KB |
Output is correct |
41 |
Correct |
282 ms |
16248 KB |
Output is correct |