Submission #59864

# Submission time Handle Problem Language Result Execution time Memory
59864 2018-07-23T08:16:09 Z tmwilliamlin168 007 (CEOI14_007) C++14
0 / 100
414 ms 84608 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN=2e5;
int n, m, s, d, a, b, da[mxN], db[mxN], qu[mxN], qh, qt, dp[mxN];
vector<int> adj[mxN];

inline void bfs(int s, int dist[mxN]) {
	qh=qt=0;
	memset(dist, 0x3F, 4*n);
	qu[qt++]=s;
	dist[s]=0;
	while(qh<qt) {
		int u=qu[qh++];
		for(int v : adj[u]) {
			if(dist[v]>n) {
				qu[qt++]=v;
				dist[v]=dist[u]+1;
			}
		}
	}
}

int cdp(int u) {
	if(!dp[u]) {
		dp[u]=da[u];
		for(int v : adj[u])
			if(da[v]==da[u]-1&&da[v]==db[v])
				dp[u]=min(dp[v], dp[u]);
	}
	return dp[u];
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m >> s >> d >> a >> b, --s, --d, --a, --b;
	while(m--) {
		int u, v;
		cin >> u >> v, --u, --v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	bfs(a, da);
	bfs(b, db);
	if(da[s]!=db[s]||da[d]!=db[d])
		cout << max(min(da[d]-da[s], db[d]-db[s]), -1);
	else
		cout << max(da[d]-da[s]-(cdp(d)<cdp(s)), -1);
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4984 KB Output is correct
2 Correct 7 ms 5096 KB Output is correct
3 Correct 7 ms 5096 KB Output is correct
4 Incorrect 8 ms 5140 KB Output isn't correct
5 Incorrect 7 ms 5220 KB Output isn't correct
6 Partially correct 7 ms 5228 KB Partially correct
7 Correct 7 ms 5232 KB Output is correct
8 Incorrect 7 ms 5232 KB Output isn't correct
9 Correct 8 ms 5300 KB Output is correct
10 Correct 9 ms 5316 KB Output is correct
11 Correct 8 ms 5316 KB Output is correct
12 Incorrect 7 ms 5372 KB Output isn't correct
13 Correct 9 ms 5376 KB Output is correct
14 Correct 7 ms 5384 KB Output is correct
15 Correct 9 ms 5516 KB Output is correct
16 Incorrect 7 ms 5516 KB Output isn't correct
17 Incorrect 8 ms 5516 KB Output isn't correct
18 Incorrect 10 ms 5516 KB Output isn't correct
19 Correct 8 ms 5532 KB Output is correct
20 Correct 6 ms 5556 KB Output is correct
21 Correct 8 ms 5704 KB Output is correct
22 Partially correct 9 ms 5704 KB Partially correct
23 Partially correct 9 ms 5704 KB Partially correct
24 Incorrect 9 ms 5704 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 7712 KB Output is correct
2 Incorrect 49 ms 9216 KB Output isn't correct
3 Correct 37 ms 9216 KB Output is correct
4 Incorrect 58 ms 10540 KB Output isn't correct
5 Correct 46 ms 10540 KB Output is correct
6 Correct 44 ms 10856 KB Output is correct
7 Partially correct 51 ms 11492 KB Partially correct
8 Correct 38 ms 12052 KB Output is correct
9 Incorrect 66 ms 13520 KB Output isn't correct
10 Correct 257 ms 23152 KB Output is correct
11 Incorrect 66 ms 23152 KB Output isn't correct
12 Correct 96 ms 23804 KB Output is correct
13 Incorrect 90 ms 24212 KB Output isn't correct
14 Correct 71 ms 24512 KB Output is correct
15 Correct 110 ms 27268 KB Output is correct
16 Correct 92 ms 29044 KB Output is correct
17 Correct 92 ms 29800 KB Output is correct
18 Correct 133 ms 31040 KB Output is correct
19 Correct 219 ms 34976 KB Output is correct
20 Incorrect 325 ms 43208 KB Output isn't correct
21 Incorrect 133 ms 43348 KB Output isn't correct
22 Correct 151 ms 44228 KB Output is correct
23 Correct 142 ms 47016 KB Output is correct
24 Correct 133 ms 48840 KB Output is correct
25 Incorrect 143 ms 50300 KB Output isn't correct
26 Correct 155 ms 51772 KB Output is correct
27 Correct 180 ms 54616 KB Output is correct
28 Correct 167 ms 56516 KB Output is correct
29 Correct 253 ms 60400 KB Output is correct
30 Incorrect 361 ms 68240 KB Output isn't correct
31 Incorrect 181 ms 68984 KB Output isn't correct
32 Correct 192 ms 70020 KB Output is correct
33 Correct 169 ms 72176 KB Output is correct
34 Incorrect 225 ms 74900 KB Output isn't correct
35 Incorrect 160 ms 76600 KB Output isn't correct
36 Incorrect 171 ms 78964 KB Output isn't correct
37 Correct 232 ms 81252 KB Output is correct
38 Correct 204 ms 81252 KB Output is correct
39 Correct 253 ms 81252 KB Output is correct
40 Incorrect 327 ms 82580 KB Output isn't correct
41 Correct 414 ms 84608 KB Output is correct