# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
110779 |
2019-05-12T08:14:20 Z |
MAMBA |
007 (CEOI14_007) |
C++17 |
|
402 ms |
42232 KB |
#include <bits/stdc++.h>
using namespace std;
#define rep(i , j , k) for (int i = j; i < (int)k; i++)
#define pb push_back
#define mt make_tuple
#define for_all(x) x.begin(),x.end()
typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef long double ld;
typedef complex<ld> point;
inline void fileIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
template<class T , class S>
inline bool smin(T &a, S b) { return (T)b < a ? a = b , 1 : 0; }
template<class T , class S>
inline bool smax(T &a, S b) { return a < (T)b ? a = b , 1 : 0; }
constexpr int N = 1e6 + 10;
constexpr int MOD = 1e9 + 7;
template<typename T>
inline T mod(T &v) { return v = (v % MOD + MOD) % MOD; }
template<typename S, typename T>
inline S add(S &l, T r) { return mod(l += r); }
ll po(ll v, ll u) { return u ? po(v * v % MOD , u >> 1) * (u & 1 ? v : 1) % MOD : 1; }
int n , m;
int s , t , a , b, dist[N];
vector<int> adj[N];
int L , R , Q[N];
void bfs(int so) {
memset(dist , -1, sizeof(dist));
dist[so] = 0;
L = 0, R = 1;
Q[0] = so;
while (L < R) {
int me = Q[L++];
for (auto e : adj[me])
if (!~dist[e]) {
dist[e] = dist[me] + 1;
Q[R++] = e;
}
}
}
int arr[N];
void dfs(int v, int col) {
arr[v] += col;
for (auto e : adj[v])
if (dist[e] + 1 == dist[v] && arr[e] < col)
dfs(e , col);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#ifndef LOCAL
// fileIO("forbidden1");
#endif
cin >> n >> m >> s >> t >> a >> b;
rep(i , 0 , m) {
int u , v;
cin >> u >> v;
adj[u].pb(v);
adj[v].pb(u);
}
bfs(s);
int A = dist[a];
int B = dist[b];
dfs(a , 1);
dfs(b , 2);
int alpha = 0;
rep(i , 0 , n + 1)
if (arr[i] == 3)
smax(alpha , dist[i]);
bfs(t);
int C = dist[a];
int D = dist[b];
memset(arr , 0 , sizeof(arr));
dfs(a , 1);
dfs(b , 2);
int beta = 0;
rep(i , 0 , n + 1)
if (arr[i] == 3)
smax(beta , dist[i]);
int res = min(C - A , D - B);
if (res < 0) return cout << -1 << endl, 0;
if (A == B && C == D && alpha < beta)
res--;
cout << res << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
31608 KB |
Output is correct |
2 |
Correct |
33 ms |
31612 KB |
Output is correct |
3 |
Correct |
27 ms |
31616 KB |
Output is correct |
4 |
Correct |
34 ms |
31616 KB |
Output is correct |
5 |
Correct |
29 ms |
31616 KB |
Output is correct |
6 |
Partially correct |
29 ms |
31736 KB |
Partially correct |
7 |
Partially correct |
29 ms |
31744 KB |
Partially correct |
8 |
Correct |
34 ms |
31716 KB |
Output is correct |
9 |
Partially correct |
28 ms |
31616 KB |
Partially correct |
10 |
Correct |
33 ms |
31584 KB |
Output is correct |
11 |
Correct |
28 ms |
31616 KB |
Output is correct |
12 |
Correct |
30 ms |
31616 KB |
Output is correct |
13 |
Partially correct |
31 ms |
31616 KB |
Partially correct |
14 |
Correct |
31 ms |
31616 KB |
Output is correct |
15 |
Partially correct |
31 ms |
31736 KB |
Partially correct |
16 |
Correct |
51 ms |
31736 KB |
Output is correct |
17 |
Correct |
39 ms |
31672 KB |
Output is correct |
18 |
Correct |
33 ms |
31608 KB |
Output is correct |
19 |
Partially correct |
35 ms |
31708 KB |
Partially correct |
20 |
Partially correct |
32 ms |
31608 KB |
Partially correct |
21 |
Correct |
33 ms |
31744 KB |
Output is correct |
22 |
Partially correct |
33 ms |
31740 KB |
Partially correct |
23 |
Partially correct |
33 ms |
31864 KB |
Partially correct |
24 |
Correct |
29 ms |
31744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
54 ms |
33064 KB |
Partially correct |
2 |
Correct |
64 ms |
34044 KB |
Output is correct |
3 |
Partially correct |
67 ms |
33272 KB |
Partially correct |
4 |
Correct |
69 ms |
34040 KB |
Output is correct |
5 |
Correct |
50 ms |
33016 KB |
Output is correct |
6 |
Correct |
51 ms |
33528 KB |
Output is correct |
7 |
Partially correct |
73 ms |
33400 KB |
Partially correct |
8 |
Correct |
51 ms |
33400 KB |
Output is correct |
9 |
Correct |
68 ms |
33784 KB |
Output is correct |
10 |
Partially correct |
169 ms |
38136 KB |
Partially correct |
11 |
Correct |
108 ms |
34936 KB |
Output is correct |
12 |
Partially correct |
128 ms |
35704 KB |
Partially correct |
13 |
Correct |
106 ms |
35192 KB |
Output is correct |
14 |
Correct |
121 ms |
34680 KB |
Output is correct |
15 |
Partially correct |
89 ms |
35832 KB |
Partially correct |
16 |
Correct |
103 ms |
35984 KB |
Output is correct |
17 |
Correct |
83 ms |
35576 KB |
Output is correct |
18 |
Correct |
87 ms |
35524 KB |
Output is correct |
19 |
Partially correct |
145 ms |
36728 KB |
Partially correct |
20 |
Correct |
308 ms |
39508 KB |
Output is correct |
21 |
Correct |
174 ms |
38264 KB |
Output is correct |
22 |
Partially correct |
120 ms |
36600 KB |
Partially correct |
23 |
Correct |
128 ms |
37920 KB |
Output is correct |
24 |
Partially correct |
120 ms |
37888 KB |
Partially correct |
25 |
Correct |
138 ms |
36984 KB |
Output is correct |
26 |
Correct |
114 ms |
36728 KB |
Output is correct |
27 |
Correct |
128 ms |
37448 KB |
Output is correct |
28 |
Correct |
138 ms |
37352 KB |
Output is correct |
29 |
Partially correct |
186 ms |
38136 KB |
Partially correct |
30 |
Correct |
262 ms |
40184 KB |
Output is correct |
31 |
Correct |
162 ms |
39288 KB |
Output is correct |
32 |
Partially correct |
135 ms |
37240 KB |
Partially correct |
33 |
Correct |
182 ms |
37624 KB |
Output is correct |
34 |
Correct |
212 ms |
37752 KB |
Output is correct |
35 |
Correct |
159 ms |
38392 KB |
Output is correct |
36 |
Correct |
207 ms |
38904 KB |
Output is correct |
37 |
Correct |
176 ms |
38648 KB |
Output is correct |
38 |
Correct |
171 ms |
38392 KB |
Output is correct |
39 |
Correct |
201 ms |
38392 KB |
Output is correct |
40 |
Correct |
334 ms |
40184 KB |
Output is correct |
41 |
Partially correct |
402 ms |
42232 KB |
Partially correct |