# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
391843 |
2021-04-20T03:33:46 Z |
syl123456 |
007 (CEOI14_007) |
C++17 |
|
268 ms |
18376 KB |
#include <bits/stdc++.h>
#define all(i) (i).begin(), (i).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl
using namespace std;
template<typename T1, typename T2>
ostream& operator << (ostream &i, pair<T1, T2> j) {
return i << j.first << ' ' << j.second;
}
template<typename T>
ostream& operator << (ostream &i, vector<T> j) {
i << '{' << j.size() << ':';
for (T ii : j) i << ' ' << ii;
return i << '}';
}
typedef long long ll;
typedef pair<int, int> pi;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, m, s, d, a, b;
cin >> n >> m >> s >> d >> a >> b;
--s, --d, --a, --b;
vector<int> g[n];
for (int i = 0; i < m; ++i) {
int x, y;
cin >> x >> y;
--x, --y;
g[x].push_back(y), g[y].push_back(x);
}
vector<int> disd(n, -1), diss(n, -1), disa(n, -1), disb(n, -1);
queue<int> q;
disd[d] = 0, q.push(d);
while (!q.empty()) {
int i = q.front();
q.pop();
for (int j : g[i]) if (disd[j] == -1)
disd[j] = disd[i] + 1, q.push(j);
}
diss[s] = 0, q.push(s);
while (!q.empty()) {
int i = q.front();
q.pop();
for (int j : g[i]) if (diss[j] == -1)
diss[j] = diss[i] + 1, q.push(j);
}
if (disd[a] != disd[b]) {
if (disd[a] < disd[b]) cout << max(disd[a] - diss[a], -1);
else cout << max(disd[b] - diss[b], -1);
}
else {
int tmp = max(disd[a] - 1 - diss[a], disd[b] - 1 - diss[b]);
vector<int> disa(n, -1), disb(n, -1);
disa[a] = 0, q.push(a);
while (!q.empty()) {
int i = q.front();
q.pop();
for (int j : g[i]) if (disa[j] == -1)
disa[j] = disa[i] + 1, q.push(j);
}
disb[b] = 0, q.push(b);
while (!q.empty()) {
int i = q.front();
q.pop();
for (int j : g[i]) if (disb[j] == -1)
disb[j] = disb[i] + 1, q.push(j);
}
int x = d;
for (int i = 0; i < n; ++i)
if (disa[i] == disb[i] && disd[i] + disa[i] == disd[a] && disa[i] < disa[x])
x = i;
for (int i = 0; i < n; ++i) if (disa[i] <= disa[x] && disb[i] <= disb[x])
tmp = max(tmp, disd[x] - diss[i] + disa[x] - max(disa[i], disb[i]));
cout << max(tmp, -1);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
3396 KB |
Output is correct |
2 |
Correct |
31 ms |
4892 KB |
Output is correct |
3 |
Correct |
25 ms |
3644 KB |
Output is correct |
4 |
Correct |
32 ms |
5052 KB |
Output is correct |
5 |
Correct |
19 ms |
2976 KB |
Output is correct |
6 |
Correct |
19 ms |
3444 KB |
Output is correct |
7 |
Correct |
31 ms |
4128 KB |
Output is correct |
8 |
Correct |
28 ms |
4164 KB |
Output is correct |
9 |
Correct |
39 ms |
4652 KB |
Output is correct |
10 |
Correct |
157 ms |
9312 KB |
Output is correct |
11 |
Correct |
55 ms |
7364 KB |
Output is correct |
12 |
Correct |
80 ms |
9064 KB |
Output is correct |
13 |
Correct |
76 ms |
7964 KB |
Output is correct |
14 |
Correct |
54 ms |
6732 KB |
Output is correct |
15 |
Correct |
76 ms |
9296 KB |
Output is correct |
16 |
Correct |
83 ms |
8848 KB |
Output is correct |
17 |
Correct |
66 ms |
8772 KB |
Output is correct |
18 |
Correct |
74 ms |
8820 KB |
Output is correct |
19 |
Correct |
108 ms |
10040 KB |
Output is correct |
20 |
Correct |
194 ms |
13100 KB |
Output is correct |
21 |
Correct |
124 ms |
12800 KB |
Output is correct |
22 |
Correct |
101 ms |
11160 KB |
Output is correct |
23 |
Correct |
97 ms |
11588 KB |
Output is correct |
24 |
Correct |
111 ms |
12528 KB |
Output is correct |
25 |
Correct |
126 ms |
11856 KB |
Output is correct |
26 |
Correct |
73 ms |
10180 KB |
Output is correct |
27 |
Correct |
117 ms |
12832 KB |
Output is correct |
28 |
Correct |
140 ms |
12876 KB |
Output is correct |
29 |
Correct |
142 ms |
12580 KB |
Output is correct |
30 |
Correct |
213 ms |
14244 KB |
Output is correct |
31 |
Correct |
123 ms |
14664 KB |
Output is correct |
32 |
Correct |
137 ms |
12676 KB |
Output is correct |
33 |
Correct |
97 ms |
11852 KB |
Output is correct |
34 |
Correct |
132 ms |
13636 KB |
Output is correct |
35 |
Correct |
122 ms |
13188 KB |
Output is correct |
36 |
Correct |
116 ms |
13688 KB |
Output is correct |
37 |
Correct |
114 ms |
13984 KB |
Output is correct |
38 |
Correct |
155 ms |
15168 KB |
Output is correct |
39 |
Correct |
173 ms |
15136 KB |
Output is correct |
40 |
Correct |
213 ms |
16580 KB |
Output is correct |
41 |
Correct |
268 ms |
18376 KB |
Output is correct |