# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
556521 |
2022-05-03T09:38:39 Z |
alextodoran |
007 (CEOI14_007) |
C++17 |
|
1000 ms |
16116 KB |
/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 200000;
int N, M;
int me, him, sv1, sv2;
vector <int> adj[N_MAX + 2];
void bfs (int start, int dist[]) {
fill(dist + 1, dist + N + 1, INT_MAX);
queue <int> q;
dist[start] = 0;
q.push(start);
while (q.empty() == false) {
int u = q.front(); q.pop();
for (int v : adj[u]) {
if (dist[v] == INT_MAX) {
dist[v] = dist[u] + 1;
q.push(v);
}
}
}
}
int dist1[N_MAX + 2];
int dist2[N_MAX + 2];
int dfs (int u) {
int ret = 0;
for (int v : adj[u]) {
if (dist1[u] > dist1[v] && dist2[u] > dist2[v]) {
ret = max(ret, dfs(v) + 1);
}
}
return ret;
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N >> M;
cin >> me >> him >> sv1 >> sv2;
for (int i = 1; i <= M; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
bfs(sv1, dist1);
bfs(sv2, dist2);
int wait1 = dist1[him] - dist1[me];
int wait2 = dist2[him] - dist2[me];
int wait;
if (wait1 != wait2) {
wait = min(wait1, wait2);
} else {
int decme = dfs(me);
int dechim = dfs(him);
if (wait1 + decme >= dechim) {
wait = wait1;
} else {
wait = wait1 - 1;
}
}
cout << (wait >= 0 ? wait : -1) << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
3 ms |
4944 KB |
Output is correct |
7 |
Correct |
3 ms |
4924 KB |
Output is correct |
8 |
Correct |
3 ms |
5024 KB |
Output is correct |
9 |
Correct |
4 ms |
4948 KB |
Output is correct |
10 |
Correct |
3 ms |
4948 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
3 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
3 ms |
4948 KB |
Output is correct |
18 |
Correct |
3 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
3 ms |
4948 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
2 ms |
4948 KB |
Output is correct |
24 |
Correct |
6 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
6512 KB |
Output is correct |
2 |
Correct |
35 ms |
7484 KB |
Output is correct |
3 |
Correct |
18 ms |
6700 KB |
Output is correct |
4 |
Correct |
22 ms |
7636 KB |
Output is correct |
5 |
Correct |
17 ms |
6488 KB |
Output is correct |
6 |
Correct |
19 ms |
6748 KB |
Output is correct |
7 |
Correct |
24 ms |
6952 KB |
Output is correct |
8 |
Correct |
20 ms |
6916 KB |
Output is correct |
9 |
Execution timed out |
1092 ms |
7372 KB |
Time limit exceeded |
10 |
Execution timed out |
1073 ms |
11700 KB |
Time limit exceeded |
11 |
Correct |
44 ms |
8596 KB |
Output is correct |
12 |
Correct |
54 ms |
9396 KB |
Output is correct |
13 |
Correct |
41 ms |
8716 KB |
Output is correct |
14 |
Correct |
31 ms |
8308 KB |
Output is correct |
15 |
Correct |
71 ms |
9644 KB |
Output is correct |
16 |
Correct |
56 ms |
9788 KB |
Output is correct |
17 |
Correct |
53 ms |
9244 KB |
Output is correct |
18 |
Correct |
44 ms |
9236 KB |
Output is correct |
19 |
Execution timed out |
1091 ms |
10500 KB |
Time limit exceeded |
20 |
Execution timed out |
1096 ms |
13240 KB |
Time limit exceeded |
21 |
Correct |
95 ms |
11980 KB |
Output is correct |
22 |
Correct |
83 ms |
10440 KB |
Output is correct |
23 |
Correct |
69 ms |
12328 KB |
Output is correct |
24 |
Correct |
68 ms |
11596 KB |
Output is correct |
25 |
Correct |
79 ms |
10828 KB |
Output is correct |
26 |
Correct |
75 ms |
10676 KB |
Output is correct |
27 |
Correct |
73 ms |
11376 KB |
Output is correct |
28 |
Correct |
96 ms |
11212 KB |
Output is correct |
29 |
Execution timed out |
1094 ms |
11920 KB |
Time limit exceeded |
30 |
Execution timed out |
1085 ms |
13928 KB |
Time limit exceeded |
31 |
Correct |
107 ms |
13132 KB |
Output is correct |
32 |
Correct |
75 ms |
11208 KB |
Output is correct |
33 |
Correct |
75 ms |
11648 KB |
Output is correct |
34 |
Correct |
101 ms |
11748 KB |
Output is correct |
35 |
Correct |
99 ms |
12336 KB |
Output is correct |
36 |
Correct |
109 ms |
12560 KB |
Output is correct |
37 |
Correct |
96 ms |
12504 KB |
Output is correct |
38 |
Correct |
98 ms |
12448 KB |
Output is correct |
39 |
Correct |
98 ms |
12460 KB |
Output is correct |
40 |
Execution timed out |
1097 ms |
14028 KB |
Time limit exceeded |
41 |
Execution timed out |
1077 ms |
16116 KB |
Time limit exceeded |