# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
83999 |
2018-11-12T08:54:57 Z |
aminra |
007 (CEOI14_007) |
C++17 |
|
406 ms |
45648 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int infint = 1e9;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e6 + 7;
int dist1[MAXN], dist2[MAXN], dist3[MAXN], n, m, s, d, a, b;
vector<int> G[MAXN];
void bfs(int s, int type)
{
if(type == 0)
dist1[s] = 0;
else
if(type == 1)
dist2[s] = 0;
else
dist3[s] = 0;
queue<int> q;
q.push(s);
while(!q.empty())
{
int st = q.front();
q.pop();
for (auto v : G[st])
{
if(type == 0 && dist1[v] == -1)
dist1[v] = dist1[st] + 1, q.push(v);
else
if(type == 1 && dist2[v] == -1)
dist2[v] = dist2[st] + 1, q.push(v);
else
if(type == 2 && dist3[v] == -1)
dist3[v] = dist3[st] + 1, q.push(v);
}
}
}
bool check(int u, int v)
{
if(dist1[v] < dist1[u] || dist2[v] < dist2[u])
return 0;
return 1;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
memset(dist1, -1, sizeof dist1);
memset(dist2, -1, sizeof dist2);
memset(dist3, -1, sizeof dist3);
cin >> n >> m >> s >> d >> a >> b;
for (int i = 0; i < m; i++)
{
int u, v;
cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
bfs(a, 0);
bfs(b, 1);
bfs(d, 2);
if(check(s, d) == 0)
return cout << -1, 0;
int L = 0, R = n + 1;
while(R - L > 1)
{
int mid = (L + R) >> 1;
bool c = 1;
for (int i = 1; i <= n; i++)
if(dist3[i] <= mid && check(s, i) == 0)
c = 0;
if(c)
L = mid;
else
R = mid;
}
cout << L;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
35576 KB |
Output is correct |
2 |
Correct |
32 ms |
35776 KB |
Output is correct |
3 |
Correct |
34 ms |
35776 KB |
Output is correct |
4 |
Incorrect |
32 ms |
35792 KB |
Output isn't correct |
5 |
Incorrect |
33 ms |
35792 KB |
Output isn't correct |
6 |
Correct |
33 ms |
35792 KB |
Output is correct |
7 |
Correct |
33 ms |
35792 KB |
Output is correct |
8 |
Incorrect |
35 ms |
35792 KB |
Output isn't correct |
9 |
Correct |
35 ms |
35992 KB |
Output is correct |
10 |
Correct |
33 ms |
35992 KB |
Output is correct |
11 |
Correct |
35 ms |
35992 KB |
Output is correct |
12 |
Incorrect |
36 ms |
35992 KB |
Output isn't correct |
13 |
Correct |
43 ms |
35992 KB |
Output is correct |
14 |
Incorrect |
34 ms |
35992 KB |
Output isn't correct |
15 |
Correct |
37 ms |
35992 KB |
Output is correct |
16 |
Incorrect |
33 ms |
35992 KB |
Output isn't correct |
17 |
Incorrect |
33 ms |
35992 KB |
Output isn't correct |
18 |
Incorrect |
34 ms |
35992 KB |
Output isn't correct |
19 |
Correct |
33 ms |
35992 KB |
Output is correct |
20 |
Correct |
35 ms |
35992 KB |
Output is correct |
21 |
Correct |
39 ms |
35992 KB |
Output is correct |
22 |
Correct |
34 ms |
35992 KB |
Output is correct |
23 |
Correct |
36 ms |
35992 KB |
Output is correct |
24 |
Incorrect |
37 ms |
35992 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
37116 KB |
Output is correct |
2 |
Incorrect |
71 ms |
37680 KB |
Output isn't correct |
3 |
Correct |
60 ms |
37680 KB |
Output is correct |
4 |
Incorrect |
73 ms |
37760 KB |
Output isn't correct |
5 |
Correct |
56 ms |
37760 KB |
Output is correct |
6 |
Correct |
57 ms |
37760 KB |
Output is correct |
7 |
Correct |
66 ms |
37760 KB |
Output is correct |
8 |
Correct |
61 ms |
37760 KB |
Output is correct |
9 |
Incorrect |
97 ms |
37804 KB |
Output isn't correct |
10 |
Correct |
217 ms |
42060 KB |
Output is correct |
11 |
Incorrect |
96 ms |
42060 KB |
Output isn't correct |
12 |
Correct |
113 ms |
42060 KB |
Output is correct |
13 |
Incorrect |
105 ms |
42060 KB |
Output isn't correct |
14 |
Correct |
78 ms |
42060 KB |
Output is correct |
15 |
Correct |
106 ms |
42060 KB |
Output is correct |
16 |
Correct |
111 ms |
42060 KB |
Output is correct |
17 |
Correct |
100 ms |
42060 KB |
Output is correct |
18 |
Incorrect |
107 ms |
42060 KB |
Output isn't correct |
19 |
Correct |
150 ms |
42060 KB |
Output is correct |
20 |
Incorrect |
279 ms |
43200 KB |
Output isn't correct |
21 |
Incorrect |
144 ms |
43200 KB |
Output isn't correct |
22 |
Correct |
137 ms |
43200 KB |
Output is correct |
23 |
Correct |
141 ms |
43200 KB |
Output is correct |
24 |
Correct |
143 ms |
43200 KB |
Output is correct |
25 |
Incorrect |
133 ms |
43200 KB |
Output isn't correct |
26 |
Correct |
147 ms |
43200 KB |
Output is correct |
27 |
Correct |
149 ms |
43200 KB |
Output is correct |
28 |
Correct |
198 ms |
43200 KB |
Output is correct |
29 |
Correct |
230 ms |
43200 KB |
Output is correct |
30 |
Incorrect |
290 ms |
43788 KB |
Output isn't correct |
31 |
Incorrect |
174 ms |
43788 KB |
Output isn't correct |
32 |
Correct |
170 ms |
43788 KB |
Output is correct |
33 |
Correct |
163 ms |
43788 KB |
Output is correct |
34 |
Incorrect |
190 ms |
43788 KB |
Output isn't correct |
35 |
Incorrect |
155 ms |
43788 KB |
Output isn't correct |
36 |
Incorrect |
152 ms |
43788 KB |
Output isn't correct |
37 |
Correct |
192 ms |
43788 KB |
Output is correct |
38 |
Correct |
193 ms |
43788 KB |
Output is correct |
39 |
Correct |
231 ms |
43788 KB |
Output is correct |
40 |
Incorrect |
266 ms |
43788 KB |
Output isn't correct |
41 |
Correct |
406 ms |
45648 KB |
Output is correct |